:root {
  --bg: #0b1220;
  --panel: #111a2e;
  --raised: #1e293b;
  --line: #334155;
  --ink: #e2e8f0;
  --muted: #94a3b8;
  --accent: #3b82f6;
  --tag: #93c5fd;
  --dock-h: 84px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.4 Inter, system-ui, -apple-system, sans-serif;
  padding-bottom: calc(var(--dock-h) + 40px + env(safe-area-inset-bottom));
}

button { font: inherit; cursor: pointer; touch-action: manipulation; }

/* ---------- Header ---------- */

.head {
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px 20px 8px;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px 16px;
  align-items: center;
}
.head input {
  min-width: 0;
  padding: 0;
  border: 0;
  background: transparent;
  font-family: inherit;
}
.head input:focus { outline: none; }
#title { color: #fff; font-size: 26px; font-weight: 700; }
#tags { grid-column: 1; color: var(--tag); font-size: 14px; font-weight: 500; }
.head input::placeholder { color: #475569; }

.actions {
  grid-row: 1 / 3;
  grid-column: 2;
  display: flex;
  gap: 8px;
  align-items: center;
}
.seg {
  display: inline-flex;
  padding: 3px;
  border-radius: 999px;
  background: var(--raised);
}
.seg button {
  padding: 6px 14px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font-weight: 600;
}
.seg button.active { background: var(--line); color: #fff; }
.ex {
  padding: 7px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: transparent;
  color: var(--ink);
  font-weight: 600;
}
.ex.primary { background: var(--accent); border-color: var(--accent); color: #fff; }

/* ---------- Board ---------- */

.board, .notes { max-width: 1200px; margin: 0 auto; padding: 8px 20px; }
.frame { padding: 14px; border-radius: 18px; background: var(--panel); }

#rink {
  display: block;
  width: 100%;
  height: auto;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
#rink .item { cursor: move; }
#rink .selected { filter: drop-shadow(0 0 6px var(--accent)); }

@media (min-width: 801px) {
  #rink.half {
    width: auto;
    max-width: 100%;
    height: calc(100vh - var(--dock-h) - 150px);
    min-height: 480px;
    margin: 0 auto;
  }
}

.notes textarea {
  width: 100%;
  min-height: 110px;
  padding: 14px;
  border: 1px solid var(--raised);
  border-radius: 14px;
  background: var(--panel);
  color: var(--ink);
  font: inherit;
  resize: vertical;
}
.notes textarea::placeholder { color: #475569; }
.notes textarea:focus { outline: none; border-color: var(--line); }

/* ---------- Dock ---------- */

.dock {
  position: fixed;
  left: 50%;
  bottom: calc(18px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 5;
  display: flex;
  align-items: center;
  max-width: calc(100vw - 16px);
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: var(--raised);
  box-shadow: 0 10px 30px rgb(0 0 0 / 0.45);
}
.dgroup { display: flex; align-items: center; gap: 2px; padding: 0 4px; }
.dgroup + .dgroup { border-left: 1px solid var(--line); }

.dock button, .labelbox {
  width: 58px;
  height: 58px;
  padding: 6px 0 4px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: #cbd5e1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  flex: none;
}
.dock button svg { width: 24px; height: 24px; }
.dock button span, .labelbox span { font-size: 11px; font-weight: 500; line-height: 1; }
.dock button:hover { background: rgb(255 255 255 / 0.06); }
.dock button.active { background: var(--accent); color: #fff; }

.labelbox input {
  width: 44px;
  height: 26px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  color: #fff;
  text-align: center;
  font: 600 13px Inter, sans-serif;
}
.labelbox span { color: #cbd5e1; }

#straight .i-free, #straight.freehand .i-straight { display: none; }
#straight.freehand .i-free { display: block; }

.dock .swatch {
  width: 26px;
  height: 26px;
  margin: 0 4px;
  padding: 0;
  border-radius: 50%;
  background: var(--c);
  border: 2px solid var(--raised);
}
.dock .swatch:hover { background: var(--c); }
.dock .swatch.active { background: var(--c); box-shadow: 0 0 0 2px var(--accent); }

@media (max-width: 800px) {
  :root { --dock-h: 150px; }
  .head { grid-template-columns: 1fr; padding: 14px 12px 4px; }
  .actions { grid-row: auto; grid-column: 1; flex-wrap: wrap; margin-top: 8px; }
  #title { font-size: 21px; }
  .board, .notes { padding: 6px 10px; }
  .frame { padding: 6px; border-radius: 12px; }
  .dock {
    bottom: calc(8px + env(safe-area-inset-bottom));
    width: calc(100vw - 16px);
    flex-wrap: wrap;
    justify-content: center;
    row-gap: 4px;
    border-radius: 16px;
  }
  .dgroup { padding: 0 2px; }
  .dgroup + .dgroup { border-left: 0; }
  .dock button, .labelbox { width: 50px; height: 52px; }
  .dock .swatch { width: 24px; height: 24px; margin: 0 3px; }
}

/* ---------- Save fallback (iOS) ---------- */

.save-sheet {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgb(0 0 0 / 0.6);
}
.save-card {
  max-width: 100%;
  padding: 12px;
  border-radius: 10px;
  background: var(--panel);
  color: var(--ink);
}
.save-card img { display: block; max-width: 100%; max-height: 70vh; }
.save-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 10px; }
.save-actions button {
  height: 40px;
  padding: 0 16px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  color: var(--ink);
  font: inherit;
}
