:root {
  /* Classic look: white paper, navy ink, blue accents. */
  --bg: #e9eff8;
  --surface: #ffffff;
  --ink: #0f2147;
  --muted: #4f6182;
  --line: #a9bad6;
  --line-strong: #0f2a5c;
  --accent: #1f4e9c;
  --accent-ink: #ffffff;
  --accent-soft: #d5e2f6;
  --peer: #e6eefa;
  --same: #b7cdef;
  --given: #0b1530;
  --entry: #1a56c4;
  --wrong: #c0392b;
  --wrong-soft: #f8dcd8;
  --hint: #fff1a8;
  --bar: #163a78;
  --bar-ink: #ffffff;
  --bar-muted: #c7d6f0;
  --bar-hover: #24509a;
  --button-top: #ffffff;
  --button-bottom: #e3ebf7;
  --radius: 3px;
  --board: min(92vw, 540px);
  font-family: Verdana, Tahoma, "DejaVu Sans", Geneva, sans-serif;
  color: var(--ink);
  background: var(--bg);
}

/* Dark theme, the default. index.html sets data-theme from the saved choice before first paint. */
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0b1628;
  --surface: #12223b;
  --ink: #e4ecf8;
  --muted: #94a8c8;
  --line: #2b4269;
  --line-strong: #9fbbe6;
  --accent: #4a86dc;
  --accent-ink: #ffffff;
  --accent-soft: #1d3a66;
  --peer: #182c4b;
  --same: #26487c;
  --given: #f3f7fd;
  --entry: #8fc0ff;
  --wrong: #ff7b6b;
  --wrong-soft: #4a2622;
  --hint: #5a4d1f;
  --bar: #081222;
  --bar-ink: #ffffff;
  --bar-muted: #9fb3d3;
  --bar-hover: #16305a;
  --button-top: #1a2f50;
  --button-bottom: #12223b;
}
:root[data-theme="light"] { color-scheme: light; }

* { box-sizing: border-box; }
body { margin: 0; }

/* ---------- layout: left side panel, content on the right ---------- */
.layout { display: grid; grid-template-columns: 200px minmax(0, 1fr); min-height: 100vh; }
.sidebar {
  position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 20px;
  padding: 20px 14px; background: var(--bar); color: var(--bar-ink); border-right: 1px solid var(--line-strong);
}
.content { display: flex; flex-direction: column; min-width: 0; }
a { color: var(--accent); }
button { font: inherit; color: inherit; }

.brand { padding: 0 6px; display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 1.25rem; color: var(--bar-ink); text-decoration: none; }
.brand-mark {
  width: 26px; height: 26px; border-radius: 2px; background: var(--accent); border: 1px solid var(--bar-ink);
  background-image:
    linear-gradient(var(--accent-ink) 0 0), linear-gradient(var(--accent-ink) 0 0),
    linear-gradient(var(--accent-ink) 0 0), linear-gradient(var(--accent-ink) 0 0);
  background-size: 1.5px 100%, 1.5px 100%, 100% 1.5px, 100% 1.5px;
  background-position: 33.3% 0, 66.6% 0, 0 33.3%, 0 66.6%;
  background-repeat: no-repeat;
}
nav { display: flex; flex-direction: column; gap: 4px; }
nav a { padding: 9px 12px; border-radius: var(--radius); color: var(--bar-muted); text-decoration: none; font-weight: 500; }
nav a:hover { color: var(--bar-ink); background: var(--bar-hover); }
nav a[aria-current="page"] { color: var(--bar-ink); background: var(--accent); font-weight: 700; }

main { flex: 1; width: 100%; max-width: 1000px; margin: 0 auto; padding: 24px 24px 32px; outline: none; }
.site-footer {
  display: flex; flex-wrap: wrap; justify-content: space-between; gap: 6px 20px;
  max-width: 1000px; width: 100%; margin: 0 auto; padding: 16px 20px 24px;
  color: var(--muted); font-size: 0.85rem; border-top: 1px solid var(--line);
}
.loading, .noscript { color: var(--muted); text-align: center; padding: 40px 0; }

h1 { font-size: 1.45rem; margin: 4px 0 2px; color: var(--line-strong); }
h2 { font-size: 1.1rem; margin: 24px 0 8px; color: var(--line-strong); }
.sub { color: var(--muted); margin: 0 0 16px; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

.badge { display: inline-block; padding: 2px 10px; border-radius: var(--radius); font-size: 0.8rem; font-weight: 600; background: var(--accent-soft); color: var(--ink); }
.badge.l1 { background: #d8efd9; color: #1d4d24; }
.badge.l2 { background: #f3e8c4; color: #5a4709; }
.badge.l3 { background: #f6d6c1; color: #6b3110; }
.badge.l4 { background: #ecc9d8; color: #5d1838; }
[data-theme="dark"] .badge.l1 { background: #24402a; color: #bfe6c4; }
[data-theme="dark"] .badge.l2 { background: #463c1c; color: #f0dfa6; }
[data-theme="dark"] .badge.l3 { background: #4b2f1e; color: #f3c3a3; }
[data-theme="dark"] .badge.l4 { background: #47233a; color: #f0bcd4; }

/* Theme and language switches at the foot of the side panel. */
.prefs { margin-top: auto; display: flex; flex-wrap: wrap; gap: 8px; padding: 0 6px; }
.seg { display: inline-flex; border: 1px solid var(--bar-muted); border-radius: var(--radius); overflow: hidden; }
.seg button { border: 0; background: transparent; color: var(--bar-muted); padding: 5px 9px; cursor: pointer; font-size: 0.85rem; font-weight: 600; line-height: 1.2; }
.seg button + button { border-left: 1px solid var(--bar-muted); }
.seg button:hover { color: var(--bar-ink); background: var(--bar-hover); }

/* Phones and narrow windows: the side panel becomes a bar above the content. */
@media (max-width: 820px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar {
    position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center;
    justify-content: space-between; gap: 8px 16px; padding: 12px 16px; border-right: none; border-bottom: 1px solid var(--line-strong);
  }
  nav { flex-direction: row; flex-wrap: wrap; }
  nav a { padding: 6px 12px; }
  .prefs { margin-top: 0; padding: 0; }
  main { padding: 16px 16px 28px; }
}

/* ---------- game layout ---------- */
.game { display: grid; grid-template-columns: var(--board) minmax(220px, 1fr); gap: 28px; align-items: start; }
@media (max-width: 1060px) { .game { grid-template-columns: 1fr; justify-items: center; gap: 16px; } .panel { width: var(--board); } }

.board {
  width: var(--board); aspect-ratio: 1; display: grid;
  grid-template-columns: repeat(9, 1fr); grid-template-rows: repeat(9, 1fr);
  background: var(--surface); border: 3px solid var(--line-strong); border-radius: 0;
  overflow: hidden; touch-action: manipulation; user-select: none; -webkit-user-select: none;
}
.board:focus-within { box-shadow: 0 0 0 3px var(--accent-soft); }
.cell {
  position: relative; display: grid; place-items: center; cursor: pointer;
  border-right: 1px solid var(--line); border-bottom: 1px solid var(--line);
  font-size: calc(var(--board) / 15); line-height: 1; color: var(--entry); outline: none;
}
.cell:nth-child(9n) { border-right: none; }
.cell:nth-child(n + 73) { border-bottom: none; }
.cell:nth-child(9n + 3), .cell:nth-child(9n + 6) { border-right: 2.5px solid var(--line-strong); }
.cell:nth-child(n + 19):nth-child(-n + 27), .cell:nth-child(n + 46):nth-child(-n + 54) { border-bottom: 2.5px solid var(--line-strong); }
.cell.given { color: var(--given); font-weight: 700; }
.cell.peer { background: var(--peer); }
.cell.same { background: var(--same); }
.cell.selected { background: var(--accent); color: var(--accent-ink); }
.cell.selected .notes { color: var(--accent-ink); }
.cell.wrong { color: var(--wrong); background: var(--wrong-soft); }
.cell.selected.wrong { background: var(--wrong); color: #fff; }
.cell.hint { background: var(--hint); }
.cell.clash::after { content: ""; position: absolute; inset: 3px; border: 2px solid var(--wrong); border-radius: 4px; }
.notes {
  position: absolute; inset: 2px; display: grid; grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(3, 1fr);
  font-size: calc(var(--board) / 40); color: var(--muted); font-weight: 500;
}
.notes span { display: grid; place-items: center; }
.notes span.same { color: var(--accent); font-weight: 800; }

.panel { display: flex; flex-direction: column; gap: 14px; }
.status { display: flex; justify-content: space-between; align-items: center; font-variant-numeric: tabular-nums; }
.clock { display: inline-flex; align-items: center; gap: 2px; }
.timer, .timer-edit { font: inherit; font-size: 1.4rem; font-weight: 600; color: var(--ink); font-variant-numeric: tabular-nums; }
.timer { background: none; border: 0; padding: 0 4px 0 0; cursor: text; }
.timer-edit { width: 5.5ch; padding: 0 4px; border: 1px solid var(--accent); border-radius: 4px; background: var(--surface); }
.tbtn { font: inherit; font-size: 1rem; line-height: 1; width: 26px; height: 26px; padding: 0; border: 0; border-radius: 50%; background: none; color: var(--muted); cursor: pointer; opacity: 0.8; transition: opacity 0.1s, background 0.1s; }
.tbtn:hover, .tbtn:focus-visible { opacity: 1; background: var(--button-bottom); color: var(--ink); }
.clock.paused .timer { color: var(--muted); }
.clock.paused [data-timer="toggle"] { opacity: 1; color: var(--accent); }
.clock.done .tbtn { visibility: hidden; }
.clock.done .timer { cursor: default; }
.pad { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
.pad button, .tools button, .btn {
  border: 1px solid var(--line); background: linear-gradient(var(--button-top), var(--button-bottom)); border-radius: var(--radius); padding: 10px 8px; cursor: pointer; color: var(--ink);
  font-weight: 600; transition: background 0.1s, border-color 0.1s;
}
.pad button { font-size: 1.35rem; padding: 12px 0; position: relative; color: var(--entry); }
.pad button small { position: absolute; top: 3px; right: 6px; font-size: 0.65rem; color: var(--muted); font-weight: 500; }
.pad button.done { opacity: 0.35; }
.pad button:hover, .tools button:hover, .btn:hover { border-color: var(--accent); }
.pad button:active, .tools button:active, .btn:active { transform: translateY(1px); }
.tools { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.tools button { font-size: 0.9rem; }
.tools [data-act="clear"] { grid-column: 1 / -1; }
button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn:disabled, .tools button:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.armed, .tools button.armed { background: var(--wrong-soft); color: var(--wrong); border-color: var(--wrong); }
.message { min-height: 3em; padding: 10px 12px; border-radius: var(--radius); border: 1px solid var(--line); background: var(--peer); font-size: 0.95rem; line-height: 1.4; }
.message:empty { visibility: hidden; }
.message.good { background: var(--accent-soft); }
.message.bad { background: var(--wrong-soft); }
.options { display: flex; flex-direction: column; gap: 6px; font-size: 0.9rem; }
.options label { display: flex; gap: 8px; align-items: center; cursor: pointer; }
.options input { accent-color: var(--accent); width: 16px; height: 16px; }
details.more summary { cursor: pointer; color: var(--muted); font-size: 0.9rem; }
details.more[open] summary { margin-bottom: 8px; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
select, input[type="text"] { font: inherit; padding: 8px 10px; border-radius: var(--radius); border: 1px solid var(--line); background: var(--surface); color: var(--ink); }
input[type="text"] { width: 100%; font-family: ui-monospace, monospace; font-size: 0.8rem; }
.keys { color: var(--muted); font-size: 0.8rem; line-height: 1.5; }
kbd { font-family: inherit; font-size: 0.75rem; border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 4px; padding: 0 4px; background: var(--surface); }

/* ---------- lists ---------- */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; }
.card {
  display: flex; flex-direction: column; gap: 6px; padding: 16px; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--line); color: var(--ink); text-decoration: none;
}
a.card:hover { border-color: var(--accent); }
.card strong { font-size: 1.05rem; }
.days { list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 8px; }
.days a { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 10px 12px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--line); color: var(--ink); text-decoration: none; }
.days a:hover { border-color: var(--accent); }
.days .tick, .days .going { font-size: 0.8rem; font-weight: 600; }
.days .tick { color: var(--accent); }
.days .going { color: var(--muted); }
.days.mine { grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
/* The badge keeps one line inside the card; the date and status wrap instead. */
.days a > span { min-width: 0; }
.days a > .badge { flex-shrink: 0; white-space: nowrap; }
.days.mine li { display: flex; gap: 4px; }
.days.mine li > a { flex: 1; min-width: 0; }
.days.mine .del { font: inherit; font-size: 0.75rem; padding: 0 10px; border-radius: var(--radius); border: 1px solid var(--line); background: var(--surface); color: var(--muted); cursor: pointer; }
.days.mine .del:hover { color: var(--wrong); border-color: var(--wrong); }
.days.mine .del.armed { background: var(--wrong-soft); color: var(--wrong); border-color: var(--wrong); }
.months { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; }
.months a { padding: 6px 12px; border-radius: var(--radius); border: 1px solid var(--line); text-decoration: none; color: var(--ink); background: var(--surface); }
.months a[aria-current="page"] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.empty { color: var(--muted); }

/* ---------- print ---------- */
#print-area { display: none; }
@media print {
  @page { margin: 12mm; }
  body > *:not(#print-area) { display: none !important; }
  #print-area { display: block; color: #000; }
  .sheet { display: grid; gap: 10mm; justify-items: center; }
  .sheet.c2 { grid-template-columns: 1fr; }
  .sheet.c4 { grid-template-columns: 1fr 1fr; }
  .sheet h3 { margin: 0 0 2mm; font: 600 11pt system-ui, sans-serif; }
  .pgrid { border-collapse: collapse; border: 2.5px solid #000; }
  .pgrid td { border: 1px solid #777; text-align: center; vertical-align: middle; font: 600 16pt system-ui, sans-serif; width: 11mm; height: 11mm; padding: 0; }
  .sheet.c2 .pgrid td { width: 10mm; height: 10mm; font-size: 14pt; }
  .sheet.c4 .pgrid td { width: 8.5mm; height: 8.5mm; font-size: 12pt; }
  .pgrid td.entry { font-weight: 400; color: #444; }
  .pgrid tr:nth-child(3n) td { border-bottom: 2px solid #000; }
  .pgrid td:nth-child(3n) { border-right: 2px solid #000; }
}


/* Privacy page */
.prose { max-width: 620px; line-height: 1.55; }
.prose ul { padding-left: 1.2em; }
.prose li { margin-bottom: 10px; }
.prose .muted { color: var(--muted); font-size: 0.9rem; }
