:root {
  --ink: #1d2a55;
  --panel: rgba(22, 32, 72, 0.82);
  --panel-line: rgba(255, 255, 255, 0.14);
  --accent: #ffd34d;
  --accent-ink: #4a3300;
  --sky: #8ec5ff;
  --text: #ffffff;
  --muted: rgba(255, 255, 255, 0.7);
  --radius: 18px;
  font-family: 'Fredoka', system-ui, sans-serif;
}

html, body { margin: 0; height: 100%; overflow: hidden; background: var(--sky); color: var(--text); }
button { font: inherit; color: inherit; }
#scene { display: block; width: 100vw; height: 100vh; touch-action: none; cursor: grab; }

/* ---------- top bar */
#hud {
  position: fixed; top: 16px; left: 16px; right: 16px;
  display: flex; justify-content: space-between; align-items: flex-start; gap: 12px;
  pointer-events: none;
}
.brand, .discovered {
  background: var(--panel); border: 1px solid var(--panel-line); border-radius: var(--radius);
  backdrop-filter: blur(8px); box-shadow: 0 8px 24px rgba(20, 30, 80, 0.25);
}
.brand { display: flex; align-items: center; gap: 12px; padding: 10px 16px 10px 10px; }
.logo {
  display: grid; place-items: center; width: 44px; height: 44px; border-radius: 14px;
  background: var(--accent); color: var(--accent-ink); font-size: 24px; transform: rotate(-8deg);
}
.brand h1 { margin: 0; font-size: 18px; font-weight: 700; }
.brand p { margin: 0; font-size: 12px; color: var(--muted); }
.discovered { padding: 10px 16px; min-width: 130px; text-align: right; }
.discovered .caption { display: block; font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.discovered strong { display: inline-block; font-size: 22px; }
.bar { height: 6px; margin-top: 6px; border-radius: 3px; background: rgba(255, 255, 255, .18); overflow: hidden; }
#progress { height: 100%; width: 0; background: var(--accent); transition: width .5s cubic-bezier(.34, 1.56, .64, 1); }

/* ---------- dock */
#dock { position: fixed; left: 16px; bottom: 16px; display: flex; gap: 8px; }
#dock button {
  display: flex; align-items: center; gap: 8px; padding: 8px 10px 8px 12px; cursor: pointer;
  background: var(--panel); border: 1px solid var(--panel-line); border-radius: 14px;
  backdrop-filter: blur(8px); transition: transform .15s, background .15s;
}
#dock button:hover { transform: translateY(-2px); }
#dock button:active { transform: scale(.94); }
#dock button.active { background: var(--accent); color: var(--accent-ink); }
#dock svg { width: 22px; height: 22px; fill: currentColor; }
#dock .label { font-weight: 600; font-size: 14px; }
#dock .kbd { width: 26px; height: 26px; opacity: .85; }
#dock button.active .kbd { filter: invert(1) brightness(.35); }

/* ---------- panels */
.panel {
  position: fixed; left: 16px; bottom: 76px; width: min(460px, calc(100vw - 32px));
  max-height: calc(100vh - 180px); overflow: auto; padding: 16px;
  background: var(--panel); border: 1px solid var(--panel-line); border-radius: var(--radius);
  backdrop-filter: blur(10px); box-shadow: 0 16px 40px rgba(20, 30, 80, 0.35);
  animation: pop .28s cubic-bezier(.34, 1.56, .64, 1);
  box-sizing: border-box;
}
.panel[hidden] { display: none; }
@keyframes pop { from { opacity: 0; transform: translateY(12px) scale(.96); } }
.panel header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.panel h2 { margin: 0; font-size: 20px; }
.close { background: rgba(255, 255, 255, .12); border: 0; border-radius: 10px; width: 32px; height: 32px; cursor: pointer; }
.close:hover { background: rgba(255, 255, 255, .22); }

.tabs { display: flex; gap: 6px; margin-bottom: 12px; flex-wrap: wrap; }
.tab { background: rgba(255, 255, 255, .1); border: 0; border-radius: 999px; padding: 6px 12px; cursor: pointer; font-size: 13px; font-weight: 600; }
.tab.selected { background: var(--accent); color: var(--accent-ink); }
.tab-page { display: none; }
.tab-page.selected { display: block; }

.control-row { display: flex; align-items: center; gap: 14px; padding: 8px 0; border-top: 1px solid var(--panel-line); }
.control-row:first-child { border-top: 0; }
.visual { display: flex; align-items: center; gap: 6px; flex: 0 0 auto; min-width: 150px; }
.label { font-size: 14px; color: var(--muted); }
.or { font-size: 11px; color: var(--muted); }
.cluster { display: flex; flex-direction: column; align-items: center; }
.cluster > div { display: flex; }
.keycap {
  width: 40px; height: 40px; padding: 0; border: 0; background: none; cursor: pointer;
  border-radius: 8px; transition: transform .08s; touch-action: none;
}
.keycap.wide { width: 56px; }
.keycap img { width: 100%; height: 100%; pointer-events: none; }
.keycap:hover { transform: translateY(-1px); }
.keycap.active, .keycap:active { transform: translateY(2px) scale(.92); filter: drop-shadow(0 0 6px var(--accent)); }
.glyph { display: inline-grid; width: 44px; height: 44px; border-radius: 10px; transition: transform .08s; }
.glyph img { width: 100%; height: 100%; }
.glyph.active { transform: scale(.9); filter: drop-shadow(0 0 6px var(--accent)); }
.chip { padding: 6px 10px; border-radius: 10px; background: var(--accent); color: var(--accent-ink); font-weight: 700; font-size: 12px; }
.pad-status { font-size: 13px; color: var(--muted); margin: 10px 0 0; }
.pad-status.ok { color: #9dffb0; }
.hint { font-size: 12px; color: var(--muted); margin: 12px 0 0; }

.game-grid { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 10px; }
.game-grid a {
  display: block; text-decoration: none; color: inherit; border-radius: 12px; overflow: hidden;
  background: rgba(255, 255, 255, .08); transition: transform .15s;
}
.game-grid a:hover { transform: translateY(-3px) rotate(-1deg); }
.game-grid img { display: block; width: 100%; aspect-ratio: 315 / 250; object-fit: cover; }
.game-grid span { display: block; padding: 6px 8px; }
.game-grid strong { display: block; font-size: 13px; }
.game-grid small { color: var(--muted); }
.game-grid .locked img { filter: grayscale(1) brightness(.6); }
.game-grid .locked small::after { content: ' · locked'; }
.panel { scrollbar-width: thin; scrollbar-color: rgba(255, 255, 255, .3) transparent; }

/* ---------- touch boost */
#touch-boost {
  display: none; position: fixed; right: 20px; bottom: 24px; width: 84px; height: 84px; border-radius: 50%;
  border: 0; background: var(--accent); color: var(--accent-ink); font-weight: 700; letter-spacing: .05em;
  box-shadow: 0 6px 0 #c99a12, 0 10px 24px rgba(20, 30, 80, .35); touch-action: none;
}
#touch-boost:active { transform: translateY(4px); box-shadow: 0 2px 0 #c99a12; }
@media (pointer: coarse) {
  #touch-boost { display: block; }
  .panel { bottom: 124px; max-height: calc(100vh - 210px); }
}

/* ---------- toast, overlays */
#toast {
  position: fixed; top: 90px; left: 50%; transform: translate(-50%, -20px); opacity: 0;
  padding: 10px 18px; border-radius: 999px; background: var(--accent); color: var(--accent-ink);
  font-weight: 700; pointer-events: none; white-space: nowrap;
}
#toast.show { animation: toast 2.6s cubic-bezier(.34, 1.56, .64, 1); }
@keyframes toast {
  0% { opacity: 0; transform: translate(-50%, -20px) scale(.8); }
  12%, 80% { opacity: 1; transform: translate(-50%, 0) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -10px) scale(.95); }
}
#paused { position: fixed; inset: 0; display: grid; place-items: center; background: rgba(30, 50, 120, .35); pointer-events: none; text-align: center; }
#paused[hidden] { display: none; }
#paused strong { display: block; font-size: 40px; }
#paused span { color: var(--muted); }
#loading {
  position: fixed; inset: 0; display: grid; place-content: center; justify-items: center; gap: 14px;
  font-size: 20px; background: var(--sky); transition: opacity .6s;
}
#loading.done { opacity: 0; pointer-events: none; }
.spinner { width: 40px; height: 40px; border-radius: 50%; border: 4px solid rgba(255, 255, 255, .4); border-top-color: #fff; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- small screens */
@media (max-width: 640px) {
  .brand p, .discovered .caption { display: none; }
  .brand h1 { font-size: 15px; }
  #dock .label, #dock .kbd { display: none; }
  .panel { bottom: 72px; max-height: calc(100vh - 160px); }
  .visual { min-width: 110px; }
}
