:root {
  --bg: #0d0f17;
  --panel: #161a26;
  --panel2: #1e2333;
  --line: #2b3247;
  --text: #e7eaf3;
  --dim: #8b93ab;
  --accent: #ffcc33;
  --good: #4ade80;
  --bad: #ff5d6c;
  --blue: #5ab4ff;
  --mono: 'JetBrains Mono', ui-monospace, monospace;
  --display: 'Chakra Petch', system-ui, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font-family: system-ui, -apple-system, Segoe UI, sans-serif; }
body { min-height: 100vh; background: radial-gradient(1200px 600px at 50% -10%, #1d2340 0%, var(--bg) 60%); }
button, input, textarea { font: inherit; color: inherit; }
button {
  background: var(--accent); color: #1a1400; border: 0; border-radius: 10px; padding: 10px 18px;
  font-family: var(--display); font-weight: 700; letter-spacing: .5px; cursor: pointer; transition: transform .08s, filter .15s;
}
button:hover { filter: brightness(1.08); }
button:active { transform: translateY(1px); }
button.ghost { background: transparent; color: var(--text); border: 1px solid var(--line); }
button.small { padding: 5px 10px; font-size: 13px; border-radius: 8px; }
button:disabled { opacity: .45; cursor: not-allowed; }
input, textarea {
  background: var(--panel2); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; outline: none;
}
input:focus, textarea:focus { border-color: var(--accent); }

.top { display: flex; align-items: center; justify-content: space-between; padding: 12px 20px; max-width: 1200px; margin: 0 auto; gap: 12px; }
.logo { font-family: var(--display); font-weight: 700; font-size: 26px; letter-spacing: 2px; }
.logo span { color: var(--accent); }
#topinfo { color: var(--dim); font-size: 14px; display: flex; gap: 14px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }
#topinfo b { color: var(--text); }
main { max-width: 1200px; margin: 0 auto; padding: 0 16px 120px; }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 20px; }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 760px) { .grid2 { grid-template-columns: 1fr; } }
.dim { color: var(--dim); }
.center { text-align: center; }
h1, h2, h3 { font-family: var(--display); margin: 0 0 10px; letter-spacing: .5px; }
h1 { font-size: 34px; }
.phase-title { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; margin: 8px 0 14px; flex-wrap: wrap; }
.timer { font-family: var(--mono); font-size: 22px; color: var(--accent); }
.timer.low { color: var(--bad); }
.tag { display: inline-block; padding: 2px 8px; border-radius: 999px; background: var(--panel2); border: 1px solid var(--line); font-size: 12px; color: var(--dim); }
.tag.gold { color: var(--accent); border-color: #6b5714; }
.tag.good { color: var(--good); border-color: #1f5c38; }

/* home */
.hero { max-width: 560px; margin: 40px auto; text-align: center; }
.hero p { color: var(--dim); line-height: 1.5; }
.hero .panel { text-align: left; display: grid; gap: 14px; margin-top: 24px; }
.steps { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 18px; }
.steps div { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 12px; font-size: 14px; color: var(--dim); }
.steps b { display: block; color: var(--text); font-family: var(--display); font-size: 16px; margin-bottom: 4px; }
@media (max-width: 560px) { .steps { grid-template-columns: 1fr; } }

/* lobby */
.players { display: grid; gap: 8px; }
.player { display: flex; align-items: center; gap: 10px; background: var(--panel2); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; }
.player .dot { width: 12px; height: 12px; border-radius: 50%; flex: none; }
.player .name { font-weight: 600; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.code { font-family: var(--mono); font-size: 32px; letter-spacing: 6px; color: var(--accent); }

/* race */
.passage { font-family: var(--mono); font-size: 22px; line-height: 1.7; padding: 18px 20px; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; user-select: none; word-break: break-word; }
@media (max-width: 600px) { .passage { font-size: 17px; } }
.passage .done { color: var(--good); }
.passage .cur { background: var(--accent); color: #111; border-radius: 3px; }
.passage .cur.err { background: var(--bad); color: #fff; }
.passage .todo { color: #c5cbe0; opacity: .75; }
.typebox { width: 100%; margin-top: 12px; font-family: var(--mono); font-size: 18px; }
.typebox.shake { animation: shake .18s; border-color: var(--bad); }
@keyframes shake { 25% { transform: translateX(-4px); } 75% { transform: translateX(4px); } }
.tracks { display: grid; gap: 8px; margin: 14px 0; }
.track { position: relative; height: 36px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.track .fill { position: absolute; inset: 0 auto 0 0; opacity: .18; transition: width .2s linear; }
.track .bot { position: absolute; top: 4px; transition: left .2s linear; font-size: 22px; line-height: 26px; transform: translateX(-50%); }
.track .label { position: absolute; left: 10px; top: 8px; font-size: 13px; color: var(--dim); z-index: 1; }
.track .flag { position: absolute; right: 8px; top: 6px; }
.stats { display: flex; gap: 18px; font-family: var(--mono); color: var(--dim); }
.stats b { color: var(--text); font-size: 20px; }
.countdown-big { font-family: var(--display); font-size: 120px; text-align: center; color: var(--accent); margin: 40px 0; }

table.results { width: 100%; border-collapse: collapse; font-size: 15px; }
table.results th, table.results td { padding: 10px 8px; border-bottom: 1px solid var(--line); text-align: left; }
table.results th { color: var(--dim); font-weight: 500; font-size: 13px; }
table.results td.num { font-family: var(--mono); }
.tokens { color: var(--accent); font-family: var(--mono); font-weight: 600; }

/* build */
.prompt-area { width: 100%; min-height: 110px; resize: vertical; font-size: 18px; line-height: 1.4; }
.wordcount { font-family: var(--mono); color: var(--dim); }
.wordcount.over { color: var(--bad); }
.catalog { font-size: 13px; color: var(--dim); display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 4px 14px; margin-top: 8px; }
.catalog b { color: var(--text); font-weight: 600; }
.catalog .cost { color: var(--accent); font-family: var(--mono); }
.examples { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.examples button { font-family: inherit; font-weight: 400; font-size: 13px; }
details summary { cursor: pointer; color: var(--dim); }

/* robot card */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 14px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 14px; position: relative; }
.card canvas { width: 100%; height: 180px; display: block; background: #0a0c13; border-radius: 10px; }
.card h3 { margin: 10px 0 2px; }
.card .quote { font-style: italic; color: var(--dim); font-size: 14px; margin: 4px 0 8px; }
.parts { display: flex; flex-wrap: wrap; gap: 5px; }
.parts .tag { color: var(--text); }
.card .announce { color: var(--accent); font-family: var(--display); font-size: 15px; margin-top: 8px; }
.card .dropped { color: var(--bad); font-size: 12px; margin-top: 6px; }
.card .prompt { font-size: 13px; color: var(--dim); margin-top: 6px; border-left: 2px solid var(--line); padding-left: 8px; }
.spinner { width: 34px; height: 34px; border: 4px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.8s linear infinite; margin: 20px auto; }
@keyframes spin { to { transform: rotate(360deg); } }

/* fight */
.arena-wrap { position: relative; }
#arena { width: 100%; max-width: calc((100vh - 230px) * 1.6); margin: 0 auto; aspect-ratio: 960 / 600; display: block; background: #0a0c13; border-radius: 16px; border: 1px solid var(--line); }
.hpbars { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 10px; margin-bottom: 10px; }
.hpbar { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; }
.hpbar .bar { height: 10px; background: #2a2f40; border-radius: 6px; overflow: hidden; margin-top: 6px; position: relative; }
.hpbar .bar i { position: absolute; inset: 0 auto 0 0; background: var(--good); transition: width .1s; }
.hpbar .bar s { position: absolute; inset: 0 auto 0 0; background: var(--blue); opacity: .7; }
.ticker { margin-top: 10px; min-height: 56px; font-family: var(--display); font-size: 18px; }
.ticker div { animation: fadein .3s; }
.ticker div:not(:first-child) { color: var(--dim); font-size: 15px; }
@keyframes fadein { from { opacity: 0; transform: translateY(-4px); } }
.banner { text-align: center; padding: 30px 10px; }
.banner .big { font-family: var(--display); font-size: 44px; color: var(--accent); }
.score { display: flex; justify-content: center; gap: 20px; flex-wrap: wrap; margin: 14px 0; }
.score div { text-align: center; }
.score b { display: block; font-family: var(--mono); font-size: 34px; }

/* chat */
#chat { position: fixed; right: 14px; bottom: 14px; width: 280px; background: rgba(22,26,38,.95); border: 1px solid var(--line); border-radius: 14px; padding: 8px; z-index: 5; }
#chatlog { max-height: 150px; overflow-y: auto; font-size: 13px; display: grid; gap: 3px; margin-bottom: 6px; }
#chatlog b { color: var(--accent); }
#chatinput { width: 100%; padding: 6px 10px; font-size: 13px; }
@media (max-width: 900px) { #chat { position: static; width: auto; margin: 0 16px 16px; } }
#toast { position: fixed; left: 50%; top: 16px; transform: translateX(-50%); background: var(--bad); color: #fff; padding: 10px 16px; border-radius: 10px; z-index: 10; }

.tablewrap { overflow-x: auto; }
@media (max-width: 700px) { #topinfo .tag { display: none; } .top { flex-wrap: wrap; } }
