:root {
  --bg: #0f1020;
  --panel: #191a33;
  --ink: #ece6d6;
  --muted: #9a97b5;
  --gold: #e8b74a;
  --good: #7ad19a;
  --bad: #ff5a5a;
  --pending: #6f6c8c;
}

* { box-sizing: border-box; }

html, body { margin: 0; height: 100%; }

body {
  background: radial-gradient(ellipse at top, #1d1f45 0%, var(--bg) 60%);
  color: var(--ink);
  font-family: Georgia, "Times New Roman", serif;
}

.app {
  max-width: 1000px;
  margin: 0 auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.top h1 {
  margin: 0;
  font-size: 1.8rem;
  color: var(--gold);
  letter-spacing: 0.04em;
}
.top .sub { margin: 4px 0 0; color: var(--muted); }

.sky-wrap {
  position: relative;
  border-radius: 14px;
  overflow: hidden;
  border: 1px solid #2c2d55;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
}
#scene { display: block; width: 100%; height: 300px; }

.flash {
  position: absolute; inset: 0;
  background: rgba(255, 40, 40, 0.45);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.35s ease-out;
}
.flash.on { opacity: 1; transition: none; }

.stats {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 10px;
}
.stat, .results > div {
  background: var(--panel);
  border: 1px solid #2c2d55;
  border-radius: 10px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.label { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }
.value { font-size: 1.6rem; font-variant-numeric: tabular-nums; }
.hits { display: flex; gap: 6px; align-items: center; min-height: 1.9rem; }
.pip {
  width: 16px; height: 16px; border-radius: 50%;
  background: #2c2d55; border: 1px solid #44466f;
}
.pip.hit { background: radial-gradient(circle at 35% 35%, #666, #111); border-color: var(--bad); box-shadow: 0 0 6px var(--bad); }

.typing {
  background: var(--panel);
  border: 1px solid #2c2d55;
  border-radius: 14px;
  padding: 22px 24px;
}
.typing.shake { animation: shake 0.25s; }

.quote {
  margin: 0;
  font-family: "Courier New", Consolas, monospace;
  font-size: 1.6rem;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: normal;
}
.quote span { color: var(--pending); border-radius: 3px; }
.quote span.ok { color: var(--good); }
.quote span.cur { color: var(--ink); background: rgba(232, 183, 74, 0.25); box-shadow: inset 0 -3px 0 var(--gold); }
.quote span.err { color: #fff; background: var(--bad); box-shadow: none; }
.quote.complete span { color: var(--gold); }

.who { margin: 10px 0 0; color: var(--gold); font-style: italic; }
.who::before { content: "- "; }
.hint { margin: 10px 0 0; color: var(--muted); font-size: 0.9rem; }
.hint.warn { color: var(--bad); }

.overlay {
  position: fixed; inset: 0;
  background: rgba(5, 5, 15, 0.75);
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
}
.overlay.hidden { display: none; }
.card {
  background: var(--panel);
  border: 1px solid var(--gold);
  border-radius: 16px;
  padding: 28px;
  max-width: 460px; width: 100%;
  text-align: center;
}
.card h2 { margin: 0 0 6px; color: var(--gold); }
.results { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 18px 0 8px; }
.best { color: var(--gold); min-height: 1.2em; }
.card button {
  font: inherit; font-size: 1.05rem;
  background: var(--gold); color: #1a1406;
  border: 0; border-radius: 10px;
  padding: 10px 20px; cursor: pointer;
}
.card button:hover { filter: brightness(1.1); }

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-6px); }
  75% { transform: translateX(6px); }
}

/* ---------- layout additions ---------- */
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
a { color: var(--gold); }

.top { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.account { display: flex; align-items: center; gap: 8px; }
#who-am-i strong { color: var(--ink); }

.btn {
  font: inherit; font-size: 0.95rem;
  background: var(--gold); color: #1a1406;
  border: 1px solid var(--gold); border-radius: 8px;
  padding: 7px 14px; cursor: pointer;
}
.btn:hover { filter: brightness(1.1); }
.btn.ghost { background: transparent; color: var(--gold); }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid #2c2d55; overflow-x: auto; }
.tabs a {
  padding: 8px 14px; text-decoration: none; color: var(--muted);
  border-bottom: 2px solid transparent; white-space: nowrap;
}
.tabs a.active { color: var(--gold); border-bottom-color: var(--gold); }

.view { display: flex; flex-direction: column; gap: 14px; }
.view > p { margin: 0; }
.panel { background: var(--panel); border: 1px solid #2c2d55; border-radius: 14px; padding: 20px; }
.panel .btn { margin-right: 6px; }
h3 { margin: 8px 0 0; color: var(--gold); font-weight: normal; }

/* ---------- sentence summary ---------- */
.summary { text-align: center; }
.summary h2 { margin: 0 0 14px; color: var(--gold); }
.sum-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.sum-grid > div {
  background: #12132a; border: 1px solid #2c2d55; border-radius: 10px;
  padding: 10px; display: flex; flex-direction: column; align-items: center;
}
.sum-grid .big .value { font-size: 2.4rem; color: var(--gold); }
.unit { font-size: 0.8rem; color: var(--muted); }
.compare { min-height: 1.3em; margin: 14px 0 0; }
.compare .pb { color: var(--good); font-weight: bold; }
.run-line { color: var(--muted); margin: 8px 0 0; }
.run-line strong { color: var(--ink); font-weight: normal; }
.continue { margin: 14px 0 0; color: var(--ink); }
kbd {
  font-family: inherit; background: #2c2d55; border: 1px solid #44466f;
  border-bottom-width: 3px; border-radius: 5px; padding: 1px 7px;
}

/* ---------- leaderboards ---------- */
.boards { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 14px; }
.board { background: var(--panel); border: 1px solid #2c2d55; border-radius: 12px; padding: 14px 16px; }
.board h3 { margin: 0 0 8px; font-size: 1.05rem; }
.board ol { margin: 0; padding: 0; list-style: none; counter-reset: r; }
.board li {
  counter-increment: r; display: flex; gap: 10px; align-items: baseline;
  padding: 5px 0; border-top: 1px solid #24254a;
}
.board li:first-child { border-top: 0; }
.board li::before { content: counter(r); width: 1.4em; color: var(--muted); text-align: right; font-variant-numeric: tabular-nums; }
.board li:nth-child(1)::before { color: var(--gold); }
.board .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.board .name small { display: block; color: var(--muted); font-size: 0.75rem; overflow: hidden; text-overflow: ellipsis; }
.board .score { font-variant-numeric: tabular-nums; color: var(--ink); }
.board .me .name { color: var(--gold); }
.board .empty { color: var(--muted); font-style: italic; }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; background: var(--panel); border: 1px solid #2c2d55; border-radius: 12px; }
.table { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
.table th, .table td { padding: 8px 10px; text-align: left; border-bottom: 1px solid #24254a; vertical-align: top; }
.table th { color: var(--muted); font-weight: normal; font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.06em; white-space: nowrap; }
.table th[data-sort] { cursor: pointer; user-select: none; }
.table th[data-sort]:hover { color: var(--ink); }
.table th.sorted::after { content: " \25BE"; }
.table th.sorted.asc::after { content: " \25B4"; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.table td.sentence { min-width: 260px; }
.table .nowrap { white-space: nowrap; }
.table td.sentence small { display: block; color: var(--muted); }
.table tr:last-child td { border-bottom: 0; }
.diff { display: inline-flex; align-items: center; gap: 6px; }
.diff .bar { width: 50px; height: 6px; background: #2c2d55; border-radius: 3px; overflow: hidden; }
.diff .bar span { display: block; height: 100%; }
.tag { font-size: 0.75rem; padding: 1px 6px; border-radius: 4px; }
.tag.ok { background: rgba(122, 209, 154, 0.15); color: var(--good); }
.tag.bad { background: rgba(255, 90, 90, 0.15); color: var(--bad); }

/* ---------- auth ---------- */
.auth-card { text-align: left; display: flex; flex-direction: column; gap: 12px; max-width: 360px; }
.auth-card h2 { text-align: center; }
.auth-card label { display: flex; flex-direction: column; gap: 4px; color: var(--muted); font-size: 0.9rem; }
.auth-card input {
  font: inherit; font-size: 1rem; color: var(--ink);
  background: #12132a; border: 1px solid #44466f; border-radius: 8px; padding: 9px 10px;
}
.auth-card input:focus { outline: 2px solid var(--gold); outline-offset: 0; }
.auth-card .small { text-align: center; margin: 0; }
.error { color: var(--bad); min-height: 1.2em; margin: 0; font-size: 0.9rem; }

@media (max-width: 640px) {
  .stats { grid-template-columns: repeat(2, 1fr); }
  .sum-grid { grid-template-columns: repeat(2, 1fr); }
  .quote { font-size: 1.2rem; }
  #scene { height: 220px; }
}
