/* Shared look with /sudoku (palette, masthead, tabs, buttons, modals) */
: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; }

.act { border: 0; background: none; border-radius: 10px; padding: 8px 0 6px; display: grid; justify-items: center; gap: 3px; font-size: 12px; font-weight: 600; }
.act:hover { background: var(--peer); }
.act:disabled { opacity: .35; cursor: default; background: none; }
.switch { position: relative; width: 40px; height: 23px; flex: none; }
.switch input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.switch i { position: absolute; inset: 0; border-radius: 99px; background: var(--line); transition: background .2s; pointer-events: none; }
.switch i::after { content: ""; position: absolute; top: 3px; left: 3px; width: 17px; height: 17px; border-radius: 50%; background: var(--paper-2); transition: transform .2s cubic-bezier(.3,.7,.3,1); box-shadow: 0 1px 2px rgba(0,0,0,.25); }
.switch input:checked + i { background: var(--ink); }
.switch input:checked + i::after { transform: translateX(17px); }
.switch input:focus-visible + i { outline: 2px solid var(--entry); outline-offset: 2px; }
.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; }


/* ---------- patiens ---------- */
:root { --card: #fffdf7; --card-line: #d3c9b4; --card-ink: #1b1a17; --card-red: #b3261e; --felt: transparent; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { --card: #ece5d3; --card-line: #b9b09a; } }
:root[data-theme="dark"] { --card: #ece5d3; --card-line: #b9b09a; }
a.icon-btn { color: inherit; }
.mast-sep { width: 1px; height: 22px; background: var(--line); align-self: center; margin: 0 4px; }
.deal-label { color: var(--muted); letter-spacing: .1em; }

.tabs-row { display: flex; align-items: flex-end; justify-content: space-between; gap: 14px; flex-wrap: wrap; }
.seg { display: inline-grid; grid-auto-flow: column; border: 1.5px solid var(--ink); border-radius: 99px; padding: 2px; margin-bottom: 8px; }
.seg button { border: 0; background: none; border-radius: 99px; padding: 5px 13px; font-weight: 700; font-size: 13px; transition: background .18s, color .18s; }
.seg button.active { background: var(--ink); color: var(--paper); }

.bar { display: flex; align-items: center; justify-content: space-between; gap: 10px 18px; flex-wrap: wrap; margin: 18px 0 14px; animation: rise .6s .08s cubic-bezier(.2,.7,.2,1) both; }
.meters { display: flex; gap: 24px; }
.meters span { display: grid; line-height: 1.1; }
.meters b { font-size: 19px; font-weight: 600; font-variant-numeric: tabular-nums; }
.meters small { font-size: 10.5px; font-weight: 700; letter-spacing: .14em; text-transform: uppercase; color: var(--muted); }
.bar-actions { display: flex; gap: 2px; flex-wrap: wrap; }
.act { min-width: 62px; padding: 7px 8px 5px; }
.act.strong { background: var(--ink); color: var(--paper); }
.act.strong:hover { background: var(--ink-2); }
.act.pulse { animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 4px color-mix(in srgb, var(--sel) 80%, transparent); } }

.table { position: relative; touch-action: none; user-select: none; -webkit-user-select: none; min-height: 300px; animation: rise .6s .14s cubic-bezier(.2,.7,.2,1) both; --cw: 80px; }
.table.instant .card { transition: none !important; }
.loading { position: absolute; inset: 0; display: grid; place-items: center; }
.spinner { width: 34px; height: 34px; border: 3px solid var(--line); border-top-color: var(--ink); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.slot {
  position: absolute; left: 0; top: 0; width: var(--cw); height: calc(var(--cw) * 1.4);
  border-radius: calc(var(--cw) * .08); border: 1.5px dashed var(--line);
  display: grid; place-items: center; color: var(--line);
}
.slot svg { width: calc(var(--cw) * .42); height: calc(var(--cw) * .42); fill: currentColor; stroke: none; opacity: .9; }
.slot.stock { cursor: pointer; border-style: solid; }
.slot.stock svg { fill: none; stroke: currentColor; stroke-width: 2; width: calc(var(--cw) * .38); }
.slot.stock.spent svg { opacity: .35; }
.slot.hint { border-color: var(--hint); color: var(--hint); box-shadow: 0 0 0 3px color-mix(in srgb, var(--hint) 35%, transparent); }

.card {
  position: absolute; left: 0; top: 0; width: var(--cw); height: calc(var(--cw) * 1.4);
  transition: transform .24s cubic-bezier(.25,.75,.3,1); will-change: transform;
}
.card .in { position: absolute; inset: 0; }
.card.flip .in { animation: flip .26s ease-out both; }
@keyframes flip { from { transform: scaleX(0); } to { transform: scaleX(1); } }
.cface, .cback { position: absolute; inset: 0; border-radius: calc(var(--cw) * .08); }
.cface {
  background: var(--card); border: 1px solid var(--card-line); color: var(--card-ink);
  box-shadow: 0 1px 2px rgba(20, 16, 8, .16), 0 0 0 .5px rgba(20,16,8,.05);
  overflow: hidden;
}
.card.red .cface { color: var(--card-red); }
.card.up .cback, .card:not(.up) .cface { display: none; }
.card.up { cursor: grab; }
.card.dragging { transition: none; cursor: grabbing; }
.card.dragging .cface { box-shadow: 0 10px 22px rgba(20, 16, 8, .28); }
.ix { position: absolute; top: 4%; left: 7%; display: flex; align-items: center; gap: calc(var(--cw) * .02); font: 600 calc(var(--cw) * .27)/1 "Fraunces", Georgia, serif; letter-spacing: -.04em; font-variation-settings: "opsz" 30; }
.ix svg, .ix-s svg { width: calc(var(--cw) * .2); height: calc(var(--cw) * .2); fill: currentColor; stroke: none; }
.ix-s { position: absolute; top: 5.5%; right: 7%; display: flex; }
.mid { position: absolute; left: 50%; top: 60%; transform: translate(-50%, -50%); display: grid; place-items: center; }
.mid svg { width: calc(var(--cw) * .44); height: calc(var(--cw) * .44); fill: currentColor; stroke: none; }
.card.ace .mid svg { width: calc(var(--cw) * .6); height: calc(var(--cw) * .6); }
.court-frame { position: absolute; left: 12%; right: 12%; top: 28%; bottom: 7%; border: 1px solid currentColor; border-radius: calc(var(--cw) * .05); opacity: .32; }
.mid.court { font: italic 500 calc(var(--cw) * .56)/1 "Fraunces", Georgia, serif; top: 63%; }
.mid.court small { position: absolute; left: 50%; top: -38%; transform: translateX(-50%); display: flex; }
.mid.court small svg { width: calc(var(--cw) * .16); height: calc(var(--cw) * .16); }

.cback { border: 1px solid rgba(0,0,0,.25); box-shadow: 0 1px 2px rgba(20, 16, 8, .2); background-color: var(--back); overflow: hidden; }
.cback::before {
  content: ""; position: absolute; inset: calc(var(--cw) * .06); border-radius: calc(var(--cw) * .04);
  border: 1px solid rgba(255,255,255,.45);
  background:
    repeating-linear-gradient(45deg, rgba(255,255,255,.16) 0 1.5px, transparent 1.5px 7px),
    repeating-linear-gradient(-45deg, rgba(255,255,255,.16) 0 1.5px, transparent 1.5px 7px);
}
.cback::after {
  content: ""; position: absolute; left: 50%; top: 50%; width: calc(var(--cw) * .3); height: calc(var(--cw) * .3);
  transform: translate(-50%, -50%) rotate(45deg); border: 1.5px solid rgba(255,255,255,.6); background: var(--back);
}
body[data-back="blue"] { --back: #23408e; }
body[data-back="red"] { --back: #9b2c25; }
body[data-back="green"] { --back: #22603f; }
body[data-back="ink"] { --back: #23211c; }

.card.hint .cface { box-shadow: 0 0 0 3px var(--hint), 0 4px 14px rgba(20,16,8,.2); }
.card.shake { animation: shake .32s ease-in-out; }
@keyframes shake { 20%, 60% { translate: -4px 0; } 40%, 80% { translate: 4px 0; } }

#fx { position: fixed; inset: 0; width: 100%; height: 100%; z-index: 40; cursor: pointer; }

.back-pick { display: flex; gap: 8px; }
.back-pick button { width: 28px; height: 38px; border-radius: 5px; border: 2px solid transparent; background: var(--c); padding: 0; }
.back-pick button.active { border-color: var(--ink); box-shadow: 0 0 0 2px var(--paper-2) inset; }

@media (max-width: 640px) {
  .act span { display: none; }
  .act { min-width: 42px; padding: 9px 6px; }
  .meters { gap: 16px; }
  .meters b { font-size: 17px; }
  .bar { margin: 12px 0 10px; }
  .tabs button { font-size: 18px; }
  .tabs { gap: 20px; }
}
@media (max-width: 420px) {
  .page { padding-top: 10px; }
  .dateline { font-size: 11px; letter-spacing: .1em; }
  .deal-label { display: none; }
}
@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; } }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-delay: 0ms !important; transition: none !important; }
}
