/*!
 * style.css — Design direction: the page reads as a hand-finished wooden
 * game case sitting on a table, not a generic "gamer UI". Palette pulls
 * from real materials: honey oak, walnut, brushed steel, brass hardware.
 * Display type is a warm book-serif (engraved-plate/rulebook feel);
 * the level/time readout uses a monospace face like a gauge or stopwatch.
 * All fonts are system stacks - no external font loading, fully offline.
 */

:root {
  --oak: #c9a06a;
  --oak-deep: #8a5a2b;
  --walnut: #6b4a2c;
  --walnut-deep: #3a2718;
  --ink: #2b1a0e;
  --steel: #5b6773;
  --steel-light: #c9d3da;
  --brass: #e0a84a;
  --brass-bright: #f4c542;
  --success: #2f9e46;
  --danger: #b5392a;

  --bg: #efe0c2;
  --surface: #fbf3e3;
  --surface-2: #f3e6cd;
  --text: var(--ink);
  --text-soft: #6b5a45;
  --panel-border: rgba(43, 26, 14, 0.16);
  --shadow-raised: 6px 6px 14px rgba(43,26,14,0.18), -6px -6px 14px rgba(255,255,255,0.55);
  --shadow-inset: inset 4px 4px 10px rgba(43,26,14,0.28), inset -4px -4px 10px rgba(255,255,255,0.35);
  --shadow-groove: inset 0 6px 14px rgba(0,0,0,0.45), inset 0 -2px 6px rgba(255,255,255,0.08);
  --glass: rgba(251, 243, 227, 0.72);

  --font-display: Iowan Old Style, Sitka Text, Georgia, "Times New Roman", serif;
  --font-body: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;

  --radius-s: 8px;
  --radius-m: 14px;
  --radius-l: 22px;
  color-scheme: light;
}

[data-theme="dark"] {
  --bg: #1a120b;
  --surface: #241a11;
  --surface-2: #2c2015;
  --text: #f1e3c8;
  --text-soft: #b8a483;
  --panel-border: rgba(255, 235, 200, 0.12);
  --shadow-raised: 6px 6px 14px rgba(0,0,0,0.55), -6px -6px 14px rgba(255,255,255,0.03);
  --shadow-inset: inset 4px 4px 10px rgba(0,0,0,0.6), inset -4px -4px 10px rgba(255,255,255,0.04);
  --glass: rgba(36, 26, 17, 0.72);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
img { max-width: 100%; display: block; }
a { color: var(--oak-deep); }
[data-theme="dark"] a { color: var(--brass); }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}
:focus-visible { outline: 3px solid var(--brass); outline-offset: 2px; }
button { font-family: inherit; }

/* ---------- Full-screen game shell ---------------------------------------
   The game page is a fixed app shell that always fills the viewport, in
   both portrait and landscape - no fixed aspect-ratio box. The maze itself
   is always square, and game.js already letterboxes it to fit whatever
   box it's given, so fitting *this container* to the real viewport is
   all that's needed for correct behaviour in any orientation/screen. */
html, body { height: 100%; }
body.game-page {
  height: 100vh; height: 100dvh; /* dvh accounts for mobile browser chrome */
  display: flex; flex-direction: column; overflow: hidden;
}

.site-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.4rem 0.8rem; flex: 0 0 auto;
}
.site-header .brand {
  font-family: var(--font-display); font-size: 1.05rem; font-weight: 700;
  color: var(--text); text-decoration: none; letter-spacing: 0.01em;
}
.site-header .brand span { color: var(--oak-deep); }
[data-theme="dark"] .site-header .brand span { color: var(--brass); }
.site-header .guide-link {
  font-size: 0.8rem; color: var(--text-soft); text-decoration: none;
  border: 1px solid var(--panel-border); border-radius: 999px; padding: 0.3rem 0.75rem;
}

/* ---------- Game case: flexes to fill all remaining space ----------------- */
.case {
  flex: 1 1 auto; min-height: 0;
  display: flex; padding: 0 clamp(4px, 1.5vw, 1rem) clamp(4px, 1.5vw, 1rem);
}
.case-frame {
  position: relative; flex: 1 1 auto; min-height: 0;
  display: flex;
  background: linear-gradient(155deg, var(--oak), var(--walnut) 85%);
  border-radius: var(--radius-l);
  padding: clamp(4px, 1.2vw, 14px);
  box-shadow: var(--shadow-raised);
  animation: case-settle 0.6s cubic-bezier(.2,.8,.2,1) both;
}
@keyframes case-settle {
  from { opacity: 0; transform: translateY(10px) scale(0.99); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
@media (prefers-reduced-motion: reduce) {
  .case-frame { animation: none; }
}
.case-frame .corner-tl, .case-frame .corner-tr, .case-frame .corner-bl, .case-frame .corner-br {
  position: absolute; width: 10px; height: 10px; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fff3d0, var(--brass) 55%, #8a5f1c 100%);
  box-shadow: 0 1px 2px rgba(0,0,0,0.5);
}
.case-frame .corner-tl { top: 10px; left: 10px; }
.case-frame .corner-tr { top: 10px; right: 10px; }
.case-frame .corner-bl { bottom: 10px; left: 10px; }
.case-frame .corner-br { bottom: 10px; right: 10px; }

.game-viewport {
  position: relative;
  background: #0e0a06;
  border-radius: var(--radius-m);
  box-shadow: var(--shadow-groove);
  overflow: hidden;
  touch-action: none;
  flex: 1 1 auto;
  min-height: 0; /* required for flex children to actually shrink to fit */
  width: 100%;
}

#game-canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

/* HUD - glass plate reading like an engraved brass gauge */
.hud-top {
  position: absolute; top: 0; left: 0; right: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between;
  gap: 0.5rem; padding: 0.5rem 0.6rem;
}
.hud-readout {
  display: flex; align-items: baseline; gap: 0.6rem;
  background: var(--glass); backdrop-filter: blur(6px);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-s); padding: 0.35rem 0.7rem;
  font-family: var(--font-mono); font-size: 0.85rem; color: var(--text);
}
#hud-timer { font-weight: 700; letter-spacing: 0.03em; }
.hud-controls { display: flex; gap: 0.35rem; }

.icon-btn {
  width: 38px; height: 38px; border-radius: 50%; border: none; cursor: pointer;
  background: var(--surface); box-shadow: var(--shadow-raised);
  font-size: 1.05rem; display: flex; align-items: center; justify-content: center;
  color: var(--text); transition: transform 0.12s ease;
}
.icon-btn:active { box-shadow: var(--shadow-inset); transform: scale(0.96); }
.icon-btn:disabled { opacity: 0.35; cursor: not-allowed; }
.icon-btn[aria-pressed="true"] {
  background: var(--brass); color: var(--ink); box-shadow: var(--shadow-inset);
}

.hud-bottom {
  position: absolute; bottom: 0; left: 0; right: 0; z-index: 5;
  display: flex; justify-content: center; gap: 0.6rem; padding: 0.6rem;
}
.pill-btn {
  border: none; cursor: pointer; border-radius: 999px; padding: 0.55rem 1.1rem;
  background: var(--glass); backdrop-filter: blur(6px);
  border: 1px solid var(--panel-border); color: var(--text);
  font-weight: 600; font-size: 0.9rem; box-shadow: var(--shadow-raised);
}
.pill-btn:disabled { opacity: 0.35; }

/* Joystick - left/top mark the center point (set from JS in zone-local
   coordinates); centering is done ONLY via transform so it stays correct
   regardless of the element's own size. Do not add margin offsets here -
   combining margin-based and transform-based centering was the bug that
   made the stick render away from the actual touch point. */
#joystick-zone { position: absolute; inset: 0; z-index: 4; touch-action: none; }
#joystick-base, #joystick-stick {
  position: absolute; left: 0; top: 0; border-radius: 50%;
  pointer-events: none; will-change: transform;
}
#joystick-base {
  width: 92px; height: 92px;
  transform: translate(-50%, -50%);
  background: rgba(255,255,255,0.08); border: 2px solid rgba(255,255,255,0.25);
}
#joystick-stick {
  width: 46px; height: 46px;
  transform: translate(-50%, -50%);
  background: radial-gradient(circle at 35% 30%, #fff, var(--steel-light) 55%, var(--steel));
  box-shadow: 0 2px 6px rgba(0,0,0,0.4);
}

.fail-flash {
  position: absolute; inset: 0; background: var(--danger); opacity: 0;
  pointer-events: none; z-index: 6; transition: opacity 0.15s ease;
}
.fail-flash.show { opacity: 0.35; }
.toast {
  position: absolute; top: 46%; left: 50%; transform: translate(-50%,-50%);
  background: var(--glass); border: 1px solid var(--panel-border);
  padding: 0.4rem 0.9rem; border-radius: 999px; font-weight: 700;
  opacity: 0; pointer-events: none; z-index: 6; transition: opacity 0.2s ease;
}
.toast.show { opacity: 1; }

/* ---------- Modals -------------------------------------------------------- */
.modal {
  position: fixed; inset: 0; z-index: 20;
  background: rgba(20,14,9,0.55);
  display: flex; align-items: center; justify-content: center; padding: 1rem;
}
.modal[hidden] { display: none; }
.modal-card {
  background: var(--surface); border-radius: var(--radius-l);
  box-shadow: var(--shadow-raised); padding: 1.4rem; max-width: 420px; width: 100%;
  max-height: 85vh; overflow-y: auto;
  border: 1px solid var(--panel-border);
}
.modal-card h2 { font-family: var(--font-display); margin: 0 0 0.75rem; font-size: 1.4rem; }
.modal-actions { display: flex; gap: 0.6rem; margin-top: 1rem; flex-wrap: wrap; }
.btn {
  border: none; border-radius: var(--radius-s); padding: 0.6rem 1rem;
  background: var(--oak-deep); color: #fff8ec; font-weight: 700; cursor: pointer;
  box-shadow: var(--shadow-raised);
}
.btn.secondary { background: var(--surface-2); color: var(--text); }
.btn.danger { background: var(--danger); color: #fff; }
.setting-row { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin: 0.7rem 0; }
.setting-row label { font-size: 0.9rem; color: var(--text-soft); }
.radio-group { display: flex; gap: 0.9rem; flex-wrap: wrap; margin: 0.5rem 0 1rem; }
.radio-group label { display: flex; align-items: center; gap: 0.35rem; font-size: 0.9rem; }

#victory-stars { font-size: 1.6rem; letter-spacing: 0.15em; color: var(--brass); }

#level-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(38px, 1fr));
  gap: 0.4rem; margin-top: 0.5rem;
}
.level-tile {
  aspect-ratio: 1; border-radius: var(--radius-s); border: none; cursor: pointer;
  background: var(--surface-2); box-shadow: var(--shadow-raised);
  font-family: var(--font-mono); font-weight: 700; font-size: 0.8rem; color: var(--text);
}
.level-tile.current { outline: 2px solid var(--brass); }
.level-tile.locked { opacity: 0.35; cursor: not-allowed; box-shadow: none; }
.level-tile.locked::after { content: "\1F512"; font-size: 0.75rem; }

/* ---------- Below-the-fold content ---------------------------------------- */
.content {
  max-width: 760px; margin: 2.5rem auto; padding: 0 1.25rem 3rem;
}
.content h2 {
  font-family: var(--font-display); font-size: 1.5rem; margin: 2.2rem 0 0.7rem;
  border-bottom: 2px solid var(--panel-border); padding-bottom: 0.4rem;
}
.content h2:first-child { margin-top: 0; }
.content p, .content li { color: var(--text); font-size: 1rem; }
.content ul { padding-left: 1.2rem; }
.feature-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(200px,1fr));
  gap: 0.9rem; list-style: none; padding: 0; margin: 0.8rem 0;
}
.feature-grid li {
  background: var(--surface); border: 1px solid var(--panel-border);
  border-radius: var(--radius-m); padding: 0.8rem 0.9rem; font-size: 0.92rem;
}
details.faq-item {
  background: var(--surface); border: 1px solid var(--panel-border);
  border-radius: var(--radius-m); padding: 0.7rem 0.9rem; margin-bottom: 0.6rem;
}
details.faq-item summary { font-weight: 700; cursor: pointer; }
details.faq-item[open] summary { margin-bottom: 0.4rem; }

/* ---------- Single full-screen interstitial ad (shown periodically) ------
   This is the only ad placement in the game. It overlays the whole screen,
   pauses the game underneath, and is dismissible once the countdown ends.
   Swap the placeholder <span> for your ad network's interstitial call. */
.interstitial {
  position: fixed; inset: 0; z-index: 50;
  background: #0e0a06;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 1rem; color: #f1e3c8; text-align: center; padding: 1.5rem;
}
.interstitial[hidden] { display: none; }
.interstitial .ad-placeholder {
  border: 1px dashed rgba(255,255,255,0.3); border-radius: var(--radius-m);
  padding: 2.5rem 1.5rem; max-width: 420px; width: 100%;
  font-size: 0.85rem; color: #cbb890;
}
.interstitial .btn { min-width: 180px; }
.interstitial .btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* ---------- Footer ---------------------------------------------------------- */
.site-footer {
  text-align: center; padding: 1.5rem 1rem 2.5rem; color: var(--text-soft); font-size: 0.85rem;
}

/* ---------- Responsive tweaks ------------------------------------------------ */
@media (max-width: 480px) {
  .modal-card { padding: 1rem; }
  .hud-readout { font-size: 0.75rem; padding: 0.3rem 0.5rem; }
  .icon-btn { width: 34px; height: 34px; }
}

/* Short landscape screens (phones on their side): the HUD bars themselves
   are the main thing eating into usable board space, so shrink them. */
@media (orientation: landscape) and (max-height: 480px) {
  .site-header { padding: 0.15rem 0.6rem; font-size: 0.85rem; }
  .hud-top, .hud-bottom { padding: 0.3rem 0.4rem; }
  .icon-btn { width: 30px; height: 30px; font-size: 0.9rem; }
  .pill-btn { padding: 0.35rem 0.75rem; font-size: 0.8rem; }
  .hud-readout { font-size: 0.7rem; padding: 0.25rem 0.5rem; }
}
