:root {
  --ink: #241d2e;
  --muted: #6f6680;
  --paper: #f6f2fa;
  --card: #fff;
  --border: #ddd3e8;
  --accent: #6b4f8a;
  --accent-soft: #e9e0f3;
  --danger: #c0392b;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --ink: #eee8f5; --muted: #a89fb8; --paper: #17131c; --card: #221c2a;
    --border: #3a3047; --accent: #b393d6; --accent-soft: #33284a; --danger: #ff7b6b;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--paper);
  color: var(--ink);
}

input, button { font: inherit; color: inherit; }

input[type="text"], input[type="number"] {
  padding: 0.45rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card);
  min-width: 0;
}

.page { max-width: 900px; margin: 0 auto; padding: 1rem; }
.page h1 { margin: 0.5rem 0 1rem; }
.back { color: var(--muted); text-decoration: none; }
.hint { color: var(--muted); font-size: 0.9rem; }
.row { display: flex; gap: 1rem; flex-wrap: wrap; margin: 0.8rem 0; }
.row label { display: flex; flex-direction: column; gap: 0.3rem; font-size: 0.85rem; color: var(--muted); }

.button {
  display: inline-block;
  padding: 0.7rem 1.1rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--card);
  text-decoration: none;
  cursor: pointer;
}
.button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }

.board-list { list-style: none; padding: 0; margin: 1.2rem 0; }
.board-list li { display: flex; justify-content: space-between; padding: 0.8rem 0; border-bottom: 1px solid var(--border); }
.board-list a { color: inherit; font-weight: 600; text-decoration: none; }
.board-list small { color: var(--muted); }

#view { display: block; max-width: 100%; touch-action: none; border-radius: 8px; }

.board-page {
  --side: min(100vw - 16px, 100dvh - 230px, 720px);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 8px calc(1rem + env(safe-area-inset-bottom));
}

.bar, .modes, .tools, .extra { width: var(--side); }
.bar { display: flex; align-items: center; gap: 0.4rem; }
.bar input { flex: 1; font-weight: 600; }
.bar input.unsaved { border-color: var(--danger); }
.bar button { flex: none; }
.bar button, .modes button, .tools button {
  border: 1px solid var(--border);
  background: var(--card);
  border-radius: 8px;
  padding: 0.45rem 0.7rem;
  cursor: pointer;
}

.modes { display: flex; gap: 0.3rem; }
.modes button { flex: 1; }
.modes button.active, .tools button.active { background: var(--accent); border-color: var(--accent); color: #fff; }

.grid {
  width: var(--side);
  height: var(--side);
  display: grid;
  grid-template-columns: repeat(var(--n), 1fr);
  grid-template-rows: repeat(var(--n), 1fr);
  background-size: cover;
  border-radius: 4px;
  overflow: hidden;
  user-select: none;
}
.grid.plan { background: var(--card) !important; }

.cell {
  position: relative;
  border: 0 solid #000;
  outline: 1px solid rgba(0, 0, 0, 0.18);
  outline-offset: -1px;
  background: transparent;
  padding: 0;
  cursor: pointer;
  font-size: calc(var(--side) / var(--n) * 0.55);
  font-weight: 800;
  line-height: 1;
  touch-action: manipulation;
}
.cell .icon { position: absolute; top: 2px; left: 3px; font-size: 0.4em; font-weight: 400; }
.cell .mark { color: #fff; text-shadow: 0 0 3px #000, 0 0 6px #000; }
.cell.cross .mark { color: #ff6b6b; font-size: 0.8em; }
.cell.conflict .mark { color: #ff3b30; }
.cell.blocked { background: rgba(0, 0, 0, 0.62); }
.plan .cell.blocked { background: #2a2530; }
.plan .cell .mark { color: var(--ink); text-shadow: none; }
.plan .cell.cross .mark { color: var(--danger); }
.plan .cell.conflict .mark { color: var(--danger); text-decoration: underline; }
.plan .cell .icon { font-size: 0.55em; top: 50%; left: 50%; transform: translate(-50%, -50%); opacity: 0.85; }
.plan .cell:has(.mark:not(:empty)) .icon { opacity: 0.25; }

.tools { display: flex; flex-wrap: wrap; gap: 0.35rem; }
.tools button { min-width: 2.6rem; font-weight: 700; }
.tools .swatch { color: #fff; text-shadow: 0 0 2px #000; }
.tools .swatch.active { outline: 3px solid var(--ink); }

.extra { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.extra .hint { width: 100%; margin: 0.2rem 0; }
.extra label { display: flex; align-items: center; gap: 0.4rem; font-size: 0.85rem; color: var(--muted); }
.extra label input { width: 9rem; }
.extra .dot { width: 14px; height: 14px; border-radius: 50%; flex: none; }
