/* Human Machine Learning game */
:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --text: #1d2330;
  --muted: #5f6878;
  --line: #d7dbe2;
  --accent: #2463b8;
  --accent-soft: #e4eefb;
  --good: #1f7a45;
  --good-soft: #e3f4ea;
  --bad: #b3261e;
  --bad-soft: #fbe7e6;
  --warn: #9a6200;
  --warn-soft: #fff3d6;
  --cell-on: rgb(79, 173, 234);
  --cell-line: #000000;
  --radius: 10px;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
main { max-width: 1240px; margin: 0 auto; padding: 16px; }
h1 { font-size: 1.6rem; margin: 0 0 8px; }
h2 { font-size: 1.25rem; margin: 0 0 6px; }
h3 { font-size: 1.05rem; margin: 18px 0 8px; }
code { background: #eef0f4; padding: 1px 5px; border-radius: 4px; }
.muted { color: var(--muted); }
.small { font-size: 0.82rem; }
.error { color: var(--bad); }
.note { color: var(--muted); min-height: 1.4em; }
[hidden] { display: none !important; }

/* ---------- cards, forms, buttons */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 16px;
}
.narrow { max-width: 460px; margin: 40px auto; }
label { display: block; margin: 0 0 12px; font-weight: 600; }
label .muted { font-weight: 400; }
input[type="text"], input[type="password"], input:not([type]) {
  display: block; width: 100%; margin-top: 4px; padding: 10px 12px;
  font: inherit; border: 1px solid var(--line); border-radius: 8px; background: #fff;
}
button, .button {
  font: inherit; cursor: pointer; border-radius: 8px; padding: 8px 14px;
  border: 1px solid var(--line); background: #fff; color: var(--text); text-decoration: none;
  display: inline-block;
}
button:hover:not(:disabled), .button:hover { border-color: var(--accent); }
button:disabled { opacity: 0.5; cursor: not-allowed; }
button.primary { background: var(--accent); color: #fff; border-color: var(--accent); font-weight: 600; }
button.link { background: none; border: none; color: var(--accent); padding: 2px 4px; text-decoration: underline; }
button.danger { color: var(--bad); }
button.small, .small button { font-size: 0.8rem; }
:focus-visible { outline: 3px solid #f2a900; outline-offset: 2px; }
.row-buttons { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-top: 12px; }

/* ---------- grids (same look as the paper slides) */
.grid {
  display: grid; grid-template-columns: repeat(5, var(--cell)); gap: 1px;
  background: var(--cell-line); border: 1px solid var(--cell-line); width: max-content;
}
.grid .cell { width: var(--cell); height: var(--cell); background: #fff; }
.grid .cell.on { background: var(--cell-on); }
.grid-xs { --cell: 9px; }
.grid-sm { --cell: 15px; }
.grid-md { --cell: 24px; }

/* ---------- team page header and tabs */
.topbar {
  position: sticky; top: 0; z-index: 10; display: flex; flex-wrap: wrap; gap: 6px 18px;
  align-items: center; justify-content: space-between; padding: 10px 16px;
  background: var(--surface); border-bottom: 1px solid var(--line);
}
.team-name { font-weight: 700; font-size: 1.1rem; margin-right: 8px; }
.phase-badge { font-size: 0.8rem; padding: 3px 10px; border-radius: 999px; background: #eceff3; }
.phase-running { background: var(--good-soft); color: var(--good); }
.phase-testing { background: var(--warn-soft); color: var(--warn); }
.phase-revealed { background: var(--accent-soft); color: var(--accent); }
.topbar-timer { font-variant-numeric: tabular-nums; color: var(--muted); }
.topbar-timer.urgent { color: var(--bad); font-weight: 700; }
.topbar-money { font-weight: 600; }
.tabs { display: flex; flex-wrap: wrap; gap: 4px; margin: 4px 0 16px; border-bottom: 1px solid var(--line); }
.tab { border: none; border-bottom: 3px solid transparent; border-radius: 0; background: none; padding: 10px 14px; color: var(--muted); }
.tab.active { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }
.tab-panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.panel-head { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-start; justify-content: space-between; margin-bottom: 12px; }
.panel-head p { margin: 0; }

/* ---------- data tab */
.class-columns { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.class-column { border: 1px solid var(--line); border-radius: var(--radius); padding: 10px; background: #fafbfc; }
.class-title { margin: 0 0 10px; font-size: 1.1rem; }
.card-list { display: flex; flex-wrap: wrap; gap: 10px; }
.sample-card { margin: 0; padding: 8px; background: #fff; border: 1px solid var(--line); border-radius: 8px; }
.sample-card figcaption { margin-top: 6px; font-size: 0.78rem; color: var(--muted); display: flex; flex-direction: column; gap: 2px; }
.sample-card.new { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

/* ---------- expert */
.expert-layout { display: grid; grid-template-columns: auto 1fr; gap: 28px; align-items: start; }
.editor {
  display: grid; grid-template-columns: repeat(5, 56px); gap: 2px;
  background: var(--cell-line); border: 2px solid var(--cell-line); width: max-content; user-select: none;
}
.editor .cell { width: 56px; height: 56px; border: none; border-radius: 0; padding: 0; background: #fff; }
.editor .cell.on { background: var(--cell-on); }
.expert-history h3 { margin-top: 0; }

/* ---------- validation sheet and choices */
.sheet-wrap { overflow-x: auto; }
.sheet { border-collapse: collapse; }
.sheet th, .sheet td { border: 1px solid var(--line); padding: 6px 8px; text-align: center; vertical-align: middle; }
.sheet thead th { background: #f0f2f5; font-size: 0.85rem; }
.sheet .grid-cell { display: flex; align-items: center; gap: 8px; border: none; border-bottom: 1px solid var(--line); }
.row-num { font-weight: 700; min-width: 1.6em; }
.sheet .draft-col { background: #fffbea; white-space: nowrap; }
.sheet .letter { font-weight: 700; font-size: 1.05rem; }
.sheet .total-row th, .sheet .total-row td { background: #f0f2f5; font-weight: 700; }
.choice { min-width: 34px; padding: 5px 0; margin: 0 1px; font-weight: 700; }
.choice.chosen { background: var(--accent); color: #fff; border-color: var(--accent); }
.draft-col:focus-visible { outline: 3px solid #f2a900; }

/* ---------- test and results */
.test-grid, .example-grid { display: flex; flex-wrap: wrap; gap: 12px; }
.test-grid > p { flex-basis: 100%; margin: 0; }
.test-item { margin: 0; padding: 10px; border: 1px solid var(--line); border-radius: 8px; background: #fff; display: flex; flex-direction: column; align-items: center; gap: 6px; }
.test-item figcaption { font-weight: 700; }
.test-item .draft-col { background: none; }
.test-item.right { border-color: var(--good); background: var(--good-soft); }
.test-item.wrong { border-color: var(--bad); background: var(--bad-soft); }
.example-grid .test-item { max-width: 190px; text-align: center; }
.example-grid .letter { font-weight: 700; }
.example-grid figcaption { font-weight: 400; }
.letter.big { font-size: 1.4rem; font-weight: 700; }
.result-summary { font-size: 1.15rem; font-weight: 600; }
.leaderboard { border-collapse: collapse; margin: 8px 0 16px; min-width: 60%; }
.leaderboard th, .leaderboard td { padding: 8px 12px; border-bottom: 1px solid var(--line); text-align: left; }
.leaderboard tr.me td { background: var(--accent-soft); font-weight: 700; }
.leaderboard tr.winner td { background: var(--good-soft); font-weight: 700; }
.rule-list li { margin-bottom: 4px; }
.rules-section ul { padding-left: 20px; }
.activity { list-style: none; padding: 0; margin: 0; }
.activity li { padding: 6px 0; border-bottom: 1px solid var(--line); }
.leave { margin-top: 24px; }

/* ---------- toast */
.toast {
  position: fixed; left: 50%; bottom: 20px; transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: #1d2330; color: #fff; padding: 12px 18px; border-radius: 10px; max-width: min(92vw, 560px);
  transition: opacity 0.2s, transform 0.2s; z-index: 50;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.good { background: var(--good); }
.toast.error { background: var(--bad); }

/* ---------- instructor */
.dash-head { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.join-card { display: flex; flex-wrap: wrap; gap: 24px 48px; align-items: center; }
.join-url { font-size: 1.2rem; font-weight: 600; word-break: break-all; }
.class-code { font-size: 2.4rem; font-weight: 800; letter-spacing: 0.15em; }
.phase-steps { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; margin-bottom: 12px; }
.phase-step { text-align: left; display: flex; flex-direction: column; gap: 4px; padding: 12px; }
.phase-step.current { background: var(--accent); border-color: var(--accent); color: #fff; }
.timer-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.toggle { display: flex; gap: 6px; align-items: center; font-weight: 400; margin: 0; }
.teams-table { border-collapse: collapse; width: 100%; font-size: 0.9rem; }
.teams-table th, .teams-table td { padding: 7px 8px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
.teams-table th { background: #f0f2f5; }
.teams-table .team-cell { font-weight: 700; white-space: normal; min-width: 160px; }
.teams-table .members { font-weight: 400; font-size: 0.82rem; color: var(--muted); }
.teams-table .flag { color: var(--warn); font-weight: 700; }
.teams-table .warn { color: var(--bad); font-weight: 700; }
.teams-table .actions { display: flex; gap: 4px; }
details summary { cursor: pointer; font-weight: 600; }

/* ---------- projector */
.projector-page main { max-width: 1500px; padding: 32px; }
.projector-page h1 { font-size: 3rem; }
.projector-page h2 { font-size: 2rem; margin-top: 28px; }
.projector-page .lead { font-size: 1.8rem; }
.join-big { font-size: 2.6rem; line-height: 1.5; margin: 24px 0; }
.join-small { font-size: 1.5rem; color: var(--muted); }
.code { letter-spacing: 0.15em; font-size: 1.2em; }
.countdown { font-size: 11rem; font-weight: 800; font-variant-numeric: tabular-nums; line-height: 1.1; }
.countdown.urgent { color: var(--bad); }
.chips { display: flex; flex-wrap: wrap; gap: 12px; }
.chip { font-size: 1.6rem; padding: 8px 18px; border-radius: 999px; background: var(--surface); border: 1px solid var(--line); }
.chip.done { background: var(--good-soft); border-color: var(--good); }
.leaderboard.big { font-size: 1.6rem; width: 100%; }
.rule-list.big { font-size: 1.5rem; }
.projector-page .example-grid .test-item { max-width: 240px; font-size: 1.1rem; }

/* ---------- small screens */
@media (max-width: 800px) {
  .class-columns { grid-template-columns: 1fr; }
  .expert-layout { grid-template-columns: 1fr; }
  .editor { grid-template-columns: repeat(5, 48px); }
  .editor .cell { width: 48px; height: 48px; }
  .phase-steps { grid-template-columns: 1fr 1fr; }
  .countdown { font-size: 6rem; }
}
