/* white-board — full-screen canvas with a floating toolbar */

:root {
  --bg: #faf9f6;
  --fg: #17171a;
  --muted: #6d6d68;
  --soft: #4a4a44;
  --line: #e3e1db;
  --card: #ffffff;
  --hover: #f1efe9;
  --accent: #1d1d1b;
  --on-accent: #faf9f6;
  --badge: #eeefe9;
  --shadow: 0 1px 2px rgba(23, 23, 26, .05), 0 16px 34px -22px rgba(23, 23, 26, .45);
  --font-ui: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

html.dark {
  --bg: #12120f;
  --fg: #f2f1ec;
  --muted: #96968e;
  --soft: #b9b9ad;
  --line: #2a2a26;
  --card: #191916;
  --hover: #232320;
  --accent: #f2f1ec;
  --on-accent: #12120f;
  --badge: #26261f;
  --shadow: 0 1px 2px rgba(0, 0, 0, .5), 0 18px 40px -24px rgba(0, 0, 0, .95);
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  overflow: hidden;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-ui);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

/* ---------- top bar ---------- */

.bar {
  flex: none;
  display: flex;
  align-items: center;
  gap: 12px;
  height: 54px;
  padding: 0 14px;
  border-bottom: 1px solid var(--line);
  background: var(--bg);
}

.home {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  color: var(--fg);
  text-decoration: none;
  font-size: 0.8125rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  white-space: nowrap;
}

.home-mark {
  width: 20px;
  height: 20px;
  border-radius: 6px;
  background: var(--accent);
  position: relative;
  flex: none;
}

.home-mark::after {
  content: "";
  position: absolute;
  inset: 5px;
  border-radius: 50%;
  border: 1.8px solid var(--bg);
  border-bottom-color: transparent;
  border-right-color: transparent;
  transform: rotate(45deg);
}

.home:hover .home-label { text-decoration: underline; text-underline-offset: 3px; }

.bar-title {
  margin: 0;
  font-size: 0.9375rem;
  font-weight: 650;
  letter-spacing: -0.015em;
  white-space: nowrap;
}

.bar-title::before {
  content: "/";
  margin-right: 12px;
  color: var(--line);
  font-weight: 400;
}

.bar-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 10px;
}

.group { display: flex; align-items: center; gap: 3px; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 34px;
  padding: 0 11px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--card);
  color: var(--fg);
  font: inherit;
  font-size: 0.8125rem;
  font-weight: 550;
  cursor: pointer;
  transition: background-color .16s ease, border-color .16s ease, color .16s ease, opacity .16s ease;
}

.btn:hover:not(:disabled) { background: var(--hover); border-color: color-mix(in srgb, var(--fg) 18%, var(--line)); }
.btn:focus-visible { outline: 2px solid var(--fg); outline-offset: 2px; }
.btn:disabled { opacity: .38; cursor: default; }

.icon-btn { width: 34px; padding: 0; }
.icon { width: 18px; height: 18px; flex: none; }

/* ---------- save menu ---------- */

.save { position: relative; }

.chev { width: 14px; height: 14px; margin-left: -2px; opacity: .55; }

.save-options {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  z-index: 40;
  min-width: 196px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--card);
  box-shadow: var(--shadow);
}

.save-options[hidden] { display: none; }

.save-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  width: 100%;
  padding: 8px 10px;
  border: 0;
  border-radius: 8px;
  background: none;
  color: var(--fg);
  font: inherit;
  font-size: 0.8125rem;
  text-align: left;
  cursor: pointer;
}

.save-item:hover { background: var(--hover); }
.save-item:focus-visible { outline: 2px solid var(--fg); outline-offset: -2px; }
.save-ext { color: var(--muted); font-size: 0.75rem; }

.zoom-label {
  min-width: 46px;
  height: 34px;
  padding: 0 4px;
  border: 0;
  border-radius: 8px;
  background: none;
  color: var(--muted);
  font: inherit;
  font-size: 0.75rem;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
}

.zoom-label:hover { color: var(--fg); background: var(--hover); }
.zoom-label:focus-visible { outline: 2px solid var(--fg); outline-offset: 1px; }

/* ---------- canvas ---------- */

.stage { position: relative; flex: 1; min-height: 0; overflow: hidden; }

#board {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: crosshair;
}

.hint {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  margin: 0;
  text-align: center;
  color: var(--muted);
  font-size: 0.875rem;
  line-height: 1.7;
  pointer-events: none;
  opacity: 1;
  transition: opacity .4s ease;
}

.hint p { max-width: 42ch; margin: 0; }
.hint.is-hidden { opacity: 0; }

.hint kbd,
.help kbd {
  font-family: inherit;
  font-size: 0.75rem;
  padding: 1px 5px;
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 5px;
  background: var(--card);
  color: var(--soft);
}

/* ---------- toolbar ---------- */

.tools {
  position: absolute;
  left: 50%;
  bottom: 16px;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 3px;
  max-width: calc(100% - 24px);
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 15px;
  background: var(--card);
  box-shadow: var(--shadow);
  z-index: 3;
}

.tool {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--soft);
  cursor: pointer;
  transition: background-color .16s ease, color .16s ease;
}

.tool .icon { width: 20px; height: 20px; }
.tool:hover { background: var(--hover); color: var(--fg); }
.tool:focus-visible { outline: 2px solid var(--fg); outline-offset: -2px; }
.tool[aria-pressed="true"] { background: var(--accent); color: var(--on-accent); }

.sep {
  width: 1px;
  height: 24px;
  margin: 0 5px;
  background: var(--line);
  flex: none;
}

.swatches { display: flex; align-items: center; gap: 4px; }

.swatch {
  position: relative;
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: none;
  cursor: pointer;
}

.swatch::before {
  content: "";
  width: 19px;
  height: 19px;
  border-radius: 50%;
  background: var(--c);
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .12);
  transition: box-shadow .16s ease, transform .16s ease;
}

.swatch:hover::before { transform: scale(1.12); }
.swatch:focus-visible { outline: 2px solid var(--fg); outline-offset: 1px; }
.swatch[aria-pressed="true"]::before { box-shadow: 0 0 0 2px var(--card), 0 0 0 4px var(--c); }

.swatch-custom { color: var(--muted); }
.swatch-custom::before {
  background: conic-gradient(from 210deg, #c0392b, #b9800f, #27795a, #1f5fa8, #6b46c1, #c0392b);
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .12);
}
.swatch-custom svg { position: absolute; width: 12px; height: 12px; color: #fff; filter: drop-shadow(0 0 1px rgba(0, 0, 0, .5)); pointer-events: none; }
.swatch-custom input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
  border: 0;
  padding: 0;
}

.widths { display: flex; align-items: center; gap: 2px; }

.wbtn {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border: 0;
  border-radius: 8px;
  background: none;
  cursor: pointer;
}

.wbtn span { display: block; width: var(--d); height: var(--d); border-radius: 50%; background: var(--soft); }
.wbtn:hover span { background: var(--fg); }
.wbtn:focus-visible { outline: 2px solid var(--fg); outline-offset: -1px; }
.wbtn[aria-pressed="true"] { background: var(--badge); }
.wbtn[aria-pressed="true"] span { background: var(--fg); }

/* ---------- status and help ---------- */

.status {
  position: absolute;
  top: 14px;
  left: 14px;
  margin: 0;
  padding: 4px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--card);
  color: var(--muted);
  font-size: 0.6875rem;
  letter-spacing: 0.02em;
  pointer-events: none;
  z-index: 2;
}

.help {
  position: absolute;
  top: 14px;
  right: 14px;
  z-index: 5;
  width: 296px;
  max-height: calc(100% - 100px);
  overflow-y: auto;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--card);
  box-shadow: var(--shadow);
}

.help-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
.help h2 { margin: 0; font-size: 0.9375rem; font-weight: 650; letter-spacing: -0.01em; }

.help-copy { margin: 0 0 14px; color: var(--muted); font-size: 0.8125rem; line-height: 1.6; }

.shortcuts { margin: 0 0 16px; display: flex; flex-direction: column; gap: 8px; }
.shortcuts div { display: flex; justify-content: space-between; gap: 12px; font-size: 0.8125rem; }
.shortcuts dt { color: var(--soft); white-space: nowrap; font-weight: 550; }
.shortcuts dd { margin: 0; color: var(--muted); text-align: right; }

.help-link {
  display: block;
  padding: 8px 0;
  border-top: 1px solid var(--line);
  color: var(--fg);
  font-size: 0.8125rem;
  text-decoration: none;
  text-underline-offset: 3px;
}

.help-link:hover { text-decoration: underline; }
.help-link:focus-visible { outline: 2px solid var(--fg); outline-offset: 2px; }

/* ---------- small screens ---------- */

@media (max-width: 760px) {
  .bar { height: 50px; gap: 8px; padding: 0 10px; }
  .home-label { display: none; }
  .bar-title { font-size: 0.875rem; }
  .bar-title::before { content: none; }
  .bar-actions { gap: 4px; }
  .zoom-group { display: none; }
  .btn { height: 32px; padding: 0 9px; }
  .icon-btn { width: 32px; padding: 0; }
  .btn-label { display: none; }
  .chev { width: 12px; height: 12px; }

  .tools {
    left: 10px;
    right: 10px;
    bottom: 10px;
    transform: none;
    max-width: none;
    gap: 1px;
    row-gap: 4px;
    padding: 5px;
  }
  .tool { width: 36px; height: 36px; }
  .swatch { width: 25px; height: 25px; }
  .swatch::before { width: 17px; height: 17px; }
  .wbtn { width: 27px; height: 27px; }
  .sep { margin: 0 2px; }

  .status { top: 10px; left: 10px; }
  .help { top: 10px; right: 10px; left: 10px; width: auto; max-height: calc(100% - 80px); }
}

@media (max-width: 420px) {
  .hint { font-size: 0.8125rem; }
  .hint kbd { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
