:root {
  --bg: #191715;
  --bg-2: #211d1c;
  --bg-3: #2a2523;
  --line: #3a3532;
  --text: #F1ECEC;
  --muted: #a49c98;
  --faint: #6f6763;
  --accent: #F5B84E;
  --font-ui: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, "Cascadia Code", "JetBrains Mono", "SF Mono", Menlo, Consolas, monospace;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html,
body {
  height: 100%;
}

body {
  font-family: var(--font-ui);
  background:
    radial-gradient(900px 560px at 50% -10%, #2b2622, transparent 70%),
    var(--bg);
  color: var(--text);
  height: 100dvh;
  display: flex;
  flex-direction: column;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  overflow: hidden;
}

a {
  color: inherit;
  text-decoration: none;
}

button {
  font: inherit;
  border: none;
  cursor: pointer;
  -webkit-user-select: none;
  user-select: none;
}

/* ---------- topbar ---------- */

.topbar {
  width: 100%;
  max-width: 860px;
  margin: 0 auto;
  padding: 14px 16px 4px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.back {
  font-family: var(--font-mono);
  font-size: .82rem;
  color: var(--muted);
  padding: 8px 12px;
  border-radius: 9px;
  border: 1px solid transparent;
  transition: color .15s, border-color .15s, background .15s;
}

.back:hover {
  color: var(--text);
  background: var(--bg-2);
  border-color: var(--line);
}

.topbar h1 {
  font-size: 1.1rem;
  font-weight: 600;
  letter-spacing: .02em;
}

.icon-btn {
  background: var(--bg-2);
  border: 1px solid var(--line);
  color: var(--text);
  width: 38px;
  height: 38px;
  border-radius: 10px;
  font-size: 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: filter .15s, transform .1s;
}

.icon-btn:hover {
  filter: brightness(1.2);
}

.icon-btn:active {
  transform: scale(.94);
}

.select-wrap {
  position: relative;
  display: inline-flex;
  align-items: center;
}

.nav-select {
  appearance: none;
  -webkit-appearance: none;
  font-family: var(--font-mono);
  font-size: .8rem;
  letter-spacing: .02em;
  color: var(--text);
  background:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%23a49c98' stroke-width='1.6' fill='none' stroke-linecap='round'/%3E%3C/svg%3E") no-repeat right 12px center,
    var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 8px 32px 8px 12px;
  cursor: pointer;
  max-width: 190px;
  transition: border-color .15s, filter .15s;
}

.nav-select:hover {
  border-color: var(--faint);
  filter: brightness(1.08);
}

.nav-select:focus-visible {
  outline: 2px dashed var(--accent);
  outline-offset: 3px;
}

.nav-select option {
  background: var(--bg-2);
  color: var(--text);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

@media (max-width: 560px), (max-width: 760px) and (orientation: portrait) {
  .nav-select {
    max-width: 150px;
    font-size: .74rem;
    padding: 7px 28px 7px 10px;
  }
}

/* ---------- layout ---------- */

.layout {
  width: 100%;
  max-width: 860px;
  margin: 0 auto;
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 10px 16px;
}

.panel {
  width: 172px;
  flex: none;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.card {
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px;
}

.card .label {
  font-family: var(--font-mono);
  font-size: .72rem;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--faint);
  margin-bottom: 10px;
}

.stat {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: 7px 2px;
  border-bottom: 1px solid rgba(255, 255, 255, .05);
}

.stat:last-child {
  border-bottom: none;
}

.stat span {
  font-family: var(--font-mono);
  font-size: .74rem;
  color: var(--muted);
}

.stat b {
  font-size: 1.02rem;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}

.stat b.hot {
  color: var(--accent);
}

.mini {
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
}

.mini canvas {
  display: block;
  width: 64px;
  height: 64px;
  background: rgba(255, 255, 255, .03);
  border: 1px solid rgba(255, 255, 255, .05);
  border-radius: 8px;
}

/* ---------- stage ---------- */

.stage {
  position: relative;
  flex: none;
  padding: 10px;
  background: #100e0d;
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, .5), inset 0 0 0 1px rgba(255, 255, 255, .03);
}

#canvas {
  display: block;
  border-radius: 10px;
  touch-action: none;
  background: #0c0a09;
}

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(10, 8, 7, .82);
  backdrop-filter: blur(4px);
  border-radius: 16px;
  padding: 16px;
  z-index: 5;
}

.overlay.hidden {
  display: none;
}

.ov-card {
  text-align: center;
  max-width: 300px;
  padding: 14px;
  border-radius: 14px;
  animation: pop .25s ease;
}

@media (max-width: 560px), (max-height: 560px) {
  .overlay {
    position: fixed;
    inset: var(--site-header-height) 0 0;
    align-items: safe center;
    overflow-y: auto;
    border-radius: 0;
  }

  .embedded-game .overlay { inset-block-start: 0; }
}

@keyframes pop {
  from {
    transform: scale(.92);
    opacity: 0;
  }
}

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

.ov-card h2 {
  font-size: 1.5rem;
  font-weight: 600;
  margin-bottom: 8px;
  color: var(--accent);
}

.ov-card p {
  color: var(--muted);
  font-size: .9rem;
  line-height: 1.55;
  margin-bottom: 18px;
}

.ov-card button {
  background: var(--accent);
  color: #1a1613;
  font-weight: 700;
  padding: 11px 26px;
  border-radius: 12px;
  font-size: .98rem;
  box-shadow: 0 6px 22px rgba(245, 184, 78, .35);
  transition: transform .1s, filter .15s;
}

.ov-card button:hover {
  filter: brightness(1.08);
}

.ov-card button:active {
  transform: scale(.96);
}

.ov-card .hint {
  margin-top: 16px;
  margin-bottom: 0;
  font-family: var(--font-mono);
  font-size: .72rem;
  line-height: 1.7;
  color: var(--faint);
}

/* ---------- touch keys ---------- */

.keys .krow {
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
}

.keys .krow:last-child {
  margin-bottom: 0;
}

.keys button {
  flex: 1;
  min-height: 52px;
  background: var(--bg-3);
  border: 1px solid var(--line);
  border-radius: 11px;
  color: var(--text);
  font-size: 1.15rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform .08s, filter .12s;
}

.keys button:hover {
  filter: brightness(1.18);
}

.keys button:active {
  transform: scale(.94);
  background: var(--line);
}

/* ---------- mobile ---------- */

@media (max-width: 560px), (max-width: 760px) and (orientation: portrait) {
  .topbar {
    padding: 8px 14px 0;
  }

  .layout {
    flex-wrap: wrap;
    gap: 8px;
    padding: 8px 12px;
  }

  .panel {
    width: 100%;
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: center;
  }

  .panel-left {
    order: 1;
  }

  .stage {
    order: 2;
  }

  .panel-right {
    order: 3;
  }

  .panel .card {
    flex: 1 1 0;
    min-width: 0;
    padding: 8px 10px;
  }

  .stats {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 4px;
  }

  .stats .stat {
    flex: 1;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    border: none;
    padding: 2px;
  }

  .stats .stat span {
    font-size: .62rem;
    margin-right: 0;
  }

  .stats .stat b {
    font-size: .85rem;
  }

  .card .label {
    margin-bottom: 8px;
  }

  .mini {
    flex-direction: row;
    gap: 8px;
  }

  .mini canvas {
    width: 40px;
    height: 40px;
  }

  .keys .krow button {
    min-height: 40px;
    font-size: 1.1rem;
  }
}

@media (max-width: 380px) {
  .keys .krow button {
    min-height: 44px;
    font-size: 1.2rem;
  }
}

@media (max-height: 520px) and (orientation: landscape) {
  .topbar {
    padding: 8px 16px 0;
  }

  .panel .mini {
    flex-direction: row;
    gap: 8px;
  }

  .mini canvas {
    width: 40px;
    height: 40px;
  }

  .card .label {
    margin-bottom: 8px;
  }

  .keys .krow button {
    min-height: 40px;
    font-size: 1.1rem;
  }
}

@media (max-height: 560px) and (max-width: 560px), (max-height: 560px) and (orientation: portrait) {
  body {
    height: auto;
    min-height: 100dvh;
    overflow: visible;
  }

  .layout {
    align-items: flex-start;
  }
}
