:root {
  --bg: #0d1117;
  --panel: #161b22;
  --line: #262d38;
  --text: #e6edf3;
  --muted: #8b949e;
  --red: #ef4444;
  --blue: #3b82f6;
  --accent: #f59e0b;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  overflow: hidden;
}
#app {
  display: grid;
  grid-template-columns: 1fr 300px;
  grid-template-rows: auto 1fr;
  grid-template-areas: "top side" "stage side";
  height: 100%;
}

#topbar {
  grid-area: top;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 24px;
  padding: 10px 24px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.score { display: flex; align-items: baseline; gap: 12px; }
.score.blue { justify-content: flex-end; }
.score .label { font-weight: 700; letter-spacing: .12em; font-size: 13px; }
.score .value { font-size: 46px; font-weight: 800; font-variant-numeric: tabular-nums; line-height: 1; }
.score.red .label, .score.red .value { color: var(--red); }
.score.blue .label, .score.blue .value { color: var(--blue); }

.clock { text-align: center; min-width: 220px; }
.clock .phase { font-size: 12px; letter-spacing: .18em; color: var(--muted); }
.clock .time { font-size: 42px; font-weight: 800; font-variant-numeric: tabular-nums; line-height: 1.05; }
.clock .hint { font-size: 11px; color: var(--muted); min-height: 14px; }
.clock.auto .time { color: var(--accent); }
.clock.endgame .time { color: var(--red); }

#stage { grid-area: stage; position: relative; display: grid; place-items: center; padding: 12px; min-height: 0; }
#field { background: #11161d; border-radius: 6px; touch-action: none; }
#field.editing { cursor: crosshair; outline: 2px solid var(--accent); }
#field.grabbable { cursor: grab; }
#field.dragging { cursor: grabbing; }

#toast {
  position: absolute; bottom: 18px; left: 50%; transform: translateX(-50%);
  background: rgba(0,0,0,.78); border: 1px solid var(--line); border-radius: 999px;
  padding: 7px 16px; font-size: 13px; opacity: 0; transition: opacity .25s; pointer-events: none;
}
#toast.show { opacity: 1; }

#sidebar {
  grid-area: side; background: var(--panel); border-left: 1px solid var(--line);
  padding: 14px; overflow-y: auto;
}
#sidebar section { margin-bottom: 20px; }
#sidebar h2 { font-size: 11px; letter-spacing: .14em; text-transform: uppercase; color: var(--muted); margin: 0 0 8px; }
.row { display: flex; gap: 6px; align-items: center; margin-bottom: 6px; flex-wrap: wrap; }
button, select, input[type=file] {
  background: #21262d; color: var(--text); border: 1px solid var(--line);
  border-radius: 5px; padding: 6px 10px; font: inherit; cursor: pointer;
}
button:hover, select:hover { border-color: #3d4652; }
button.active { background: var(--accent); color: #111; border-color: var(--accent); }
button.r { color: var(--red); }
button.b { color: var(--blue); }
input[type=file] { width: 100%; cursor: pointer; }
.note { font-size: 11px; color: var(--muted); margin: 6px 0 0; }
.row.slider { gap: 8px; }
.row.slider label { font-size: 12px; color: var(--muted); }
.row.slider input[type=range] { flex: 1; min-width: 0; accent-color: var(--accent); }
.row.slider .value { font-size: 12px; font-variant-numeric: tabular-nums; min-width: 26px; text-align: right; }

.drivers, .breakdown { list-style: none; margin: 0; padding: 0; }
.drivers li {
  display: flex; align-items: center; gap: 8px;
  padding: 5px 8px; border-radius: 5px; background: #0f141b; margin-bottom: 4px; font-size: 12px;
}
.drivers .dot { width: 9px; height: 9px; border-radius: 50%; background: #39414d; flex: 0 0 auto; }
.drivers li.on .dot { background: #22c55e; }
.drivers .who { font-weight: 600; }
.drivers li.red .who { color: var(--red); }
.drivers li.blue .who { color: var(--blue); }
.drivers .src { margin-left: auto; color: var(--muted); }

.breakdown li {
  display: grid; grid-template-columns: 34px 1fr 34px; align-items: center;
  gap: 6px; padding: 3px 0; font-size: 12px;
}
.breakdown .k { text-align: center; color: var(--muted); }
.breakdown .v { font-variant-numeric: tabular-nums; font-weight: 700; }
.breakdown .v.r { color: var(--red); text-align: left; }
.breakdown .v.b { color: var(--blue); text-align: right; }
.breakdown li.empty { opacity: .38; }

/* Login screen: covers the whole app until the password is accepted. */
#login {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  background: radial-gradient(circle at 50% 35%, #16202c, var(--bg) 70%);
}
#login[hidden] { display: none; }
#login form {
  display: grid;
  gap: 12px;
  width: min(340px, calc(100vw - 48px));
  padding: 28px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, .45);
  text-align: center;
}
#login h1 { margin: 0; font-size: 18px; letter-spacing: .02em; }
#login .sub { margin: -4px 0 8px; color: var(--muted); font-size: 12px; letter-spacing: .04em; }
#login input {
  padding: 10px 12px;
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  text-align: center;
}
#login input:focus { outline: none; border-color: var(--accent); }
#login input:disabled { opacity: .5; }
#login button {
  padding: 10px 12px;
  font: inherit;
  font-weight: 600;
  color: #1a1206;
  background: var(--accent);
  border: 0;
  border-radius: 8px;
  cursor: pointer;
}
#login button:hover { filter: brightness(1.08); }
#login .err { margin: 0; min-height: 1.2em; color: var(--red); font-size: 12px; }
#login.shake form { animation: login-shake .32s; }
@keyframes login-shake {
  25% { transform: translateX(-7px); }
  50% { transform: translateX(7px); }
  75% { transform: translateX(-4px); }
}

/* Per-robot archetype rows: station name on the left, its build on the right. */
.archetypes { list-style: none; margin: 0; padding: 0; }
.archetypes li {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 4px 8px; border-radius: 5px; background: #0f141b; margin-bottom: 4px;
}
.archetypes li span { font-size: 12px; font-weight: 600; }
.archetypes li span.red { color: var(--red); }
.archetypes li span.blue { color: var(--blue); }
.archetypes select { flex: 0 1 auto; font-size: 12px; padding: 3px 6px; }
