/* Shared look with /sudoku and /patiens */
:root {
  --paper: #f4efe4;
  --paper-2: #fbf8f1;
  --ink: #1b1a17;
  --ink-2: #3b3830;
  --muted: #736d60;
  --line: #d6cdb9;
  --rule: #1b1a17;
  --entry: #2346b8;
  --sel: #ffd84a;
  --peer: #ebe3cf;
  --same: #f1dc93;
  --bad: #c4362b;
  --bad-bg: #f6d9d3;
  --good: #2f7d4f;
  --hint: #2346b8;
  --hint-bg: #dfe6fb;
  --shadow: #1b1a17;
  --grain-op: .32;
  --grain-blend: multiply;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #151410; --paper-2: #1d1c17; --ink: #efe8d6; --ink-2: #cfc8b4; --muted: #9a937f;
    --line: #3a372d; --rule: #efe8d6; --entry: #93b2ff; --sel: #7d6312; --peer: #27251e; --same: #4b3f19;
    --bad: #ff8070; --bad-bg: #4a2420; --good: #6fcf97; --hint: #93b2ff; --hint-bg: #22304f; --shadow: #000;
    --grain-op: .18; --grain-blend: soft-light; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper: #151410; --paper-2: #1d1c17; --ink: #efe8d6; --ink-2: #cfc8b4; --muted: #9a937f;
  --line: #3a372d; --rule: #efe8d6; --entry: #93b2ff; --sel: #7d6312; --peer: #27251e; --same: #4b3f19;
  --bad: #ff8070; --bad-bg: #4a2420; --good: #6fcf97; --hint: #93b2ff; --hint-bg: #22304f; --shadow: #000;
  --grain-op: .18; --grain-blend: soft-light; color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 15px/1.45 "Libre Franklin", "Franklin Gothic Medium", "Helvetica Neue", sans-serif;
  min-height: 100vh;
  padding: env(safe-area-inset-top, 0) 0 env(safe-area-inset-bottom, 0);
}
body::before {
  content: "";
  position: fixed; inset: 0; pointer-events: none; z-index: 0;
  opacity: var(--grain-op);
  mix-blend-mode: var(--grain-blend);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='220' height='220'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .5 0 0 0 0 .45 0 0 0 0 .38 0 0 0 .55 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}
button { font: inherit; color: inherit; cursor: pointer; -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }

.page { position: relative; z-index: 1; max-width: 1020px; margin: 0 auto; padding: 18px max(16px, env(safe-area-inset-left)) 40px; }

/* ---------- masthead ---------- */
.masthead { animation: rise .55s cubic-bezier(.2,.7,.2,1) both; }
.mast-row { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; }
.title {
  font-family: "Fraunces", Georgia, serif;
  font-weight: 800;
  font-variation-settings: "opsz" 144;
  font-size: clamp(44px, 8vw, 76px);
  letter-spacing: -.035em;
  line-height: .9;
  margin: 0;
}
.mast-actions { display: flex; gap: 4px; padding-bottom: 6px; }
.icon-btn {
  width: 42px; height: 42px; border-radius: 50%; border: 0; background: transparent;
  display: grid; place-items: center; transition: background .15s;
}
.icon-btn:hover { background: var(--peer); }
a.icon-btn { color: inherit; }
.mast-sep { width: 1px; height: 22px; background: var(--line); align-self: center; margin: 0 4px; }
.icon-btn.small { width: 34px; height: 34px; }
.dateline {
  margin-top: 12px; padding: 7px 0;
  border-top: 3px double var(--rule); border-bottom: 1px solid var(--rule);
  display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap;
  font-size: 12.5px; font-weight: 600; letter-spacing: .14em; text-transform: uppercase;
}
.today-link { border: 0; background: none; padding: 0; font-weight: 700; letter-spacing: .08em; color: var(--entry); text-transform: uppercase; font-size: 12px; }
.today-link:hover { text-decoration: underline; }

.tabs { display: flex; gap: 26px; margin-top: 14px; }
.tabs button {
  position: relative; border: 0; background: none; padding: 6px 0 9px;
  font-family: "Fraunces", Georgia, serif; font-size: 21px; font-weight: 600; color: var(--muted);
  font-variation-settings: "opsz" 48;
}
.tabs button::after {
  content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 3px; background: var(--ink);
  transform: scaleX(0); transform-origin: left; transition: transform .25s cubic-bezier(.2,.7,.2,1);
}
.tabs button.active { color: var(--ink); }
.tabs button.active::after { transform: scaleX(1); }
.tabs button:hover { color: var(--ink); }
.tab-mark { display: inline-block; width: 7px; height: 7px; border-radius: 50%; margin-left: 6px; vertical-align: 4px; }
.tab-mark.started { border: 1.5px solid var(--muted); }
.tab-mark.solved { background: var(--good); }
.tabs.small { gap: 18px; margin: 4px 0 16px; }
.tabs.small button { font-size: 17px; }

.kbd-help { margin-top: 22px; font-size: 12px; color: var(--muted); line-height: 1.9; }
kbd { font: 600 11px/1 "Libre Franklin", sans-serif; border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 4px; padding: 2px 5px; background: var(--paper-2); }

.primary, .ghost {
  border-radius: 99px; padding: 11px 22px; font-weight: 700; border: 1.5px solid var(--ink);
  transition: transform .08s;
}
.primary { background: var(--ink); color: var(--paper); }
.ghost { background: transparent; }
.primary:active, .ghost:active { transform: scale(.96); }
.primary.small, .ghost.small { padding: 7px 15px; font-size: 13px; }
.primary.danger { background: var(--bad); border-color: var(--bad); color: #fff; }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(26px + env(safe-area-inset-bottom, 0)); transform: translateX(-50%);
  background: var(--ink); color: var(--paper); padding: 11px 20px; border-radius: 99px; font-weight: 600;
  z-index: 50; max-width: calc(100vw - 32px); text-align: center; animation: toast .25s ease-out both;
}
@keyframes toast { from { opacity: 0; transform: translate(-50%, 8px); } to { opacity: 1; transform: translate(-50%, 0); } }

/* ---------- modals ---------- */
.modal {
  border: 1.5px solid var(--ink); background: var(--paper-2); color: var(--ink);
  box-shadow: 8px 8px 0 var(--shadow); padding: 26px 28px 24px; width: min(440px, calc(100vw - 32px));
  max-height: calc(100vh - 40px); overflow: auto;
}
.modal[open] { animation: pop .2s ease-out both; }
.modal::backdrop { background: color-mix(in srgb, var(--paper) 55%, transparent); backdrop-filter: blur(2px); }
.modal-kicker { margin: 0 0 6px; font-size: 12px; font-weight: 700; letter-spacing: .16em; text-transform: uppercase; color: var(--muted); }
.modal-x { position: absolute; top: 10px; right: 12px; border: 0; background: none; font-size: 28px; line-height: 1; width: 36px; height: 36px; border-radius: 50%; }
.modal-x:hover { background: var(--peer); }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; margin-top: 22px; }
.fine { font-size: 12px; color: var(--muted); margin: 16px 0 0; }

.win-title { font-family: "Fraunces", Georgia, serif; font-size: 46px; line-height: 1; margin: 2px 0 8px; font-weight: 800; letter-spacing: -.03em; }
.win-sub { margin: 0; color: var(--ink-2); }
.win-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 20px; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); padding: 14px 0; }
.win-stats div { text-align: center; }
.win-stats b, .stats-grid b { display: block; font-family: "Fraunces", Georgia, serif; font-size: 30px; font-weight: 600; line-height: 1.1; font-variant-numeric: tabular-nums; }
.win-stats span, .stats-grid span { font-size: 11.5px; font-weight: 600; color: var(--muted); letter-spacing: .04em; }
.win-burst { position: absolute; top: -40px; right: -40px; width: 160px; height: 160px; border-radius: 50%; background: var(--sel); opacity: .55; pointer-events: none; animation: burst .7s cubic-bezier(.2,.8,.2,1) both; }
.modal#dlg-win { overflow: hidden; }
.modal#dlg-win > *:not(.win-burst):not(.modal-x) { position: relative; }
@keyframes burst { from { transform: scale(0); } to { transform: scale(1); } }

.stats-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 18px 8px; text-align: center; }

.cal-head { display: flex; align-items: center; justify-content: space-between; margin: 4px 0 10px; }
.cal-head h3 { margin: 0; font-family: "Fraunces", Georgia, serif; font-size: 22px; font-weight: 600; text-transform: capitalize; }
.cal-head button:disabled { opacity: .25; cursor: default; background: none; }
.cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal .dow { text-align: center; font-size: 11px; font-weight: 700; color: var(--muted); letter-spacing: .06em; padding-bottom: 4px; }
.cal .day {
  border: 1px solid var(--line); background: var(--paper); border-radius: 8px; aspect-ratio: 1;
  display: grid; grid-template-rows: 1fr auto; justify-items: center; padding: 4px 0 6px; font-weight: 600; font-size: 14px;
}
.cal .day:hover:not(:disabled) { border-color: var(--ink); }
.cal .day:disabled { opacity: .3; cursor: default; }
.cal .day.today { border: 2px solid var(--ink); }
.cal .day.current { background: var(--sel); border-color: var(--ink); }
.cal .dots { display: flex; gap: 3px; }
.dot { display: inline-block; width: 6px; height: 6px; border-radius: 50%; border: 1px solid var(--line); vertical-align: 0; }
.dot.started { border-color: var(--muted); background: transparent; border-width: 1.5px; }
.dot.solved { background: var(--good); border-color: var(--good); }
.cal-legend .dot { margin: 0 2px 0 6px; }

.settings { display: grid; gap: 2px; margin-top: 8px; }
.setting { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 11px 0; border-bottom: 1px solid var(--line); cursor: pointer; }
.setting:last-child { border-bottom: 0; }
.setting b { display: block; font-weight: 600; }
.setting small { display: block; color: var(--muted); font-size: 12.5px; }
.setting select { font: inherit; padding: 5px 8px; border: 1.5px solid var(--line); border-radius: 8px; background: var(--paper); color: var(--ink); }
.confirm-text { font-family: "Fraunces", Georgia, serif; font-size: 19px; margin: 4px 0 0; }

@keyframes rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes pop { from { opacity: 0; transform: translateY(-4px) scale(.98); } to { opacity: 1; transform: none; } }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- fyra i rad ---------- */
:root { --board: #23408e; --board-rim: #1a3172; --p1: #c8372d; --p2: #f0c419; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { --board: #1f3a82; --board-rim: #142a63; } }
:root[data-theme="dark"] { --board: #1f3a82; --board-rim: #142a63; }
a.icon-btn { color: inherit; }
.mast-sep { width: 1px; height: 22px; background: var(--line); align-self: center; margin: 0 4px; }
.online { display: inline-flex; align-items: center; gap: 7px; color: var(--muted); letter-spacing: .1em; }
.dot-live { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.online.up .dot-live { background: var(--good); box-shadow: 0 0 0 3px color-mix(in srgb, var(--good) 25%, transparent); }

.lobby { margin-top: 26px; animation: rise .6s .08s cubic-bezier(.2,.7,.2,1) both; }
.nick-row { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.nick-row span { font-size: 12px; font-weight: 700; letter-spacing: .14em; text-transform: uppercase; color: var(--muted); }
.nick-row input, .invite-link input {
  font: inherit; font-weight: 600; padding: 8px 15px; border-radius: 99px; border: 1.5px solid var(--ink);
  background: var(--paper-2); color: var(--ink); min-width: 0;
}
.nick-row input { width: min(260px, 100%); }
.nick-row input:focus, .invite-link input:focus { outline: 2px solid var(--entry); outline-offset: 1px; }
.nick-row input.bad { border-color: var(--bad); }
.options { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 18px; margin-top: 20px; }
.opt {
  background: var(--paper-2); border: 1.5px solid var(--ink); box-shadow: 6px 6px 0 var(--shadow);
  padding: 20px 22px 22px; display: flex; flex-direction: column;
}
#opt-online { border-width: 2.5px; }
.opt-kicker { margin: 0; font-size: 11.5px; font-weight: 700; letter-spacing: .16em; text-transform: uppercase; color: var(--muted); }
.opt h2 { font-family: "Fraunces", Georgia, serif; font-size: 27px; font-weight: 600; line-height: 1.1; margin: 6px 0 8px; letter-spacing: -.01em; }
.opt-text { margin: 0; color: var(--ink-2); }
.opt-meta { margin: 10px 0 0; font-size: 12.5px; color: var(--muted); font-weight: 600; }
.opt-actions { margin-top: auto; padding-top: 18px; display: flex; gap: 8px; }
.field { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 12px; }
.field > span { font-weight: 600; }
.seg { display: inline-grid; grid-auto-flow: column; border: 1.5px solid var(--ink); border-radius: 99px; padding: 2px; }
.seg button { border: 0; background: none; border-radius: 99px; padding: 5px 12px; font-weight: 700; font-size: 13px; transition: background .18s, color .18s; }
.seg button.active { background: var(--ink); color: var(--paper); }
.searching { margin-top: 16px; text-align: center; }
.searching p { margin: 10px 0; }
.pulse-discs { display: flex; justify-content: center; gap: 8px; }
.pulse-discs i { width: 18px; height: 18px; border-radius: 50%; background: var(--p1); animation: bob 1.2s ease-in-out infinite; }
.pulse-discs i:nth-child(even) { background: var(--p2); }
.pulse-discs i:nth-child(2) { animation-delay: .15s; } .pulse-discs i:nth-child(3) { animation-delay: .3s; } .pulse-discs i:nth-child(4) { animation-delay: .45s; }
@keyframes bob { 0%, 100% { transform: translateY(0); } 40% { transform: translateY(-10px); } }
.invite { margin-top: 16px; }
.invite-link { display: flex; gap: 8px; }
.invite-link input { flex: 1; font-size: 13px; }
.link { border: 0; background: none; padding: 0; font: inherit; font-weight: 700; color: var(--entry); cursor: pointer; }
.link:hover { text-decoration: underline; }

.game { margin-top: 12px; animation: rise .5s cubic-bezier(.2,.7,.2,1) both; display: grid; justify-items: center; }
.players { width: min(100%, 600px); display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 10px; }
.player { display: flex; align-items: center; gap: 10px; padding: 8px 12px; border-radius: 99px; border: 1.5px solid transparent; transition: border-color .2s, background .2s; min-width: 0; }
.player.opp { justify-content: flex-end; }
.player.active { border-color: var(--ink); background: var(--paper-2); }
.pname { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ptimer { font-variant-numeric: tabular-nums; font-weight: 700; font-size: 13px; color: var(--muted); }
.ptimer.low { color: var(--bad); }
.disc-icon { width: 22px; height: 22px; border-radius: 50%; flex: none; box-shadow: inset 0 -2px 0 rgba(0,0,0,.18); }
.disc-icon.c1 { background: var(--p1); } .disc-icon.c2 { background: var(--p2); }
.score { font-family: "Fraunces", Georgia, serif; font-size: 24px; font-weight: 600; font-variant-numeric: tabular-nums; }
.timebar { width: min(100%, 600px); height: 3px; background: var(--line); margin-top: 6px; border-radius: 2px; overflow: hidden; visibility: hidden; }
.timebar.on { visibility: visible; }
.timebar i { display: block; height: 100%; width: 100%; background: var(--ink); transform-origin: left; }
.board-wrap { width: min(100%, 560px, calc((100svh - 330px) * 700 / 680)); min-width: 280px; margin-top: 2px; }
.board { display: block; width: 100%; height: auto; touch-action: manipulation; user-select: none; -webkit-user-select: none; cursor: pointer; overflow: visible; }
.board.locked { cursor: default; }
.board .frame { fill: var(--board); }
.board #hole-rims circle { fill: none; stroke: var(--board-rim); stroke-width: 4; }
.disc { stroke: rgba(0,0,0,.18); stroke-width: 3; }
.disc.p1 { fill: url(#g1); } .disc.p2 { fill: url(#g2); }
.ghost-disc { opacity: .45; transition: cx .12s ease-out; pointer-events: none; }
.ghost-disc.p1 { fill: var(--p1); } .ghost-disc.p2 { fill: var(--p2); }
.mark-last { fill: rgba(255,255,255,.75); }
.mark-win { fill: none; stroke: #fff; stroke-width: 6; animation: winpulse 1s ease-in-out infinite; }
@keyframes winpulse { 50% { stroke-width: 11; opacity: .7; } }
.status { margin: 14px 0 0; font-family: "Fraunces", Georgia, serif; font-size: 22px; font-weight: 600; min-height: 1.4em; text-align: center; }
.status .sub { display: block; font-family: "Libre Franklin", sans-serif; font-size: 13px; font-weight: 500; color: var(--muted); }
.game-actions { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; margin-top: 12px; }
.game-actions .primary.glow { animation: glow 1.3s ease-in-out infinite; }
@keyframes glow { 50% { box-shadow: 0 0 0 5px color-mix(in srgb, var(--p2) 60%, transparent); } }
.kbd-help { font-size: 12px; color: var(--muted); margin-top: 16px; text-align: center; }
.stats-table { display: grid; grid-template-columns: auto repeat(3, 1fr); gap: 8px 14px; align-items: baseline; margin-top: 10px; }
.stats-table .h { font-size: 11px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); text-align: center; }
.stats-table .l { font-weight: 600; }
.stats-table b { font-family: "Fraunces", Georgia, serif; font-size: 22px; font-weight: 600; text-align: center; font-variant-numeric: tabular-nums; }

@media (max-width: 900px) { .options { grid-template-columns: 1fr; } .opt { box-shadow: 4px 4px 0 var(--shadow); } }
@media (max-width: 420px) {
  .page { padding-top: 10px; }
  .title { font-size: 44px; }
  .dateline { font-size: 11px; letter-spacing: .1em; }
  .player { padding: 6px 8px; gap: 6px; }
  .status { font-size: 19px; }
  .kbd-help { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-delay: 0ms !important; transition: none !important; }
}
