:root {
  --bg: #F2F5F6;
  --board: #FFFFFF;
  --card: #F0F4F5;
  --ink: #16262E;
  --muted: #4F6A75;
  --line: #D5DFE3;
  --accent: #0E7C86;
  --accent-ink: #FFFFFF;
  --folder: #D6EAF6;
  --flash: #B9DFF5;
  --danger: #C0453F;
  --shadow: 0 1px 2px rgba(22, 38, 46, 0.06), 0 4px 14px rgba(22, 38, 46, 0.07);
  --c-navy: #1F3D69; --c-teal: #0D7D87; --c-green: #2E7D4F; --c-amber: #C78A1C;
  --c-rose: #B3475C; --c-purple: #6B4FA1; --c-slate: #596B78;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0B1114; --board: #0F1518; --card: #1A2429; --ink: #E6EDEF; --muted: #93A8B0;
    --line: #2C3A41; --accent: #53B7C0; --accent-ink: #08262A; --folder: #223D50; --flash: #3D6E8C;
    --danger: #E06B64; --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 4px 14px rgba(0, 0, 0, 0.35);
    --c-navy: #2E4F80; --c-teal: #298C96; --c-green: #388C5E; --c-amber: #C79433;
    --c-rose: #BD546B; --c-purple: #7A61B0; --c-slate: #6B7D8C;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0B1114; --board: #0F1518; --card: #1A2429; --ink: #E6EDEF; --muted: #93A8B0;
  --line: #2C3A41; --accent: #53B7C0; --accent-ink: #08262A; --folder: #223D50; --flash: #3D6E8C;
  --danger: #E06B64; --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 4px 14px rgba(0, 0, 0, 0.35);
  --c-navy: #2E4F80; --c-teal: #298C96; --c-green: #388C5E; --c-amber: #C79433;
  --c-rose: #BD546B; --c-purple: #7A61B0; --c-slate: #6B7D8C;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  font-size: 16px; line-height: 1.45; -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); }
button, input, textarea, select { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.btn, .btn-quiet {
  border-radius: 999px; padding: 8px 16px; font-size: 14.5px; font-weight: 600; cursor: pointer;
  border: 1px solid var(--line); background: var(--board); color: var(--ink); white-space: nowrap;
}
.btn { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn-quiet:hover { border-color: var(--muted); }
.btn-danger { color: var(--danger); }
.spacer { flex: 1; }

/* top bar */
.bar { display: flex; align-items: center; gap: 14px; padding: 14px 16px; border-bottom: 1px solid var(--line); background: var(--board); position: sticky; top: 0; z-index: 5; }
@media (min-width: 720px) { .bar { padding: 14px 28px; } }
.wordmark { font-weight: 700; font-size: 21px; letter-spacing: -0.03em; color: var(--ink); text-decoration: none; }
.bar-title { color: var(--muted); font-size: 15px; }
@media (max-width: 480px) { .bar-title { display: none; } }
.status { font-size: 13.5px; color: var(--muted); display: inline-flex; align-items: center; gap: 6px; }
.status::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.status[data-kind="saved"]::before { background: #2E9E5B; }
.status[data-kind="saving"]::before, .status[data-kind="unsaved"]::before { background: #C79433; }
.status[data-kind="error"]::before { background: var(--danger); }

/* pairing */
.pair { max-width: 980px; margin: 0 auto; padding: 48px 16px 64px; display: grid; gap: 40px; align-items: center; }
@media (min-width: 820px) { .pair { grid-template-columns: 1.1fr 0.9fr; padding: 72px 28px; } }
.pair h1 { font-size: clamp(32px, 5vw, 48px); line-height: 1.08; letter-spacing: -0.03em; margin: 0 0 24px; }
.steps { margin: 0 0 24px; padding-left: 1.4em; font-size: 18px; display: grid; gap: 8px; }
.note { color: var(--muted); margin: 0; max-width: 32em; }
.note b { color: var(--ink); }
.qr-card { background: var(--board); border: 1px solid var(--line); border-radius: 24px; padding: 28px; display: flex; flex-direction: column; align-items: center; gap: 14px; box-shadow: var(--shadow); }
.qr { width: min(280px, 100%); aspect-ratio: 1; border-radius: 12px; overflow: hidden; background: #fff; }
.qr svg { display: block; width: 100%; height: 100%; }
.qr-wait { margin: 0; color: var(--muted); font-size: 15px; display: flex; align-items: center; gap: 10px; }
.qr-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.qr-small { margin: 0; max-width: 280px; text-align: center; font-size: 13px; color: var(--muted); }
.qr-small b { color: var(--ink); }
.spinner { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--line); border-top-color: var(--accent); animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* editor */
.editor { display: grid; grid-template-columns: 1fr; gap: 20px; padding: 20px 16px 48px; max-width: 1280px; margin: 0 auto; }
@media (min-width: 900px) { .editor { grid-template-columns: 1fr 340px; padding: 24px 28px 64px; align-items: start; } }
.conflict { grid-column: 1 / -1; background: var(--folder); border-radius: 16px; padding: 14px 18px; display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: space-between; }
.conflict p { margin: 0; font-weight: 600; }
.conflict-actions { display: flex; gap: 8px; }
.board-col { background: var(--board); border: 1px solid var(--line); border-radius: 22px; padding: 16px; min-width: 0; }
.toolbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.crumbs { display: flex; flex-wrap: wrap; align-items: center; gap: 2px; font-size: 15px; }
.crumbs button { background: none; border: 0; padding: 6px 8px; border-radius: 8px; cursor: pointer; color: var(--accent); font-weight: 600; }
.crumbs button[aria-current="page"] { color: var(--ink); cursor: default; }
.crumbs button.drop { background: var(--flash); }
.crumbs .sep { color: var(--muted); }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(112px, 1fr)); gap: 12px; }
.hint { color: var(--muted); font-size: 13.5px; margin: 14px 2px 0; }
.then-home { color: var(--ink); font-weight: 600; }
.use-here { display: flex; gap: 9px; align-items: flex-start; color: var(--muted); font-size: 13.5px; line-height: 1.45; margin: 12px 2px 0; cursor: pointer; }
.use-here input { margin-top: 2px; flex-shrink: 0; }
.use-here b { color: var(--ink); font-weight: 600; }
@media (max-width: 480px) {
  .grid { grid-template-columns: repeat(3, 1fr); gap: 8px; }
  .board-col { padding: 12px; }
  .tile { border-radius: 16px; padding: 6px; }
  .tile .nm { font-size: 13.5px; }
  .tile .nm.long { font-size: 12px; }
  .tile .emoji { font-size: 26px; }
}

.tile {
  position: relative; aspect-ratio: 1; border-radius: 20px; border: 0; padding: 8px; overflow: hidden;
  background: var(--card); color: var(--ink); cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  text-align: center; box-shadow: var(--shadow); font-weight: 600; line-height: 1.15;
  transition: transform 0.08s ease;
}
.tile:active { transform: scale(0.97); }
.tile.folder { background: var(--folder); }
.tile.colored { color: #fff; }
.tile .nm { font-size: 16px; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; word-break: break-word; }
.tile .nm.long { font-size: 13.5px; }
.tile .emoji { font-size: 34px; line-height: 1; }
.tile .emoji.big { font-size: 52px; }
.tile .sub { font-size: 11px; font-weight: 500; opacity: 0.7; }
.tile.blank .nm { font-size: 26px; color: var(--muted); }
.tile.pic { padding: 0; }
.tile.pic img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.tile.pic .cap { position: absolute; left: 0; right: 0; bottom: 0; padding: 4px 6px; background: rgba(0, 0, 0, 0.45); color: #fff; font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile .ring { position: absolute; inset: 0; border-radius: inherit; pointer-events: none; }
.tile.selected { outline: 3px solid var(--accent); outline-offset: 3px; }
.tile.drag-before { box-shadow: -5px 0 0 0 var(--accent), var(--shadow); }
.tile.drag-after { box-shadow: 5px 0 0 0 var(--accent), var(--shadow); }
.tile.drag-into { outline: 3px dashed var(--accent); outline-offset: 3px; }
.tile.dragging { opacity: 0.4; }
.tile.add { background: none; box-shadow: inset 0 0 0 1.5px var(--line); color: var(--muted); font-weight: 500; font-size: 14px; }
.tile.add::before { content: "+"; font-size: 26px; font-weight: 400; color: var(--accent); line-height: 1; }

/* side panel */
.panel { background: var(--board); border: 1px solid var(--line); border-radius: 22px; padding: 20px; }
@media (min-width: 900px) { .panel { position: sticky; top: 78px; max-height: calc(100vh - 100px); overflow-y: auto; } }
.panel h2 { font-size: 19px; margin: 0 0 16px; letter-spacing: -0.01em; }
.panel .empty { color: var(--muted); margin: 0; }
.field { display: block; margin-bottom: 16px; }
.field > span, .label { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 6px; }
.field input[type="text"], .field textarea, .field select {
  width: 100%; border: 1px solid var(--line); border-radius: 12px; background: var(--bg);
  padding: 9px 12px; font-size: 15px;
}
.field textarea { min-height: 140px; resize: vertical; line-height: 1.45; }
.small { font-size: 12.5px; color: var(--muted); margin: 6px 0 0; }
.swatches { display: flex; flex-wrap: wrap; gap: 7px; }
.sw { width: 28px; height: 28px; border-radius: 8px; border: 0; cursor: pointer; position: relative; box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.12); }
.sw[aria-pressed="true"]::after { content: ""; position: absolute; inset: -4px; border-radius: 12px; border: 2px solid var(--accent); }
.sw.plain { background: var(--card); }
.sw.txt { width: auto; padding: 0 10px; font-size: 12.5px; font-weight: 600; background: var(--bg); }
.sw.ring { background: var(--board); }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.row input[type="text"] { width: 80px; text-align: center; }
.check { display: flex; gap: 8px; align-items: center; font-size: 14.5px; margin-top: 10px; }
.divider { border: 0; border-top: 1px solid var(--line); margin: 18px 0; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 10px);
  background: var(--ink); color: var(--board); padding: 10px 18px; border-radius: 999px;
  font-size: 14px; font-weight: 600; opacity: 0; pointer-events: none; transition: opacity 0.2s, transform 0.2s;
  max-width: calc(100vw - 32px); text-align: center; z-index: 20;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
