:root {
  --bg: #f6f5f1;
  --panel: #fff;
  --text: #1d1d1b;
  --muted: #6b6a65;
  --line: #d8d5cc;
  --accent: #2a78d6;
  --accent-dark: #1f5fae;
  --piece: #2a78d6;
  --piece-selected: #164d92;
  --silhouette: #4a4946;
  --select: #e08a00;
  --reject: #e34948;
  --round1: #2a78d6;
  --round2: #eb6834;
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  font-size: 17px;
  line-height: 1.45;
  color: var(--text);
  background: var(--bg);
}

* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; display: flex; flex-direction: column; }
main { flex: 1; width: 100%; max-width: 1600px; margin: 0 auto; padding: 0.75rem 1rem 1.5rem; }
h1, h2, h3, h4 { line-height: 1.2; margin: 0.4em 0; }
h2 { font-size: 1.45rem; }
h3 { font-size: 1.1rem; }
p { margin: 0.5em 0; }
[hidden] { display: none !important; }

.top { display: flex; align-items: baseline; gap: 1rem; padding: 0.5rem 1rem; background: var(--panel); border-bottom: 1px solid var(--line); }
.top h1 { font-size: 1.1rem; margin: 0; white-space: nowrap; }
#info { flex: 1; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.top .countdown { font-size: 1.5rem; font-weight: 700; font-variant-numeric: tabular-nums; }
body:has(.moderator) .top .countdown { display: none; }

footer { display: flex; gap: 1.5rem; justify-content: center; padding: 0.75rem; font-size: 0.85rem; }
footer a { color: var(--muted); }

.offline, .toast { position: fixed; left: 50%; transform: translateX(-50%); z-index: 10; padding: 0.6rem 1rem; border-radius: 6px; box-shadow: 0 2px 8px rgb(0 0 0 / 0.2); max-width: 90vw; }
.offline { top: 3.2rem; background: #fff4d6; border: 1px solid #e0b84a; }
.toast { bottom: 2rem; background: #2b2a28; color: #fff; }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 0.75rem 1rem; min-width: 0; }
.panel + .panel { margin-top: 1rem; }
.two { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 1rem; align-items: start; }
.two > .panel + .panel { margin-top: 0; }
.with-side { display: grid; grid-template-columns: minmax(14rem, 22rem) minmax(0, 1fr); gap: 1rem; align-items: start; }
.muted { color: var(--muted); }
.center { text-align: center; }
.big { font-size: 1.25rem; }
.error { color: #b3261e; font-weight: 600; }
.warn { color: #8a5a00; }
.actions { display: flex; flex-wrap: wrap; gap: 0.75rem; margin: 0.75rem 0; }
.row { display: flex; justify-content: space-between; align-items: center; gap: 1rem; }
.code { font-family: ui-monospace, Menlo, Consolas, monospace; letter-spacing: 0.08em; }

button { font: inherit; padding: 0.5rem 1rem; border-radius: 6px; border: 1px solid var(--line); background: var(--panel); cursor: pointer; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
button.primary:hover:not(:disabled) { background: var(--accent-dark); }
button:disabled { opacity: 0.5; cursor: default; }
button.small { padding: 0.15rem 0.6rem; font-size: 0.85em; }

form label { display: block; margin: 0.6rem 0; }
form input:not([type='radio']) { display: block; width: 100%; margin-top: 0.25rem; font: inherit; padding: 0.45rem 0.6rem; border: 1px solid var(--line); border-radius: 6px; }
fieldset { border: 0; padding: 0; margin: 0.5rem 0; }
legend { padding: 0; margin-bottom: 0.25rem; }
label.choice { margin: 0.25rem 0; }
.entry .lead { font-size: 1.15rem; max-width: 50rem; }
.narrow { max-width: 28rem; }

textarea { display: block; width: 100%; font: inherit; padding: 0.6rem; border: 1px solid var(--line); border-radius: 6px; resize: vertical; min-height: 12rem; }
.count { color: var(--muted); font-variant-numeric: tabular-nums; }
.description { white-space: pre-wrap; overflow-wrap: anywhere; max-height: 55vh; overflow: auto; background: #fbfaf7; border: 1px solid var(--line); border-radius: 6px; padding: 0.6rem 0.75rem; }
.role { font-size: 2rem; font-weight: 700; color: var(--accent-dark); }

/* Pictures: board units are the SVG units; strokes keep their pixel width. */
svg.figure { display: block; width: 100%; height: auto; max-height: 60vh; }
.figure .shape, .piece polygon { fill: var(--piece); stroke: #fff; stroke-width: 1.5px; stroke-linejoin: round; vector-effect: non-scaling-stroke; }
.silhouette .shape { fill: var(--silhouette); stroke: var(--silhouette); stroke-width: 2px; vector-effect: non-scaling-stroke; }
.area { fill: #fff; stroke: #bdb9ae; stroke-width: 1px; vector-effect: non-scaling-stroke; }
.tray { fill: #e9e6dd; }
.live svg.figure { max-height: 65vh; }

/* Editor */
.editor-svg { display: block; width: 100%; height: auto; max-height: calc(100vh - 13rem); min-height: 14rem; touch-action: none; user-select: none; -webkit-user-select: none; }
.piece { cursor: grab; }
.piece.selected polygon { fill: var(--piece-selected); }
/* Dropped where it does not fit; wins over the selection, which then shows only through the handle. */
.piece.red polygon { fill: var(--reject); }
.piece.snapped polygon { animation: snapped 0.25s ease-out; }
@keyframes snapped { 0% { fill: #7fb0ea; } }
.handle-line { stroke: var(--select); stroke-width: 2px; stroke-dasharray: 4 3; vector-effect: non-scaling-stroke; pointer-events: none; }
.handle-hit { fill: transparent; cursor: grab; }
.handle-dot { fill: #fff; stroke: var(--select); stroke-width: 2.5px; vector-effect: non-scaling-stroke; }
.handle-arrow { fill: none; stroke: var(--select); stroke-width: 2px; stroke-linecap: round; vector-effect: non-scaling-stroke; pointer-events: none; }
.editor-tools { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem 1rem; margin-top: 0.4rem; font-size: 0.9rem; }
.editor-help { color: var(--muted); }
.editor-hint { margin: 0; color: var(--reject); font-weight: 600; }
.editor-tools .done { margin-left: auto; }
.minigame .counter { font-size: 1.1rem; }
.cheer { color: #1b7f3b; font-weight: 700; min-height: 1.45em; margin: 0; }

/* Moderation: on the projector, so everything is larger. */
.moderator { font-size: 1.3rem; }
.moderator h2 { font-size: 2.2rem; }
.moderator h3 { font-size: 1.5rem; }
.mod-head { display: flex; justify-content: space-between; align-items: center; gap: 1rem; }
.moderator .countdown { font-size: 5rem; font-weight: 800; font-variant-numeric: tabular-nums; line-height: 1; }
.moderator .actions button { font-size: 1.3rem; padding: 0.6rem 1.4rem; }
.join { display: flex; align-items: center; justify-content: space-between; gap: 2rem; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 1rem 1.5rem; margin-bottom: 1rem; }
.join .link { font-size: 2rem; font-weight: 700; overflow-wrap: anywhere; margin: 0.2em 0; }
.join .code { font-size: 2.6rem; }
.qr { width: 15rem; height: 15rem; flex: none; }
.persons { list-style: none; padding: 0; margin: 0; columns: 3 16rem; }
.persons li { display: flex; align-items: center; gap: 0.5rem; padding: 0.2rem 0; break-inside: avoid; }
.persons li .person { flex: 1; }
.dot { width: 0.7rem; height: 0.7rem; border-radius: 50%; background: #b5b2a9; flex: none; }
.dot.online { background: #1baf7a; }
.offline small { color: #b3261e; }
.person.offline { color: var(--muted); }
table.pairs { width: 100%; border-collapse: collapse; }
.pairs th, .pairs td { text-align: left; padding: 0.35rem 0.6rem; border-bottom: 1px solid var(--line); }
.pairs th { font-size: 0.85em; color: var(--muted); font-weight: 600; }
.progress { font-weight: 700; }
.progress.done, .progress.submitted { color: #1b7f3b; }
.progress.typing, .progress.building { color: var(--accent-dark); }

/* Evaluation */
.charts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 2rem; }
.chart-box { margin: 0; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 0.75rem; }
.chart-box figcaption { font-size: 1.6rem; font-weight: 700; text-align: center; }
svg.chart { display: block; width: 100%; height: auto; max-height: 50vh; }
.chart .bar.r1 { fill: var(--round1); }
.chart .bar.r2 { fill: var(--round2); }
.chart .value { font-size: 46px; font-weight: 800; fill: var(--text); }
.chart .round { font-size: 22px; font-weight: 700; fill: var(--text); }
.chart .round-name { font-size: 22px; fill: var(--muted); }
.chart .baseline { stroke: #8a877e; stroke-width: 2; }
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(34rem, 1fr)); gap: 1rem; }
.pair-result { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 0.75rem 1rem; font-size: 1rem; }
.pair-result h3 { font-size: 1.4rem; }
.pair-result h4 { font-size: 1.05rem; }
.round-result { border-top: 1px solid var(--line); padding-top: 0.4rem; margin-top: 0.4rem; }
.compare { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.compare figure { margin: 0; text-align: center; }
.compare svg.figure { height: 11rem; max-height: none; }
.compare figcaption { color: var(--muted); font-size: 0.9rem; }
.nothing { height: 11rem; display: grid; place-items: center; color: var(--muted); border: 1px dashed var(--line); border-radius: 6px; }
.score { font-size: 1.15rem; margin: 0.3rem 0; }
.brief .description { max-height: 12rem; }

/* Phones held sideways: the editor gets the full width. */
@media (max-height: 500px) {
  .with-side { grid-template-columns: minmax(0, 1fr); }
  .editor-svg { max-height: calc(100vh - 3rem); min-height: 0; }
}

@media (max-width: 800px) {
  main { padding: 0.5rem; }
  .two, .with-side, .charts { grid-template-columns: minmax(0, 1fr); }
  .gallery { grid-template-columns: minmax(0, 1fr); }
  .editor-svg { max-height: none; min-height: 0; }
  .join { flex-direction: column; align-items: flex-start; }
  .moderator { font-size: 1rem; }
  .moderator .countdown { font-size: 3rem; }
  .top { flex-wrap: wrap; gap: 0 0.75rem; }
  #info { order: 3; flex-basis: 100%; font-size: 0.85rem; }
  .top .countdown { margin-left: auto; }
}
