:root {
  --bg: #f3f4f6; --card: #ffffff; --ink: #1f2937; --muted: #6b7280; --line: #d1d5db;
  --accent: #1565c0; --accent-ink: #ffffff; --danger: #b91c1c;
}
* { box-sizing: border-box; }
/* .btn sets a display value, which would otherwise beat the browser's
   [hidden] rule and leave hidden buttons on screen. */
[hidden] { display: none !important; }
html, body { margin: 0; }
body { font: 15px/1.45 "Segoe UI", "Helvetica Neue", Helvetica, Arial, sans-serif; color: var(--ink); background: var(--bg); }
header.top { display: flex; align-items: center; gap: 10px; padding: 8px 14px; background: #fff; border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
header.top h1 { font-size: 17px; margin: 0; flex: 1 1 auto; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
header.top .actions { display: flex; gap: 6px; }
.badge { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: #92400e; background: #fef3c7; border: 1px solid #f59e0b; border-radius: 999px; padding: 2px 8px; }
main { display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(340px, 1fr); gap: 14px; padding: 14px; max-width: 1500px; margin: 0 auto; align-items: start; }
.plan-col { position: sticky; top: 56px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 12px; margin-bottom: 12px; }
.card h3 { margin: 0; font-size: 16px; }
.card h3.sub { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 14px 0 6px; }
.fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 8px; margin-bottom: 8px; }
label.f { display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: var(--muted); }
input[type=text], input[type=date], input[type=number], select, textarea { font: inherit; padding: 6px 8px; border: 1px solid var(--line); border-radius: 6px; background: #fff; color: var(--ink); min-width: 0; width: 100%; }
input[type=color] { width: 34px; height: 30px; padding: 0 2px; border: 1px solid var(--line); border-radius: 6px; background: #fff; flex: 0 0 auto; }
textarea { resize: vertical; }
.plan-tools { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 6px; }
.zoom { display: inline-flex; gap: 4px; }
.zoom .btn, .stepper .btn { min-width: 34px; padding: 4px 8px; }
.plan-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
#plan { width: var(--plan-zoom, 100%); touch-action: pan-x pan-y; }
#plan.editing { touch-action: none; }
#plan svg { width: 100%; height: auto; display: block; }
#plan .hit { cursor: pointer; }
#plan .hit:hover rect, #plan .hit:focus-visible rect { stroke: var(--accent); stroke-width: 4; }
#plan .hit:focus { outline: none; }
#plan .ed { cursor: move; }
.legend { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 8px; font-size: 12px; color: var(--muted); }
.legend span::before { content: ""; display: inline-block; width: 13px; height: 13px; border: 1px solid #000; vertical-align: -2px; margin-right: 5px; background: var(--sw, #fff); }
.legend .hatch::before { background: repeating-linear-gradient(45deg, transparent 0 2px, rgba(31,41,55,.55) 2px 3.5px); }
.btn { font: inherit; text-decoration: none; display: inline-block; line-height: normal; font-weight: 600; padding: 8px 14px; border-radius: 8px; border: 1px solid var(--accent); background: var(--accent); color: var(--accent-ink); cursor: pointer; white-space: nowrap; }
.btn.ghost { background: #fff; color: var(--accent); }
.btn.danger { background: var(--danger); border-color: var(--danger); }
.btn.small { padding: 5px 10px; font-size: 13px; }
.btn:disabled, .btn.busy { opacity: .5; cursor: default; }
.icon { border: none; background: transparent; font-size: 20px; line-height: 1; cursor: pointer; color: var(--muted); padding: 2px 6px; }
.icon:hover { color: var(--danger); }
.row { display: flex; gap: 8px; align-items: center; margin-top: 8px; flex-wrap: wrap; }
.row input[type=text] { flex: 1 1 140px; }
.muted { color: var(--muted); margin: 0; }
.small { font-size: 12px; }
.tabs { display: flex; gap: 4px; align-items: flex-end; margin: 0; padding: 0; }
.tabs button { flex: 1 1 0; display: flex; align-items: center; justify-content: center; gap: 6px; font: inherit; font-size: 14px; font-weight: 700; padding: 11px 6px; border: 1px solid var(--line); border-bottom: none; border-radius: 10px 10px 0 0; background: #e9ecf1; color: #4b5563; cursor: pointer; transition: background .12s, color .12s; }
.tabs button:hover { background: #dde2ea; color: var(--ink); }
.tabs button.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.tabs .ico { display: none; }
.tabs .ico svg { display: block; width: 24px; height: 24px; }
.card.tab { border-top: 3px solid var(--accent); border-top-left-radius: 0; border-top-right-radius: 0; }
h1 .t-short { display: none; }
.sheet { border-color: var(--accent); box-shadow: 0 4px 16px rgba(0,0,0,.12); }
.sheet-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.sheet-head h3 { flex: 0 0 auto; }
.sheet-head .current { padding: 2px 10px; border-radius: 999px; border: 1px solid var(--line); font-weight: 600; }
.sheet-head .close { margin-left: auto; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; }
.chip { font: inherit; font-size: 14px; padding: 6px 11px; border-radius: 999px; border: 1px solid #9ca3af; background: #fff; cursor: pointer; }
.chip:hover { border-color: var(--accent); }
.chip.active { outline: 3px solid var(--accent); outline-offset: 1px; }
.chip.elsewhere { opacity: .75; }
.chip.num { min-width: 42px; text-align: center; font-weight: 700; }
.chip-note { font-size: 11px; opacity: .7; }
table.grid { width: 100%; border-collapse: collapse; font-size: 14px; }
table.grid th, table.grid td { border: 1px solid var(--line); padding: 3px 4px; text-align: left; }
table.grid th { background: #e5e7eb; font-weight: 600; }
table.grid td.num { width: 28px; text-align: center; font-weight: 700; }
table.grid select, table.grid input { padding: 5px 6px; }
.stepper { display: inline-flex; align-items: center; gap: 6px; }
.stepper-label { font-size: 13px; color: var(--muted); }
.stepper output { min-width: 22px; text-align: center; font-weight: 700; }
#roster-list, #sections-list { list-style: none; padding: 0; margin: 0 0 8px; }
#roster-list li, #sections-list li { display: flex; gap: 6px; align-items: center; margin-bottom: 6px; flex-wrap: wrap; }
#roster-list input.rank, #new-rank { width: 64px; flex: 0 0 64px; }
#roster-list li input[type=text]:not(.rank) { flex: 1 1 110px; }
#roster-form { display: flex; gap: 6px; align-items: center; }
.swatches { display: inline-flex; gap: 4px; align-items: center; }
.swatch { width: 26px; height: 26px; border-radius: 50%; border: 1px solid #9ca3af; cursor: pointer; padding: 0; }
.swatch.active { outline: 3px solid var(--accent); outline-offset: 1px; }
#editor .fields { margin-top: 6px; }
.toast { position: fixed; left: 50%; bottom: 20px; transform: translate(-50%, 20px); background: #111827; color: #fff; padding: 10px 16px; border-radius: 8px; opacity: 0; transition: .2s; pointer-events: none; z-index: 30; max-width: 90vw; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: var(--danger); }
#print-sheet { display: none; }

@media (max-width: 960px) {
  main { grid-template-columns: 1fr; padding: 8px; gap: 8px; }
  .plan-col { position: static; }
  .card { padding: 10px; border-radius: 8px; }
  header.top .btn { padding: 7px 10px; font-size: 13px; }
  .fields.three { grid-template-columns: 1fr 1fr; }
  .fields.three label:first-child { grid-column: 1 / -1; }
  main { padding-bottom: calc(74px + env(safe-area-inset-bottom)); }
  h1 .t-long { display: none; }
  h1 .t-short { display: inline; }
  header.top .actions { overflow-x: auto; scrollbar-width: none; }
  header.top .actions::-webkit-scrollbar { display: none; }
  /* Printing and a second PDF button are desktop conveniences; Share covers both here. */
  #btn-print { display: none; }
  #btn-share:not([hidden]) ~ #btn-pdf { display: none; }
  /* Tabs become a thumb-reachable bottom bar. */
  .tabs { position: fixed; left: 0; right: 0; bottom: 0; z-index: 25; gap: 0; background: #fff; border-top: 1px solid var(--line); box-shadow: 0 -2px 12px rgba(0,0,0,.1); padding-bottom: env(safe-area-inset-bottom); }
  .tabs button { flex-direction: column; gap: 3px; min-height: 58px; padding: 7px 2px 6px; font-size: 11px; font-weight: 600; border: none; border-radius: 0; background: transparent; color: var(--muted); }
  .tabs button:hover { background: transparent; }
  .tabs button.active { background: transparent; color: var(--accent); }
  .tabs .ico { display: block; padding: 2px 12px; border-radius: 999px; line-height: 0; }
  .tabs button.active .ico { background: #dceafa; }
  .card.tab { border-top: 1px solid var(--line); border-radius: 8px; }
  .sheet { position: fixed; left: 0; right: 0; bottom: calc(58px + env(safe-area-inset-bottom)); margin: 0; border-radius: 14px 14px 0 0; max-height: 52vh; overflow-y: auto; z-index: 20; box-shadow: 0 -6px 24px rgba(0,0,0,.2); }
  .toast { bottom: calc(74px + env(safe-area-inset-bottom)); }
  /* 16px keeps iOS from zooming in when a field is focused. */
  input[type=text], input[type=date], input[type=number], select, textarea { font-size: 16px; }
  .chip { padding: 10px 15px; font-size: 15px; }
  .btn.small { padding: 9px 13px; }
  .icon { padding: 6px 10px; font-size: 22px; }
  .swatch { width: 32px; height: 32px; }
  table.grid select, table.grid input { padding: 8px 6px; }
}
@media print {
  body { background: #fff; }
  header.top, main, .toast { display: none !important; }
  #print-sheet { display: block; }
  #print-sheet svg { width: 210mm; height: 297mm; }
  @page { size: A4 portrait; margin: 0; }
}
