: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: #22c55e;
  --primary-2: #4ade80;
  --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: #16a34a;
  --primary-2: #15803d;
  --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;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 9px 18px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  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: 16px;
  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;
}

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

.tabs {
  display: flex;
  gap: 6px;
  margin-left: auto;
}

.tab {
  background: transparent;
  color: var(--muted);
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 7px 12px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}

.tab:hover {
  color: var(--text);
}

.tab.active {
  color: var(--text);
  background: var(--panel-2);
  border-color: var(--primary);
}

.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;
}

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

.btn.primary {
  border-color: var(--primary);
  color: var(--primary-2);
}

.mode-btn {
  flex: 1;
}

.mode-row {
  display: flex;
  gap: 6px;
  margin-bottom: 10px;
}

.mode-btn.active {
  border-color: var(--primary);
  background: color-mix(in srgb, var(--primary) 18%, var(--panel-2));
}

.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;
}

.cockpit {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 330px;
  min-height: 0;
}

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

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

#view {
  display: block;
  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-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;
}

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

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

.slider-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--muted);
  margin: 6px 0;
}

.slider-row input[type="range"] {
  flex: 1;
  accent-color: var(--primary);
}

.slider-row b {
  min-width: 52px;
  text-align: right;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

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

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

.log-panel {
  flex: 1;
  min-height: 100px;
  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: 240px;
}

.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;
}

.hidden {
  display: none !important;
}

.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);
}

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

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

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

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

  .subtitle {
    display: none;
  }
}

/* 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;
}
