:root {
  --bg: #151b25; --panel: #1d2533; --panel2: #243045; --line: #2f3b50; --text: #e9eef6; --muted: #93a1b5;
  --gold: #ffc94a; --green: #5ec46b; --green2: #4aa957; --red: #ef5350; --blue: #7fd8ff; --purple: #b39ddb;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font-family: 'Fredoka', system-ui, -apple-system, 'Segoe UI', sans-serif; overflow: hidden; -webkit-tap-highlight-color: transparent; user-select: none; -webkit-user-select: none; }
button { font: inherit; color: inherit; cursor: pointer; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.center { text-align: center; }
#app { position: fixed; inset: 0; }
.screen { position: absolute; inset: 0; display: none; flex-direction: column; }
.screen.on { display: flex; }
.scroll { flex: 1; overflow-y: auto; padding: 16px; -webkit-overflow-scrolling: touch; }

/* buttons */
.big { display: flex; align-items: center; justify-content: center; gap: 10px; width: 100%; padding: 13px 18px; font-size: 20px; font-weight: 600; background: var(--panel2); border: 2px solid var(--line); border-radius: 14px; transition: transform .08s, background .15s; }
.big:hover { background: #2b3952; }
.big:active { transform: scale(.98); }
.big small { font-size: 13px; font-weight: 400; color: #e8f5e9; opacity: .9; }
.big.primary { background: var(--green2); border-color: #6fd27b; flex-direction: column; gap: 0; }
.big.primary:hover { background: #55b862; }
.big.ghost { background: transparent; }
.pill { display: inline-flex; align-items: center; gap: 4px; font-size: 14px; font-weight: 600; padding: 3px 10px; border-radius: 99px; background: rgba(0,0,0,.25); }
.pill.cr { color: var(--blue); }
.btn { padding: 9px 14px; border-radius: 10px; border: 2px solid var(--line); background: var(--panel2); font-weight: 600; font-size: 15px; }
.btn:hover:not(:disabled) { background: #2b3952; }
.btn:disabled { opacity: .45; cursor: default; }
.btn.primary { background: var(--green2); border-color: #6fd27b; }
.btn.primary:hover:not(:disabled) { background: #55b862; }
.btn.gold { background: #8a6d1d; border-color: var(--gold); }
.btn.gold:hover:not(:disabled) { background: #9c7c22; }
.btn.danger { background: #7b2f2e; border-color: var(--red); }

/* menu */
#scr-menu { align-items: center; justify-content: center; }
.menu-bg { position: absolute; inset: 0; background-size: cover; background-position: center; filter: blur(3px) saturate(1.1); transform: scale(1.05); opacity: .45; }
#scr-menu::after { content: ''; position: absolute; inset: 0; background: radial-gradient(ellipse at center, rgba(21,27,37,.35), rgba(21,27,37,.92)); pointer-events: none; }
.menu-wrap { position: relative; z-index: 1; width: min(380px, 92vw); display: flex; flex-direction: column; align-items: center; max-height: 100%; overflow-y: auto; padding: 20px 0; }
.logo { font-size: clamp(44px, 9vw, 64px); margin: 0; letter-spacing: 1px; color: #fff; text-shadow: 0 4px 0 #3f6b2d, 0 8px 24px rgba(0,0,0,.5); font-weight: 700; }
.tagline { color: #cfe8c0; margin: 2px 0 22px; font-size: 18px; }
.menu-buttons { display: flex; flex-direction: column; gap: 10px; width: 100%; }
#daily { margin-top: 16px; width: 100%; }
.daily { display: flex; align-items: center; gap: 12px; padding: 10px 14px; border-radius: 14px; background: linear-gradient(135deg, #3a2f6b, #2a3f6b); border: 2px solid #6f5fc7; }
.daily .gift { font-size: 30px; line-height: 1; display: flex; }
.daily .txt { flex: 1; font-size: 14px; line-height: 1.3; }
.daily .txt b { font-size: 16px; }
#menuStats { margin-top: 14px; font-size: 13px; text-align: center; line-height: 1.6; }

/* top bars */
.bar { display: flex; align-items: center; gap: 12px; padding: 10px 14px; background: var(--panel); border-bottom: 1px solid var(--line); }
.bar h2 { margin: 0; font-size: 22px; flex: 1; font-weight: 600; }
.back { width: 40px; height: 40px; border-radius: 12px; border: 2px solid var(--line); background: var(--panel2); font-size: 20px; }

/* map select */
#mapGrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 14px; max-width: 1200px; margin: 0 auto; }
.mcard { position: relative; background: var(--panel); border: 2px solid var(--line); border-radius: 16px; overflow: hidden; cursor: pointer; transition: transform .12s, border-color .12s; }
.mcard:hover { transform: translateY(-2px); border-color: #4a5c7a; }
.mcard img { display: block; width: 100%; aspect-ratio: 5/3; }
.mcard .mi { padding: 8px 12px 10px; }
.mcard .mname { font-weight: 600; font-size: 17px; }
.mcard .mmeta { font-size: 13px; color: var(--muted); display: flex; justify-content: space-between; margin-top: 2px; }
.stars { color: var(--gold); letter-spacing: 2px; font-size: 18px; }
.stars .off { color: #4a556a; }
.mcard.locked { cursor: default; }
.mcard.locked img { filter: grayscale(1) brightness(.45); }
.mcard .lockov { position: absolute; left: 0; right: 0; top: 0; aspect-ratio: 5/3; display: flex; align-items: center; justify-content: center; font-size: 15px; color: #cfd8dc; text-align: center; padding: 10px; }
.mcard .run { position: absolute; top: 8px; right: 8px; background: var(--green2); font-size: 12px; padding: 2px 8px; border-radius: 99px; }
.tag-endless { color: var(--purple); }

/* research */
#resList { max-width: 860px; margin: 0 auto; }
.rcat { margin: 18px 0 8px; font-size: 14px; text-transform: uppercase; letter-spacing: 1.5px; color: var(--muted); }
.rgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 10px; }
.res { display: flex; gap: 10px; align-items: center; padding: 10px 12px; background: var(--panel); border: 2px solid var(--line); border-radius: 14px; }
.res img { width: 40px; height: 40px; flex: none; }
.res .ri { flex: 1; min-width: 0; }
.res .rn { font-weight: 600; }
.res .rn span { font-weight: 400; color: var(--muted); font-size: 13px; }
.res .rd { font-size: 13px; color: var(--muted); }
.res .rb { height: 5px; border-radius: 3px; background: #2b3548; margin-top: 6px; overflow: hidden; }
.res .rb i { display: block; height: 100%; background: linear-gradient(90deg, #4fc3f7, #b39ddb); }
.res button { flex: none; min-width: 72px; }
.res.max { border-color: #4b6b3f; }

/* achievements */
#achList { max-width: 760px; margin: 0 auto; display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 8px; }
.ach { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 12px; background: var(--panel); border: 2px solid var(--line); }
.ach .ico { font-size: 24px; width: 32px; text-align: center; filter: grayscale(1); opacity: .4; }
.ach.done { border-color: #6b5a1f; background: #2a2a24; }
.ach.done .ico { filter: none; opacity: 1; }
.ach .an { font-weight: 600; }
.ach .ad { font-size: 13px; color: var(--muted); }
.ach .ar { margin-left: auto; color: var(--blue); font-size: 14px; white-space: nowrap; }

/* game */
#scr-game { background: #121821; }
#hud { display: flex; align-items: center; gap: 6px; padding: 6px 8px; background: var(--panel); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
#hud .grow { flex: 1; }
#hud button { height: 38px; min-width: 38px; padding: 0 10px; border-radius: 10px; border: 2px solid var(--line); background: var(--panel2); font-weight: 600; font-size: 15px; }
#hud button:hover:not(:disabled) { background: #2b3952; }
#hud button:disabled { opacity: .5; cursor: default; }
#hud button.primary { background: var(--green2); border-color: #6fd27b; min-width: 110px; }
#hud button.primary:hover:not(:disabled) { background: #55b862; }
#hud button.primary.early { background: #8a6d1d; border-color: var(--gold); }
#hud button.tog.on { background: #2f5d8a; border-color: #64b5f6; }
.stat { display: flex; align-items: center; gap: 6px; padding: 4px 10px; background: rgba(0,0,0,.22); border-radius: 10px; font-size: 18px; min-width: 64px; }
.stat b { font-weight: 600; }
.stat .lbl { font-size: 12px; color: var(--muted); }
.stat.crs { color: var(--blue); }
.heart { color: #ff6b6b; }
.coin { display: inline-block; width: 15px; height: 15px; border-radius: 50%; background: radial-gradient(circle at 35% 35%, #fff3c4, #ffc107 45%, #c79100); box-shadow: inset 0 0 0 1.5px #b07f00; vertical-align: -2px; }
.stat.flash b { animation: flash .5s; }
@keyframes flash { 0% { color: #ff8a80; transform: scale(1.3); } 100% { color: inherit; transform: none; } }
.spell { position: relative; overflow: hidden; font-size: 18px !important; }
.spell i { position: absolute; left: 0; right: 0; bottom: 0; background: rgba(0,0,0,.55); pointer-events: none; }
.spell.on { border-color: #ff8a65 !important; background: #5a3326 !important; }

#play { flex: 1; display: flex; min-height: 0; }
#cwrap { flex: 1; display: flex; align-items: center; justify-content: center; min-width: 0; min-height: 0; padding: 6px; }
#cv { display: block; border-radius: 10px; box-shadow: 0 6px 30px rgba(0,0,0,.45); touch-action: none; cursor: pointer; }
#side { width: 264px; flex: none; display: flex; flex-direction: column; background: var(--panel); border-left: 1px solid var(--line); min-height: 0; }
#shop { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; padding: 8px; border-bottom: 1px solid var(--line); }
.tb { position: relative; display: flex; flex-direction: column; align-items: center; gap: 0; padding: 4px 4px 5px; background: var(--panel2); border: 2px solid var(--line); border-radius: 12px; transition: border-color .1s, background .1s; }
.tb:hover { background: #2b3952; }
.tb img { width: 44px; height: 44px; }
.tb .nm { font-size: 13px; font-weight: 500; line-height: 1.1; }
.tb .cost { font-size: 13px; color: var(--gold); font-weight: 600; display: flex; align-items: center; gap: 3px; }
.tb .cost .coin { width: 11px; height: 11px; }
.tb kbd { position: absolute; top: 3px; left: 6px; font: 600 10px 'Fredoka', sans-serif; color: #6e7d94; }
.tb.sel { border-color: var(--gold); background: #3a3a2a; }
.tb.poor { opacity: .5; }
.tb.locked { opacity: .45; cursor: default; }
.tb.locked .nm { font-size: 11px; color: var(--muted); text-align: center; }
.tb .lockic { font-size: 22px; height: 44px; display: flex; align-items: center; }
#info { flex: 1; overflow-y: auto; padding: 10px 12px; font-size: 14px; line-height: 1.4; }
#info h3 { margin: 0 0 6px; font-size: 17px; font-weight: 600; display: flex; align-items: center; gap: 8px; }
#info .theme { font-size: 12px; padding: 2px 8px; border-radius: 99px; background: #34425a; color: #cfd8dc; font-weight: 500; }
#info .theme.boss { background: #6a3a7a; }
.wlist { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0 10px; }
.went { display: flex; align-items: center; gap: 4px; padding: 2px 8px 2px 2px; background: rgba(0,0,0,.2); border-radius: 99px; font-size: 13px; }
.went img { width: 26px; height: 26px; }
.hint { background: #3b3520; border: 1px solid #6b5a1f; color: #ffe9a8; padding: 8px 10px; border-radius: 10px; margin: 0 0 10px; font-size: 13.5px; }
.tip { color: var(--muted); font-size: 13px; border-top: 1px solid var(--line); padding-top: 8px; margin-top: 8px; }
.newfoe { font-size: 13px; color: #ffcc80; margin: -4px 0 8px; }
.thead { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.thead img { width: 46px; height: 46px; }
.thead .tn { flex: 1; }
.thead .tn b { font-size: 17px; display: block; font-weight: 600; }
.thead .tn span { font-size: 12.5px; color: var(--muted); }
.thead .x { width: 30px; height: 30px; border-radius: 8px; border: 1px solid var(--line); background: transparent; color: var(--muted); }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 1px 10px; font-size: 13.5px; margin-bottom: 8px; }
.kv span { color: var(--muted); }
.kv .up { color: #9ccc65; }
.tmodes { display: flex; gap: 4px; margin: 6px 0 8px; }
.tmodes button { flex: 1; padding: 5px 0; border-radius: 8px; border: 1px solid var(--line); background: var(--panel2); font-size: 12px; }
.tmodes button.on { border-color: var(--gold); background: #3a3a2a; }
.upg { width: 100%; text-align: left; display: block; margin-bottom: 6px; padding: 8px 10px; border-radius: 10px; border: 2px solid #6fd27b; background: #2d5532; }
.upg:hover:not(:disabled) { background: #356b3b; }
.upg:disabled { opacity: .5; cursor: default; }
.upg .ut { display: flex; justify-content: space-between; font-weight: 600; }
.upg .ut .cost { color: var(--gold); display: flex; align-items: center; gap: 4px; }
.upg .ud { font-size: 12.5px; color: #c8e6c9; }
.upg.spec { border-color: #b39ddb; background: #3b3156; }
.upg.spec:hover:not(:disabled) { background: #473b69; }
.upg.spec .ud { color: #d1c4e9; }
.sellb { width: 100%; padding: 7px; border-radius: 10px; border: 1px solid #7b3b3a; background: #3a2526; color: #ffcdd2; font-size: 13.5px; }
.sellb:hover { background: #4a2a2b; }
.maxed { text-align: center; color: var(--gold); font-size: 13px; margin: 4px 0 8px; }

/* modal */
#modalBg { position: fixed; inset: 0; z-index: 50; background: rgba(8,12,18,.66); display: flex; align-items: center; justify-content: center; padding: 16px; backdrop-filter: blur(2px); }
#modal { width: min(440px, 100%); max-height: 100%; overflow-y: auto; background: var(--panel); border: 2px solid var(--line); border-radius: 18px; padding: 20px; box-shadow: 0 20px 60px rgba(0,0,0,.5); animation: pop .18s ease-out; }
@keyframes pop { from { transform: scale(.92); opacity: 0; } to { transform: none; opacity: 1; } }
#modal h2 { margin: 0 0 8px; font-size: 26px; text-align: center; font-weight: 600; }
#modal p { margin: 6px 0; text-align: center; color: #cfd8e3; }
#modal .mbtns { display: flex; flex-direction: column; gap: 8px; margin-top: 16px; }
#modal .bigstars { text-align: center; font-size: 46px; letter-spacing: 6px; margin: 4px 0; }
#modal .bigstars span { display: inline-block; color: #4a556a; }
#modal .bigstars span.on { color: var(--gold); animation: star .5s backwards; text-shadow: 0 0 18px rgba(255,201,74,.6); }
@keyframes star { from { transform: scale(2.2) rotate(-30deg); opacity: 0; } to { transform: none; opacity: 1; } }
#modal .reward { text-align: center; font-size: 20px; color: var(--blue); font-weight: 600; margin: 8px 0; }
#modal ul.unl { list-style: none; padding: 0; margin: 10px 0 0; }
#modal ul.unl li { background: #2c3a2a; border: 1px solid #4b6b3f; border-radius: 10px; padding: 7px 10px; margin-top: 6px; display: flex; align-items: center; gap: 8px; }
#modal ul.unl img { width: 30px; height: 30px; }
#modal img.mprev { width: 100%; border-radius: 12px; display: block; margin: 6px 0; }
.setrow { display: flex; justify-content: space-between; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line); }
.switch { width: 52px; height: 30px; border-radius: 99px; border: 2px solid var(--line); background: #2b3548; position: relative; padding: 0; }
.switch::after { content: ''; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #8a97aa; transition: left .15s, background .15s; }
.switch.on { background: #2f5d3a; border-color: #6fd27b; }
.switch.on::after { left: 25px; background: #fff; }
textarea.save { width: 100%; height: 90px; background: #121821; color: var(--text); border: 1px solid var(--line); border-radius: 8px; font: 12px monospace; user-select: text; -webkit-user-select: text; }
.keys { font-size: 13px; color: var(--muted); line-height: 1.7; margin-top: 10px; }
.keys kbd { background: #2b3548; border-radius: 4px; padding: 0 5px; font: 600 12px 'Fredoka', sans-serif; color: var(--text); }

/* toasts */
#toasts { position: fixed; bottom: 14px; left: 50%; transform: translateX(-50%); z-index: 60; display: flex; flex-direction: column-reverse; align-items: center; gap: 6px; pointer-events: none; width: max-content; max-width: 92vw; }
.toast { background: rgba(28,36,50,.95); border: 1px solid #44536d; padding: 8px 14px; border-radius: 12px; font-size: 14.5px; box-shadow: 0 6px 20px rgba(0,0,0,.4); animation: tin .2s ease-out; text-align: center; }
.toast.ach { border-color: var(--gold); background: rgba(58,52,26,.96); }
.toast.cr { border-color: #4fc3f7; }
.toast.out { opacity: 0; transform: translateY(-6px); transition: all .3s; }
@keyframes tin { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* compact landscape (phones) */
@media (max-height: 520px) and (orientation: landscape) {
  #hud { padding: 3px 6px; gap: 4px; }
  #hud button { height: 32px; min-width: 32px; padding: 0 7px; font-size: 13px; }
  #hud button.primary { min-width: 84px; }
  .stat { font-size: 15px; padding: 2px 7px; min-width: 50px; }
  .stat .lbl { display: none; }
  #side { width: 196px; }
  #shop { grid-template-columns: repeat(4, 1fr); gap: 3px; padding: 4px; }
  .tb { padding: 2px 1px 3px; border-radius: 9px; }
  .tb img { width: 30px; height: 30px; }
  .tb .nm { display: none; }
  .tb .cost { font-size: 11px; }
  .tb kbd { display: none; }
  .tb .lockic { height: 30px; }
  #info { padding: 6px 8px; font-size: 12.5px; }
  #info .kv { grid-template-columns: auto 1fr auto 1fr; font-size: 11.5px; gap: 0 6px; margin-bottom: 5px; }
  .thead img { width: 34px; height: 34px; }
  .thead .tn b { font-size: 15px; }
  .tmodes button { font-size: 10.5px; padding: 3px 0; }
  .upg { padding: 5px 8px; }
  .upg .ud { font-size: 11px; }
  #cwrap { padding: 3px; }
}
/* portrait: panel moves below the board */
@media (orientation: portrait) {
  #play { flex-direction: column; }
  #side { width: auto; flex: 1; border-left: 0; border-top: 1px solid var(--line); min-height: 0; }
  #cwrap { flex: none; padding: 4px; }
  #shop { grid-template-columns: repeat(4, 1fr); }
  .tb img { width: 34px; height: 34px; }
  .tb kbd { display: none; }
  .stat { font-size: 15px; min-width: 0; padding: 3px 7px; }
  .stat .lbl { display: none; }
  #hud button { height: 34px; padding: 0 8px; font-size: 14px; }
  #hud button.primary { min-width: 90px; }
}

.gem { display: inline-block; width: 11px; height: 11px; margin: 0 3px 0 2px; transform: rotate(45deg); border-radius: 2px; background: linear-gradient(135deg, #e1f5fe, #4fc3f7 45%, #0277bd); box-shadow: inset 0 0 0 1px rgba(255,255,255,.45), 0 0 6px rgba(79,195,247,.35); vertical-align: 0; }
.lock { vertical-align: -4px; }
.rbadge { flex: none; width: 40px; height: 40px; border-radius: 12px; display: flex; align-items: center; justify-content: center; font-size: 22px; font-weight: 700; color: #fff; box-shadow: inset 0 -3px 0 rgba(0,0,0,.25); }
.spic { font-size: 22px; width: 30px; text-align: center; }
.ach .ico { color: var(--gold); }
