:root {
  --bg: #0b0f19;
  --bg-card: rgba(15, 23, 42, 0.94);
  --border: rgba(255, 255, 255, 0.09);
  --text: #f8fafc;
  --muted: #94a3b8;
  --dim: #64748b;
  --primary: #14b8a6;
  --primary-2: #2dd4bf;
  --danger: #f43f5e;
  --warn: #fbbf24;
  --ok: #34d399;
  --panel: #0f172a;
  --panel-2: #111c30;
  --shadow: 0 8px 30px rgba(0, 0, 0, 0.45);
}

html[data-theme="light"] {
  --bg: #f1f5f9;
  --bg-card: rgba(255, 255, 255, 0.96);
  --border: rgba(15, 23, 42, 0.12);
  --text: #0f172a;
  --muted: #475569;
  --dim: #64748b;
  --primary: #0d9488;
  --primary-2: #0f766e;
  --danger: #e11d48;
  --warn: #b45309;
  --ok: #059669;
  --panel: #ffffff;
  --panel-2: #f8fafc;
  --shadow: 0 8px 30px rgba(15, 23, 42, 0.12);
}

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

html,
body {
  height: 100%;
}

body {
  font-family:
    ui-sans-serif,
    system-ui,
    -apple-system,
    "Segoe UI",
    Roboto,
    sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ------------------------------------------------------------------ header */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 18px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(8px);
  z-index: 5;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-logo {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.brand h1 {
  font-size: 17px;
  font-weight: 800;
  letter-spacing: -0.02em;
  white-space: nowrap;
}

.badge {
  font-size: 10px;
  font-weight: 700;
  color: var(--primary-2);
  border: 1px solid var(--primary);
  border-radius: 999px;
  padding: 2px 8px;
  vertical-align: middle;
  margin-left: 4px;
}

.subtitle {
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

.btn {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 7px 13px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition:
    transform 0.1s,
    border-color 0.15s,
    background 0.15s;
}

.btn:hover {
  border-color: var(--primary);
  transform: translateY(-1px);
}

.btn.muted {
  opacity: 0.55;
}

/* ------------------------------------------------------------------ layout */
.cockpit {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 340px;
  min-height: 0;
}

.stage-wrap {
  position: relative;
  min-width: 0;
  min-height: 0;
  padding: 10px;
}

#pixi-stage {
  position: relative;
  width: 100%;
  height: 100%;
  border-radius: 14px;
  overflow: hidden;
  border: 1px solid var(--border);
  background: #0b0f19;
  display: grid;
  place-items: center;
}

html[data-theme="light"] #pixi-stage {
  background: #f3f6fb;
}

#pixi-stage canvas {
  display: block;
  /* Hard containment guarantee: the map canvas can never exceed the stage */
  max-width: 100%;
  max-height: 100%;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 10px 12px 12px 0;
  overflow-y: auto;
  min-height: 0;
}

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

.panel h2 {
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 10px;
}

.hud-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
  padding: 4px 0;
  border-bottom: 1px dashed var(--border);
}

.hud-row:last-of-type {
  border-bottom: none;
}

.hud-row span {
  color: var(--muted);
}

.hud-row b {
  font-variant-numeric: tabular-nums;
}

.hud-row b.warn {
  color: var(--warn);
}

/* outcome card in the sidebar */
.hud-result {
  margin-top: 10px;
  border-radius: 10px;
  padding: 10px 12px;
  border: 1.5px solid;
  font-size: 13px;
}

.hud-result.win {
  border-color: var(--ok);
  background: color-mix(in srgb, var(--ok) 12%, transparent);
}

.hud-result.fail {
  border-color: var(--danger);
  background: color-mix(in srgb, var(--danger) 12%, transparent);
}

.hud-result-title {
  font-weight: 800;
  font-size: 14px;
}

.hud-result-sub {
  color: var(--muted);
  margin-top: 2px;
}

.hud-result-key {
  margin-top: 6px;
  font-size: 12px;
  color: var(--dim);
}

.hud-result.hidden {
  display: none;
}

/* ------------------------------------------------------------------ controls */
.last-key {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
  color: var(--muted);
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 10px;
  margin-bottom: 10px;
}

.last-key b {
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.ctrl-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin-bottom: 10px;
}

.ctrl {
  height: 42px;
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 16px;
  cursor: pointer;
  transition:
    border-color 0.12s,
    background 0.12s,
    transform 0.08s;
}

.ctrl:hover {
  border-color: var(--primary);
}

.ctrl:active {
  transform: scale(0.95);
}

.ctrl.key-pressed {
  border-color: var(--primary);
  background: color-mix(in srgb, var(--primary) 22%, var(--panel-2));
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--primary) 30%, transparent);
}

.keys {
  list-style: none;
  font-size: 12px;
  color: var(--muted);
  line-height: 1.7;
}

.keys b {
  color: var(--text);
}

/* ------------------------------------------------------------------ log */
.log-panel {
  flex: 1;
  min-height: 120px;
  display: flex;
  flex-direction: column;
}

.log {
  flex: 1;
  overflow-y: auto;
  font-size: 12px;
  font-family: ui-monospace, "Cascadia Code", Menlo, monospace;
  color: var(--muted);
  line-height: 1.6;
  max-height: 300px;
}

/* ------------------------------------------------------------------ toast */
.game-banner {
  position: absolute;
  left: 14px;
  top: 14px;
  z-index: 6;
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: 420px;
  background: var(--bg-card);
  border: 2px solid var(--text);
  border-radius: 14px;
  padding: 12px 16px;
  box-shadow: var(--shadow);
  pointer-events: none;
}

.game-banner.win {
  border-color: var(--ok);
}

.game-banner.fail {
  border-color: var(--danger);
}

.banner-emoji {
  font-size: 30px;
  line-height: 1;
}

.banner-title {
  font-weight: 800;
  font-size: 17px;
}

.game-banner.win .banner-title {
  color: var(--ok);
}

.game-banner.fail .banner-title {
  color: var(--danger);
}

.banner-sub {
  font-size: 12.5px;
  color: var(--text);
  margin-top: 2px;
}

.game-banner.hidden {
  display: none;
}

/* ------------------------------------------------------------------ hintbar */
.hintbar {
  padding: 7px 18px;
  font-size: 12px;
  color: var(--dim);
  border-top: 1px solid var(--border);
  background: var(--bg-card);
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ------------------------------------------------------------------ modal */
.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.modal.hidden {
  display: none;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(2, 6, 23, 0.6);
  backdrop-filter: blur(3px);
}

.modal-card {
  position: relative;
  width: min(680px, 100%);
  max-height: 85vh;
  overflow-y: auto;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 26px 28px;
  box-shadow: var(--shadow);
}

.modal-card h2 {
  font-size: 19px;
  font-weight: 800;
  margin-bottom: 14px;
}

.modal-card h3 {
  font-size: 14px;
  font-weight: 800;
  color: var(--primary-2);
  margin: 16px 0 6px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.modal-card p,
.modal-card li {
  font-size: 13.5px;
  line-height: 1.65;
  color: var(--muted);
}

.modal-card ul {
  padding-left: 18px;
  margin: 6px 0;
}

.modal-card code {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 1px 6px;
  font-size: 12px;
}

.modal-card a {
  color: var(--primary-2);
}

.modal-close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 30px;
  height: 30px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--muted);
  font-size: 13px;
  cursor: pointer;
}

.modal-close:hover {
  color: var(--text);
  border-color: var(--primary);
}

/* ------------------------------------------------------------------ responsive */
@media (max-width: 1024px) {
  .cockpit {
    grid-template-columns: 1fr 290px;
  }
}

@media (max-width: 860px) {
  body {
    overflow: auto;
  }

  .cockpit {
    grid-template-columns: 1fr;
    grid-template-rows: 55vh 1fr;
  }

  .sidebar {
    flex-direction: row;
    flex-wrap: wrap;
    padding: 10px;
    overflow: visible;
  }

  .panel {
    flex: 1;
    min-width: 220px;
  }

  .log-panel {
    min-height: 140px;
  }

  .subtitle {
    display: none;
  }
}

.guide-tabs {
  display: flex;
  gap: 8px;
  margin: 4px 0 16px;
}
.guide-tab {
  flex: 1;
  padding: 8px 10px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text);
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
}
.guide-tab.active {
  border-color: var(--primary);
  background: color-mix(in srgb, var(--primary) 18%, var(--panel-2));
}
.guide-panel h3 {
  margin-top: 18px;
}
.guide-panel p {
  line-height: 1.6;
}
.guide-panel .math {
  text-align: center;
  padding: 8px 0;
}

/* wisesloth.app-style scrollbars */
::-webkit-scrollbar {
  width: 20px;
  height: 20px;
}
::-webkit-scrollbar-track {
  background-color: transparent;
}
::-webkit-scrollbar-button {
  display: none;
  width: 0;
  height: 0;
}
::-webkit-scrollbar-thumb {
  background-color: #d6dee1;
  border-radius: 20px;
  border: 6px solid transparent;
  background-clip: content-box;
}
::-webkit-scrollbar-thumb:hover {
  background-color: #a8bbbf;
}
* {
  scrollbar-width: thin;
  scrollbar-color: #d6dee1 transparent;
}

/* unified theme button + GitHub link (navbar right) */
.theme-btn,
.gh-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  text-decoration: none;
  line-height: 1;
}
.gh-link svg,
.theme-btn svg {
  flex-shrink: 0;
}
.theme-btn .ic-moon {
  display: none;
}
[data-theme="dark"] .theme-btn .ic-sun {
  display: none;
}
[data-theme="dark"] .theme-btn .ic-moon {
  display: block;
}
