/* Layout: a painted porch. White clapboard header, a haint-blue beadboard table that holds the game, ad space kept to the edges, the how-to guide below. */
:root {
  --paint: #eef1ec;          /* porch-white page */
  --paint-2: #e2e8e3;        /* trim, panels */
  --ink: #1c2a33;            /* text */
  --muted: #56666b;
  --line: #c5cfca;
  --haint: #8cbfb8;          /* haint-blue table */
  --haint-deep: #6fa69f;     /* slots, board seams */
  --haint-ink: #2f5d58;      /* text on the table */
  --lantern: #c27512;        /* accent: porch-lantern amber */
  --lantern-ink: #ffffff;
  --card: #fbfaf6;
  --card-edge: #c9cfc9;
  --card-red: #b42d25;
  --card-black: #18222c;
  --back: #2c4c66;
  --back-line: #6d93ad;
  --shadow: rgba(18, 38, 44, .28);
  --ad: rgba(28, 42, 51, .045);

  --f-display: "Young Serif", "Georgia", "Times New Roman", serif;
  --f-body: "Atkinson Hyperlegible", "Verdana", "Segoe UI", system-ui, sans-serif;

  --step-0: 1.0625rem;
  --step-1: 1.25rem;
  --step-2: 1.6rem;
  --step-3: 2.3rem;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paint: #121b20; --paint-2: #1a262c; --ink: #e5ece8; --muted: #9eb0ae; --line: #2f3f45;
    --haint: #1f4846; --haint-deep: #2a5b58; --haint-ink: #a9d4cd;
    --lantern: #eaa23c; --lantern-ink: #1a1408;
    --card: #f1eee6; --card-edge: #0d1518; --shadow: rgba(0,0,0,.5); --ad: rgba(229,236,232,.05);
    --back: #24435b; --back-line: #5b84a0;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paint: #121b20; --paint-2: #1a262c; --ink: #e5ece8; --muted: #9eb0ae; --line: #2f3f45;
  --haint: #1f4846; --haint-deep: #2a5b58; --haint-ink: #a9d4cd;
  --lantern: #eaa23c; --lantern-ink: #1a1408;
  --card: #f1eee6; --card-edge: #0d1518; --shadow: rgba(0,0,0,.5); --ad: rgba(229,236,232,.05);
  --back: #24435b; --back-line: #5b84a0;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; }
img, svg { max-width: 100%; }
:root { padding-top: env(safe-area-inset-top, 0px); }
html, body { overflow-x: hidden; }
body {
  background: var(--paint); color: var(--ink);
  font-family: var(--f-body); font-size: var(--step-0); line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
.wrap {
  max-width: 1320px; margin: 0 auto;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
}
button { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--lantern); outline-offset: 2px; }

/* Header: clapboard siding */
.site {
  background:
    repeating-linear-gradient(180deg, transparent 0 13px, var(--line) 13px 14px),
    var(--paint-2);
  border-bottom: 1px solid var(--line);
}
.site .wrap { display: flex; align-items: center; justify-content: space-between; gap: 12px 24px; flex-wrap: wrap; padding-block: 12px; }
.brand { display: flex; align-items: baseline; gap: 10px; text-decoration: none; color: var(--ink); background: var(--paint-2); padding: 2px 8px 2px 0; }
.brand b { font-family: var(--f-display); font-weight: 400; font-size: 1.55rem; letter-spacing: .005em; line-height: 1.1; }
.brand b span { color: var(--lantern); }
.brand small { color: var(--muted); font-size: .9rem; }
.games { display: flex; gap: 6px; flex-wrap: wrap; list-style: none; margin: 0; padding: 0; }
.games li { display: flex; }
.games a, .games span {
  display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: 999px;
  font-size: .95rem; text-decoration: none; color: var(--ink); background: var(--paint); border: 1px solid var(--line);
}
.games a[aria-current="page"] { background: var(--ink); color: var(--paint); border-color: var(--ink); }
.games span { color: var(--muted); }
.games em { font-style: normal; font-size: .72rem; letter-spacing: .06em; text-transform: uppercase; }
@media (max-width: 700px) {
  .site .wrap { padding-block: 8px; gap: 8px; }
  .brand small { display: none; }
  .brand b { font-size: 1.35rem; }
  .site nav { width: 100%; overflow-x: auto; scrollbar-width: none; }
  .games { flex-wrap: nowrap; }
  .games a, .games span { white-space: nowrap; padding: 4px 10px; font-size: .9rem; }
}

/* Play area */
.play { display: grid; grid-template-columns: minmax(0, 1fr); gap: 20px; padding-block: 16px; }
.rail { display: none; }
@media (min-width: 1100px) {
  .play { grid-template-columns: minmax(0, 1fr) 300px; }
  .rail { display: block; }
}
.game { min-width: 0; display: grid; gap: 12px; }
.play.solo { grid-template-columns: minmax(0, 1fr); }
.play.solo .game { width: 100%; max-width: 1040px; margin: 0 auto; }

.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.tb {
  display: inline-flex; align-items: center; gap: 7px; min-height: 44px; padding: 0 14px;
  border-radius: 10px; border: 1px solid var(--line); background: var(--paint-2); cursor: pointer;
  font-size: 1rem; font-weight: 700;
}
.tb:hover { border-color: var(--haint-deep); }
.tb svg { width: 20px; height: 20px; flex: none; }
.tb.primary { background: var(--lantern); color: var(--lantern-ink); border-color: var(--lantern); }
.tb[disabled] { opacity: .45; cursor: default; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.seg button { min-height: 44px; padding: 0 12px; border: 0; background: var(--paint-2); cursor: pointer; font-weight: 700; font-size: .95rem; }
.seg button + button { border-left: 1px solid var(--line); }
.seg button[aria-pressed="true"] { background: var(--ink); color: var(--paint); }
.hud { margin-left: auto; display: flex; gap: 16px; font-variant-numeric: tabular-nums; color: var(--muted); font-size: .98rem; }
.hud b { color: var(--ink); }
@media (max-width: 640px) {
  .tb { padding: 0 10px; font-size: .92rem; }
  .tb .lbl-long { display: none; }
  .hud { margin-left: 0; width: 100%; justify-content: space-between; order: -1; }
}

/* The table: haint-blue beadboard */
.table {
  position: relative; border-radius: 16px; padding: clamp(10px, 1.6vw, 20px);
  background:
    repeating-linear-gradient(90deg, transparent 0 calc(14.2857% - 1px), color-mix(in srgb, var(--haint-deep) 45%, transparent) calc(14.2857% - 1px) 14.2857%),
    radial-gradient(120% 90% at 50% 0%, color-mix(in srgb, #ffffff 14%, var(--haint)) 0%, var(--haint) 60%);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--haint-deep) 70%, transparent), inset 0 10px 30px -18px var(--shadow);
}
#board { position: relative; width: 100%; user-select: none; -webkit-user-select: none; }
.slot {
  position: absolute; left: 0; top: 0; width: var(--cw); height: var(--ch);
  border-radius: calc(var(--cw) * .08);
  border: 2px solid color-mix(in srgb, var(--haint-ink) 35%, transparent);
  background: color-mix(in srgb, var(--haint-deep) 40%, transparent);
  display: grid; place-items: center; color: color-mix(in srgb, var(--haint-ink) 70%, transparent);
  font-family: var(--f-display); font-size: calc(var(--cw) * .42); line-height: 1;
}
.slot.stock { cursor: pointer; }
.slot.stock svg { width: 42%; height: 42%; }
.slot.hint, .card.hint { box-shadow: 0 0 0 4px var(--lantern), 0 0 18px 2px var(--lantern) !important; }

.card {
  position: absolute; left: 0; top: 0; width: var(--cw); height: var(--ch);
  border-radius: calc(var(--cw) * .08); background: var(--card);
  box-shadow: 0 0 0 1px var(--card-edge), 0 1px 3px var(--shadow);
  transition: transform .22s cubic-bezier(.2,.8,.25,1);
  touch-action: none; cursor: pointer; will-change: transform;
  font-family: var(--f-body);
}
.card.red { color: var(--card-red); }
.card.black { color: var(--card-black); }
.card .face { position: absolute; inset: 0; overflow: hidden; border-radius: inherit; }
.card .ix {
  position: absolute; top: calc(var(--cw) * .04); left: calc(var(--cw) * .07); right: calc(var(--cw) * .07);
  display: flex; justify-content: space-between; align-items: baseline;
  font-weight: 700; font-size: calc(var(--cw) * .31); line-height: 1; letter-spacing: -.03em;
}
.card .ix i { font-style: normal; font-size: .92em; }
.card .pip { position: absolute; left: 0; right: 0; bottom: 8%; text-align: center; font-size: calc(var(--cw) * .62); line-height: 1; }
.card .court {
  position: absolute; left: 0; right: 0; bottom: 9%; text-align: center; line-height: 1;
  font-family: var(--f-display); font-size: calc(var(--cw) * .56);
}
.card .court i { font-style: normal; font-family: var(--f-body); font-size: .5em; vertical-align: .55em; margin-left: .06em; }
.card .back {
  position: absolute; inset: 0; border-radius: inherit; border: calc(var(--cw) * .055) solid var(--card);
  background:
    repeating-linear-gradient(45deg, transparent 0 7px, var(--back-line) 7px 9px),
    repeating-linear-gradient(-45deg, transparent 0 7px, var(--back-line) 7px 9px),
    var(--back);
}
.card.up .back, .card:not(.up) .face { display: none; }
.card:not(.up) { cursor: default; }
.card.drag { transition: none; box-shadow: 0 0 0 1px var(--card-edge), 0 14px 28px var(--shadow); cursor: grabbing; }
.card.shake { animation: shake .32s; }
@keyframes shake { 20% { translate: -6px 0; } 40% { translate: 6px 0; } 60% { translate: -4px 0; } 80% { translate: 3px 0; } }
#board.notrans .card { transition: none; }

.below { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 6px 16px; color: var(--muted); font-size: .95rem; font-variant-numeric: tabular-nums; }
.below b { color: var(--ink); }

/* Win panel */
.win {
  position: absolute; inset: 0; display: grid; place-items: center; padding: 16px; z-index: 2000;
  background: color-mix(in srgb, var(--haint) 55%, transparent); border-radius: 16px;
}
.win .panel {
  background: var(--paint); color: var(--ink); border-radius: 14px; padding: 26px 28px; max-width: 360px; width: 100%;
  text-align: center; box-shadow: 0 20px 50px var(--shadow); display: grid; gap: 10px;
}
.win h2 { font-family: var(--f-display); font-weight: 400; font-size: var(--step-3); margin: 0; line-height: 1.1; }
.win p { margin: 0; color: var(--muted); font-variant-numeric: tabular-nums; }
.win .tb { justify-content: center; margin-top: 8px; }
#fx { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 1500; }

.toast {
  position: fixed; left: 50%; bottom: calc(84px + env(safe-area-inset-bottom, 0px)); translate: -50% 0; z-index: 3000;
  background: var(--ink); color: var(--paint); padding: 10px 16px; border-radius: 10px; font-size: .98rem;
  max-width: calc(100% - 32px); text-align: center; box-shadow: 0 8px 20px var(--shadow);
}

/* Reserved ad space (prototype placeholders) */
.ad {
  display: grid; place-items: center; text-align: center; color: var(--muted); font-size: .78rem;
  letter-spacing: .08em; text-transform: uppercase; background: var(--ad);
  border: 1px dashed var(--line); border-radius: 8px;
}
.ad-sky { width: 300px; height: 600px; position: sticky; top: 16px; }
.ad-leader { width: 100%; max-width: 728px; height: 90px; margin: 4px auto 0; }
.ad-anchor { display: none; }
@media (max-width: 700px) {
  .ad-leader { display: none; }
  .ad-anchor {
    display: grid; position: fixed; left: 0; right: 0; bottom: 0; z-index: 1000; height: calc(56px + env(safe-area-inset-bottom, 0px));
    padding-bottom: env(safe-area-inset-bottom, 0px); border-radius: 0; border: 0; border-top: 1px solid var(--line);
    background: var(--paint-2);
  }
  body { padding-bottom: 64px; }
}

/* Guide */
.guide { display: grid; grid-template-columns: minmax(0, 1fr); gap: 32px; padding-block: 28px 56px; border-top: 1px solid var(--line); }
@media (min-width: 900px) { .guide { grid-template-columns: minmax(0, 1fr) 320px; } }
.guide article { max-width: 68ch; min-width: 0; }
.guide h1 { font-family: var(--f-display); font-weight: 400; font-size: var(--step-3); line-height: 1.12; margin: 0 0 12px; text-wrap: balance; }
.guide h2 { font-family: var(--f-display); font-weight: 400; font-size: var(--step-2); line-height: 1.2; margin: 32px 0 10px; text-wrap: balance; }
.guide p, .guide li { color: var(--ink); }
.guide a, .page a { color: var(--ink); text-decoration-color: var(--lantern); text-decoration-thickness: 2px; text-underline-offset: 3px; }
.guide table { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; }
.guide th, .guide td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
.guide th { font-size: .85rem; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.table-scroll { overflow-x: auto; }
.more a { color: var(--ink); font-weight: 700; }
.page { max-width: 72ch; padding-block: 32px 64px; }
.page h1 { font-family: var(--f-display); font-weight: 400; font-size: var(--step-3); line-height: 1.12; margin: 0 0 16px; }
.page h2 { font-family: var(--f-display); font-weight: 400; font-size: var(--step-2); margin: 28px 0 8px; }
.page .muted { color: var(--muted); }
.guide ol, .guide ul { padding-left: 1.3em; display: grid; gap: 8px; }
.guide .lede { font-size: var(--step-1); color: var(--muted); }
.side { display: grid; gap: 16px; align-content: start; }
.box { background: var(--paint-2); border: 1px solid var(--line); border-radius: 12px; padding: 18px 20px; }
.box h3 { margin: 0 0 10px; font-size: .8rem; letter-spacing: .09em; text-transform: uppercase; color: var(--muted); }
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 0; }
.stats div { display: grid; }
.stats dt { color: var(--muted); font-size: .88rem; }
.stats dd { margin: 0; font-family: var(--f-display); font-size: 1.6rem; font-variant-numeric: tabular-nums; line-height: 1.2; }
.more { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.more li { display: flex; justify-content: space-between; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.more li:last-child { border-bottom: 0; }
.more span { color: var(--muted); font-size: .9rem; }
kbd { font-family: var(--f-body); font-size: .85em; padding: 1px 6px; border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 5px; background: var(--paint); }

footer { border-top: 1px solid var(--line); color: var(--muted); font-size: .92rem; }
footer .wrap { display: flex; flex-wrap: wrap; gap: 8px 20px; justify-content: space-between; padding-block: 20px; }
footer nav { display: flex; gap: 16px; flex-wrap: wrap; }
footer a { color: var(--muted); }

@media (prefers-reduced-motion: reduce) {
  .card { transition: none; }
  .card.shake { animation: none; }
}
