:root {
  --bg: #0f172a;
  --card: #1e293b;
  --card-2: #273449;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --accent: #38bdf8;
  --accent-2: #f472b6;
  --good: #4ade80;
  --warn: #facc15;
  --bad: #f87171;
  --border: #334155;
}
:root[data-theme="light"] {
  --bg: #f8fafc;
  --card: #ffffff;
  --card-2: #eef2f7;
  --text: #0f172a;
  --muted: #475569;
  --accent: #0284c7;
  --accent-2: #db2777;
  --good: #16a34a;
  --warn: #ca8a04;
  --bad: #dc2626;
  --border: #cbd5e1;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  transition: background .3s, color .3s;
}
a { color: var(--accent); }
code, .mono { font-family: ui-monospace, "Cascadia Code", Consolas, monospace; }

/* ---------- Header / Navigation ---------- */
header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.header-inner {
  max-width: 960px;
  margin: 0 auto;
  padding: .9rem 1rem;
  display: flex;
  align-items: center;
  gap: 1rem;
}
.logo { font-weight: 700; font-size: 1.2rem; text-decoration: none; color: var(--text); margin-right: auto; }
.logo span { color: var(--accent); }
nav { display: flex; gap: .3rem; }
nav a {
  color: var(--muted);
  text-decoration: none;
  padding: .35rem .7rem;
  border-radius: 6px;
}
nav a:hover { color: var(--accent); }
nav a.active { color: var(--accent); background: var(--card); }
.icon-btn {
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--text);
  width: 38px; height: 38px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 1.1rem;
  flex-shrink: 0;
}
#menu-btn { display: none; }

@media (max-width: 700px) {
  #menu-btn { display: block; }
  nav {
    display: none;
    position: absolute;
    top: 100%; left: 0; right: 0;
    flex-direction: column;
    background: var(--bg);
    border-bottom: 1px solid var(--border);
    padding: .5rem 1rem 1rem;
  }
  nav.open { display: flex; }
}

/* ---------- Layout ---------- */
main {
  flex: 1;
  max-width: 960px;
  width: 100%;
  margin: 0 auto;
  padding: 2.5rem 1rem 3rem;
}
section + section { margin-top: 3rem; }
h1 { font-size: clamp(2rem, 6vw, 3.2rem); line-height: 1.15; margin-bottom: 1rem; }
h1 span, h2 span { color: var(--accent); }
h2 { font-size: 1.5rem; margin-bottom: 1rem; }
.lead { color: var(--muted); font-size: 1.15rem; max-width: 620px; }
.muted { color: var(--muted); }

.button {
  display: inline-block;
  padding: .7rem 1.3rem;
  background: var(--accent);
  color: var(--bg);
  border: none;
  border-radius: 8px;
  text-decoration: none;
  font-weight: 600;
  font-size: 1rem;
  cursor: pointer;
  transition: transform .15s, opacity .15s;
}
.button:hover { transform: translateY(-2px); }
.button:active { transform: translateY(0); }
.button.ghost { background: transparent; color: var(--accent); border: 1px solid var(--accent); }
.buttons { display: flex; flex-wrap: wrap; gap: .7rem; margin-top: 1.6rem; }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 1rem;
}
.card {
  background: var(--card);
  border: 1px solid var(--border);
  padding: 1.4rem;
  border-radius: 12px;
  transition: transform .2s, border-color .2s;
}
a.card { text-decoration: none; color: var(--text); display: block; }
a.card:hover { transform: translateY(-4px); border-color: var(--accent); }
.card h3 { font-size: 1.1rem; margin-bottom: .4rem; }
.card p { color: var(--muted); font-size: .95rem; }
.emoji { font-size: 1.8rem; margin-bottom: .5rem; }

/* ---------- Stats ---------- */
.stat-label { color: var(--muted); font-size: .85rem; }
.stat-value { font-size: 1.8rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.dot {
  display: inline-block;
  width: 10px; height: 10px;
  border-radius: 50%;
  background: var(--good);
  margin-right: .4rem;
  box-shadow: 0 0 0 0 var(--good);
  animation: pulse 2s infinite;
}
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--good) 70%, transparent); }
  70% { box-shadow: 0 0 0 10px transparent; }
  100% { box-shadow: 0 0 0 0 transparent; }
}

/* ---------- Typewriter ---------- */
.cursor { display: inline-block; width: 3px; background: var(--accent); margin-left: 2px; animation: blink 1s steps(1) infinite; }
@keyframes blink { 50% { opacity: 0; } }

/* ---------- Terminal ---------- */
.terminal {
  background: #020617;
  color: #cbd5e1;
  border-radius: 12px;
  border: 1px solid var(--border);
  overflow: hidden;
  font-family: ui-monospace, "Cascadia Code", Consolas, monospace;
  font-size: .9rem;
}
.terminal-bar { background: #1e293b; padding: .5rem .8rem; display: flex; gap: .4rem; align-items: center; }
.terminal-bar i { width: 11px; height: 11px; border-radius: 50%; display: inline-block; }
.terminal-bar i:nth-child(1) { background: #f87171; }
.terminal-bar i:nth-child(2) { background: #facc15; }
.terminal-bar i:nth-child(3) { background: #4ade80; }
.terminal-bar span { margin-left: .6rem; color: #94a3b8; font-size: .8rem; }
.terminal-body { padding: 1rem; min-height: 260px; max-height: 360px; overflow-y: auto; white-space: pre-wrap; word-break: break-word; }
.terminal-body .p { color: #4ade80; }
.terminal-body .c { color: #38bdf8; }
.terminal-input { display: flex; align-items: center; padding: 0 1rem 1rem; }
.terminal-input label { color: #4ade80; margin-right: .5rem; white-space: nowrap; }
.terminal-input input {
  flex: 1; min-width: 0;
  background: transparent; border: none; outline: none;
  color: #e2e8f0; font: inherit;
}

/* ---------- Forms ---------- */
input[type="text"], input[type="number"], textarea, select {
  width: 100%;
  background: var(--card-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: .6rem .8rem;
  border-radius: 8px;
  font: inherit;
}
textarea { resize: vertical; min-height: 90px; }
input[type="range"] { width: 100%; accent-color: var(--accent); }
.row { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; }
.output {
  background: var(--card-2);
  border-radius: 8px;
  padding: .7rem .9rem;
  margin-top: .8rem;
  font-family: ui-monospace, "Cascadia Code", Consolas, monospace;
  word-break: break-all;
  min-height: 2.8rem;
}

/* ---------- Bars ---------- */
.bar-row { margin-bottom: .9rem; }
.bar-row .row { justify-content: space-between; font-size: .9rem; }
.bar { height: 10px; background: var(--card-2); border-radius: 99px; overflow: hidden; margin-top: .3rem; }
.bar > div { height: 100%; background: var(--accent); border-radius: 99px; width: 0; transition: width 1.2s ease-out; }

/* ---------- Game ---------- */
.game-wrap { display: flex; flex-direction: column; align-items: center; gap: 1rem; }
#game {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  width: 100%;
  max-width: 420px;
  aspect-ratio: 1;
  touch-action: none;
}
.dpad { display: grid; grid-template-columns: repeat(3, 56px); gap: .4rem; }
.dpad button { height: 56px; font-size: 1.3rem; }
.dpad .up { grid-column: 2; }
.dpad .left { grid-column: 1; grid-row: 2; }
.dpad .down { grid-column: 2; grid-row: 2; }
.dpad .right { grid-column: 3; grid-row: 2; }

/* ---------- Toast ---------- */
#toast {
  position: fixed;
  left: 50%; bottom: 1.5rem;
  transform: translate(-50%, 150%);
  background: var(--accent);
  color: var(--bg);
  padding: .7rem 1.2rem;
  border-radius: 8px;
  font-weight: 600;
  transition: transform .3s;
  z-index: 50;
  max-width: calc(100% - 2rem);
  text-align: center;
}
#toast.show { transform: translate(-50%, 0); }

/* ---------- Reveal on scroll ---------- */
.reveal { opacity: 0; transform: translateY(20px); transition: opacity .6s, transform .6s; }
.reveal.visible { opacity: 1; transform: none; }

/* ---------- Party mode (Konami) ---------- */
body.party { animation: hue 3s linear infinite; }
@keyframes hue { to { filter: hue-rotate(360deg); } }

footer {
  text-align: center;
  padding: 1.5rem 1rem;
  color: var(--muted);
  font-size: .85rem;
  border-top: 1px solid var(--border);
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
  .reveal { opacity: 1; transform: none; }
}
