/* =========================================================
   MATCHSTICK: 100 TRAP ROOMS — Full-Screen Saw-Comedy HUD
   Crisp Edge-to-Edge Pixel Art + Danger Pressure Bar + Mobile
   ========================================================= */

@import url('https://fonts.googleapis.com/css2?family=Press+Start+2P&family=Silkscreen:wght@400;700&display=swap');

:root {
  --glass-bg: rgba(14, 15, 22, 0.72);
  --glass-border: rgba(255, 255, 255, 0.2);
  --touch-bg: rgba(16, 18, 28, 0.45);
  --touch-active: rgba(255, 209, 102, 0.52);
  --accent-red: #d93829;
  --accent-gold: #ffd166;
  --font-px: 'Press Start 2P', 'Courier New', monospace;
  --font-ui: 'Silkscreen', 'Courier New', monospace;

  --sat: env(safe-area-inset-top, 0px);
  --sar: env(safe-area-inset-right, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
}

* {
  box-sizing: border-box;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #0c0d12;
  font-family: var(--font-ui);
  color: #f8fafc;
  overscroll-behavior: none;
  touch-action: none;
}

.game-viewport {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100dvh;
  background: #0c0d12;
  overflow: hidden;
}

#gameCanvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

.screen-vignette {
  position: absolute;
  inset: 0;
  pointer-events: none;
  box-shadow: inset 0 0 70px rgba(0, 0, 0, 0.42);
  z-index: 2;
  transition: box-shadow 0.2s ease;
}

.screen-vignette.danger {
  box-shadow: inset 0 0 95px rgba(255, 42, 42, 0.62);
  animation: dangerPulse 0.55s infinite alternate;
}

.screen-vignette.heat {
  box-shadow: inset 0 0 110px rgba(255, 102, 0, 0.68);
  animation: dangerPulse 0.42s infinite alternate;
}

@keyframes dangerPulse {
  from { opacity: 0.72; }
  to { opacity: 1; }
}

/* Top Floating HUD */
.ios-hud-top {
  position: absolute;
  top: calc(10px + var(--sat));
  left: calc(12px + var(--sal));
  right: calc(12px + var(--sar));
  z-index: 10;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  pointer-events: none;
}

.hud-left, .hud-right {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  pointer-events: auto;
}

/* Corner Dummy-Cam */
.dummy-cam-widget {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 5px;
  background: var(--glass-bg);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 2px solid var(--glass-border);
  border-radius: 12px;
  cursor: pointer;
  transition: transform 0.08s ease, border-color 0.15s;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.4);
}
.dummy-cam-widget:active { transform: scale(0.93); }
.dummy-cam-widget.poked { animation: camShake 0.28s linear; }
.dummy-cam-widget.cam-danger { border-color: #ff4d4d; box-shadow: 0 0 16px rgba(255, 60, 60, 0.55); }

@keyframes camShake {
  0%, 100% { transform: translate(0, 0) rotate(0deg); }
  25% { transform: translate(-3px, 2px) rotate(-4deg); }
  50% { transform: translate(3px, -2px) rotate(4deg); }
  75% { transform: translate(-2px, -1px) rotate(-2deg); }
}

.dummy-cam-frame {
  width: 56px;
  height: 56px;
  background: #f2e4b7;
  border: 2px solid #161822;
  border-radius: 8px;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}
#faceCanvas { width: 100%; height: 100%; image-rendering: pixelated; image-rendering: crisp-edges; }
.dummy-cam-mood {
  font-family: var(--font-ui);
  font-weight: 700;
  font-size: 9px;
  color: #f8fafc;
  letter-spacing: 0.3px;
  text-shadow: 0 1px 0 #090a10;
  white-space: nowrap;
}

.hud-stats-stack { display: flex; flex-direction: column; gap: 4px; }

/* Live Saw Pressure Bar */
.pressure-track {
  position: relative;
  height: 15px;
  width: 100%;
  min-width: 215px;
  background: rgba(12, 10, 16, 0.85);
  border: 1.5px solid rgba(255, 209, 102, 0.5);
  border-radius: 7px;
  overflow: hidden;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.35);
}
.pressure-track.danger { border-color: #ff4d4d; }
.pressure-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #52e069 0%, #ffd166 55%, #ff3b30 100%);
  transition: width 0.08s linear;
}
.pressure-fill.heat-fill {
  background: linear-gradient(90deg, #ff9f1c 0%, #ff5400 55%, #ff1e1e 100%);
}
.pressure-fill.walls-fill {
  background: linear-gradient(90deg, #74c0fc 0%, #ffd166 55%, #ff3b30 100%);
}
.pressure-label {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-ui);
  font-weight: 700;
  font-size: 9px;
  color: #ffffff;
  text-shadow: 0 1px 2px #000, 0 0 4px #000;
}

.hud-sub-row { display: flex; flex-wrap: wrap; gap: 5px; }

.hud-pill {
  font-family: var(--font-ui);
  font-weight: 700;
  font-size: 11px;
  color: #f8fafc;
  background: var(--glass-bg);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1.5px solid var(--glass-border);
  padding: 5px 10px;
  border-radius: 10px;
  letter-spacing: 0.4px;
  text-shadow: 0 1px 0 rgba(0, 0, 0, 0.8);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  white-space: nowrap;
}
.world-pill { color: var(--accent-gold); border-color: rgba(255, 209, 102, 0.4); }
.aura-pill { color: var(--accent-gold); }
.aura-pill.aura-negative { color: #ff6b6b; border-color: rgba(255, 107, 107, 0.5); }
.rank-pill { font-size: 10px; color: #e2e8f0; }
.bonk-pill { font-size: 10px; color: #fca5a5; }
.timer-pill { font-size: 12px; color: #f1f5f9; padding: 7px 11px; }

.diff-pill { font-size: 10px; }
.diff-pill.mode-easy { color: #ffb3d9; border-color: rgba(255, 143, 199, 0.65); background: rgba(64, 22, 54, 0.75); }
.diff-pill.mode-normal { color: #7ee081; border-color: rgba(126, 224, 129, 0.5); }
.diff-pill.mode-hard { color: #ff6b6b; border-color: rgba(255, 107, 107, 0.55); }
.diff-pill.mode-ultimate { color: #e0aaff; border-color: rgba(199, 125, 255, 0.7); background: rgba(58, 12, 92, 0.75); }

.hud-icon-btn {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  border: 1.5px solid var(--glass-border);
  background: var(--glass-bg);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  color: #ffffff;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}
.hud-icon-btn:active { transform: scale(0.92); background: rgba(255, 255, 255, 0.22); }

/* Floating Troll Toast */
.troll-toast {
  position: absolute;
  top: calc(96px + var(--sat));
  left: 50%;
  transform: translate(-50%, -10px);
  z-index: 12;
  max-width: min(440px, 80vw);
  padding: 7px 14px;
  background: rgba(18, 12, 20, 0.88);
  backdrop-filter: blur(8px);
  border: 2px solid rgba(255, 77, 77, 0.7);
  border-radius: 12px;
  font-size: 11px;
  color: #fff6db;
  text-align: center;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.18s ease, transform 0.18s ease;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.5);
}
.troll-toast.visible { opacity: 1; transform: translate(-50%, 0); }

/* Multi-Touch Thumb Controls */
.touch-layer {
  position: absolute;
  left: calc(18px + var(--sal));
  right: calc(18px + var(--sar));
  bottom: calc(16px + var(--sab));
  z-index: 15;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  pointer-events: none;
  transition: opacity 0.25s ease;
}
.touch-layer.hidden { display: none; }
.touch-layer.keyboard-dim { opacity: 0.36; }

.touch-move-pad {
  display: flex; align-items: center; gap: 14px;
  pointer-events: auto; touch-action: none; padding: 6px; border-radius: 24px;
}
.touch-action-pad {
  display: flex; align-items: flex-end; gap: 14px;
  pointer-events: auto; touch-action: none;
}
.touch-btn {
  display: flex; align-items: center; justify-content: center;
  background: var(--touch-bg);
  backdrop-filter: blur(6px);
  border: 2px solid rgba(255, 255, 255, 0.28);
  color: rgba(255, 255, 255, 0.94);
  font-family: var(--font-px);
  cursor: pointer; touch-action: none;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.2);
}
.move-btn { width: 68px; height: 68px; border-radius: 20px; font-size: 22px; }
.jump-btn { width: 82px; height: 82px; border-radius: 50%; font-size: 11px; background: rgba(217, 56, 41, 0.56); border-color: rgba(255, 235, 220, 0.5); }
.retry-btn { width: 52px; height: 52px; border-radius: 50%; font-size: 20px; margin-bottom: 4px; }
.touch-btn.pressed, .touch-btn:active { transform: scale(0.92); background: var(--touch-active); border-color: #ffd166; color: #fff; }
.jump-btn.pressed, .jump-btn:active { background: rgba(255, 92, 74, 0.8); }

/* Modals */
.modal-overlay {
  position: absolute;
  inset: 0;
  z-index: 30;
  background: rgba(10, 10, 16, 0.82);
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(14px + var(--sat)) calc(14px + var(--sar)) calc(14px + var(--sab)) calc(14px + var(--sal));
}
.modal-overlay.hidden { display: none; }

.modal-card {
  width: 100%;
  max-width: 540px;
  max-height: 92dvh;
  overflow-y: auto;
  text-align: center;
  background: #171822;
  border: 3px solid #f4ecd8;
  border-radius: 14px;
  box-shadow: 0 18px 45px rgba(0, 0, 0, 0.72), 6px 6px 0 #090a10;
  padding: 20px 22px;
}
.modal-card.wide-card { max-width: 680px; }
.modal-card.small { max-width: 340px; }

.title-tag { font-family: var(--font-px); font-size: 9px; color: var(--accent-gold); margin-bottom: 10px; letter-spacing: 0.7px; }
.pixel-title { font-family: var(--font-px); font-size: clamp(18px, 3.6vw, 27px); line-height: 1.35; margin: 0 0 8px; color: #fff6e5; text-shadow: 3px 3px 0 var(--accent-red); }
.pixel-subtitle { font-family: var(--font-px); font-size: 14px; margin: 4px 0 12px; color: #fff6e5; }
.title-footnote { font-size: 11px; color: #ffb4a2; margin-bottom: 14px; }

.tier-strip {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  background: rgba(0, 0, 0, 0.36); border: 1.5px solid rgba(255, 255, 255, 0.15);
  border-radius: 8px; padding: 6px 10px; margin-bottom: 12px;
}
.tier-badge { font-size: 10px; color: #7ee081; }
.tier-strip-actions { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }

.diff-selector { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-bottom: 12px; }
@media (max-width: 480px) { .diff-selector { grid-template-columns: repeat(2, 1fr); } }

.diff-card {
  background: #232538; border: 2.5px solid #484d6e; border-radius: 10px;
  padding: 8px 4px; color: #e2e8f0; cursor: pointer; text-align: center;
  box-shadow: 3px 3px 0 #090a10;
}
.diff-card:hover { border-color: #cbd5e1; }
.diff-card.active[data-diff="easy"] { background: #421c38; border-color: #ff8fc7; color: #fff; }
.diff-card.active[data-diff="normal"] { background: #1c3627; border-color: #7ee081; color: #fff; }
.diff-card.active[data-diff="hard"] { background: #3d1b20; border-color: #ff6b6b; color: #fff; }
.diff-card.active[data-diff="ultimate"] { background: #34154d; border-color: #c77dff; color: #fff; }
.diff-name { font-family: var(--font-px); font-size: 9px; margin-bottom: 5px; }
.diff-troll { font-size: 8px; color: #cbd5e1; }

.easy-troll-banner {
  margin-bottom: 12px; padding: 7px 10px;
  background: rgba(255, 143, 199, 0.14); border: 2px dashed #ff8fc7;
  border-radius: 8px; font-size: 10px; line-height: 1.4; color: #ffd6eb;
}

.modal-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.modal-stack { display: flex; flex-direction: column; gap: 9px; }

.pixel-btn {
  font-family: var(--font-px); font-size: 11px; padding: 11px 16px;
  border: 3px solid #f4ecd8; border-radius: 8px; background: #282c42;
  color: #fff6e5; cursor: pointer; box-shadow: 3px 3px 0 #090a10;
}
.pixel-btn.primary { background: var(--accent-red); }
.pixel-btn.danger-btn { background: #8f1d1d; border-color: #ff8787; }
.pixel-btn:hover { filter: brightness(1.12); }
.pixel-btn:active { transform: translate(2px, 2px); box-shadow: 1px 1px 0 #090a10; }

.controls-hint {
  margin-top: 12px; display: flex; justify-content: center; flex-wrap: wrap;
  gap: 10px; font-size: 10px; color: #c7d0e6;
}
.controls-hint b { color: var(--accent-gold); }

.legal-footer {
  margin-top: 10px; display: flex; justify-content: center; flex-wrap: wrap;
  gap: 8px; font-size: 10px; color: #64748b;
}
.legal-link { font-size: 10px; color: #94a3b8; text-decoration: underline; }
.legal-link:hover { color: #ffd166; }

.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  font-family: var(--font-px); font-size: 11px; color: var(--accent-gold);
  margin-bottom: 10px; border-bottom: 2px solid rgba(255, 255, 255, 0.15); padding-bottom: 8px;
}

.tiny-link {
  background: transparent; border: 1.5px solid var(--accent-gold); border-radius: 6px;
  color: var(--accent-gold); font-family: var(--font-ui); font-size: 10px; padding: 3px 8px; cursor: pointer;
}
.tiny-link.prem-locked { border-color: #a78bfa; color: #c4b5fd; background: rgba(124, 92, 255, 0.14); }
.tiny-link.prem-ready { border-color: #ffd166; color: #161822; background: #ffd166; font-weight: 700; }
.tiny-link.danger-link { border-color: #ff6b6b; color: #ff8787; }

/* 5 Wing Tabs for 100 Rooms */
.wing-tabs {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 5px;
  margin-bottom: 8px;
}
@media (max-width: 520px) { .wing-tabs { grid-template-columns: repeat(3, 1fr); } }
.wing-tab {
  background: #232638; border: 2px solid #474d6e; border-radius: 7px;
  color: #cbd5e1; font-family: var(--font-ui); font-size: 10px; font-weight: 700;
  padding: 6px 4px; cursor: pointer;
}
.wing-tab.active { background: #3d1820; border-color: #ff595e; color: #ffd166; }
.wing-subtitle { font-size: 10px; color: #ffb4a2; margin-bottom: 8px; }

.world-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(145px, 1fr));
  gap: 6px;
  margin-bottom: 12px;
  max-height: 48dvh;
  overflow-y: auto;
  text-align: left;
}
.world-item {
  display: flex; flex-direction: column; justify-content: space-between;
  padding: 8px 9px; background: #222536; border: 2px solid #454a6b;
  border-radius: 8px; color: #fff; cursor: pointer; font-family: var(--font-ui); font-size: 10px;
}
.world-item.boss-room { border-color: #ff9f1c; background: #2d1d24; }
.world-item.cleared-room { border-color: #52e069; }
.world-item:hover:not(.locked) { border-color: var(--accent-gold); background: #2d324a; }
.world-item.locked { opacity: 0.42; cursor: not-allowed; }
.world-item .w-top { display: flex; justify-content: space-between; align-items: center; gap: 4px; font-weight: 700; }
.world-item .w-meta { font-size: 8.5px; color: #9ba6c7; margin-top: 3px; }
.world-item .w-stat-line { font-size: 8.5px; color: var(--accent-gold); margin-top: 3px; }
.world-item .w-badge { font-family: var(--font-px); font-size: 7px; padding: 2px 4px; border-radius: 4px; background: #141724; color: #7ee081; }
.world-item.locked .w-badge { color: #ff7b7b; }

.modal-stats {
  font-size: 12px; line-height: 1.7; color: #d7e0f5; margin-bottom: 12px;
  background: rgba(0, 0, 0, 0.34); padding: 10px; border-radius: 8px; border: 1px solid rgba(255, 255, 255, 0.12);
}
.victory-quote { font-size: 11px; color: var(--accent-gold); font-style: italic; margin-bottom: 14px; }

/* Portal SSO & Account Delete */
.tier-pills-row { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; margin-bottom: 10px; }
.tpill { font-size: 9px; padding: 3px 7px; border-radius: 5px; background: #23283d; color: #cbd5e1; border: 1px solid #485073; }
.tpill.active { border-color: #7ee081; color: #7ee081; }
.tpill.prem { border-color: #a78bfa; color: #c4b5fd; }

.portal-sso-box { display: flex; flex-direction: column; gap: 12px; padding: 6px 2px 2px; }
.portal-sso-copy { font-size: 11px; color: #d6deed; line-height: 1.5; }
.portal-link-btn { text-decoration: none; display: inline-block; }
.coppa-hint { font-size: 10px; color: #9aa6c4; line-height: 1.4; }
.acct-actions-row { display: flex; align-items: center; justify-content: center; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.game-auth-form { display: flex; flex-direction: column; gap: 8px; }
.game-auth-form input {
  background: #0d101a; border: 2px solid #485073; border-radius: 7px; padding: 8px 10px;
  color: #fff; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; font-size: 13px;
}
.auth-err-msg { min-height: 14px; font-size: 11px; color: #ff6b6b; }
.delete-acct-box { margin: 10px 0; padding: 10px; border: 1.5px solid rgba(255, 107, 107, 0.55); border-radius: 8px; background: rgba(143, 29, 29, 0.16); }
.delete-title { font-family: var(--font-px); font-size: 11px; color: #ff8787; }
.delete-warn { font-size: 10px; color: #fca5a5; line-height: 1.4; }

.acct-stats-scroll { margin-top: 10px; max-height: 150px; overflow-y: auto; border: 1px solid rgba(255, 255, 255, 0.14); border-radius: 6px; background: rgba(8, 10, 18, 0.55); }
.acct-stats-table { width: 100%; border-collapse: collapse; font-size: 10px; text-align: left; }
.acct-stats-table th, .acct-stats-table td { padding: 5px 6px; border-bottom: 1px solid rgba(255, 255, 255, 0.08); white-space: nowrap; }
.acct-stats-table th { position: sticky; top: 0; background: #141826; color: var(--accent-gold); font-size: 9px; }
.acct-stats-empty { margin-top: 8px; font-size: 10px; color: #9ba6c7; }

/* Portrait Rotate Prompt */
.rotate-banner {
  position: absolute; inset: 0; z-index: 40;
  background: rgba(10, 11, 18, 0.92);
  display: none; align-items: center; justify-content: center; padding: 20px;
}
.rotate-card { text-align: center; max-width: 300px; }
.rotate-icon { font-size: 42px; margin-bottom: 10px; }
.rotate-title { font-family: var(--font-px); font-size: 13px; color: var(--accent-gold); margin-bottom: 8px; }
.rotate-sub { font-size: 12px; color: #cbd5e1; margin-bottom: 16px; }
@media (orientation: portrait) and (max-width: 560px) {
  .rotate-banner:not(.dismissed) { display: flex; }
}
@media (max-height: 460px) {
  .dummy-cam-frame { width: 44px; height: 44px; }
  .hud-pill { font-size: 10px; padding: 4px 8px; }
  .move-btn { width: 58px; height: 58px; }
  .jump-btn { width: 70px; height: 70px; }
}
