/* OneScreen Write — guest board.
 *
 * Built to the panel's Elementary design (ModeStyle.kt, BottomToolbar.kt, ElementaryPenPopup.kt):
 * the same three floating clusters, the same pill bar, the same purple "well" behind the chosen
 * tool. Sizes are the panel's dp values at a 1920-wide reference, scaled by --s exactly as the
 * panel scales them (screen width / 1920, clamped to 0.5–1).
 */

@font-face { font-family: Fredoka; src: url(../fonts/fredoka.ttf) format('truetype'); font-weight: 300 700; font-display: swap; }
@font-face { font-family: Caveat; src: url(../fonts/caveat.ttf) format('truetype'); font-weight: 400 700; font-display: swap; }

:root {
  --s: clamp(0.62, calc(100vw / 1920px), 1);
  --amethyst: #6F3393;
  --amethyst-dark: #5E2B7E;
  --grape-tint: #F4E3FF;
  --navy: #1E2340;
  --ink: #1A1A1C;
  --muted: #6B6B70;
  --hairline: #E2E1DE;
  --surface: #FFFFFF;
  --canvas: #FFFFFF;
  --shadow: 0 calc(4px * var(--s)) calc(12px * var(--s)) rgba(26, 26, 28, 0.12);
  --well: rgba(111, 51, 147, 0.10);
  --danger: #C62828;
  --font: Fredoka, Roboto, 'Segoe UI', system-ui, sans-serif;
}

@media (max-width: 700px) { :root { --s: 0.62; } }

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--font);
  color: var(--ink);
  background: #FAFAFA;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

.screen { position: fixed; inset: 0; }

/* ── Join ─────────────────────────────────────────────────────────────── */

#join, #ended {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 16px;
  background:
    radial-gradient(circle at 15% 20%, rgba(111, 51, 147, 0.08) 0, transparent 40%),
    radial-gradient(circle at 85% 80%, rgba(130, 195, 65, 0.10) 0, transparent 40%),
    #FAFAFA;
  overflow-y: auto;
}
.join-card {
  width: min(420px, 100%);
  background: var(--surface);
  border-radius: 28px;
  box-shadow: 0 8px 28px rgba(26, 26, 28, 0.10);
  padding: 32px 28px 28px;
  display: flex; flex-direction: column; gap: 14px;
}
.join-mark { width: 92px; height: 92px; align-self: center; margin: -10px 0 -14px; }
.join-card h1 { margin: 0; text-align: center; font-weight: 600; font-size: 26px; letter-spacing: 0.01em; }
.join-sub { margin: -4px 0 6px; text-align: center; color: var(--muted); font-size: 15px; line-height: 1.4; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field span { font-weight: 600; font-size: 13px; letter-spacing: 0.04em; color: var(--muted); }
.field input {
  font: inherit; font-size: 18px;
  padding: 12px 16px;
  border: 2px solid var(--hairline);
  border-radius: 16px;
  outline: none;
  background: #FFF;
  transition: border-color 0.15s;
}
.field input:focus { border-color: var(--amethyst); }
#join-code { font-size: 28px; font-weight: 600; letter-spacing: 0.2em; text-align: center; }
.join-error { margin: 0; min-height: 1.2em; color: var(--danger); font-size: 14px; text-align: center; }
.btn-primary {
  background: var(--amethyst); color: #FFF;
  font-weight: 600; font-size: 18px; letter-spacing: 0.02em;
  border-radius: 999px; padding: 14px 20px;
  transition: background 0.15s, transform 0.1s;
}
.btn-primary:hover { background: var(--amethyst-dark); }
.btn-primary:active { transform: scale(0.98); }
.btn-primary:disabled { opacity: 0.5; cursor: default; }
.brand { margin-top: 18px; color: var(--amethyst); font-weight: 600; letter-spacing: 0.04em; }

/* ── Board ────────────────────────────────────────────────────────────── */

#board { background: var(--canvas); touch-action: none; }
#canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
#board[data-tool="move"] #canvas { cursor: grab; }
#board[data-tool="move"].panning #canvas { cursor: grabbing; }
#board[data-tool="pen"] #canvas, #board[data-tool="shape"] #canvas { cursor: crosshair; }
#board[data-tool="text"] #canvas { cursor: text; }
#board[data-tool="eraser"] #canvas { cursor: none; }

/* Session pill, top centre — who you're with and whether you're connected. */
#session-pill {
  position: absolute; top: max(12px, env(safe-area-inset-top)); left: 50%; transform: translateX(-50%);
  display: flex; align-items: center; gap: 10px;
  background: var(--surface); border-radius: 999px; box-shadow: var(--shadow);
  padding: 6px 6px 6px 16px;
  font-size: 15px; font-weight: 500; white-space: nowrap; max-width: calc(100vw - 24px);
  z-index: 5;
}
#session-title { overflow: hidden; text-overflow: ellipsis; max-width: 30vw; }
.code { font-weight: 600; color: var(--amethyst); letter-spacing: 0.08em; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: #B8B8BC; flex: none; }
.dot.online { background: #43A047; }
.dot.reconnecting, .dot.connecting { background: #F5A623; animation: pulse 1s infinite alternate; }
@keyframes pulse { to { opacity: 0.35; } }
.people-btn {
  display: flex; align-items: center; gap: 4px;
  background: var(--grape-tint); border-radius: 999px; padding: 4px 12px 4px 8px;
  font-weight: 600; color: var(--amethyst);
}
.people-btn svg { width: 22px; height: 22px; }

.banner {
  position: absolute; top: calc(max(12px, env(safe-area-inset-top)) + 54px); left: 50%; transform: translateX(-50%);
  background: var(--navy); color: #FFF; border-radius: 999px; padding: 8px 18px;
  font-size: 14px; font-weight: 500; box-shadow: var(--shadow); z-index: 5; white-space: nowrap;
}
.banner.warn { background: #B4561B; }

.toast {
  position: absolute; left: 50%; top: calc(max(12px, env(safe-area-inset-top)) + 100px); transform: translate(-50%, -12px);
  background: var(--ink); color: #FFF; border-radius: 14px; padding: 10px 18px;
  font-size: 15px; opacity: 0; pointer-events: none; transition: opacity 0.2s, transform 0.2s; z-index: 30;
  max-width: calc(100vw - 32px); text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ── Toolbar: three floating clusters, as on the panel ─────────────────── */

.toolbar {
  position: absolute; left: 0; right: 0;
  bottom: max(calc(40px * var(--s)), env(safe-area-inset-bottom));
  padding: 0 calc(50px * var(--s));
  display: flex; align-items: flex-end; justify-content: space-between; gap: 12px;
  pointer-events: none; z-index: 10;
}
.cluster {
  pointer-events: auto;
  display: flex; align-items: center;
  height: calc(99px * var(--s));
  padding: calc(14.5px * var(--s)) calc(15px * var(--s));
  background: var(--surface);
  border-radius: 999px;
  box-shadow: var(--shadow);
}
#cluster-tools { padding: 0 calc(13px * var(--s)); }
.tile {
  position: relative;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  min-width: calc(76px * var(--s));
  height: 100%;
  padding: 0 calc(4px * var(--s));
  gap: calc(46px * var(--s) * 10 / 92);
}
.tile img, .tile .glyph { width: calc(46px * var(--s)); height: calc(46px * var(--s)); position: relative; z-index: 1; }
.tile span {
  font-weight: 600; font-size: calc(16px * var(--s)); letter-spacing: 0.04em; line-height: 1;
  color: var(--ink); white-space: nowrap; position: relative; z-index: 1;
}
/* The "well": a capsule behind the icon only. */
.tile::before {
  content: ''; position: absolute;
  width: calc(74px * var(--s)); height: calc(50px * var(--s));
  top: calc(50% - (46px * var(--s) * 10 / 92 + 16px * var(--s)) / 2 - 25px * var(--s));
  left: 50%; transform: translateX(-50%) scale(0.85);
  border-radius: 999px; background: var(--well);
  opacity: 0; transition: opacity 0.15s, transform 0.15s;
}
.tile.active::before, .tile:active:not(:disabled)::before { opacity: 1; transform: translateX(-50%) scale(1); }
.tile:disabled { opacity: 0.3; cursor: default; }
.tile.locked { opacity: 0.3; }
.tile.locked::after {
  content: ''; position: absolute; top: calc(6px * var(--s)); right: calc(10px * var(--s));
  width: calc(18px * var(--s)); height: calc(18px * var(--s));
  background: url(../icons/osw_lock.svg) center / contain no-repeat; z-index: 2;
}
.tile.raised::before { opacity: 1; transform: translateX(-50%) scale(1); background: rgba(245, 166, 35, 0.25); }

.page-pill {
  min-width: calc(84.5px * var(--s)); height: calc(99px * var(--s) * 0.44);
  margin: 0 calc(8px * var(--s));
  display: flex; align-items: center; justify-content: center; padding: 0 12px;
  border: calc(2px * var(--s)) solid #E2E1DE; border-radius: 999px;
  font-weight: 600; font-size: calc(16px * var(--s)); white-space: nowrap;
}

/* Below ~1150 px the clusters stack, tools on top — as BottomToolbar does. */
@media (max-width: 1150px) {
  .toolbar { display: grid; grid-template-columns: auto auto; justify-content: center; gap: 10px; }
  #cluster-tools { grid-column: 1 / -1; justify-self: center; order: -1; }
}
@media (max-width: 560px) {
  .tile { min-width: calc(62px * var(--s)); }
  .tile span { font-size: 10px; }
}

/* ── Popups ───────────────────────────────────────────────────────────── */

.popup {
  position: absolute; z-index: 20;
  background: var(--surface); border-radius: 20px; box-shadow: var(--shadow);
  padding: 15px 18px 18px;
  max-width: calc(100vw - 24px);
  max-height: calc(100vh - 200px); overflow: auto;
}
.popup::after {
  /* The tail, pointing at the tool that opened it. */
  content: ''; position: absolute; bottom: -11px; left: var(--tail, 50%);
  width: 25.5px; height: 22.5px; transform: translateX(-50%);
  background: var(--surface);
  clip-path: polygon(0 0, 100% 0, 50% 100%);
}
.popup.no-tail::after { display: none; }
.pop-head { display: flex; align-items: center; gap: 12px; margin-bottom: 8px; }
.pop-head h2 { margin: 0; font-size: 18px; font-weight: 500; letter-spacing: 0.04em; flex: 1; }
.pop-close { width: 30px; height: 30px; border-radius: 50%; background: var(--grape-tint); display: grid; place-items: center; }
.pop-close img { width: 13px; height: 13px; }
.popup h3 { margin: 14px 0 8px; font-size: 14px; font-weight: 600; letter-spacing: 0.02em; color: var(--ink); }

.pen-body { display: flex; gap: 30px; }
.pen-left { flex: 1; min-width: 0; }
.pen-right { width: 200px; display: flex; flex-direction: column; align-items: center; border-left: 1px solid var(--hairline); padding-left: 24px; }
.pen-right h3 { margin-top: 0; align-self: flex-start; }
#pen-preview { width: 178.5px; height: 151.5px; border: 0.8px solid var(--hairline); border-radius: 14px; }
@media (max-width: 640px) { .pen-body { flex-direction: column; gap: 0; } .pen-right { display: none; } }

.pen-types { display: flex; gap: 8px; }
.pen-type {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  min-width: 78px; padding: 8px 10px; border-radius: 11px; border: 1px solid transparent;
  font-size: 12px; font-weight: 600;
}
.pen-type img { width: 32px; height: 32px; }
.pen-type.active { background: var(--grape-tint); border-color: var(--amethyst); }
.stroke-sample { width: 42px; height: 8px; border-radius: 4px; background: currentColor; }
.stroke-sample[data-sample="highlighter"] { opacity: 0.45; height: 10px; border-radius: 2px; }

.size-row { display: flex; align-items: center; gap: 12px; font-size: 13px; color: var(--muted); }
.taper {
  -webkit-appearance: none; appearance: none; flex: 1; height: 30px; margin: 0; background: transparent; cursor: pointer;
  --pct: 50%;
}
.taper::-webkit-slider-runnable-track {
  height: 13px;
  background:
    linear-gradient(90deg, var(--amethyst) var(--pct), #E6E2D9 var(--pct));
  clip-path: polygon(0 42%, 100% 0, 100% 100%, 0 58%);
  border-radius: 2px;
}
.taper::-moz-range-track {
  height: 13px; background: linear-gradient(90deg, var(--amethyst) var(--pct), #E6E2D9 var(--pct));
  clip-path: polygon(0 42%, 100% 0, 100% 100%, 0 58%);
}
.taper::-webkit-slider-thumb {
  -webkit-appearance: none; width: 26px; height: 26px; margin-top: -6.5px; border-radius: 50%;
  background: radial-gradient(circle, var(--amethyst) 0 2px, #FFF 2.5px);
  border: 1.5px solid var(--navy);
}
.taper::-moz-range-thumb {
  width: 23px; height: 23px; border-radius: 50%;
  background: radial-gradient(circle, var(--amethyst) 0 2px, #FFF 2.5px);
  border: 1.5px solid var(--navy);
}

.swatches { display: flex; flex-wrap: wrap; gap: 12px; }
.swatch {
  width: 32px; height: 32px; border-radius: 50%; position: relative;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.06);
}
.swatch.white { box-shadow: inset 0 0 0 1px var(--hairline); }
/* The student's own colour: first in the row, marked with a small "you" dot. */
.swatch.mine::before {
  content: ''; position: absolute; right: -3px; top: -3px; width: 11px; height: 11px;
  border-radius: 50%; background: #FFF; box-shadow: inset 0 0 0 3px var(--amethyst);
}
.swatch.active { box-shadow: 0 0 0 1.85px #FFF, 0 0 0 3.7px var(--navy); }
.swatch.active::after {
  content: ''; position: absolute; inset: 8px;
  background: url(../icons/ele_penpop_check.svg) center / contain no-repeat;
}

.eraser-body { display: flex; align-items: center; gap: 18px; }
.eraser-preview { width: 90px; height: 90px; display: grid; place-items: center; }
#eraser-dot { display: block; border-radius: 50%; background: rgba(111, 51, 147, 0.2); box-shadow: 0 0 0 2px #FFF, 0 0 0 3.5px var(--amethyst); }
#pop-eraser { width: 420px; }

#pop-shape { width: 540px; }
.shape-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(58px, 1fr)); gap: 3px; }
.shape-cell {
  aspect-ratio: 1; border-radius: 15px; border: 1.5px solid transparent;
  display: grid; place-items: center;
}
.shape-cell img { width: 80%; height: 80%; }
.shape-cell:hover { background: var(--grape-tint); }
.shape-cell.active { border-color: var(--amethyst); }

.seg { display: inline-flex; background: var(--grape-tint); border-radius: 999px; padding: 3px; gap: 2px; }
.seg button { padding: 6px 14px; border-radius: 999px; font-weight: 500; }
.seg button.active { background: var(--amethyst); color: #FFF; }
#pop-text, #pop-sticky { width: 420px; }

.people { width: 340px; }
#people-list, #perm-list { list-style: none; margin: 0; padding: 0; }
#people-list li { display: flex; align-items: center; gap: 10px; padding: 7px 0; font-size: 15px; }
#people-list .swatch-dot { width: 14px; height: 14px; border-radius: 50%; flex: none; }
#people-list .you { color: var(--muted); font-size: 13px; }
#people-list .hand { margin-left: auto; font-size: 18px; }
.you-can { border-top: 1px solid var(--hairline); margin-top: 8px; }
#perm-list li { display: flex; align-items: center; gap: 8px; padding: 4px 0; font-size: 14px; }
#perm-list li::before { content: '✓'; color: #43A047; font-weight: 700; width: 14px; }
#perm-list li.off { color: var(--muted); }
#perm-list li.off::before { content: '✕'; color: #B8B8BC; }

/* Selection bar, floating over the selection. */
.sel-bar {
  position: absolute; z-index: 15; display: flex; gap: 4px;
  background: var(--surface); border-radius: 999px; box-shadow: var(--shadow); padding: 6px 10px;
}
.sel-bar button { display: flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: 999px; font-weight: 600; font-size: 14px; }
.sel-bar button:hover { background: var(--grape-tint); }
.sel-bar img { width: 22px; height: 22px; }

#text-editor {
  position: absolute; z-index: 12;
  margin: 0; padding: 0; border: 1.5px dashed var(--amethyst); border-radius: 4px;
  background: rgba(255, 255, 255, 0.6); outline: none; resize: none; overflow: hidden;
  line-height: 1.25; white-space: pre-wrap;
}
#text-editor.sticky { background: transparent; border-color: transparent; }
