:root {
  --bg: #f4f5f8;
  --panel: #ffffff;
  --ink: #1d2433;
  --muted: #6b7385;
  --line: #d5d9e2;
  --accent: #3a5bd9;
  --accent-soft: #e6ebfc;
  --danger: #c2413b;
  --chair-empty: #f8f9fb;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(20, 30, 60, .08), 0 2px 8px rgba(20, 30, 60, .06);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); }
h1, h2 { margin: 0; }
h2 { font-size: 15px; font-weight: 650; }
ul { list-style: none; margin: 0; padding: 0; }

/* ---------- Top bar ---------- */
.topbar {
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 10px 20px; background: var(--panel); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 10;
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 17px; color: var(--accent); }
.home-link { font-weight: 700; font-size: 15px; color: var(--muted); text-decoration: none; white-space: nowrap; }
.home-link span { font-weight: 300; }
.home-link:hover { color: var(--ink); }
.title-input {
  flex: 1 1 280px; min-width: 0; font: inherit; font-size: 16px; font-weight: 600;
  padding: 8px 12px; border: 1px solid transparent; border-radius: 8px; background: var(--bg);
}
.title-input:hover { border-color: var(--line); }
.title-input:focus { outline: none; border-color: var(--accent); background: #fff; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- Buttons ---------- */
.btn {
  font: inherit; font-size: 14px; padding: 7px 14px; border-radius: 8px; cursor: pointer;
  border: 1px solid var(--line); background: #fff; color: var(--ink);
}
.btn:hover { border-color: #b3b9c7; background: #fafbfc; }
.btn:focus-visible, .icon-btn:focus-visible, .chair:focus-visible, .student-item:focus-visible, .add-chair:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.primary:disabled { opacity: .5; cursor: default; filter: none; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.ghost:hover { background: var(--bg); color: var(--ink); }
.btn.small { font-size: 13px; padding: 4px 10px; }
.btn.toggle { display: inline-flex; align-items: center; gap: 6px; }
.btn.toggle[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.icon-btn {
  font: inherit; width: 26px; height: 26px; border-radius: 6px; border: 1px solid transparent;
  background: transparent; color: var(--muted); cursor: pointer; display: inline-grid; place-items: center;
  font-size: 16px; line-height: 1; padding: 0;
}
.icon-btn:hover { background: var(--bg); border-color: var(--line); color: var(--ink); }
.icon-btn.danger:hover { color: var(--danger); }

/* ---------- Layout ---------- */
.layout { display: grid; grid-template-columns: 320px minmax(0, 1fr); gap: 16px; padding: 16px; align-items: start; }
.sidebar { display: flex; flex-direction: column; gap: 16px; position: sticky; top: 72px; max-height: calc(100vh - 88px); overflow-y: auto; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); }
.panel > h2, .panel-head { margin-bottom: 10px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.hint { color: var(--muted); font-size: 12.5px; margin: 8px 0 0; }
.count {
  display: inline-block; min-width: 22px; padding: 1px 7px; margin-left: 4px; border-radius: 999px;
  background: var(--bg); color: var(--muted); font-size: 12px; font-weight: 600; text-align: center;
}

textarea {
  width: 100%; font: inherit; font-size: 14px; padding: 8px 10px; border: 1px solid var(--line);
  border-radius: 8px; resize: vertical; min-height: 44px;
}
textarea:focus { outline: none; border-color: var(--accent); }
.row-buttons { display: flex; gap: 8px; margin-top: 8px; }

/* ---------- Roster ---------- */
.student-list { display: flex; flex-direction: column; gap: 4px; }
.student-item {
  display: flex; align-items: center; gap: 8px; padding: 6px 6px 6px 8px; border-radius: 8px;
  background: var(--bg); border: 1px solid transparent; cursor: grab; user-select: none;
  touch-action: pan-y; font-size: 14px;
}
.student-item:hover { border-color: var(--line); }
.student-item.selected { background: var(--accent-soft); border-color: var(--accent); }
.student-item .grip { color: #aab0bd; font-size: 12px; letter-spacing: -2px; }
.student-item .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.seat-badge { font-size: 12px; font-weight: 600; color: var(--accent); background: #fff; border-radius: 6px; padding: 1px 6px; }
.empty-note { color: var(--muted); font-size: 13px; padding: 6px 2px; }
.roster-drop.drop-target { outline: 2px dashed var(--accent); outline-offset: -4px; background: var(--accent-soft); }
.drop-hint { display: none; }
body.is-dragging .drop-hint { display: block; }
details { margin-top: 12px; border-top: 1px solid var(--line); padding-top: 10px; }
summary { cursor: pointer; font-size: 14px; font-weight: 600; margin-bottom: 8px; }

/* ---------- Full screen ---------- */
.chart-area.is-fullscreen {
  width: 100vw; height: 100vh; margin: 0; border: 0; border-radius: 0; box-shadow: none;
  padding: 16px 24px; display: flex; flex-direction: column; background: var(--panel);
}
.chart-area.pseudo-fullscreen { position: fixed; inset: 0; z-index: 50; } /* for browsers without the Fullscreen API */
.chart-area:fullscreen::backdrop { background: var(--panel); }
.is-fullscreen .print-title { display: block; text-align: center; font-size: 24px; margin-bottom: 6px; }
.is-fullscreen .print-title:empty { display: none; }
.is-fullscreen .chart-viewport { flex: 1; min-height: 0; max-height: none; display: flex; }
.is-fullscreen .stage-sizer { margin: auto; flex-shrink: 0; } /* centred both ways */

/* ---------- Color swatches ---------- */
.swatches { display: flex; flex-wrap: wrap; gap: 6px; }
.swatch {
  position: relative; width: 28px; height: 28px; border-radius: 50%; padding: 0; cursor: pointer;
  border: 2px solid #fff; box-shadow: 0 0 0 1px var(--line); background: var(--sw);
  display: grid; place-items: center; color: var(--muted);
}
.swatch:hover { box-shadow: 0 0 0 1px #9aa2b4; }
.swatch[aria-pressed="true"], .swatch.active { box-shadow: 0 0 0 2px var(--ink); }
.swatch:focus-visible, .swatch.custom:focus-within { outline: 2px solid var(--accent); outline-offset: 2px; }
.swatch.eraser { background: #fff; }
.swatch.custom { background: conic-gradient(#e53935, #fdd835, #43a047, #1e88e5, #8e24aa, #e53935); }
.swatch.custom::after { content: ""; width: 14px; height: 14px; border-radius: 50%; background: var(--sw, #fff); border: 2px solid #fff; pointer-events: none; }
.swatch.custom input { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; border: 0; padding: 0; }

/* ---------- Rows panel ---------- */
.row-list { display: flex; flex-direction: column; gap: 6px; }
.row-item { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-radius: 8px; background: var(--bg); }
.row-label { flex: 1; min-width: 0; display: flex; flex-direction: column; font-size: 14px; }
.row-range { font-size: 12px; color: var(--muted); }
.stepper { display: flex; align-items: center; gap: 2px; background: #fff; border: 1px solid var(--line); border-radius: 8px; }
.stepper span { min-width: 22px; text-align: center; font-size: 14px; font-weight: 600; }
.stepper .icon-btn { width: 28px; height: 28px; }

/* ---------- Chart ---------- */
.chart-area { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px 24px; box-shadow: var(--shadow); min-width: 0; }
.chart-status { display: flex; flex-wrap: wrap; gap: 6px 16px; align-items: baseline; justify-content: space-between; font-size: 13px; color: var(--muted); min-height: 22px; }
.chart-status .hint { margin: 0; flex: 1; text-align: right; }
.chart-status .hint.active { color: var(--accent); font-weight: 600; }
.chart-viewport { position: relative; width: 100%; padding-top: 12px; overflow: hidden; }
.stage-sizer { margin: 0 auto; }
.stage-sizer { position: relative; }
.stage { position: absolute; top: 0; left: 0; transform-origin: 0 0; }

.chair {
  position: absolute; width: 80px; height: 80px; border-radius: 12px;
  background: #fff; border: 2px solid #c3c9d6; box-shadow: var(--shadow);
  display: flex; align-items: center; justify-content: center; padding: 16px 4px 6px;
  user-select: none; touch-action: none; transition: border-color .12s, background-color .12s, transform .12s;
  transform: rotate(var(--rot, 0deg));
}
.chair.filled { cursor: grab; border-color: #8f9bb8; }
.chair.empty { background: var(--chair-empty); border-style: dashed; box-shadow: none; padding: 0; cursor: pointer; }
.chair-num { position: absolute; top: 3px; left: 7px; font-size: 11px; font-weight: 700; color: var(--muted); }
.chair.empty .chair-num { position: static; font-size: 18px; color: #a2a9b8; }
.chair-name {
  font-size: 13px; font-weight: 600; line-height: 1.15; text-align: center; overflow: hidden;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical;
  overflow-wrap: anywhere; hyphens: auto;
}
.chair-name.name-sm { font-size: 11.5px; }
.chair-name.name-xs { font-size: 10.5px; }
/* Colored chairs (set with the paint tools). :where() keeps specificity low so selected/drop-target win. */
.chair.colored { border-color: var(--chair-color); background: color-mix(in srgb, var(--chair-color) 20%, #fff); }
.chair.colored:where(.empty) { background: color-mix(in srgb, var(--chair-color) 12%, #fff); }
.chair.colored .chair-num { color: color-mix(in srgb, var(--chair-color) 55%, #1d2433); }
body.painting .chair, body.painting .chair * { cursor: crosshair; }
.chair.selected { border-color: var(--accent); background: var(--accent-soft); border-style: solid; }
.chair.drop-target { border-color: var(--accent); background: var(--accent-soft); border-style: solid; transform: rotate(var(--rot, 0deg)) scale(1.08); }
.chair.drag-source { opacity: .4; }
body.selecting .chair.empty { border-color: var(--accent); }

/* Blank space: holds a spot on the arc but has no number and can't be sat in. */
.blank {
  position: absolute; width: 80px; height: 80px; border-radius: 12px;
  border: 2px dashed transparent; display: grid; place-items: center;
  transform: rotate(var(--rot, 0deg)); transition: border-color .12s;
}
.blank-label { font-size: 10.5px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: #c9ced8; }
.blank:hover, .blank:focus-within { border-color: #dde1e8; }

.chair-btn {
  position: absolute; top: -9px; width: 22px; height: 22px; border-radius: 50%;
  border: 1px solid var(--line); background: #fff; color: var(--muted); font-size: 14px; line-height: 1;
  display: grid; place-items: center; cursor: pointer; padding: 0; opacity: 0; transition: opacity .12s;
}
.chair-x { right: -9px; }
.chair-toggle { left: -9px; }
.chair:hover .chair-btn, .chair:focus-within .chair-btn, .chair.selected .chair-btn,
.blank:hover .chair-btn, .blank:focus-within .chair-btn { opacity: 1; }
.chair-x:hover { color: var(--danger); border-color: var(--danger); }
.chair-toggle:hover { color: var(--accent); border-color: var(--accent); }
.chair-btn:focus-visible { opacity: 1; outline: 2px solid var(--accent); outline-offset: 1px; }
@media (hover: none) { .chair-btn { opacity: .75; } }

.add-chair {
  position: absolute; width: 36px; height: 36px; border-radius: 50%;
  border: 2px dashed #b9c0ce; background: transparent; color: var(--muted);
  font-size: 22px; line-height: 1; cursor: pointer; display: grid; place-items: center; padding: 0;
}
.add-chair:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); border-style: solid; }

.podium {
  position: absolute; display: grid; place-items: center; border-radius: 14px;
  background: var(--ink); color: #fff; font-size: 18px; font-weight: 700; letter-spacing: .08em;
}

.drag-ghost {
  position: fixed; top: 0; left: 0; z-index: 1000; pointer-events: none;
  padding: 8px 14px; border-radius: 10px; background: var(--accent); color: #fff;
  font-size: 14px; font-weight: 600; box-shadow: 0 6px 20px rgba(20, 30, 60, .25); white-space: nowrap;
}
body.is-dragging, body.is-dragging * { cursor: grabbing !important; user-select: none; }

.print-title, .print-list { display: none; }

/* ---------- Export menu ---------- */
.menu { position: relative; }
.menu-list {
  position: absolute; right: 0; top: calc(100% + 4px); z-index: 20; min-width: 220px;
  background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 4px;
  box-shadow: 0 8px 24px rgba(20, 30, 60, .15); display: flex; flex-direction: column;
}
.menu-list[hidden] { display: none; }
.menu-item { font: inherit; font-size: 14px; text-align: left; padding: 8px 10px; border: 0; border-radius: 6px; background: none; cursor: pointer; color: var(--ink); }
.menu-item:hover, .menu-item:focus-visible { background: var(--accent-soft); outline: none; }

/* ---------- Import dialog ---------- */
.mode-group { border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; margin: 0; display: flex; flex-direction: column; gap: 8px; }
.mode-group[hidden], .names-options[hidden] { display: none; }
.mode-group legend { font-size: 13px; font-weight: 600; padding: 0 4px; }
.mode-group .check { align-items: flex-start; }
.mode-group input { margin-top: 3px; }
.mode-note { display: block; margin: 2px 0 0; }
.names-options { display: flex; flex-direction: column; gap: 12px; }
dialog { border: none; border-radius: 14px; padding: 0; width: min(460px, calc(100vw - 32px)); box-shadow: 0 20px 60px rgba(20, 30, 60, .3); }
dialog::backdrop { background: rgba(20, 30, 60, .35); }
.dialog-body { padding: 20px; display: flex; flex-direction: column; gap: 12px; }
.dialog-body .hint { margin: -6px 0 0; }
.field { display: flex; flex-direction: column; gap: 4px; font-size: 14px; }
.field select { font: inherit; padding: 7px 8px; border-radius: 8px; border: 1px solid var(--line); }
.check { display: flex; align-items: center; gap: 8px; font-size: 14px; }
.preview { background: var(--bg); border-radius: 8px; padding: 10px 12px; font-size: 13.5px; }
.preview-head { font-weight: 600; margin-bottom: 4px; }
.preview ul { color: var(--muted); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; }

/* ---------- Small screens ---------- */
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; padding: 12px; }
  .sidebar { position: static; max-height: none; }
  .chart-area { order: -1; }
  .topbar { padding: 10px 12px; }
}

/* ---------- Print ---------- */
@page { size: landscape; margin: 0.4in; }
@media print {
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  body { background: #fff; }
  .topbar, .sidebar, .chart-status, .chair-btn, .add-chair, .drag-ghost { display: none !important; }
  .blank { visibility: hidden; }
  .layout { display: block; padding: 0; }
  .chart-area { border: none; box-shadow: none; padding: 0; }
  .print-title { display: block; text-align: center; font-size: 20px; margin-bottom: 8px; }
  .print-title:empty { display: none; }
  .chart-viewport { padding-top: 0; overflow: visible; }
  .chair { box-shadow: none; }
  .chair.selected { background: #fff; border-color: #8f9bb8; }
  .print-list { display: block; break-before: page; }
  .print-list h2 { font-size: 16px; margin-bottom: 10px; }
  .print-list ol { columns: 4; column-gap: 24px; margin: 0; padding: 0; list-style: none; font-size: 12px; }
  .print-list li { break-inside: avoid; padding: 3px 0; border-bottom: 1px solid #e4e7ee; }
  .print-list .num { display: inline-block; width: 2.2em; font-weight: 700; color: var(--muted); }
}
