/* The one typeface, Libre Franklin, is in web/src/fonts: the Latin subset of the variable
   font from Google Fonts (SIL Open Font License), so that the page and the iOS app need
   nothing from the network. The suit symbols aren't in it and come from the system's. */
@font-face {
  font-family: "Libre Franklin";
  src: url("fonts/libre-franklin.woff2") format("woff2");
  font-weight: 400 900;
  font-display: swap;
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

/* A card room: a green lamp over the dummies at the top, the deal on a felt table, and
   ivory panels on parchment. In dark mode the room goes dark (at the end of the file). */
:root {
  --bg: #efe6d3;
  --card: #fffaf0;
  --ink: #22201b;
  --muted: #6d675b;
  --line: #e2d5b9;
  --red: #c8102e;
  --black: #22201b;
  --accent: #1d5c3f;
  --vul: #c8102e;
  --felt: #1d5c3f;
  --felt-dark: #123d2a;
  --rail: #6b4226;
  --gold: #c9a24a;
  --gold-light: #ecca7a;
  --room: #0b1f15;
  --on-felt: #f7f0dc;
  --on-felt-muted: #d6ccb0;
  /* One typeface for everything: the headlines are Libre Franklin too, ExtraBold. */
  --display: "Libre Franklin", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --display-weight: 800;
  font-family: "Libre Franklin", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  /* Form controls stay light in either mode, like the ivory panels they sit on and
     next to: spades and clubs black and hearts and diamonds red, as on cards. */
  color-scheme: light;
}
* { box-sizing: border-box; }
/* The dark room shows when the page is pulled past either end, as the header and footer do. */
html { background: var(--room); }
body { margin: 0; background: var(--bg); color: var(--ink); overflow-x: clip; }
main { max-width: 980px; margin: 0 auto; padding: 0 16px; }
h2 { font-family: var(--display); font-weight: var(--display-weight); font-size: 1.4rem; margin: 0 0 8px; }

/* The header and footer run the window's full width, past main's sides, with their
   contents lined up with main's. */
.masthead, footer.site { margin-inline: calc(50% - 50vw); padding-inline: calc(50vw - 50%); }
/* A green lamp hangs over the dummies, its light falling in a cone over the title. */
.masthead {
  position: relative;
  text-align: center;
  padding-block: 80px 26px;
  margin-bottom: 24px;
  background:
    radial-gradient(ellipse 30% 70% at 50% 66px, rgba(255, 222, 150, 0.5) 0%, rgba(255, 222, 150, 0.16) 40%, transparent 70%),
    conic-gradient(from 150deg at 50% 66px, rgba(255, 226, 160, 0.17) 0deg 60deg, transparent 60deg),
    radial-gradient(ellipse 80% 100% at 50% 100%, var(--felt) 0%, #0e2a1d 70%), var(--room);
  border-bottom: 8px solid var(--rail);
  box-shadow: 0 2px 0 #4a2d18;
}
.masthead::before { content: ""; position: absolute; left: 50%; top: 0; width: 3px; height: 30px; margin-left: -1.5px; background: #1a1a1a; }
.masthead::after {
  content: ""; position: absolute; left: 50%; top: 28px; width: 190px; height: 38px; transform: translateX(-50%);
  background: linear-gradient(180deg, #2c7a55, #154a33); clip-path: polygon(22% 0, 78% 0, 100% 100%, 0 100%);
  border-bottom: 4px solid var(--gold);
}
/* The picture is 3:1 with a transparent background, so the dummies sit on the felt. */
.banner { display: block; width: 100%; max-width: 640px; height: auto; margin: 0 auto 12px; filter: drop-shadow(0 12px 16px rgba(0, 0, 0, 0.35)); }
.masthead h1 { margin: 0; font-family: var(--display); font-weight: var(--display-weight); font-size: clamp(2.3rem, 7vw, 3.4rem); line-height: 1; color: #f6e7c1; text-shadow: 0 0 24px rgba(255, 214, 140, 0.35); }
.masthead .suits { margin: 10px 0 0; padding-left: 0.4em; letter-spacing: 0.4em; font-size: 0.85rem; color: var(--gold); }
.masthead .sub { margin: 6px 0 0; font-size: 1.05rem; color: var(--on-felt-muted); }
.masthead .to-daily { display: inline-block; margin-top: 12px; padding: 6px 16px; border-radius: 999px; border: 1px solid color-mix(in srgb, var(--gold) 60%, transparent); color: var(--gold-light); font-weight: 600; text-decoration: none; }
.masthead .to-daily:hover, .masthead .to-daily:focus-visible { background: color-mix(in srgb, var(--gold) 18%, transparent); }

footer.site {
  margin-top: 44px;
  padding-block: 26px 30px;
  text-align: center;
  color: var(--on-felt-muted);
  background: radial-gradient(ellipse 80% 100% at 50% 0, var(--felt-dark) 0%, var(--room) 70%), var(--room);
  border-top: 8px solid var(--rail);
}
footer.site p { margin: 0; }
footer.site .made a { white-space: nowrap; font-family: var(--display); font-weight: var(--display-weight); font-size: 1.2rem; color: var(--gold-light); text-decoration: none; border-bottom: 1px solid color-mix(in srgb, var(--gold-light) 50%, transparent); }
footer.site .made a:hover, footer.site .made a:focus-visible { border-bottom-color: var(--gold-light); }
/* Where else to find it: X and Bluesky, quieter than the line above. */
footer.site .social { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px 20px; margin-top: 12px; font-size: 0.9rem; }
footer.site .social a { display: inline-flex; align-items: center; gap: 6px; color: var(--on-felt-muted); text-decoration: none; }
footer.site .social a:hover, footer.site .social a:focus-visible { color: var(--gold-light); }

.controls { display: grid; gap: 8px; margin-bottom: 16px; }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
input, select, button { font: inherit; padding: 6px 10px; border: 1px solid var(--line); border-radius: 10px; background: var(--card); color: var(--ink); }
button { cursor: pointer; padding: 7px 18px; border-radius: 999px; font-weight: 600; background: var(--accent); color: var(--on-felt); border-color: var(--felt-dark); }
button[type="button"] { background: var(--card); color: var(--ink); border-color: var(--line); }
button.primary { background: var(--accent); color: var(--on-felt); border-color: var(--felt-dark); }
input.pbn { flex: 1 1 200px; min-width: 0; font-family: ui-monospace, Menlo, monospace; font-size: 0.9rem; }
label { display: inline-flex; gap: 6px; align-items: center; color: var(--muted); }
/* Random deal at one end of its row, the seed and Deal at the other. */
.controls label.seed { margin-left: auto; }
/* A number, so right-aligned, with digits of one width. */
.controls label.seed input { text-align: right; font-variant-numeric: tabular-nums; }
:is(button, input, select, a):focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
/* Narrow enough that Random deal, the seed and Deal share a row on a phone. */
.controls input[inputmode="numeric"] { width: 6em; }
@media (max-width: 480px) { button { padding: 7px 14px; } }

.error { color: var(--red); background: var(--card); border: 1px solid var(--red); padding: 8px 12px; border-radius: 6px; }

/* The deal's side a little wider, for the felt table's rail around long hands in play. */
.board { display: grid; grid-template-columns: minmax(0, 1.55fr) minmax(0, 1fr); gap: 24px; align-items: start; }
@media (max-width: 720px) { .board { grid-template-columns: 1fr; } }

/* The deal on a felt table with a wooden rail, each hand on an ivory card. */
.diagram {
  background: radial-gradient(ellipse 70% 60% at 50% 50%, #2b7d57 0%, var(--felt) 55%, #164a33 100%);
  border: 10px solid var(--rail);
  border-radius: 48px;
  box-shadow: inset 0 0 0 2px #4a2d18, 0 10px 24px rgba(40, 25, 10, 0.25);
  padding: 20px 14px;
  overflow-x: auto;
}
/* A thinner rail where the deal has its own row, so long hands in play still leave the
   compass in the middle with West and East the same distance from it. */
@media (max-width: 720px) { .diagram { border-width: 8px; padding: 16px 10px; } }
/* A standard bridge diagram, centred in its card: West and East in columns of the
   same width (the wider hand's), right- and left-aligned against the compass, so
   the compass sits in the middle and both gaps match. The middle column is the
   compass's width; North and South, usually wider, stand centred over and under it
   and spill evenly into the columns either side. */
.dgrid {
  display: grid;
  grid-template-columns: minmax(8em, 1fr) 72px minmax(8em, 1fr);
  grid-template-rows: auto auto auto;
  width: max-content;
  margin: 0 auto;
  align-items: center;
  column-gap: 12px;
  row-gap: 14px;
}
.dgrid:has(.compass.playing) { grid-template-columns: minmax(8em, 1fr) 120px minmax(8em, 1fr); }
.pos0 { grid-column: 2; grid-row: 1; justify-self: unsafe center; width: max-content; }
.pos3 { grid-column: 1; grid-row: 2; justify-self: end; }
.pos1 { grid-column: 3; grid-row: 2; justify-self: start; }
.pos2 { grid-column: 2; grid-row: 3; justify-self: unsafe center; width: max-content; }
.compass {
  grid-column: 2; grid-row: 2;
  width: 72px; height: 72px; justify-self: center;
  display: grid; grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(3, 1fr);
  font-size: 0.8rem; color: var(--on-felt-muted);
  border: 2px solid rgba(247, 240, 220, 0.35); border-radius: 50%;
}
.compass span { display: flex; align-items: center; justify-content: center; }
.compass .c0 { grid-column: 2; grid-row: 1; }
.compass .c1 { grid-column: 3; grid-row: 2; }
.compass .c2 { grid-column: 2; grid-row: 3; }
.compass .c3 { grid-column: 1; grid-row: 2; }
.hand { min-width: 0; font-variant-numeric: tabular-nums; background: var(--card); border-radius: 10px; padding: 6px 8px 8px; box-shadow: 0 3px 8px rgba(0, 0, 0, 0.35); }
.who { display: flex; gap: 6px; align-items: baseline; margin-bottom: 2px; font-size: 0.85rem; color: var(--muted); }
.who .name.vul { color: var(--vul); font-weight: 600; }
.who .dealer { border: 1px solid var(--muted); border-radius: 3px; padding: 0 3px; font-size: 0.7rem; }
.who .hcp::before { content: "· "; }
.suit { display: flex; gap: 6px; line-height: 1.45; white-space: nowrap; }
.sym { width: 1em; text-align: center; }
.s0, .s3 { color: var(--black); }
.s4 { color: var(--ink); }
.s1, .s2 { color: var(--red); }
.ranks { letter-spacing: 0.02em; }

/* At phone width there is no room for the compass between West and East: they sit
   side by side under North, centred, and the compass (in play) goes below South. */
@media (max-width: 480px) {
  .diagram { padding: 14px 8px; border-width: 8px; border-radius: 32px; }
  .dgrid, .dgrid:has(.compass.playing) { grid-template-columns: auto auto; column-gap: 20px; }
  .pos0 { grid-column: 1 / span 2; grid-row: 1; justify-self: center; }
  .pos3 { grid-column: 1; grid-row: 2; justify-self: end; }
  .pos1 { grid-column: 2; grid-row: 2; justify-self: start; }
  .pos2 { grid-column: 1 / span 2; grid-row: 3; justify-self: center; }
  .compass { display: none; }
}

.analysis { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 14px; box-shadow: 0 8px 22px rgba(70, 50, 20, 0.08); }
.analysis h2 { text-align: center; }
/* An instruction, not a button: green words under the heading and nothing around them. */
.cta { margin: -2px 0 10px; text-align: center; font-size: 0.92rem; font-weight: 600; color: var(--felt); }
table.dd { border-collapse: collapse; font-variant-numeric: tabular-nums; width: 100%; max-width: 360px; margin-inline: auto; }
table.dd th, table.dd td { padding: 6px 8px; text-align: center; border-bottom: 1px solid var(--line); }
table.dd thead th { font-size: 1.1rem; }
table.dd tbody th { color: var(--muted); font-weight: 600; text-align: left; }
table.dd td { font-size: 1.15rem; }
table.dd td.make { font-weight: 700; }
table.dd td.wait { color: var(--muted); }
/* The reels while a strain is solved, and the number landing when it locks in. */
table.dd td.wait .spin { display: inline-block; min-width: 1.4em; padding: 4px 0; opacity: 0.55; filter: blur(0.4px); }
@keyframes land { from { transform: scale(1.35); color: var(--gold); } to { transform: none; } }
table.dd td button.cell { animation: land 0.32s ease-out; }
@media (prefers-reduced-motion: reduce) { table.dd td button.cell { animation: none; } }
.par { margin: 12px 0 4px; }
.meta { color: var(--muted); font-size: 0.85rem; margin: 4px 0; }
.wait { color: var(--muted); }
/* Par, the solve time and the copy button centred, under the centred table. */
.analysis .par, .analysis .meta, .pbn-out { text-align: center; }
.pbn-out { margin: 12px 0 0; display: grid; gap: 6px; }
.pbn-out .row { justify-content: center; }
.blurlink { justify-content: center; font-size: 0.8rem; }
/* A puzzle link's table and par, blurred until the reader asks to see them. */
table.dd.blurred td, table.dd.blurred td.make { filter: blur(7px); font-weight: 400; }
.par.blurred strong { filter: blur(6px); }
.unblur { margin: 12px 0 0; text-align: center; }
.pbn-out button { display: inline-flex; align-items: center; justify-content: center; gap: 6px; font-size: 0.82rem; padding: 5px 14px 5px 11px; }
/* A copy button's states, icon and label each, in one cell: one shows, centred. */
.states { display: inline-grid; }
.states > .state { grid-area: 1 / 1; display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
.states > .off { visibility: hidden; }
code { font-family: ui-monospace, Menlo, monospace; white-space: nowrap; }

/* ---- Play ---- */
.left { display: grid; gap: 12px; min-width: 0; }
.rank { margin-right: 0.28em; }
.rank.gone { opacity: 0.3; text-decoration: line-through; }
/* The same weight for every seat's name, so the player to move's hand doesn't widen. */
.who .name { font-weight: 600; }
.hand.mover .who .name { color: var(--accent); }
.hand.hidden .unseen { color: var(--muted); font-style: italic; padding: 8px 0; }
/* In play every hand sets each card in a slot of the same make, with room at the
   bottom for declarer's tricks, and the same gap between any two cards, in a group or
   not. Only the player to move fills that room and has buttons, so a hand keeps its
   size when its turn comes and goes. A group's shading and its label take no space. */
.suit.play { align-items: flex-start; }
.suit.play .sym { padding-top: 1px; }
.suit.play .ranks { display: inline-flex; gap: 2px; }
.slot { display: inline-block; min-width: 1.05em; padding: 1px 0.12em calc(0.8rem + 2px); line-height: 1.3; text-align: center; border-radius: 5px; }
.slot.gone { opacity: 0.3; text-decoration: line-through; }
.group { position: relative; display: inline-flex; gap: 2px; border-radius: 6px; background: color-mix(in srgb, var(--ink) 6%, transparent); box-shadow: inset 0 0 0 1px var(--line); }
.group.best { background: color-mix(in srgb, var(--accent) 14%, transparent); box-shadow: inset 0 0 0 1px var(--accent); }
button.card { font-family: inherit; font-size: 1rem; font-weight: inherit; line-height: 1.3; letter-spacing: inherit; color: var(--ink); background: transparent; border: 0; }
button.card:hover, button.card:focus-visible { box-shadow: inset 0 0 0 1.5px var(--ink); }
.group .val { position: absolute; left: 0; right: 0; bottom: 2px; font-size: 0.68rem; line-height: 0.8rem; text-align: center; color: var(--muted); pointer-events: none; }
.group.best .val { color: var(--accent); font-weight: 700; }
.group .cost { color: var(--red); margin-left: 3px; font-weight: 700; }
.compass.playing { width: 120px; height: 120px; position: relative; }
.compass.playing span.played b { font-size: 1rem; padding: 1px 4px; border-radius: 4px; background: var(--card); box-shadow: 0 1px 2px rgba(0, 0, 0, 0.45); }
.compass .last { opacity: 0.45; }
.compass .turn { color: var(--gold-light); font-weight: 700; }
.compass .mid { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 0.65rem; color: var(--on-felt-muted); pointer-events: none; }
@media (max-width: 480px) {
  .slot { min-width: 1em; padding-inline: 0.08em; }
  .compass.playing { display: grid; grid-column: 1 / span 2; grid-row: 4; justify-self: center; }
}
table.dd td { padding: 2px; }
button.cell { width: 100%; padding: 4px 0; font-size: 1.15rem; background: transparent; color: inherit; border: 1px solid transparent; font-weight: inherit; }
button.cell:hover { border-color: color-mix(in srgb, var(--felt) 35%, transparent); background: color-mix(in srgb, var(--felt) 8%, transparent); }
td.chosen button.cell { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 15%, transparent); }
.hint { color: var(--muted); font-size: 0.85rem; }
.tabs { display: flex; gap: 4px; }
.tabs button { background: var(--card); color: var(--muted); border-color: var(--line); }
.tabs button.on { background: var(--accent); color: var(--on-felt); border-color: var(--felt-dark); }
.pane { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 14px; display: grid; gap: 8px; box-shadow: 0 8px 22px rgba(70, 50, 20, 0.08); }
.pane select { margin-left: 8px; padding: 2px 6px; }
.row.between { justify-content: space-between; }
.status { margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 0.8rem; margin: 0; }
button:disabled { opacity: 0.45; cursor: default; }
/* The cards in the order played, in four narrow columns of the same width, numbered. */
ol.tricks { margin: 0; padding: 0; list-style: none; font-size: 0.85rem; columns: 2; column-gap: 24px; counter-reset: trick; font-variant-numeric: tabular-nums; }
ol.tricks li { display: grid; grid-template-columns: 1.6em repeat(4, 3.7em); align-items: center; gap: 2px; min-height: 24px; break-inside: avoid; counter-increment: trick; }
ol.tricks li::before { content: counter(trick) "."; color: var(--muted); }
ol.tricks li span { justify-self: start; padding: 0 5px; white-space: nowrap; }
/* The trick's winning card: a gold outline. */
ol.tricks li span.won { box-shadow: inset 0 0 0 1.5px var(--gold); border-radius: 7px; }
@media (max-width: 420px) { ol.tricks { columns: 1; } }

/* ---- Simulate ---- */
.rules { display: grid; gap: 6px; }
.rule select, .rule input { padding: 4px 6px; margin: 0; }
.progress { height: 6px; background: var(--line); border-radius: 3px; overflow: hidden; }
.progress div { height: 100%; background: var(--accent); }
.stats { margin: 6px 0; font-size: 0.9rem; }
table.simrows { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; }
table.simrows th, table.simrows td { padding: 3px 6px; text-align: left; border-bottom: 1px solid var(--line); }
table.simrows thead th { font-size: 0.75rem; color: var(--muted); font-weight: 600; }
table.simrows td.num { text-align: right; width: 4.5em; }
table.simrows td.bar { width: 30%; }
table.simrows td.bar div { height: 10px; background: var(--accent); border-radius: 2px; }
table.simrows td.bar.makes div { background: #b08a2e; }
button.stop { background: var(--red); border-color: var(--red); }

.secret p { font-size: 0.9rem; }
button.reveal { background: var(--card); color: var(--ink); border-color: var(--line); margin-top: 8px; }

details.meta summary { cursor: pointer; list-style: none; }
details.meta summary::-webkit-details-marker { display: none; }
details.meta .more { text-decoration: underline; font-size: 0.8rem; margin-left: 4px; }
details.meta[open] .more { display: none; }
details.meta .times { margin: 4px 0 0; }

/* ---- Dark mode: the room after dark ---- */
/* The page goes dark brown and the lamp's light spills over the felt. The panels and
   the hands stay ivory, so the cards' colours are the same in both modes. */
@media (prefers-color-scheme: dark) {
  :root { --bg: #2a1f17; }
  body { background: radial-gradient(ellipse 60% 600px at 50% 380px, rgba(255, 214, 140, 0.09), transparent 70%), var(--bg); }
  .controls label { color: #d8c8a8; }
  .controls button[type="button"]:not(.primary), .tabs button { border-color: transparent; }
  .diagram {
    background: radial-gradient(ellipse 55% 45% at 50% 42%, rgba(255, 220, 150, 0.24), transparent 70%),
      radial-gradient(ellipse 70% 60% at 50% 50%, #2b7d57 0%, var(--felt) 55%, #164a33 100%);
    box-shadow: inset 0 0 0 2px #4a2d18, 0 18px 40px rgba(0, 0, 0, 0.5);
  }
  .analysis, .pane { border-color: transparent; box-shadow: 0 18px 40px rgba(0, 0, 0, 0.45); }
}
