:root {
  --bg: #0b0e17;
  --ink: #e8ecf6;
  --mute: #7c87a6;
  --glow: #5ff2ff;
  --gold: #ffd166;
  --line: #26304a;
  --panel: #121828;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; height: 100%;
  background: radial-gradient(ellipse at top, color-mix(in srgb, var(--glow) 10%, #0b0e17), #07090f 70%);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overflow: hidden; touch-action: none; user-select: none; -webkit-user-select: none;
  overscroll-behavior: none; /* no pull-to-refresh / rubber-band scrolling (1.7.4) */
  transition: background .6s;
}
/* Fit the page to the visible screen, never scroll while playing (1.7.4). --app-h is set by game.js from the
   visual viewport (the real visible height on phones, without the browser's address bar); 100dvh is the fallback. */
body { position: fixed; inset: 0; width: 100%; }
#app {
  height: 100%; height: 100dvh; height: var(--app-h, 100dvh); overflow: hidden;
  display: flex; flex-direction: column; align-items: center;
  padding: calc(10px + env(safe-area-inset-top)) 10px calc(10px + env(safe-area-inset-bottom)); gap: 8px;
}
header { width: 100%; max-width: 560px; display: flex; align-items: center; justify-content: space-between; gap: 10px; min-width: 0; flex: none; }
h1 { min-width: 0; white-space: nowrap; }
h1 small { overflow: hidden; text-overflow: ellipsis; }
.stats { flex: none; }
h1 {
  font-size: 19px; margin: 0; letter-spacing: .2em; font-weight: 800;
  color: var(--glow); text-shadow: 0 0 14px color-mix(in srgb, var(--glow) 55%, transparent);
}
h1 small { display: block; font-size: 10px; letter-spacing: .22em; color: var(--mute); text-shadow: none; font-weight: 600; }
.stats { display: flex; gap: 12px; align-items: center; font-size: 10px; letter-spacing: .12em; text-transform: uppercase; color: var(--mute); }
.stats b { display: block; color: var(--ink); font-size: 18px; letter-spacing: 0; font-variant-numeric: tabular-nums; }
#next { display: block; margin-top: 2px; }
#pauseBtn { width: 36px; height: 36px; font-size: 14px; border-radius: 10px; }
#progress { flex: none; width: 100%; max-width: 560px; height: 6px; border-radius: 3px; background: #1a2136; overflow: hidden; }
#bar { height: 100%; width: 0; background: linear-gradient(90deg, var(--glow), var(--gold)); box-shadow: 0 0 10px var(--glow); transition: width .4s; }
#stage { flex: 1; min-height: 0; min-width: 0; overflow: hidden; width: 100%; display: flex; align-items: center; justify-content: center; }
#board { cursor: pointer; filter: drop-shadow(0 16px 40px rgba(0,0,0,.5)); }
#controls { flex: none; display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; width: 100%; max-width: 560px; }
#controls button { height: clamp(40px, 7.5vh, 54px); font-size: 22px; }
button {
  font: inherit; color: var(--ink); background: #1a2136; border: 1px solid var(--line);
  border-radius: 12px; cursor: pointer; touch-action: manipulation;
}
#controls button { touch-action: none; }
button:active { background: #243052; border-color: var(--glow); }
button:disabled { opacity: .35; cursor: default; }

.overlay {
  position: fixed; inset: 0; background: rgba(6, 8, 14, .86); backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center; padding: 20px; z-index: 5; overflow-y: auto;
  touch-action: pan-y; overscroll-behavior: contain; /* menus may scroll, the game never does */
}
.overlay.hidden { display: none; }
.card {
  max-width: 400px; width: 100%; background: var(--panel); border: 1px solid var(--line);
  border-radius: 16px; padding: 24px; text-align: center; box-shadow: 0 30px 80px rgba(0,0,0,.6);
  margin: auto;
}
.card h2 {
  margin: 0 0 4px; font-size: 26px; letter-spacing: .15em; color: var(--glow);
  text-shadow: 0 0 16px color-mix(in srgb, var(--glow) 50%, transparent);
}
.card .sub { color: var(--mute); font-size: 12px; letter-spacing: .2em; text-transform: uppercase; margin-bottom: 14px; }
.card p { color: #c3cae0; font-size: 14px; line-height: 1.5; margin: 8px 0; text-align: left; }
.card ul { text-align: left; color: #c3cae0; font-size: 14px; line-height: 1.5; padding-left: 20px; margin: 8px 0; }
.card .big { font-size: 40px; font-weight: 800; margin: 6px 0; text-align: center; color: var(--gold); }
.card .primary {
  margin-top: 14px; width: 100%; height: 50px; font-size: 16px; font-weight: 700; letter-spacing: .15em;
  background: linear-gradient(90deg, color-mix(in srgb, var(--glow) 30%, #111), color-mix(in srgb, var(--gold) 30%, #111));
  border-color: var(--glow);
}
.card .secondary { margin-top: 8px; width: 100%; height: 42px; font-size: 14px; letter-spacing: .12em; }
.levels { display: grid; gap: 8px; margin-top: 14px; }
.lvrow { display: flex; gap: 6px; }
.lvrow .lv {
  flex: 1; display: flex; align-items: center; gap: 12px; padding: 10px 14px; text-align: left; height: auto; min-width: 0;
}
.lvrow .inf { width: 46px; flex: none; font-size: 22px; color: var(--gold); }
.card.wide { max-width: 680px; }
/* The menu card stays at the top with a fixed size, so closing a folder doesn't move it (1.5.0) */
.card.menu { margin: 0 auto auto; min-height: 100%; }
.field {
  width: 100%; margin-top: 12px; padding: 12px; font: inherit; font-size: 16px; color: var(--ink);
  background: #0c111d; border: 1px solid var(--line); border-radius: 10px; user-select: text; -webkit-user-select: text;
}
textarea.field { font-size: 12px; resize: none; }
.levels .lv .n { font-size: 20px; font-weight: 800; width: 34px; flex: none; text-align: center; }
.levels .lv .n.hash { font-size: 16px; letter-spacing: .05em; opacity: .75; }
/* Level folders (1.4.0) */
.levels .folder {
  display: flex; align-items: center; gap: 10px; width: 100%; height: 40px; padding: 0 14px; margin-top: 6px;
  text-align: left; font-size: 12px; font-weight: 700; letter-spacing: .14em; text-transform: uppercase;
  background: color-mix(in srgb, var(--glow) 7%, transparent); border-color: color-mix(in srgb, var(--glow) 35%, transparent);
}
.levels .folder:first-child { margin-top: 0; }
.levels .folder .fa { color: var(--glow); width: 12px; }
.levels .folder .fn { flex: 1; color: var(--ink); }
.levels .folder .fc { color: var(--mute); font-weight: 600; letter-spacing: .08em; text-transform: none; }
.levels .folder.soon { opacity: .55; border-style: dashed; cursor: default; border-width: 1px; border-radius: 12px; }
.levels .lv .t { flex: 1; }
.levels .lv .t b { display: block; font-size: 14px; }
.levels .lv .t span { font-size: 11px; color: var(--mute); letter-spacing: .08em; }
.levels .lv .dot { width: 10px; height: 10px; border-radius: 50%; }
.keys { font-size: 12px; color: var(--mute); margin-top: 12px; line-height: 1.7; text-align: center; }
kbd { background: #1a2136; border: 1px solid var(--line); border-radius: 4px; padding: 1px 5px; font-size: 11px; color: var(--ink); }
.card .ver { margin-top: 10px; font-size: 11px; color: var(--mute); letter-spacing: .1em; opacity: .7; }
.mech {
  margin: 10px 0; padding: 10px 12px; text-align: left; border-radius: 12px;
  border: 1px solid var(--glow); background: color-mix(in srgb, var(--glow) 8%, transparent);
}
.mech b { font-size: 15px; }
.mech p { margin: 4px 0 0; }
.mech-tag { font-size: 10px; letter-spacing: .18em; text-transform: uppercase; color: var(--glow); margin-bottom: 2px; }
.setrow { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 12px 0; text-align: left; }
.setrow > span { color: #c3cae0; font-size: 14px; }
.seg { display: flex; gap: 6px; }
.seg.langs { display: grid; grid-template-columns: repeat(3, 1fr); margin-bottom: 12px; } /* 10 languages (1.7.0) */
.seg.langs button { padding: 8px 4px; }
/* SHARE stands out (1.7.0) */
.card .share { border-color: var(--gold); color: var(--gold); background: color-mix(in srgb, var(--gold) 14%, transparent); }
.seg button { padding: 8px 12px; font-size: 13px; }
.seg button.on { background: color-mix(in srgb, var(--glow) 35%, #111); border-color: var(--glow); }
.vol { display: flex; align-items: center; gap: 10px; }
.vol input { width: 150px; accent-color: var(--glow); }
.vol b { width: 40px; text-align: right; font-variant-numeric: tabular-nums; font-size: 13px; }
.diff, .levels .lv .t .diff { font-size: 10px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; padding: 1px 6px; border-radius: 6px; margin-left: 4px; vertical-align: 1px; }
.diff-easy, .levels .lv .t .diff-easy { color: #7dff9a; background: rgba(125,255,154,.12); }
.diff-medium, .levels .lv .t .diff-medium { color: #ffd166; background: rgba(255,209,102,.12); }
.diff-hard, .levels .lv .t .diff-hard { color: #ff6b8b; background: rgba(255,107,139,.14); }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.row2 .secondary { margin-top: 10px; }
.star { font-size: 13px; text-shadow: 0 0 8px currentColor; }
.reward { margin: 10px 0; padding: 8px 10px; border-radius: 10px; color: var(--gold); border: 1px solid var(--gold); font-size: 13px; }
.card .sec { margin: 16px 0 6px; text-align: left; }
.stats-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 12px; }
.stat { background: #0c111d; border: 1px solid var(--line); border-radius: 10px; padding: 8px; }
.stat b { display: block; font-size: 18px; color: var(--ink); font-variant-numeric: tabular-nums; }
.stat span { font-size: 10px; color: var(--mute); letter-spacing: .08em; text-transform: uppercase; }
table.hs { width: 100%; border-collapse: collapse; font-size: 12px; font-variant-numeric: tabular-nums; }
table.hs th { font-size: 10px; color: var(--mute); letter-spacing: .08em; text-transform: uppercase; font-weight: 600; text-align: right; padding: 4px 6px; }
table.hs td { padding: 5px 6px; border-top: 1px solid #1c2336; text-align: right; color: #c3cae0; }
table.hs td:nth-child(2), table.hs th:nth-child(2) { text-align: left; }
table.hs td:first-child { color: var(--mute); }
.badges { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.badge { display: flex; gap: 8px; align-items: center; text-align: left; padding: 8px; border-radius: 10px; border: 1px solid var(--line); opacity: .45; font-size: 12px; }
.badge small { color: var(--mute); }
.badge.on { opacity: 1; border-color: var(--b); background: color-mix(in srgb, var(--b) 10%, transparent); }
.badge-icon { font-size: 22px; color: var(--mute); }
.badge.on .badge-icon { color: var(--b); text-shadow: 0 0 10px var(--b); }
.themes { display: flex; flex-wrap: wrap; gap: 8px; }
.theme { display: flex; align-items: center; gap: 8px; padding: 8px 12px; font-size: 13px; }
.theme.on { border-color: var(--glow); background: color-mix(in srgb, var(--glow) 18%, #111); }
.theme .sw { width: 22px; height: 12px; border-radius: 6px; }
@media (max-width: 480px) { .stats-grid, .badges { grid-template-columns: repeat(2, 1fr); } }

/* Menu brand (port of the app 1.1.0 brand header, browser since 1.2.0) */
.brand { display: flex; flex-direction: column; align-items: center; gap: 8px; margin-bottom: 2px; }
.brand .logo { width: 84px; height: 84px; border-radius: 22px; background: #121a30;
  border: 1px solid color-mix(in srgb, var(--glow) 35%, transparent); }
.card .brand .brand-title { display: inline-block; margin: 0; letter-spacing: .12em; background: linear-gradient(90deg, var(--glow), var(--gold));
  -webkit-background-clip: text; background-clip: text; color: transparent; text-shadow: none;
  filter: drop-shadow(0 0 10px color-mix(in srgb, var(--glow) 45%, transparent)); }

/* Small screens (1.7.4): shrink the header and buttons so the whole board fits without scrolling */
@media (max-width: 420px) {
  #app { gap: 6px; padding-left: 6px; padding-right: 6px; }
  header { gap: 6px; }
  h1 { font-size: 15px; letter-spacing: .12em; }
  h1 small { font-size: 9px; letter-spacing: .14em; }
  .stats { gap: 8px; font-size: 9px; letter-spacing: .06em; }
  .stats b { font-size: 15px; }
  #pauseBtn { width: 32px; height: 32px; }
  #controls { gap: 6px; }
}
@media (max-height: 640px) {
  #app { gap: 5px; padding-top: calc(6px + env(safe-area-inset-top)); padding-bottom: calc(6px + env(safe-area-inset-bottom)); }
  #controls button { height: 40px; font-size: 19px; }
  .stats b { font-size: 15px; }
}
/* Phone held sideways: little height, so the buttons go small and the title shrinks */
@media (max-height: 460px) {
  h1 small { display: none; }
  #controls button { height: 34px; font-size: 17px; }
  #progress { height: 4px; }
}
