:root {
  --c1: #00b3c7; --c2: #00657c; --dlg: #00c7df; --txt: #004358;
  --noise: url(assets/noise_blue.png); --noise-dk: url(assets/noise_blue_dk.png); --edge: #004358; --sec: #00b3c7;
  --safe-t: env(safe-area-inset-top, 0px); --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px); --safe-r: env(safe-area-inset-right, 0px);
}
body.theme-forest { --c1: #1bc700; --c2: #137b00; --dlg: #1ddc00; --txt: #0d4e00; --noise: url(assets/noise_green.png); --noise-dk: url(assets/noise_green_dk.png); --edge: #0d4e00; }
body.theme-hell   { --c1: #c71800; --c2: #7c0d00; --dlg: #e11a00; --txt: #5c0900; --noise: url(assets/noise_red_dk.png); --noise-dk: url(assets/noise_red_dk.png); --edge: #5c0900; }

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; overscroll-behavior: none; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: #fff; user-select: none; -webkit-user-select: none;
  background: url(assets/background.png) center / cover, #38a9c9;
}
body.theme-forest { background: url(assets/background_forest.png) center / cover, #4cae4c; }
body.theme-hell { background: url(assets/background_fire.png) center / cover, #808080; }
#app { position: fixed; inset: 0; }
.screen { position: absolute; inset: 0; display: none; flex-direction: column;
  padding: var(--safe-t) var(--safe-r) var(--safe-b) var(--safe-l); }
.screen.active { display: flex; }

/* ---- buttons ---- */
.btn {
  font: inherit; font-weight: 700; color: #fff; cursor: pointer;
  padding: 12px 22px; border-radius: 14px; border: 2px solid rgba(255,255,255,.35);
  background: linear-gradient(var(--c1), var(--c2));
  box-shadow: 0 4px 0 rgba(0,0,0,.35), 0 8px 18px rgba(0,0,0,.25);
  transition: transform .08s, box-shadow .08s, filter .15s;
  text-shadow: 0 1px 2px rgba(0,0,0,.4);
}
.btn:hover { filter: brightness(1.12); }
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 rgba(0,0,0,.35); }
.btn.big { font-size: 1.6rem; padding: 16px 64px; }
.btn.small { font-size: .95rem; padding: 9px 16px; }
.btn.primary { background: linear-gradient(#ffb020, #d46a00); }
.btn.danger { background: linear-gradient(#e0483a, #8f1c12); }
.btn:focus-visible, .icon-btn:focus-visible, .card:focus-visible { outline: 3px solid #fff; outline-offset: 2px; }
.icon-btn {
  width: 44px; height: 44px; border-radius: 12px; font-size: 1.4rem; line-height: 1; color: #fff; cursor: pointer;
  border: 2px solid rgba(255,255,255,.3); background: rgba(0,0,0,.3);
}
.icon-btn:hover { background: rgba(255,255,255,.18); }
.icon-btn:disabled { opacity: .35; cursor: default; }

/* ---- menu (same look in both designs: the original artwork) ---- */
#screen-menu { align-items: center; justify-content: center; text-align: center; }
.menu-inner { display: flex; flex-direction: column; align-items: center; gap: 22px; padding: 24px; }
.title { margin: 0; }
.title img { width: min(86vw, 520px); image-rendering: pixelated; display: block; }
.tagline { margin: 0; max-width: 24em; color: #0d4e6e; font-weight: 700; }
.row { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; }
#btn-start { border: 0; padding: 0; background: none; box-shadow: none; cursor: pointer; }
#btn-start img { width: min(70vw, 375px); image-rendering: pixelated; display: block; transition: transform .08s; }
#btn-start:hover img { filter: brightness(1.1); }
#btn-start:active img { content: url(assets/menu_button_start_s.png); transform: translateY(2px); }
#screen-menu .btn, #screen-levels .btn {
  background: var(--noise), var(--c1); background-blend-mode: multiply;
  border: 4px solid var(--edge); border-radius: 6px; box-shadow: 0 4px 0 rgba(0,0,0,.35); image-rendering: pixelated;
}

/* ---- level select ---- */
.bar, .hud { display: flex; align-items: center; gap: 10px; padding: 10px 12px; background: rgba(0,0,0,.35); backdrop-filter: blur(6px); }
#screen-levels .bar { background: var(--noise-dk), var(--c2); background-blend-mode: multiply; backdrop-filter: none; border-bottom: 4px solid var(--edge); }
.bar h2 { margin: 0; font-size: 1.2rem; flex: 1; text-align: center; }
.bar .progress { min-width: 44px; font-size: .85rem; font-weight: 700; text-align: right; white-space: nowrap; }
.grid {
  flex: 1; overflow-y: auto; padding: 8px 14px 24px; display: grid; gap: 12px; align-content: start;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); max-width: 980px; width: 100%; margin: 0 auto;
}
.lv-section {
  grid-column: 1 / -1; display: flex; align-items: center; gap: 12px; margin: 14px 2px 0;
  font-weight: 900; letter-spacing: .1em; text-transform: uppercase; color: #fff; text-shadow: 0 2px 0 rgba(0,0,0,.35);
}
.lv-section::after { content: ''; flex: 1; height: 5px; border-radius: 3px; background: var(--sec); border: 1px solid rgba(0,0,0,.25); }
.lv-section small { font-weight: 700; letter-spacing: 0; text-transform: none; opacity: .9; }
.card {
  position: relative; text-align: left; font: inherit; color: #fff; cursor: pointer; min-height: 84px; padding: 10px;
  display: grid; grid-template-columns: 64px 1fr; align-items: center; gap: 12px;
  background: var(--cn), var(--cc1); background-blend-mode: multiply; border: 4px solid var(--ce); border-radius: 6px;
  box-shadow: 0 4px 0 rgba(0,0,0,.3); transition: transform .1s, filter .15s;
}
.card:hover:not(.locked) { transform: translateY(-2px); filter: brightness(1.1); }
.card .thumb, .card .lockbox {
  width: 64px; height: 64px; border-radius: 4px; border: 3px solid rgba(0,0,0,.4); background: rgba(0,0,0,.2);
}
.card .lockbox { display: grid; place-items: center; font-size: 1.6rem; }
.card .meta { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.card .name { font-weight: 800; font-size: 1.1rem; text-shadow: 0 1px 2px rgba(0,0,0,.45); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card .score { font-size: .82rem; opacity: .95; }
.card .badge { position: absolute; top: 4px; right: 8px; font-size: 1.05rem; text-shadow: 0 1px 2px #000; }
.card .badge.star { color: #ffe36b; }
.card.done .badge.ok { color: #c8ffb0; }
.card.locked { --cc1: #c4c4c7; --cn: url(assets/noise_grey.png); --ce: #79787c; color: #555458; cursor: default; opacity: .85; }
.card.t-ice { --cc1: #00b3c7; --cn: url(assets/noise_blue.png); --ce: #00657c; }
.card.t-forest { --cc1: #1bc700; --cn: url(assets/noise_green.png); --ce: #137b00; }
.card.t-hell { --cc1: #c71800; --cn: url(assets/noise_red_dk.png); --ce: #7c0d00; }
.card.locked { --cc1: #c4c4c7; --cn: url(assets/noise_grey.png); --ce: #79787c; }

/* ---- game ---- */
.hud-info { flex: 1; text-align: center; min-width: 0; }
.hud-level { font-weight: 800; font-size: 1.15rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hud-sub { font-size: .9rem; opacity: .9; display: flex; gap: 14px; justify-content: center; flex-wrap: wrap; }
.stage { position: relative; flex: 1; min-height: 0; }
.stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; display: block; }

/* ---- dialogs ---- */
.modal { position: fixed; inset: 0; display: none; align-items: center; justify-content: center; padding: 16px;
  background: rgba(0,0,0,.55); backdrop-filter: blur(3px); z-index: 10; }
.modal.open { display: flex; }
.dialog {
  width: min(92vw, 420px); padding: 22px; border-radius: 20px; text-align: center;
  background: linear-gradient(var(--dlg), var(--c1)); color: var(--txt); border: 4px solid rgba(255,255,255,.55);
  box-shadow: 0 16px 50px rgba(0,0,0,.5); animation: pop .18s ease-out;
}
@keyframes pop { from { transform: scale(.9); opacity: 0; } }
.dialog h3 { margin: 0 0 10px; font-size: 1.5rem; }
.dialog p { margin: 8px 0; line-height: 1.4; font-weight: 600; }
.dialog .sub { opacity: .8; font-size: .9rem; }
.dlg-buttons { display: flex; gap: 12px; justify-content: center; margin-top: 16px; }
.dlg-buttons .btn { flex: 1; padding: 12px 10px; }
.dlg-buttons.col { flex-direction: column; }

.toast {
  position: fixed; left: 50%; top: 18%; transform: translateX(-50%) translateY(-10px); opacity: 0; pointer-events: none; z-index: 20;
  padding: 10px 20px; border-radius: 14px; font-weight: 700; color: #fff; background: rgba(0,0,0,.75); transition: .25s;
  border: 2px solid var(--c1);
}
.toast.show { opacity: 1; transform: translateX(-50%); }

@media (prefers-reduced-motion: reduce) { .dialog { animation: none; } }
