:root {
  --bg: #F2F4F0;
  --surface: #FFFFFF;
  --ink: #1A231E;
  --muted: #667069;
  --line: #D6DBD4;
  --line-strong: #B9C2BA;
  --felt: #1F6C4A;
  --felt-deep: #12482F;
  --felt-tint: rgba(31,108,74,.22);
  --loss: #B33A3A;
  --loss-tint: rgba(179,58,58,.20);
  --act-stand: #B33A3A;
  --act-hit: #2E8B57;
  --act-double: #E3B341;
  --act-split: #2E5CA6;
  --act-surr: #7A8580;
  --chip: #EEF1EC;
  --focus: #2E5CA6;
  --shadow: 0 1px 0 rgba(0,0,0,.04);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0F1813; --surface: #16211B; --ink: #E9EDE8; --muted: #98A39C;
    --line: #26332C; --line-strong: #3A4A41; --felt: #3FA97A; --felt-deep: #2C7D58;
    --felt-tint: rgba(63,169,122,.16); --loss: #E06A6A; --loss-tint: rgba(224,106,106,.16);
    --act-stand: #D95F5F; --act-hit: #3FA97A; --act-double: #E8C25A; --act-split: #6F9BE6; --act-surr: #6E7A74; --chip: #1F2C25; --focus: #6F9BE6;
  }
}
:root[data-theme="dark"] {
  --bg: #0F1813; --surface: #16211B; --ink: #E9EDE8; --muted: #98A39C;
  --line: #26332C; --line-strong: #3A4A41; --felt: #3FA97A; --felt-deep: #2C7D58;
  --felt-tint: rgba(63,169,122,.16); --loss: #E06A6A; --loss-tint: rgba(224,106,106,.16);
  --act-stand: #D95F5F; --act-hit: #3FA97A; --act-double: #E8C25A; --act-split: #6F9BE6; --act-surr: #6E7A74; --chip: #1F2C25; --focus: #6F9BE6;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font-family: "IBM Plex Sans", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 15px; line-height: 1.45;
  font-variant-numeric: tabular-nums;
}
h1, h2, h3 { font-family: "Fraunces", Georgia, "Times New Roman", serif; font-weight: 600; margin: 0; letter-spacing: -0.01em; }
h1 { font-size: 1.7rem; line-height: 1.15; }
h2 { font-size: 1.15rem; }
p { margin: 0; }
button, select, input { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.wrap { max-width: 1320px; margin: 0 auto; padding: 22px 18px 48px; }

header.top { display: flex; flex-wrap: wrap; gap: 14px 24px; align-items: flex-end; justify-content: space-between; margin-bottom: 20px; }
header.top .sub { color: var(--muted); max-width: 60ch; margin-top: 4px; }
.tabs { display: inline-flex; border: 1px solid var(--line-strong); border-radius: 8px; overflow: hidden; background: var(--surface); }
.tabs button { border: 0; background: transparent; padding: 8px 14px; font-weight: 500; color: var(--muted); }
.tabs button + button { border-left: 1px solid var(--line-strong); }
.tabs button[aria-selected="true"] { background: var(--felt); color: #fff; }
.tabs a.tablink { display: inline-block; padding: 8px 14px; font-weight: 500; color: var(--muted); text-decoration: none; border-left: 1px solid var(--line-strong); }
.tabs a.tablink:first-child { border-left: 0; }
.tabs a.tablink.current { background: var(--felt); color: #fff; }

.layout { display: grid; grid-template-columns: 260px minmax(0, 1fr); gap: 22px; align-items: start; }
@media (max-width: 860px) { .layout { grid-template-columns: 1fr; } aside.rules { order: 2; } main { order: 1; } }

aside.rules { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 16px; box-shadow: var(--shadow); position: sticky; top: 14px; }
@media (max-width: 860px) { aside.rules { position: static; } }
aside.rules h2 { margin-bottom: 10px; }
.rule { display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: center; padding: 7px 0; border-top: 1px solid var(--line); }
.rule:first-of-type { border-top: 0; }
.rule label { color: var(--ink); }
.rule select { border: 1px solid var(--line-strong); background: var(--chip); border-radius: 6px; padding: 4px 6px; max-width: 132px; }
.rule input[type=checkbox] { width: 18px; height: 18px; accent-color: var(--felt); margin: 0; }
.preset { margin-bottom: 8px; display: grid; gap: 4px; }
.preset select { border: 1px solid var(--line-strong); background: var(--chip); border-radius: 6px; padding: 6px 8px; width: 100%; }
.preset span { color: var(--muted); font-size: .85rem; }

main { min-width: 0; }
section.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 18px; box-shadow: var(--shadow); }
section.panel + section.panel { margin-top: 18px; }

/* Hand builder */
.hand-row { display: flex; flex-wrap: wrap; align-items: center; gap: 14px 22px; margin-bottom: 14px; }
.hand-cards { display: flex; gap: 6px; min-height: 58px; align-items: center; }
.card {
  width: 42px; height: 58px; border-radius: 6px; border: 1px solid var(--line-strong); background: var(--surface);
  display: grid; place-items: center; font-family: "Fraunces", Georgia, serif; font-size: 1.35rem; font-weight: 600;
  position: relative; box-shadow: 0 1px 2px rgba(0,0,0,.08);
}
.card.red { color: var(--loss); }
.card.slot { border-style: dashed; color: var(--muted); font-family: inherit; font-size: .8rem; font-weight: 400; box-shadow: none; background: transparent; }
button.card { padding: 0; }
button.card:hover { border-color: var(--felt); }
button.card .x { position: absolute; top: -7px; right: -7px; width: 18px; height: 18px; border-radius: 50%; background: var(--ink); color: var(--bg); font: 600 11px/18px "IBM Plex Sans", sans-serif; opacity: 0; transition: opacity .12s; }
button.card:hover .x, button.card:focus-visible .x { opacity: 1; }
.hand-name { font-family: "Fraunces", Georgia, serif; font-size: 1.5rem; font-weight: 600; line-height: 1.1; }
.hand-name small { display: block; font-family: "IBM Plex Sans", sans-serif; font-weight: 400; font-size: .9rem; color: var(--muted); margin-top: 3px; }
.deal { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.deal .lbl { color: var(--muted); margin-right: 4px; }
.deal button.add { width: 36px; height: 36px; border-radius: 6px; border: 1px solid var(--line-strong); background: var(--chip); font-weight: 600; }
.deal button.add:hover { background: var(--felt-tint); border-color: var(--felt); }
button.linkbtn { border: 0; background: transparent; color: var(--muted); text-decoration: underline; text-underline-offset: 3px; padding: 6px 4px; margin: 0; }
button.linkbtn:hover { color: var(--ink); }
.deal button.clear { margin-left: 8px; border: 0; background: transparent; color: var(--muted); text-decoration: underline; text-underline-offset: 3px; padding: 6px 4px; }
.deal button.clear:hover { color: var(--ink); }

/* Results table */
.tablewrap { overflow-x: auto; }
table.ev { border-collapse: collapse; width: 100%; min-width: 720px; }
table.ev th { text-align: left; font-weight: 500; color: var(--muted); font-size: .85rem; padding: 6px 8px; border-bottom: 1px solid var(--line-strong); white-space: nowrap; }
table.ev th.num, table.ev td.num { text-align: right; }
table.ev td { padding: 0; border-bottom: 1px solid var(--line); vertical-align: middle; height: 40px; }
table.ev td.up { padding: 0 8px; font-family: "Fraunces", Georgia, serif; font-size: 1.15rem; font-weight: 600; width: 96px; white-space: nowrap; }
table.ev td.up small { font-family: "IBM Plex Sans", sans-serif; font-weight: 400; font-size: .8rem; color: var(--muted); margin-left: 6px; }
table.ev td.bust { padding: 0 8px; color: var(--muted); font-size: .85rem; width: 64px; }
table.ev td.evc { width: 15%; }
.cell { position: relative; height: 40px; display: flex; align-items: center; justify-content: flex-end; padding: 0 8px; }
.cell::before { content: ""; position: absolute; left: 50%; top: 5px; bottom: 5px; width: 1px; background: var(--line-strong); }
.cell .bar { position: absolute; top: 5px; bottom: 5px; }
.cell .bar.pos { left: 50%; background: var(--felt-tint); border-radius: 0 3px 3px 0; }
.cell .bar.neg { right: 50%; background: var(--loss-tint); border-radius: 3px 0 0 3px; }
.cell .v { position: relative; font-weight: 500; }
.cell .v.pos { color: var(--felt); }
.cell .v.neg { color: var(--loss); }
.cell.na { color: var(--muted); justify-content: center; }
.cell.na::before { display: none; }
.cell.na::before { display: none; }
td.best .cell { background: var(--felt); border-radius: 6px; margin: 4px 2px; height: 32px; }
td.best .cell::before, td.best .cell .bar, td.best .cell::before { display: none; }
td.best .cell .v { color: #fff; }
table.ev td.play { padding: 0 8px; white-space: nowrap; }
.play { line-height: 1.2; }
.play .name { font-weight: 600; }
.play .fb { color: var(--muted); font-size: .8rem; display: block; }
.play .fb.close { color: var(--hit); }
.a-stand { color: var(--felt); } .a-hit { color: var(--hit); } .a-double { color: var(--dbl); } .a-split { color: var(--split); } .a-surrender { color: var(--surr); }
.notes { color: var(--muted); font-size: .85rem; margin-top: 12px; display: grid; gap: 4px; }
.empty { color: var(--muted); padding: 24px 0; }
.status { color: var(--muted); font-size: .9rem; margin-top: 8px; min-height: 1.3em; }

/* Strategy chart */
.chart-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 18px; }
table.chart { border-collapse: separate; border-spacing: 2px; font-size: .85rem; }
table.chart th { font-weight: 500; color: var(--muted); padding: 2px 4px; text-align: center; }
table.chart th.rowh { text-align: right; padding-right: 8px; font-weight: 600; color: var(--ink); white-space: nowrap; }
table.chart td { width: 30px; height: 28px; text-align: center; border-radius: 4px; font-weight: 600; color: #fff; cursor: default; }
table.chart td sub { font-size: .65em; font-weight: 500; vertical-align: baseline; position: relative; top: .25em; margin-left: 1px; }
td.c-S { background: var(--act-stand); } td.c-H { background: var(--act-hit); } td.c-D { background: var(--act-double); color: #1A231E; } td.c-P { background: var(--act-split); } td.c-R { background: var(--act-surr); }
td.c-B { background: var(--chip); color: var(--muted); }
.legend { display: flex; flex-wrap: wrap; gap: 8px 16px; margin: 10px 0 16px; color: var(--muted); font-size: .85rem; }
.legend span::before { content: ""; display: inline-block; width: 12px; height: 12px; border-radius: 3px; vertical-align: -1px; margin-right: 6px; background: var(--sw); }
.progress { height: 6px; border-radius: 3px; background: var(--chip); overflow: hidden; margin: 10px 0; }
.progress i { display: block; height: 100%; width: 0; background: var(--felt); transition: width .15s; }
.hidden { display: none !important; }
button.primary { border: 0; background: var(--felt); color: #fff; border-radius: 8px; padding: 9px 16px; font-weight: 500; }
button.primary:hover { background: var(--felt-deep); }
button.primary:disabled { opacity: .6; cursor: default; }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

.head-right { display: flex; align-items: center; gap: 8px; }
.theme-btn { width: 36px; height: 36px; border-radius: 8px; border: 1px solid var(--line-strong); background: var(--surface); color: var(--muted); font-size: 1.05rem; line-height: 1; display: inline-grid; place-items: center; }
.theme-btn:hover { color: var(--ink); border-color: var(--felt); }
.tablink { padding: 8px 14px; font-weight: 500; color: var(--muted); text-decoration: none; display: inline-block; }
.tablink + .tablink, .tablink + button { border-left: 1px solid var(--line-strong); }
.tablink.current { background: var(--felt); color: #fff; }

details.about summary { cursor: pointer; list-style: none; }
details.about summary::-webkit-details-marker { display: none; }
details.about summary::after { content: " \25BE"; color: var(--muted); }
details.about[open] summary::after { content: " \25B4"; }
.about-body { margin-top: 10px; display: grid; gap: 8px; max-width: 70ch; }
.about-body p { margin: 0; }

/* consistent collapsible panels: heading left, round chevron right */
details.pl > summary { list-style: none; cursor: pointer; display: flex; align-items: center; justify-content: space-between; gap: 10px; }
details.pl > summary::-webkit-details-marker, details.pl > summary::marker { display: none; content: ""; }
details.pl > summary::after { content: none; }
details.pl > summary .sh { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
details.pl > summary h2 { display: inline; }
.collapse-btn.chev { width: 30px; height: 30px; border-radius: 8px; border: 1px solid var(--line-strong); background: var(--surface); color: var(--muted); display: inline-grid; place-items: center; flex: none; }
.collapse-btn.chev svg { transition: transform .15s; transform: rotate(-90deg); }
details.pl[open] > summary .chev svg { transform: rotate(0deg); }
details.about summary::after, details.about[open] summary::after { content: none; }

/* header account button, shared by all pages */
.menu-btn { width: 36px; height: 36px; border-radius: 8px; border: 1px solid var(--line-strong); background: var(--surface); color: var(--muted); display: grid; place-items: center; cursor: pointer; padding: 0; }
.menu-btn:hover, .menu-btn[aria-expanded="true"] { color: var(--ink); border-color: var(--felt); }
.acct-btn { width: auto; padding: 0 10px; gap: 6px; grid-template-columns: auto auto; }
.acct-nick { font-size: .85rem; font-weight: 500; max-width: 110px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.acct-nick:empty { display: none; }
a.acct-btn { text-decoration: none; }
.head-right .btn { border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink); border-radius: 8px; padding: 7px 12px; font: inherit; cursor: pointer; }

/* phones: tabs never wrap; the strip scrolls sideways if it must */
@media (max-width: 600px) {
  .head-right { width: 100%; gap: 6px; }
  .tabs { flex: 1 1 auto; min-width: 0; overflow-x: auto; overflow-y: hidden; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
  .tabs::-webkit-scrollbar { display: none; }
  .tablink, .tabs a.tablink, .tabs button, .play-tab { white-space: nowrap; padding: 8px 10px; font-size: .88rem; }
  .menu-btn, .theme-btn { flex: none; }
}
@media (max-width: 600px) {
  .acct-nick { display: none; }
  .acct-btn { padding: 0; width: 36px; grid-template-columns: auto; }
  .tablink, .tabs a.tablink, .tabs button, .play-tab { padding: 8px 8px; }
}

/* shared popover menus (account and Play menus on every page) */
.menu { position: relative; }
.menu-body { position: absolute; right: 0; top: 42px; z-index: 20; background: var(--surface); border: 1px solid var(--line-strong); border-radius: 10px; padding: 12px 14px; display: grid; gap: 8px; min-width: 220px; box-shadow: 0 8px 24px rgba(0,0,0,.18); }
.menu-body label { display: flex; gap: 8px; align-items: center; font-size: .9rem; cursor: pointer; }
.menu-body input[type=checkbox] { width: 16px; height: 16px; accent-color: var(--felt); margin: 0; }
.menu-body select { border: 1px solid var(--line-strong); background: var(--chip); border-radius: 6px; padding: 5px 8px; font-size: .9rem; }
.menu-title { color: var(--muted); text-transform: uppercase; letter-spacing: .06em; font-size: .68rem; margin-top: 2px; }
.menu-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.menu-row select { max-width: 150px; }
.menu-foot { border-top: 1px solid var(--line); padding-top: 8px; margin-top: 4px; }
.play-menu { position: relative; }
.play-tab { display: inline-flex; align-items: center; gap: 6px; border: 0; cursor: pointer; font: inherit; font-weight: 500; }
.play-tab svg { transition: transform .15s; }
.play-tab[aria-expanded="true"] svg { transform: rotate(180deg); }
.play-body { left: 0; right: auto; top: 44px; min-width: 260px; padding: 6px; gap: 2px; }
.mode-item { display: flex; flex-direction: column; align-items: flex-start; gap: 1px; width: 100%; text-align: left; border: 0; background: transparent; color: var(--ink); padding: 8px 10px; border-radius: 8px; font: inherit; font-weight: 500; cursor: pointer; }
.mode-item:hover { background: var(--chip); }
.mode-item[aria-selected="true"] { background: var(--felt); color: #fff; }
.mode-item[aria-selected="true"] .menu-hint { color: rgba(255,255,255,.8); }
.mode-item:disabled { opacity: .45; cursor: default; }
.menu-hint { font-size: .74rem; color: var(--muted); font-weight: 400; }
.acct-body { min-width: 260px; }
.acct-body input[type=text], .acct-body input[type=password] { border: 1px solid var(--line-strong); background: var(--chip); border-radius: 6px; padding: 7px 9px; font-size: .9rem; width: 100%; }
.acct-actions { display: flex; gap: 8px; }
.acct-actions .primary.small { border: 0; background: var(--felt); color: #fff; border-radius: 6px; padding: 6px 12px; font-size: .85rem; }
.acct-err { color: var(--loss); min-height: 1.2em; }
.acct-name { font-family: "Fraunces", Georgia, serif; font-size: 1.2rem; font-weight: 600; }
.acct-body label { display: flex; gap: 8px; align-items: center; font-size: .88rem; }
.acct-body input[type=checkbox] { width: 16px; height: 16px; accent-color: var(--felt); margin: 0; }
.menu-body { max-height: calc(100vh - 70px); overflow: auto; -webkit-overflow-scrolling: touch; }
.menu-body label.gated { opacity: .55; }
.acct-body { min-width: 280px; }
.acct-name { font-family: "Fraunces", Georgia, serif; font-size: 1.25rem; font-weight: 600; padding: 2px 4px 6px; }
.menu-list { display: grid; gap: 2px; margin: 0 -4px 6px; }
.menu-list .mode-item { text-decoration: none; }
.acct-opt { padding: 6px 4px 2px; border-top: 1px solid var(--line); margin-top: 4px; }
#acctSync { padding: 0 4px; }
@media (max-width: 600px) { .acct-body { position: fixed; left: 12px; right: 12px; top: 56px; } .menu-body { max-height: calc(100vh - 260px); overflow: auto; } }

.acct-ava { display: inline-grid; place-items: center; width: 20px; height: 20px; }
.acct-ava svg { width: 20px; height: 20px; }
.board-ava { display: inline-block; width: 18px; height: 18px; vertical-align: -4px; margin-right: 5px; }

/* in-app dialog */
.bj-modal { position: fixed; inset: 0; z-index: 200; display: grid; place-items: center; }
.bj-modal-back { position: absolute; inset: 0; background: rgba(0,0,0,.45); }
.bj-modal-box { position: relative; background: var(--surface); color: var(--ink); border: 1px solid var(--line-strong); border-radius: 14px; padding: 18px 20px; width: min(92vw, 420px); box-shadow: 0 12px 40px rgba(0,0,0,.35); }
.bj-modal-box h3 { margin: 0 0 8px; font-family: "Fraunces", Georgia, serif; font-size: 1.2rem; }
.bj-modal-box p { margin: 0 0 10px; color: var(--muted); font-size: .95rem; line-height: 1.5; }
.bj-modal-check { display: flex; gap: 8px; align-items: center; padding: 5px 0; font-size: .95rem; }
.bj-modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }
.bj-modal-cancel, .bj-modal-ok { border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink); border-radius: 8px; padding: 8px 14px; font: inherit; font-weight: 600; cursor: pointer; }
.bj-modal-box .bj-modal-ok { background: var(--felt); color: #fff !important; border-color: var(--felt); }
.bj-modal-box .bj-modal-ok.danger { background: var(--loss); color: #fff !important; border-color: var(--loss); }
.bj-modal-box .bj-modal-cancel { color: var(--ink) !important; }