*, *::before, *::after { box-sizing: border-box; }
:root {
  --bg: #f1f5f9;
  --panel: #ffffff;
  --ink: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --brand: #005bff;        /* Futura blue */
  --brand-ink: #ffffff;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 12px 32px -12px rgba(15, 23, 42, .18);
  font-family: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1120; --panel: #111827; --ink: #e5e7eb; --muted: #94a3b8;
    --line: #1f2937; --shadow: 0 1px 2px rgba(0,0,0,.4), 0 20px 40px -16px rgba(0,0,0,.6);
    --brand: #6ca0ff;      /* Futura blue, lightened for dark */
  }
}
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  min-height: 100%;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--brand); }
button { font: inherit; cursor: pointer; }

/* ---------- landing ---------- */
.landing {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 32px 16px;
}
.card {
  width: min(440px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 20px;
  box-shadow: var(--shadow);
  padding: 28px;
}
.brand-row { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; }
.brand-dot {
  width: 30px; height: 30px; flex: none;
  background: url("futura-mark.svg") center / contain no-repeat;
}
.brand-row h1 { font-size: 1.15rem; margin: 0; letter-spacing: -.01em; }
.card p.sub { color: var(--muted); margin: 4px 0 20px; font-size: .92rem; }
.field { display: block; margin-bottom: 14px; }
.field span { display: block; font-size: .78rem; font-weight: 600; color: var(--muted); margin-bottom: 6px; text-transform: uppercase; letter-spacing: .04em; }
.field input {
  width: 100%; padding: 12px 14px; border-radius: 11px;
  border: 1px solid var(--line); background: var(--bg); color: var(--ink);
  font-size: 1rem;
}
.field input:focus { outline: 2px solid var(--brand); outline-offset: 1px; }
#code-input { text-transform: uppercase; letter-spacing: .32em; font-weight: 700; font-size: 1.35rem; text-align: center; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; padding: 12px 16px; border-radius: 11px; border: 0;
  background: var(--brand); color: var(--brand-ink); font-weight: 650; font-size: 1rem;
}
.btn.secondary { background: transparent; color: var(--brand); border: 1px solid var(--line); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.divider { display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: .8rem; margin: 18px 0; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.err { color: #dc2626; font-size: .86rem; margin: 8px 0 0; min-height: 1.1em; }
.avatar-pick { display: flex; align-items: center; gap: 14px; margin: 4px 0 16px; }
.avatar-pick .ava {
  width: 68px; height: 68px; border-radius: 16px; overflow: hidden;
  border: 2px solid var(--line); background: var(--bg); flex: none;
}
.avatar-pick .ava svg { width: 100%; height: 100%; display: block; }

/* ---------- app shell ---------- */
.app { min-height: 100%; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 16px;
  padding: 10px 16px; background: var(--panel); border-bottom: 1px solid var(--line);
}
.topbar .brand-dot { width: 24px; height: 24px; border-radius: 7px; }
.topbar h1 { font-size: .98rem; margin: 0; }
.topbar .spacer { flex: 1; }
.you-chip { display: flex; align-items: center; gap: 8px; font-size: .85rem; color: var(--muted); }
.you-chip .ava { width: 26px; height: 26px; border-radius: 7px; overflow: hidden; border: 1px solid var(--line); }
.you-chip .ava svg { width: 100%; height: 100%; display: block; }

/* host join code */
.code-hero {
  display: flex; align-items: center; gap: 18px; flex-wrap: wrap;
  padding: 14px 16px; background: var(--panel); border-bottom: 1px solid var(--line);
}
.code-hero .lead { font-size: .8rem; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.code-hero .big {
  font-size: clamp(1.8rem, 5vw, 3rem); font-weight: 800; letter-spacing: .3em;
  line-height: 1; margin: 2px 0;
}
.code-hero .join-url { font-size: .9rem; color: var(--muted); word-break: break-all; }
.code-hero .grow { flex: 1; }
.code-hero button {
  padding: 9px 14px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--bg); color: var(--ink); font-weight: 600;
}

/* ---------- board ---------- */
.board-host { flex: 1; padding: 14px; }
.cc-wrap { display: flex; gap: 14px; height: 100%; align-items: stretch; }
.cc-main { flex: 1; display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.cc-stage {
  position: relative; width: 100%; aspect-ratio: 16 / 10;
  background: #ffffff; border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); overflow: hidden; touch-action: none;
  cursor: crosshair;
}
.cc-stage[data-active-tool="text"] { cursor: text; }
.cc-stage[data-active-tool="wipe"] { cursor: cell; }
.cc-stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.cc-overlay { position: absolute; inset: 0; pointer-events: none; }
.cc-cursor { position: absolute; transform: translate(-2px, -2px); color: var(--c); transition: left .08s linear, top .08s linear; }
.cc-cursor svg { fill: var(--c); filter: drop-shadow(0 1px 1px rgba(0,0,0,.3)); }
.cc-cursor b {
  position: absolute; left: 14px; top: 10px; white-space: nowrap;
  background: var(--c); color: #fff; font-size: 11px; font-weight: 600;
  padding: 1px 6px; border-radius: 6px;
}
.cc-banner {
  position: absolute; left: 50%; top: 14px; transform: translateX(-50%);
  background: #0f172a; color: #fff; padding: 8px 16px; border-radius: 999px;
  font-size: .9rem; font-weight: 600;
}
.cc-conn {
  position: absolute; right: 12px; bottom: 12px;
  background: #f59e0b; color: #1f2937; padding: 6px 12px; border-radius: 999px;
  font-size: .8rem; font-weight: 700;
}
.cc-textinput {
  position: absolute; z-index: 20; min-width: 150px; max-width: 75%;
  background: #ffffff; color: #0f172a;
  border: 2px solid var(--brand); border-radius: 8px;
  padding: 6px 9px; resize: none; overflow: hidden;
  font: 600 20px "Inter", ui-sans-serif, system-ui, sans-serif; line-height: 1.3;
  caret-color: var(--caret, var(--brand));
  box-shadow: 0 8px 24px -8px rgba(15, 23, 42, .35);
}
.cc-textinput::placeholder { color: #94a3b8; font-weight: 500; }
.cc-textinput:focus { outline: none; box-shadow: 0 0 0 4px color-mix(in srgb, var(--brand) 22%, transparent), 0 8px 24px -8px rgba(15, 23, 42, .35); }

/* toolbar */
.cc-toolbar {
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  padding: 8px 12px; background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.cc-toolbar.is-locked .cc-tools, .cc-toolbar.is-locked .cc-swatches,
.cc-toolbar.is-locked .cc-sizes, .cc-toolbar.is-locked [data-act="undo"] {
  opacity: .4; pointer-events: none;
}
.cc-tools, .cc-actions { display: flex; gap: 6px; }
.cc-tool {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 12px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--bg); color: var(--ink); font-size: .86rem;
}
.cc-tool.is-active { border-color: var(--brand); background: color-mix(in srgb, var(--brand) 12%, transparent); color: var(--brand); font-weight: 650; }
.cc-tool.cc-danger { color: #dc2626; border-color: color-mix(in srgb, #dc2626 35%, var(--line)); }
.cc-tool.cc-danger.is-active { border-color: #dc2626; background: color-mix(in srgb, #dc2626 12%, transparent); color: #dc2626; }
.cc-swatches { display: flex; gap: 5px; }
.cc-sw {
  width: 24px; height: 24px; border-radius: 50%; border: 2px solid var(--line);
  background: var(--sw); padding: 0;
}
.cc-sw[style*="#ffffff"] { border-color: #cbd5e1; }
.cc-sw[aria-current="true"] { outline: 2px solid var(--brand); outline-offset: 2px; }
.cc-sizes { display: flex; gap: 5px; }
.cc-size {
  width: 32px; height: 32px; border-radius: 9px; border: 1px solid var(--line);
  background: var(--bg); display: grid; place-items: center; padding: 0;
}
.cc-size i { display: block; background: var(--ink); border-radius: 50%; }
.cc-size[aria-current="true"] { border-color: var(--brand); background: color-mix(in srgb, var(--brand) 12%, transparent); }
.cc-actions { margin-left: auto; flex-wrap: wrap; }
.cc-btn {
  padding: 7px 12px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--bg); color: var(--ink); font-size: .86rem; font-weight: 600;
}
.cc-btn.is-on { background: #0f172a; color: #fff; border-color: #0f172a; }
.cc-btn.cc-danger { color: #dc2626; border-color: color-mix(in srgb, #dc2626 40%, var(--line)); }

/* sidebar */
.cc-side {
  width: 240px; flex: none; background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px;
  display: flex; flex-direction: column; gap: 10px;
}
.cc-side-head { font-size: .9rem; color: var(--muted); }
.cc-side-head span { font-weight: 800; color: var(--ink); font-size: 1.05rem; }
.cc-people { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; overflow-y: auto; flex: 1; }
.cc-person { display: flex; align-items: center; gap: 9px; }
.cc-person.is-off { opacity: .38; }
.cc-ava { width: 30px; height: 30px; border-radius: 8px; overflow: hidden; border: 1px solid var(--line); flex: none; background: var(--bg); }
.cc-ava svg { width: 100%; height: 100%; display: block; }
.cc-name { font-size: .9rem; }
.cc-name em { font-style: normal; font-size: .68rem; background: var(--brand); color: #fff; padding: 1px 5px; border-radius: 5px; margin-left: 4px; vertical-align: middle; }
.cc-attr { font-size: .72rem; color: var(--muted); }

/* present mode — the board fills the viewport under the join-code bar */
body.presenting { overflow: hidden; }
body.presenting .topbar,
body.presenting .cc-side,
body.presenting .cc-toolbar { display: none; }
body.presenting .app { height: 100vh; height: 100dvh; }
body.presenting .code-hero { z-index: 10; }
body.presenting .board-host { padding: 0; position: relative; flex: 1; min-height: 0; }
body.presenting #board-mount { position: absolute; inset: 0; }
body.presenting .cc-wrap { display: block; height: 100%; gap: 0; }
body.presenting .cc-main { height: 100%; gap: 0; }
body.presenting .cc-stage {
  height: 100%; width: 100%; aspect-ratio: auto; max-height: none;
  border: 0; border-radius: 0; box-shadow: none;
}
.present-exit { display: none; }
body.presenting .present-exit {
  display: inline-flex; align-items: center; gap: 6px;
  position: fixed; right: 14px; bottom: 14px; z-index: 20;
  padding: 9px 14px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--panel); color: var(--ink); font-weight: 600; font-size: .85rem;
  box-shadow: var(--shadow); cursor: pointer;
}

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: #0f172a; color: #fff; padding: 10px 18px; border-radius: 999px;
  font-size: .9rem; box-shadow: var(--shadow); z-index: 50; opacity: 0;
  transition: opacity .2s; pointer-events: none;
}
.toast.show { opacity: 1; }

@media (max-width: 720px) {
  .cc-wrap { flex-direction: column; }
  .cc-side { width: 100%; max-height: 150px; }
  .cc-actions { width: 100%; }
}
