/* Self-hosted so the page works behind school web filters.
   Variable font, SIL Open Font License, latin subset. */
@font-face {
  font-family: 'Baloo 2';
  font-weight: 400 800;
  font-display: swap;
  src: url(../fonts/baloo2.woff2) format('woff2');
}

:root {
  --ink: #1d1a17; --green: #2f5d3a; --line: #d9d4cc; --paper: #f6f3ee;
  --wood: #e9c995; --wood-edge: #b48a52; --c: #3b7dd8;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--paper); color: var(--ink);
  font-family: 'Baloo 2', system-ui, sans-serif;
  display: flex; flex-direction: column;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; opacity: 0.45; }
[hidden] { display: none !important; }
kbd { font: inherit; font-size: 0.85em; padding: 0 5px; border: 1.5px solid #aaa; border-bottom-width: 3px; border-radius: 5px; background: #fff; }

button {
  padding: 5px 12px; border: 2px solid var(--ink); border-radius: 9px; background: #fff;
  font-weight: 700; line-height: 1.2;
}
button.primary { background: var(--green); color: #fff; box-shadow: 2px 2px 0 var(--ink); }
button.danger { color: #a3262a; border-color: #a3262a; }
button.wide { width: 100%; margin-top: 10px; }

/* ---------- Top bar ---------- */

#top {
  display: flex; align-items: center; gap: 14px;
  padding: 10px 18px; border-bottom: 3px solid var(--ink); background: #fff;
}
#top h1 { margin: 0; font-size: 1.6rem; line-height: 1; }
.home { color: #666; font-weight: 700; text-decoration: none; font-size: 0.9rem; }
#classes { display: flex; gap: 6px; flex: 1; min-width: 120px; overflow-x: auto; padding: 2px 4px 4px 2px; }
.tab { flex: none; }
.tab {
  display: flex; align-items: center; gap: 6px; padding: 4px 12px; border-color: var(--line);
}
.tab i { width: 12px; height: 12px; border-radius: 50%; background: var(--c); }
.tab small { color: #777; font-weight: 600; }
.tab[aria-pressed="true"] { border-color: var(--c); background: color-mix(in srgb, var(--c) 14%, #fff); box-shadow: 2px 2px 0 var(--c); }
.tab.add { padding: 4px 11px; border-style: dashed; color: #555; }
.tools { display: flex; gap: 6px; align-items: center; flex: none; }
#top h1, .home { white-space: nowrap; }
#undo, #redo { font-size: 1.25rem; padding: 2px 10px; }

/* ---------- Layout ---------- */

#app { flex: 1; display: grid; grid-template-columns: 330px minmax(0, 1fr); grid-template-rows: minmax(0, 1fr); min-height: 0; }
#side {
  overflow-y: auto; padding: 14px 16px 24px; background: #fff; border-right: 3px solid var(--ink);
}
#steps { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-bottom: 14px; }
#steps button { padding: 6px 4px; border-color: var(--line); }
#steps button b {
  display: inline-grid; place-items: center; width: 1.45em; height: 1.45em; border-radius: 50%;
  background: var(--line); font-size: 0.85em; margin-right: 2px;
}
#steps button[aria-pressed="true"] { border-color: var(--ink); background: var(--ink); color: #fff; }
#steps button[aria-pressed="true"] b { background: #fff; color: var(--ink); }
.panel { display: none; }
body[data-step="names"] .panel[data-for="names"],
body[data-step="room"] .panel[data-for="room"],
body[data-step="seats"] .panel[data-for="seats"] { display: block; }
#side h2 { font-size: 1.05rem; margin: 16px 0 6px; }
#side h2:first-child { margin-top: 0; }
.hint { color: #5f5a54; font-size: 0.9rem; line-height: 1.35; margin: 4px 0 8px; }
.sub { font-weight: 700; margin: 10px 0 4px; }
.field { display: block; margin-bottom: 10px; }
.field > span { display: block; font-weight: 800; margin-bottom: 3px; }
.field input, .field textarea, dialog textarea, select {
  width: 100%; padding: 6px 9px; border: 2px solid var(--ink); border-radius: 8px; background: #fff;
}
textarea { resize: vertical; line-height: 1.35; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-top: 10px; }
.row.end { justify-content: flex-end; margin-top: 16px; }
.row.size label { display: flex; gap: 6px; align-items: center; font-weight: 700; }
.row.size input, #layout-n { width: 4.2em; padding: 2px 6px; border: 2px solid var(--ink); border-radius: 7px; }
.next { margin-top: 18px !important; }
.check { display: flex; gap: 8px; align-items: baseline; margin: 6px 0; cursor: pointer; line-height: 1.3; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.grid2 button { padding: 8px 6px; }
.seg { display: flex; flex-wrap: wrap; gap: 6px; }
.seg button[aria-pressed="true"] { background: var(--ink); color: #fff; }

.layout, .add-item {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 6px 4px 4px; border-color: var(--line); font-size: 0.8rem; font-weight: 700;
}
.layout:hover, .add-item:hover { border-color: var(--ink); }
.layout svg { width: 100%; height: auto; }
.layout svg .fl { fill: #f1e9dc; }
.layout svg rect:not(.fl) { fill: var(--wood); stroke: var(--wood-edge); stroke-width: 6; }
.add-item { touch-action: none; }
.mini { position: relative; width: 100%; max-height: 46px; container-type: inline-size; }
.mini .lab { display: none; }
.add-item span { line-height: 1.1; }

#picked { margin-top: 16px; padding: 12px; border: 2px solid var(--c); border-radius: 12px; background: color-mix(in srgb, var(--c) 7%, #fff); }
#picked h2 { margin: 0 !important; }
#picked select { margin-bottom: 8px; }
.pairs { list-style: none; margin: 0 0 6px; padding: 0; }
.pairs li { display: flex; align-items: center; justify-content: space-between; gap: 6px; padding: 2px 0 2px 8px; border-left: 4px solid #c0392b; margin-bottom: 4px; }
.pairs .x { padding: 0 8px; border-color: var(--line); }

/* ---------- Stage and room ---------- */

#stage { display: flex; flex-direction: column; min-width: 0; min-height: 0; padding: 10px 16px 12px; }
#stage-head { display: flex; align-items: baseline; gap: 14px; flex-wrap: wrap; }
#room-title { margin: 0; font-size: 1.5rem; }
#room-title::before { content: ''; display: inline-block; width: 0.55em; height: 0.55em; border-radius: 50%; background: var(--c); margin-right: 8px; vertical-align: 0.05em; }
#room-info { color: #666; font-weight: 600; }
#room-name { color: #333; font-weight: 700; }
.row.tight { gap: 5px; margin: 0 0 6px; }
.row.tight button { padding: 3px 9px; font-size: 0.9rem; }
#side .field select { padding: 5px 8px; font-weight: 700; }

#stage { position: relative; }
#welcome {
  position: absolute; z-index: 20; left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: min(560px, calc(100% - 32px)); max-height: calc(100% - 32px); overflow-y: auto;
  padding: 22px 26px; background: #fff; border: 3px solid var(--ink); border-radius: 18px;
  box-shadow: 6px 6px 0 var(--ink);
}
#welcome h2 { margin: 0 0 8px; font-size: 1.6rem; }
#welcome ol { margin: 0 0 6px; padding-left: 1.3em; line-height: 1.4; }
#welcome li { margin-bottom: 8px; }
#welcome li::marker { font-weight: 800; color: var(--green); }
body.fresh #room-wrap { opacity: 0.35; }
body.fresh #tray, body.fresh #stage-head { visibility: hidden; }
#clash { color: #b0302a; font-weight: 700; }
#turn { margin-left: auto; border-color: var(--line); }
#room-wrap { flex: 1; min-height: 260px; display: grid; place-items: center; padding: 8px 0; }

#room, .print-room {
  position: relative; container-type: inline-size;
  background-color: #f3ece0;
  background-image:
    linear-gradient(#e3d9c8 1px, transparent 1px),
    linear-gradient(90deg, #e3d9c8 1px, transparent 1px);
  border: 4px solid #6e6256; border-radius: 6px;
  user-select: none; -webkit-user-select: none; touch-action: none;
}
#items, #chips, .items, .chips { position: absolute; inset: 0; }
#items, .items { z-index: 0; }
#chips, .chips { pointer-events: none; }
#chips > *, #tray-chips > * { pointer-events: auto; }

.item { position: absolute; }
.item .chair {
  position: absolute; border-radius: 30% 30% 45% 45% / 40% 40% 60% 60%;
  background: var(--c); opacity: 0.85;
}
.it-desk, .it-pair, .it-table4, .it-table6, .it-round, .it-computer {
  background: var(--wood); border: 0.25cqw solid var(--wood-edge); border-radius: 0.6cqw;
  box-shadow: 0 0.25cqw 0 rgb(0 0 0 / 0.08);
}
.it-pair::after, .it-table4::after, .it-table6::after {
  content: ''; position: absolute; inset: 0;
  background: linear-gradient(90deg, transparent calc(50% - 1px), rgb(0 0 0 / 0.12) 50%, transparent calc(50% + 1px));
}
.it-table6::after { background: linear-gradient(90deg, transparent calc(33.3% - 1px), rgb(0 0 0 / 0.1) 33.3%, transparent calc(33.3% + 1px), transparent calc(66.6% - 1px), rgb(0 0 0 / 0.1) 66.6%, transparent calc(66.6% + 1px)); }
.it-round { border-radius: 50%; }
.it-computer .screen { position: absolute; left: 22%; right: 22%; top: 6%; height: 16%; background: #3a3f46; border-radius: 0.3cqw; }
.it-teacher { background: #c99b62; border: 0.25cqw solid #8b6435; border-radius: 0.6cqw; }
.it-board { background: #fff; border: 0.3cqw solid #555; border-radius: 0.3cqw; }
.it-door { background: #8b5a2b; border-radius: 0.2cqw; }
.it-window { background: repeating-linear-gradient(90deg, #bfe1f5 0 30%, #8fb9d1 30% 33%); border: 0.2cqw solid #6e93aa; }
.it-shelf { background: repeating-linear-gradient(90deg, #b07a43 0 8%, #8c5a2b 8% 10%); border-radius: 0.3cqw; }
.it-cupboard { background: #cfc7bb; border: 0.25cqw solid #8e877c; border-radius: 0.3cqw; }
.it-sink { background: #d9dee2; border: 0.25cqw solid #8b949b; border-radius: 0.6cqw; }
.it-sink::after { content: ''; position: absolute; inset: 22% 25%; border-radius: 40%; background: #b9c3ca; }
.it-carpet { background: #c6d9b8; border: 0.3cqw dashed #8fae79; border-radius: 1.4cqw; opacity: 0.9; }
.it-label { border: 0.2cqw dashed transparent; }
.lab {
  position: absolute; inset: 0; display: grid; place-items: center; text-align: center;
  font-weight: 700; color: rgb(0 0 0 / 0.55); line-height: 1; white-space: nowrap; pointer-events: none; z-index: 1;
}
.lab.out { inset: auto 0 auto 0; top: 100%; height: auto; padding-top: 0.25cqw; color: #6b6158; }
.it-label .lab { color: #5a5048; font-weight: 800; }
.it-sink .lab, .it-cupboard .lab { align-items: end; }

body[data-step="room"]:not(.show) .item { cursor: grab; }
body[data-step="room"]:not(.show) .it-label { border-color: #bbb; }
body[data-step="room"]:not(.show) #chips { opacity: 0.35; }
body[data-step="room"]:not(.show) #chips > * { pointer-events: none; }
.item.selected { outline: 0.3cqw solid #ff8a00; outline-offset: 0.3cqw; z-index: 2; }
.item .handle {
  position: absolute; right: -1.1cqw; bottom: -1.1cqw; width: 2.2cqw; height: 2.2cqw; min-width: 16px; min-height: 16px;
  border-radius: 50%; background: #fff; border: 0.35cqw solid #ff8a00; cursor: nwse-resize; z-index: 3;
}
#marquee { position: absolute; border: 2px dashed #ff8a00; background: rgb(255 138 0 / 0.08); pointer-events: none; }
#sel-tools {
  position: absolute; z-index: 5; display: flex; gap: 4px; transform: translate(-50%, calc(-100% - 10px));
  padding: 4px; background: var(--ink); border-radius: 10px; box-shadow: 0 4px 12px rgb(0 0 0 / 0.25); white-space: nowrap;
}
#sel-tools.below { transform: translate(-50%, 10px); }
#sel-tools button { padding: 3px 9px; font-size: 0.85rem; border: 0; }

/* Names */
.chip {
  position: absolute; display: flex; flex-direction: column; align-items: center; justify-content: center;
  background: #fff; border-radius: 0.5cqw; border-top: 0.45cqw solid var(--c);
  box-shadow: 0 0.15cqw 0.4cqw rgb(0 0 0 / 0.18);
  font-weight: 700; line-height: 1.02; text-align: center; white-space: nowrap; overflow: hidden;
  cursor: grab; touch-action: none; transition: box-shadow 0.15s, outline-color 0.15s;
}
.chip span { display: block; }
.chip.pinned::after { content: '📌'; position: absolute; top: 0; right: 0.1em; font-size: max(12px, 0.6em); }
.chip.clash { background: #ffe3df; outline: 0.35cqw solid #c0392b; }
.chip.picked { outline: 0.4cqw solid var(--ink); outline-offset: 0.15cqw; z-index: 2; }
.chip.dragging { opacity: 0.25; }
.chip.target, .spot.target { outline: 0.5cqw solid #ff8a00; outline-offset: 0.2cqw; }
.spot { position: absolute; border: 0.25cqw dashed rgb(0 0 0 / 0.25); border-radius: 0.5cqw; cursor: pointer; }
.ghost {
  position: fixed; z-index: 100; pointer-events: none; margin: 0; opacity: 0.95;
  box-shadow: 0 10px 24px rgb(0 0 0 / 0.3); rotate: -3deg;
}
.mini.ghost { container-type: size; max-height: none; background: rgb(255 255 255 / 0.6); border-radius: 6px; }

#tray {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap; min-height: 52px;
  padding: 8px 12px; border: 2px dashed var(--line); border-radius: 12px; background: #fff;
}
#tray.target { border-color: #ff8a00; background: #fff6ea; }
#tray.none { border-style: solid; }
#tray-title { color: #555; }
#tray-chips { display: flex; flex-wrap: wrap; gap: 6px; }
#tray-chips .chip { position: static; padding: 3px 10px; font-size: 1.05rem; border-radius: 7px; border-top-width: 4px; }
body[data-step="room"]:not(.show) #tray { display: none; }

#show-bar { display: none; }

/* ---------- Show on the board ---------- */

body.show #top, body.show #side { display: none; }
body.show #app { grid-template-columns: 1fr; }
body.show #stage { padding: 1.2vh 2vw; }
body.show #room-title { font-size: 2.6rem; }
body.show #room-info, body.show #clash { display: none; }
body.show #turn { display: none; }
body.show .spot { border-color: transparent; }
body.show #tray.none { display: none; }
body.show #show-bar {
  display: flex; justify-content: center; gap: 10px; padding-top: 8px; opacity: 0.35; transition: opacity 0.2s;
}
body.show #show-bar:hover, body.show #show-bar:focus-within { opacity: 1; }
body.show #show-bar button { font-size: 1.15rem; padding: 6px 16px; }

#toast {
  position: fixed; left: 50%; bottom: 24px; z-index: 200; transform: translate(-50%, 150%);
  padding: 10px 18px; background: var(--ink); color: #fff; border-radius: 12px; font-weight: 700;
  transition: transform 0.25s; pointer-events: none;
}
#toast.on { transform: translate(-50%, 0); }

dialog { border: 3px solid var(--ink); border-radius: 16px; padding: 18px 22px; width: min(560px, 92vw); }
dialog::backdrop { background: rgb(30 25 20 / 0.45); }
dialog h2 { margin: 0 0 6px; }
dialog h3 { margin: 14px 0 0; font-size: 1.05rem; }
#link-status { color: var(--green); font-weight: 700; }

#print { display: none; }

@media (max-width: 900px) {
  body { height: auto; }
  #app { grid-template-columns: 1fr; }
  #side { border-right: 0; border-bottom: 3px solid var(--ink); }
  #room-wrap { min-height: 60vw; }
}

/* ---------- Print ---------- */

@page { size: landscape; margin: 10mm; }
@media print {
  body { display: block; height: auto; background: #fff; }
  body > :not(#print) { display: none !important; }
  #print { display: block; }
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .page { break-after: page; height: 188mm; display: flex; flex-direction: column; }
  .page:last-child { break-after: auto; }
  .page header { display: flex; align-items: baseline; gap: 14px; margin-bottom: 4mm; }
  .page h1 { margin: 0; font-size: 22pt; }
  .page h1::before { content: ''; display: inline-block; width: 0.5em; height: 0.5em; border-radius: 50%; background: var(--c); margin-right: 6px; }
  .page header p { margin: 0; color: #555; }
  .print-body { flex: 1; display: flex; gap: 6mm; align-items: flex-start; min-height: 0; }
  .print-room { width: min(100%, calc(168mm * var(--ar))); flex: none; max-width: 100%; }
  .print-body:has(.roll) .print-room { max-width: calc(100% - 62mm); }
  .print-room .chip.pinned::after { display: none; }
  .print-room .chip { box-shadow: none; border: 1px solid #bbb; border-top: 0.45cqw solid var(--c); }
  .roll { margin: 0; padding-left: 7mm; columns: 1; font-size: 10pt; line-height: 1.45; flex: 1; }
  .roll li::marker { color: #888; }
  .roll li::after { content: ''; display: inline-block; width: 3.2mm; height: 3.2mm; border: 1px solid #555; margin-left: 2mm; vertical-align: -0.4mm; float: right; }
}
