/* Gnome Click — 8-bit UI. Colors are tokens; JS shifts a few of them as the story darkens. */
:root {
  --bg: #1b1424;
  --bg2: #241a33;
  --panel: #2d2240;
  --panel2: #3a2d52;
  --ink: #f6f2e6;
  --ink-dim: #b9b0cc;
  --line: #0b0812;
  --accent: #d8343f;
  --accent-hi: #ff6e6e;
  --gold: #ffd23f;
  --good: #4fb848;
  --bad: #ff6e6e;
  --paper: #f6f0dc;
  --paper-ink: #2a2233;
  --shadow: rgba(0, 0, 0, 0.45);
  --font-body: 'Pixelify Sans', 'Fusion Pixel 12px Proportional SC', ui-monospace, monospace;
  --font-display: 'Press Start 2P', 'Pixelify Sans', ui-monospace, monospace;
  --fs: 17px;
  color-scheme: dark;
}
/* Press Start 2P has no Latin Extended (ą ł ś ş ğ ı): use Pixelify for headings in those languages */
html[lang='pl'], html[lang='tr'] { --font-display: 'Pixelify Sans', ui-monospace, monospace; }
html[lang='ja'] { --font-body: 'Fusion Pixel 12px Proportional JP', 'Pixelify Sans', sans-serif; --font-display: 'Fusion Pixel 12px Proportional JP', 'Press Start 2P', sans-serif; }
html[lang='ko'] { --font-body: 'Fusion Pixel 12px Proportional KR', 'Pixelify Sans', sans-serif; --font-display: 'Fusion Pixel 12px Proportional KR', 'Press Start 2P', sans-serif; }
html[lang='zh-Hans'] { --font-body: 'Fusion Pixel 12px Proportional SC', 'Pixelify Sans', sans-serif; --font-display: 'Fusion Pixel 12px Proportional SC', 'Press Start 2P', sans-serif; }

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink); overflow: hidden; max-width: 100vw; }
body {
  font-family: var(--font-body);
  font-size: var(--fs);
  line-height: 1.3;
  -webkit-font-smoothing: none;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; cursor: pointer; }
[hidden] { display: none !important; }
img, canvas { image-rendering: pixelated; image-rendering: crisp-edges; }

.boot { position: fixed; inset: 0; display: grid; place-content: center; text-align: center; background: var(--bg); z-index: 50; }
.boot-logo { font-family: var(--font-display); font-size: 22px; color: var(--accent-hi); text-shadow: 3px 3px 0 var(--line); }
.boot-sub { margin-top: 12px; color: var(--ink-dim); }

/* ---------- layout ---------- */
.app { height: 100dvh; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 10px; padding: 6px 12px;
  background: var(--bg2); border-bottom: 3px solid var(--line);
}
.brand { margin: 0; font-family: var(--font-display); font-size: 13px; color: var(--accent-hi); text-shadow: 2px 2px 0 var(--line); white-space: nowrap; }
.counter { flex: 1; text-align: center; min-width: 0; }
.bank { font-family: var(--font-display); font-size: 18px; color: var(--gold); text-shadow: 2px 2px 0 var(--line); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bank .unit { font-family: var(--font-body); font-size: 14px; color: var(--ink-dim); text-shadow: none; }
.tps { font-size: 14px; color: var(--ink-dim); }
.floorbox { font-family: var(--font-display); font-size: 10px; padding: 6px 8px; background: var(--panel); border: 2px solid var(--line); box-shadow: 2px 2px 0 var(--shadow); white-space: nowrap; }
.floorbox.bump { animation: bump 0.5s; }
@keyframes bump { 30% { transform: scale(1.25); background: var(--gold); color: var(--paper-ink); } }
.topbtns { display: flex; gap: 6px; }
.icon-btn {
  width: 36px; height: 36px; display: grid; place-items: center; font-size: 18px;
  background: var(--panel2); border: 2px solid var(--line); box-shadow: 2px 2px 0 var(--shadow);
}
.icon-btn:active, .btn:active { transform: translate(2px, 2px); box-shadow: none; }
.icon-btn.off { opacity: 0.45; text-decoration: line-through; }
.freebar { background: #4a2030; color: #ffd6d6; font-size: 14px; text-align: center; padding: 3px 8px; border-bottom: 2px solid var(--line); }
.link-btn { background: none; border: none; color: var(--gold); text-decoration: underline; padding: 0 4px; }

.main { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(0, 1fr) 400px; }
.stage { position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 10px; min-height: 0; background: radial-gradient(ellipse at center, var(--bg2), var(--bg)); }
.stage-inner { position: relative; width: min(100%, calc((100dvh - 190px) * 4 / 3)); aspect-ratio: 4 / 3; border: 4px solid var(--line); box-shadow: 6px 6px 0 var(--shadow); background: #000; }
#scene { position: absolute; inset: 0; width: 100%; height: 100%; display: block; transition: filter 3s linear; }
.big-button {
  position: absolute; left: 39%; top: 43%; width: 22%; height: 22%;
  background: transparent; border: none; border-radius: 40% 40% 12% 12%; touch-action: manipulation;
}
.big-button:focus-visible { outline: 3px dashed var(--gold); outline-offset: 2px; }
.press-hint { position: absolute; left: 50%; top: -38%; transform: translateX(-50%); font-family: var(--font-display); font-size: clamp(10px, 1.6vw, 16px); color: var(--gold); text-shadow: 2px 2px 0 var(--line); white-space: nowrap; pointer-events: none; animation: hint 0.9s ease-in-out infinite; }
@keyframes hint { 50% { transform: translateX(-50%) translateY(-25%); } }
.goldmush { position: absolute; width: 11%; aspect-ratio: 1; background: transparent; border: none; padding: 0; touch-action: manipulation; animation: goldbob 1s ease-in-out infinite; transform-origin: center; }
.goldmush img { width: 100%; height: 100%; filter: drop-shadow(0 0 4px #ffd23f); }
.goldmush.fade { animation: goldbob 1s ease-in-out infinite, goldfade 1.5s linear infinite; }
@keyframes goldbob { 50% { transform: translateY(-6%) rotate(6deg) scale(1.06); } }
@keyframes goldfade { 50% { opacity: 0.35; } }
.floaters { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.floater { position: absolute; font-family: var(--font-display); font-size: clamp(10px, 1.4vw, 15px); color: #fff; text-shadow: 2px 2px 0 var(--line), -1px -1px 0 var(--line); white-space: nowrap; animation: floatup 0.9s ease-out forwards; transform: translate(-50%, -50%); }
.floater.fever { color: var(--gold); font-size: clamp(12px, 1.8vw, 19px); }
.floater.big { color: var(--gold); font-size: clamp(13px, 2vw, 22px); animation-duration: 1.8s; }
@keyframes floatup { to { transform: translate(-50%, -260%); opacity: 0; } }

.bubble {
  position: absolute; top: 4%; left: 50%; transform: translateX(-50%); width: min(88%, 520px);
  background: var(--paper); color: var(--paper-ink); border: 3px solid var(--line); padding: 8px 12px; font-size: 16px;
  box-shadow: 4px 4px 0 var(--shadow); cursor: pointer; animation: pop 0.25s;
}
.bubble b { display: block; font-family: var(--font-display); font-size: 9px; margin-bottom: 4px; color: var(--accent); }
@keyframes pop { from { transform: translateX(-50%) scale(0.85); opacity: 0; } }
.banner { position: absolute; top: 0; left: 0; right: 0; background: rgba(11, 8, 18, 0.85); color: #ffe28a; font-family: var(--font-display); font-size: 10px; padding: 6px 10px; border-bottom: 2px solid var(--line); line-height: 1.6; animation: slidedown 0.3s; cursor: pointer; }
.banner .src { color: var(--ink-dim); margin-right: 6px; }
@keyframes slidedown { from { transform: translateY(-100%); } }

.challenge { position: absolute; left: 50%; bottom: 3%; transform: translateX(-50%); width: min(92%, 500px); background: var(--panel); border: 3px solid var(--line); box-shadow: 4px 4px 0 var(--shadow); padding: 8px 10px; font-size: 15px; animation: pop 0.25s; }
.challenge h3 { margin: 0 0 4px; font-family: var(--font-display); font-size: 10px; color: var(--gold); }
.challenge .row { display: flex; gap: 8px; margin-top: 6px; }
.challenge .bar { height: 10px; background: var(--line); margin-top: 6px; }
.challenge .bar i { display: block; height: 100%; background: var(--gold); }

.heat { position: relative; width: min(100%, calc((100dvh - 190px) * 4 / 3)); height: 18px; margin-top: 8px; background: var(--line); border: 2px solid var(--line); }
.heat-fill { position: absolute; inset: 0; width: 0%; background: linear-gradient(90deg, #f08a3e, #d8343f); transition: width 0.12s linear; }
.heat.fever .heat-fill { background: repeating-linear-gradient(90deg, #ffd23f 0 8px, #f08a3e 8px 16px); animation: feverbar 0.4s linear infinite; }
.heat.cool .heat-fill { background: #62d4f6; }
@keyframes feverbar { to { background-position: 16px 0; } }
#heatLabel { position: absolute; inset: 0; display: grid; place-items: center; font-family: var(--font-display); font-size: 9px; text-shadow: 1px 1px 0 var(--line); }
.buffs { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; margin-top: 6px; min-height: 22px; }
.buff { font-size: 13px; padding: 2px 8px; background: var(--panel2); border: 2px solid var(--line); }
.buff.frenzy { background: #6a5410; color: var(--gold); }
.buff.storm { background: #4a1a50; color: #f2b6ff; }
.buff.boss { background: #173a50; color: #a8ecff; }

/* ---------- panel ---------- */
.panel { display: flex; flex-direction: column; min-height: 0; min-width: 0; background: var(--panel); border-left: 3px solid var(--line); }
.tabs { display: flex; flex-wrap: wrap; min-width: 0; background: var(--bg2); border-bottom: 3px solid var(--line); }
.tabs::-webkit-scrollbar { display: none; }
.tabs button { flex: 1 0 auto; padding: 9px 8px 7px; background: none; border: none; border-right: 2px solid var(--line); border-bottom: 2px solid var(--line); margin-bottom: -2px; font-size: 15px; color: var(--ink-dim); white-space: nowrap; position: relative; }
.tabs button.active { background: var(--panel); color: var(--ink); box-shadow: inset 0 -3px 0 var(--accent); }
.tabs .badge { display: inline-block; min-width: 18px; padding: 0 4px; margin-left: 4px; background: var(--accent); color: #fff; font-size: 12px; line-height: 18px; }
.tabs .badge:empty { display: none; }
.tab-body { flex: 1; min-height: 0; overflow-y: auto; padding: 10px; scrollbar-color: var(--panel2) var(--panel); }
.pane { display: none; }
.pane.active { display: block; }
.pane h2 { font-family: var(--font-display); font-size: 11px; margin: 4px 0 10px; color: var(--gold); line-height: 1.5; }
.pane p { margin: 6px 0; }
.muted { color: var(--ink-dim); font-size: 15px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 8px 14px; min-height: 40px;
  background: var(--panel2); border: 3px solid var(--line); box-shadow: 3px 3px 0 var(--shadow); font-size: 16px;
}
.btn.primary { background: var(--accent); color: #fff; }
.btn.gold { background: var(--gold); color: var(--paper-ink); }
.btn.small { padding: 4px 10px; min-height: 32px; font-size: 14px; }
.btn[disabled] { opacity: 0.5; cursor: not-allowed; }
.seg { display: flex; gap: 0; margin-bottom: 8px; }
.seg button { flex: 1; padding: 6px 4px; background: var(--panel2); border: 2px solid var(--line); margin-right: -2px; font-size: 14px; }
.seg button.active { background: var(--accent); color: #fff; }

.row-item {
  width: 100%; display: grid; grid-template-columns: 42px 1fr auto; gap: 8px; align-items: center; text-align: left;
  padding: 6px 8px; margin-bottom: 6px; background: var(--panel2); border: 3px solid var(--line); box-shadow: 3px 3px 0 var(--shadow);
}
.row-item:active { transform: translate(2px, 2px); box-shadow: none; }
.row-item.cant { opacity: 0.55; }
.row-item.locked { opacity: 0.4; cursor: default; }
.row-item img { width: 42px; height: 42px; }
.row-item .nm { font-size: 16px; }
.row-item .sub { font-size: 13px; color: var(--ink-dim); }
.row-item .right { text-align: right; }
.row-item .cost { font-size: 15px; color: var(--gold); white-space: nowrap; }
.row-item .cant-cost { color: var(--bad); }
.row-item .own { font-family: var(--font-display); font-size: 14px; }

.upg-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(52px, 1fr)); gap: 6px; }
.upg {
  position: relative; aspect-ratio: 1; padding: 4px; background: var(--panel2); border: 3px solid var(--line); box-shadow: 2px 2px 0 var(--shadow);
}
.upg img { width: 100%; height: 100%; }
.upg.cant { opacity: 0.5; }
.upg.sel { border-color: var(--gold); }
.upg .pip { position: absolute; left: 2px; right: 2px; bottom: 2px; height: 6px; }
.upg-detail { min-height: 96px; padding: 8px; margin-bottom: 10px; background: var(--bg2); border: 3px solid var(--line); }
.upg-detail .nm { font-size: 17px; color: var(--gold); }
.upg-detail .desc { font-size: 15px; margin: 4px 0 8px; }

.trophy-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(36px, 1fr)); gap: 4px; }
.trophy { aspect-ratio: 1; display: grid; place-items: center; font-size: 18px; background: var(--panel2); border: 2px solid var(--line); padding: 0; }
.trophy.got { background: #5a4510; }
.trophy.secret:not(.got) { background: #2a2235; }

.kv { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; font-size: 15px; }
.kv span:nth-child(even) { text-align: right; color: var(--gold); }
.card { padding: 10px; margin-bottom: 10px; background: var(--panel2); border: 3px solid var(--line); box-shadow: 3px 3px 0 var(--shadow); }
.keepsake { display: flex; gap: 8px; align-items: flex-start; padding: 6px 0; border-bottom: 2px dashed var(--line); font-size: 15px; }
.keepsake.locked { opacity: 0.45; }
.keepsake .ks-ico { font-size: 18px; width: 24px; text-align: center; }

.rank-list { list-style: none; padding: 0; margin: 0; }
.rank-list li { display: grid; grid-template-columns: 42px 1fr auto; gap: 6px; padding: 5px 4px; border-bottom: 2px solid var(--line); font-size: 15px; }
.rank-list li.me { background: #3a2d10; }
.rank-list .cc { font-size: 11px; color: var(--ink-dim); margin-left: 4px; }
.rank-list .esc { font-size: 11px; color: var(--good); margin-left: 4px; }

.journal-entry { padding: 8px 10px; margin-bottom: 8px; border: 3px solid var(--line); background: var(--paper); color: var(--paper-ink); white-space: pre-line; font-size: 15px; }
.journal-entry b { display: block; font-family: var(--font-display); font-size: 8px; color: var(--accent); margin-bottom: 4px; }
.journal-entry.fake { background: #e8edf2; font-family: var(--font-body); }

/* ---------- ads ---------- */
.adbar { min-height: 54px; display: flex; align-items: center; justify-content: center; gap: 10px; padding: 4px 10px; background: #120d1a; border-top: 3px solid var(--line); font-size: 14px; }
.adbar .adtag { font-size: 10px; color: var(--ink-dim); border: 1px solid var(--ink-dim); padding: 0 3px; }
.adbar .house { display: flex; align-items: center; gap: 10px; max-width: 728px; width: 100%; justify-content: center; text-align: center; }

/* ---------- modal ---------- */
.modal { position: fixed; inset: 0; z-index: 30; display: grid; place-items: center; padding: 12px; background: rgba(5, 3, 10, 0.72); animation: fadein 0.2s; }
@keyframes fadein { from { opacity: 0; } }
.modal-card { position: relative; width: min(100%, 640px); max-height: calc(100dvh - 24px); overflow-y: auto; background: var(--panel); border: 4px solid var(--line); box-shadow: 8px 8px 0 var(--shadow); padding: 16px; }
.modal-card.wide { width: min(100%, 900px); }
.modal-card h2 { font-family: var(--font-display); font-size: 13px; margin: 0 0 12px; color: var(--gold); line-height: 1.5; }
.modal-card .actions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: flex-end; margin-top: 14px; }
.modal-x { position: absolute; top: 8px; right: 8px; }
.story-card { display: grid; grid-template-columns: 96px 1fr; gap: 14px; align-items: start; }
.story-card canvas { width: 96px; height: auto; }
.story-text { white-space: pre-line; font-size: 18px; line-height: 1.4; }
.who { font-family: var(--font-display); font-size: 10px; color: var(--accent-hi); margin-bottom: 6px; }
.letter { background: var(--paper); color: var(--paper-ink); padding: 18px 20px; border: 3px solid var(--line); white-space: pre-line; font-size: 18px; line-height: 1.45; box-shadow: inset 0 0 0 4px #efe4c0; }
.letter.fake { background: #eef2f6; box-shadow: inset 0 0 0 4px #d5dde6; font-size: 17px; }
.letter .drawing { float: right; width: 96px; margin: 0 0 8px 10px; border: 2px solid #c9b98a; background: #fff; }
.memo { background: #fff6a8; color: #3a3010; padding: 16px; border: 3px solid var(--line); white-space: pre-line; transform: rotate(-1deg); font-size: 18px; }
.note { background: #e9e2d0; color: #3a3328; padding: 16px; border: 3px solid var(--line); white-space: pre-line; font-size: 18px; transform: rotate(1deg); }
.poster { background: #14244a; color: #fff; padding: 18px; border: 4px solid #0b0812; white-space: pre-line; text-align: center; font-size: 18px; }
.glitchy { animation: glitch 0.3s steps(2) 3; }
@keyframes glitch { 33% { transform: translate(-3px, 1px); filter: hue-rotate(90deg); } 66% { transform: translate(3px, -1px); filter: invert(1); } }

.field { display: flex; flex-direction: column; gap: 4px; margin: 10px 0; }
.field label { font-size: 14px; color: var(--ink-dim); }
.field input, .field select {
  font: inherit; font-size: 18px; padding: 8px 10px; background: var(--paper); color: var(--paper-ink); border: 3px solid var(--line);
}
.err { color: var(--bad); font-size: 15px; min-height: 20px; }
.toggle-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 8px 0; border-bottom: 2px dashed var(--line); }
.toggle-row input[type='range'] { width: 50%; accent-color: var(--accent); }

/* comic */
.comic { display: grid; gap: 12px; }
.panel-c { position: relative; border: 4px solid var(--line); background: #000; }
.panel-c canvas { width: min(100%, calc(50dvh * 1.6)); height: auto; aspect-ratio: 16 / 10; display: block; margin: 0 auto; }
.panel-c .cap { position: absolute; left: 0; top: 0; background: var(--gold); color: var(--paper-ink); font-family: var(--font-display); font-size: 9px; padding: 5px 7px; border: 0 solid var(--line); border-width: 0 3px 3px 0; line-height: 1.5; max-width: 80%; }
.panel-c .speech { background: var(--paper); color: var(--paper-ink); border-top: 3px solid var(--line); padding: 10px 12px; font-size: 17px; }
.comic-nav { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.dots { display: flex; gap: 6px; }
.dots i { width: 10px; height: 10px; background: var(--panel2); border: 2px solid var(--line); }
.dots i.on { background: var(--gold); }

/* toasts */
.toasts { position: fixed; top: 58px; right: 10px; z-index: 40; display: flex; flex-direction: column; gap: 6px; pointer-events: none; max-width: min(360px, calc(100vw - 20px)); }
.toast { pointer-events: auto; background: var(--panel); border: 3px solid var(--line); box-shadow: 3px 3px 0 var(--shadow); padding: 8px 10px; font-size: 15px; animation: toastin 0.25s; display: flex; gap: 8px; align-items: center; }
.toast.toast-gold { border-color: var(--gold); }
.toast.out { animation: toastout 0.3s forwards; }
@keyframes toastin { from { transform: translateX(110%); } }
@keyframes toastout { to { transform: translateX(110%); opacity: 0; } }

/* ---------- mobile ---------- */
@media (max-width: 899px) {
  :root { --fs: 16px; }
  .main { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr); }
  .tabs { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
  .stage { padding: 6px 6px 4px; }
  .stage-inner { width: min(100%, calc(42dvh * 4 / 3)); }
  .heat { width: min(100%, calc(42dvh * 4 / 3)); height: 14px; margin-top: 5px; }
  .buffs { min-height: 0; margin-top: 4px; }
  .panel { border-left: none; border-top: 3px solid var(--line); }
  .brand { display: none; }
  .bank { font-size: 15px; }
  .floorbox { font-size: 9px; padding: 5px 6px; }
  .tabs button { font-size: 14px; padding: 8px 9px 7px; }
  .adbar { min-height: 50px; }
  .story-card { grid-template-columns: 64px 1fr; }
  .story-card canvas { width: 64px; }
  .toasts { top: auto; bottom: 64px; }
}
@media (prefers-reduced-motion: reduce) {
  .floater, .goldmush, .bubble, .banner, .toast, .floorbox.bump { animation-duration: 0.01s !important; }
}
