:root {
  --bg: #f5f4f1; --panel: #fff; --text: #1f2328; --muted: #5f6670; --line: #d9d6cf;
  --accent: #14655a; --right: #1c7c43; --wrong: #b3261e;
  --tile: #fffaf0; --tile-text: #1f2328;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #16181b; --panel: #212429; --text: #e8e8e6; --muted: #a2a8b0; --line: #3a3f46;
    --accent: #4fb8a6; --right: #5ccf87; --wrong: #ff8a80; }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); line-height: 1.7;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif; }
:lang(ja) { font-family: system-ui, -apple-system, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Yu Gothic UI", "Meiryo", sans-serif;
  line-break: strict; word-break: auto-phrase; }
header, main { max-width: 760px; margin: 0 auto; padding: 0 16px; }
header { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
h1 { font-size: 1.3rem; } h2 { font-size: 1.15rem; } h3 { font-size: 1rem; margin-bottom: 4px; }
h4 { font-size: .85rem; color: var(--muted); margin: 12px 0 4px; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 16px; margin-bottom: 16px; }
button { font: inherit; color: inherit; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 6px 14px; cursor: pointer; }
button:disabled { cursor: default; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
fieldset { border: 0; padding: 0; margin: 0 0 8px; display: flex; flex-wrap: wrap; gap: 8px; }
legend { font-size: .85rem; color: var(--muted); margin-bottom: 4px; }
.chip { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); border-radius: 999px; padding: 4px 12px; cursor: pointer; }
.chip:has(input:checked) { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
input { accent-color: var(--accent); }
.help { color: var(--muted); font-size: .85rem; margin: 4px 0; }
.theme { color: var(--accent); font-weight: 600; margin-top: 0; }
.warning { color: var(--wrong); }
.scoreboard, .figures { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }
.scoreboard div { border: 1px solid var(--line); border-radius: 8px; padding: 2px 4px; text-align: center; line-height: 1.4; }
.scoreboard div.you { border: 2px solid var(--accent); }
.scoreboard span { display: block; font-size: .75rem; color: var(--muted); }
.conditions { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 8px; }
.conditions div { background: var(--bg); border-radius: 8px; padding: 8px 12px; }
dt { font-size: .8rem; color: var(--muted); } dd { margin: 0; }
.conditions dd { font-size: 1.1rem; font-weight: 600; }
.answers { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.answer { font-size: 1.15rem; font-weight: 600; padding: 14px; }
.answer.right { border-color: var(--right); box-shadow: inset 0 0 0 2px var(--right); }
.answer.wrong { border-color: var(--wrong); box-shadow: inset 0 0 0 2px var(--wrong); }
kbd { font-size: .75rem; color: var(--muted); border: 1px solid var(--line); border-radius: 4px; padding: 0 5px; margin-right: 8px; }
.verdict { font-size: 1.4rem; font-weight: 700; margin-bottom: 0; }
.verdict.right { color: var(--right); } .verdict.wrong { color: var(--wrong); }
.summary { font-size: 1.1rem; font-weight: 600; margin-top: 0; }
.explain dt { margin-top: 10px; font-weight: 600; }
.next { background: var(--accent); border-color: var(--accent); color: var(--panel); font-weight: 600; width: 100%; padding: 12px; margin-top: 16px; }
/* Grade colours follow the book's legend. */
.grade-A { --cell: #e17b8c; } .grade-B { --cell: #eaa97c; } .grade-C { --cell: #fbf6a6; }
.grade-D { --cell: #b4d286; } .grade-E { --cell: #82c8d6; } .grade-F { --cell: #7b9fd0; }
.swatch { display: inline-block; background: var(--cell); color: #111; border-radius: 4px; padding: 0 8px; margin-right: 6px; }
.compare ul { list-style: none; padding: 2px; margin: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.compare li { background: var(--cell); color: #111; border-radius: 6px; padding: 4px 10px; font-size: .8rem; display: flex; flex-direction: column; flex: 1 1 135px; }
.compare li strong { font-size: .95rem; font-variant-numeric: tabular-nums; }
.compare li.current { outline: 3px solid var(--text); outline-offset: -1px; }
.figures { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.figures dd { font-size: 1.3rem; font-weight: 700; }
.weak { padding-left: 0; list-style: none; }
.weak li { display: grid; grid-template-columns: 1fr auto auto; align-items: center; gap: 8px; border-bottom: 1px solid var(--line); padding: 4px 0; font-size: .9rem; }
.weak strong { white-space: nowrap; }
.reset, .small { font-size: .85rem; }
.reset { margin-top: 16px; }
/* Theme picker. */
details > summary { cursor: pointer; padding: 8px 0; min-height: 44px; }
.picker { margin-bottom: 8px; border-bottom: 1px solid var(--line); }
.picker > summary { font-weight: 600; }
.group { border-top: 1px solid var(--line); }
.group ul, .tips ul { list-style: none; padding: 0; margin: 0; }
.group > ul > li { padding: 8px 0 8px 8px; }
.only { margin-top: 8px; }
.theme-name { margin: 0 0 4px; font-size: .9rem; } .theme-name span { color: var(--accent); font-weight: 600; margin-right: 4px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.tips li { padding: 6px 0; font-size: .9rem; } .tips small { display: block; color: var(--muted); }
.tips > summary { color: var(--accent); font-size: .85rem; }

/* Advice shown after an answer. */
.advice ul { list-style: none; padding: 0; margin: 0; }
.advice li { border-left: 3px solid var(--accent); padding: 2px 0 2px 12px; margin-bottom: 12px; }
.advice li.exception { border-left-style: dashed; }
.advice p { margin: 0; } .advice li > p:first-child { font-weight: 600; }
.advice .note, .advice small { font-size: .85rem; } .advice small { color: var(--muted); }

/* Tiles: a face image over the tile body (tiles/SOURCE.md). Suits wrap as
   groups on narrow screens, and one long suit shrinks to fit. */
.hand { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; }
.suit-group { display: flex; gap: 1px; max-width: 100%; }
.tile { position: relative; display: inline-block; flex: 0 1 40px; min-width: 0; width: 34px; aspect-ratio: 3 / 4;
  background: url("tiles/Front.svg") center / 100% 100% no-repeat; filter: drop-shadow(0 1px 1px rgb(0 0 0 / .35)); }
.tile img { position: absolute; inset: 6% 6%; width: 88%; height: 88%; }
.tile.labelled img { inset: 2% 12% auto; width: 76%; height: 76%; }
.tile small { position: absolute; inset: auto 0 3%; color: var(--tile-text); font-size: .65rem; font-weight: 700;
  line-height: 1; text-align: center; }
@media (prefers-color-scheme: dark) { .tile { filter: brightness(.9); } }
.tiles { display: inline-flex; gap: 2px; }
.conditions dd .tile { flex: none; margin-top: 2px; }
.discards { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; margin: 8px 0; }
.reading ul { list-style: none; padding: 0; }
.reading li { display: flex; gap: 12px; align-items: flex-start; border-top: 1px solid var(--line); padding: 8px 0; }
.reading li .tile { flex: none; }
footer { max-width: 760px; margin: 0 auto 24px; padding: 0 16px; font-size: .75rem; color: var(--muted); }
footer a { color: var(--accent); }
.reading li dl { display: grid; grid-template-columns: auto 1fr; gap: 2px 12px; margin: 0; }
.reading li dt { font-size: .85rem; }
@media (max-width: 380px) { header, main { padding: 0 8px; } .panel { padding: 16px 8px; } }

/* Training layout. */
.panel.drawer-panel { padding-top: 0; padding-bottom: 0; }
.drawer > summary { font-size: .9rem; font-weight: 600; padding: 8px 0; }
.drawer[open] { padding-bottom: 12px; }
.premise { font-size: .85rem; color: var(--muted); margin: 0 0 8px; line-height: 1.5; }
.theme { margin-bottom: 4px; line-height: 1.5; }
.strip { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 8px; }
.strip > div { display: flex; flex-wrap: wrap; align-items: baseline; column-gap: 6px; background: var(--bg); border-radius: 8px; padding: 2px 10px; }
.strip dt { font-size: .75rem; } .strip dd { font-weight: 700; }
.strip .tile { width: 28px; flex: none; align-self: center; margin: 2px 0; }
.situation .help { margin: 0 0 4px; }
.hand-title { margin: 4px 0; font-size: .85rem; }
#quiz h2 { grid-column: 1 / -1; margin: 4px 0 0; }
.answers { position: relative; }
.timer { grid-column: 1 / -1; height: 4px; background: var(--line); border-radius: 2px; overflow: hidden; }
.timer span { display: block; height: 100%; background: var(--accent); transform-origin: left; animation: drain linear forwards; }
.paused .timer span { animation-play-state: paused; }
@keyframes drain { from { transform: scaleX(1); } to { transform: scaleX(0); } }
@media (prefers-reduced-motion: reduce) { .timer span { animation-timing-function: steps(15); } }
.answer.near { border-style: dashed; border-color: var(--text); }
.verdict.near { color: var(--text); }
.loss { font-weight: 600; margin: 0; }
.next { margin-top: 8px; }
.focus { display: flex; align-items: center; justify-content: space-between; gap: 8px; border-left: 3px solid var(--accent); padding-left: 8px; font-size: .85rem; }
.compare li.flip { background: none; color: var(--accent); flex: 0 0 100%; padding: 0; font-weight: 700; text-align: center; border-top: 2px dashed var(--accent); border-radius: 0; }
.detailsOpen, .moreOpen { border-top: 1px solid var(--line); margin-top: 8px; }
.source { border-top: 1px solid var(--line); margin-top: 12px; padding-top: 8px; }
.flag-form { display: flex; gap: 8px; } .flag-form input { flex: 1; font: inherit; min-width: 0; }
.flags ul { list-style: none; padding: 0; } .flags li { display: flex; justify-content: space-between; gap: 8px; font-size: .8rem; overflow-wrap: anywhere; }
textarea { width: 100%; font: inherit; font-size: .8rem; }
.session { border-top: 1px solid var(--line); margin-top: 12px; }
.trend { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 8px; list-style: none; padding: 0; }
.trend li { display: flex; flex-direction: column; align-items: center; }
.trend .bar { width: 24px; background: var(--accent); border-radius: 3px 3px 0 0; }
.trend small { font-size: .7rem; color: var(--muted); }
@media (min-width: 375px) {
  .hand { flex-wrap: nowrap; gap: 4px; }
  .suit-group { min-width: 0; flex: 0 1 auto; }
}
@media (max-width: 599px) {
  header h1 { font-size: 1rem; margin: 8px 0; }
  header button { padding: 2px 10px; }
  .panel { margin-bottom: 8px; }
  #quiz.panel { padding-top: 8px; }
  body.has-bar { padding-bottom: calc(150px + env(safe-area-inset-bottom)); }
  .answers.pending, .actions { position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; background: var(--panel);
    border-top: 1px solid var(--line); padding: 8px 12px calc(8px + env(safe-area-inset-bottom)); }
  .answers.pending { gap: 8px; } .answers.pending .answer { padding: 10px; line-height: 1.3; }
  .next { margin: 0; }
  .keys { display: none; }
  #quiz .answers.pending h2 { margin: 0; font-size: .95rem; line-height: 1.4; }
  .answers:not(.pending) h2 { margin-top: 8px; }
  .scoreboard strong { font-size: .8rem; white-space: nowrap; }
  .weak li { grid-template-columns: 1fr auto; } .weak li span { grid-column: 1 / -1; }
}
/* The narrowest phones: keep the whole situation above the answer bar. */
@media (max-width: 374px) {
  .scoreboard { gap: 3px; } .scoreboard div { padding: 0 1px; } .scoreboard strong { font-size: .7rem; }
  .strip { gap: 4px; margin-bottom: 4px; } .strip > div { padding: 0 6px; line-height: 1.5; }
  .strip .tile { width: 22px; }
  .hand { gap: 4px 6px; } .hand .tile { flex-basis: 28px; width: 28px; }
  .discards { margin: 2px 0; font-size: .85rem; } .discards .tile { width: 24px; flex: none; }
  .hand-title { margin: 2px 0; }
}

/* Table view: attackers' discards and calls. */
.threats { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0; }
.threat { flex: 1 1 220px; border: 1px solid var(--line); border-left: 4px solid var(--wrong); border-radius: 8px; padding: 4px 8px; min-width: 0; }
.threat h3 { margin: 0; font-size: .85rem; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.badge { border: 1px solid var(--wrong); color: var(--wrong); border-radius: 999px; padding: 0 8px; font-size: .75rem; }
.threat .help { margin: 0; font-size: .75rem; }
.river { display: grid; grid-template-columns: repeat(6, 26px); gap: 2px; margin: 2px 0 6px; }
.river .tile { width: 26px; flex: none; }
.melds { display: flex; flex-wrap: wrap; gap: 8px; margin: 4px 0; }
.melds .tile { width: 28px; flex: none; }
.drawn .tile { width: 34px; flex: none; outline: 2px solid var(--accent); outline-offset: 1px; border-radius: 3px; }
.reading li p { margin: 0; }
@media (max-width: 599px) {
  .threats { gap: 4px; margin: 4px 0; }
  .river { grid-template-columns: repeat(9, 22px); } .river .tile { width: 22px; }
  .river .tile.labelled small { font-size: .55rem; }
}
/* Called sets sit with the hand, underlined and named. */
.suit-group.called { position: relative; padding-bottom: 14px; border-bottom: 3px solid var(--accent); align-self: flex-start; }
.suit-group.called > small { position: absolute; left: 0; right: 0; bottom: 0; text-align: center; font-size: .65rem; line-height: 14px; color: var(--muted); }
/* An open hand may wrap at any width, so that its tiles keep their size. */
.hand { align-items: flex-start; }
.hand.open { flex-wrap: wrap; gap: 6px; }
.hand.open .suit-group { flex: 0 1 auto; }
.hand.open .tile { flex: 0 1 30px; width: 30px; }


/* Switch between decision questions and the folding section. */
#sections { display: flex; gap: 8px; margin: 0 0 12px; }
#sections a { flex: 1; text-align: center; padding: 8px 12px; border: 1px solid var(--line); border-radius: 8px;
  color: inherit; text-decoration: none; background: var(--panel); }
#sections a[aria-current="page"] { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); font-weight: 600; }
[hidden] { display: none !important; }
.problem-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(48px, 1fr)); gap: 6px; margin-bottom: 16px; }
.problem-list button { min-height: 44px; padding: 2px; line-height: 1.2; }
.problem-list button small { display: block; font-size: .7rem; }
.problem-list .perfect small { color: var(--right); }
.problem-list [aria-current="true"] { border-color: var(--accent); box-shadow: inset 0 0 0 2px var(--accent); }
.choices { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.choice { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 6px; }
.choice.picked { border-color: var(--accent); box-shadow: inset 0 0 0 2px var(--accent); }
.choice:disabled { opacity: 1; }
.place { font-weight: 600; }
.fold-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.fold-actions .next { flex: 1; }
.fold-actions .next:disabled { opacity: .5; }
.ranking { width: 100%; border-collapse: collapse; margin: 8px 0 16px; }
.ranking th, .ranking td { border-bottom: 1px solid var(--line); padding: 6px 4px; text-align: center; font-size: .9rem; }
.ranking 
/* Exercise book problems: the introduction and the table of tiles, drawn as the book sets them. */
.problem-name { font-weight: 600; margin: 0 0 8px; }
.intro { border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px; margin-bottom: 8px; }
.intro h3 { margin: 0 0 4px; font-size: 1rem; }
.intro p, .reasoning p { margin: 6px 0; line-height: 1.8; }
.intro .tile, .reasoning .tile, .dg-line .tile { width: 1.3em; flex: none; vertical-align: middle; margin: 0 1px; }
.diagram { --big: min(36px, calc((100vw - 3.4rem) / 13.8)); --small: min(28px, calc((100vw - 3.4rem) / 11));
  background: var(--bg); border-radius: 8px; padding: 8px; margin: 8px 0 12px; }
.dg-line { margin: 4px 0; font-weight: 600; }
.dg-row { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 6px 0; margin: 8px 0; }
.dg-row.large { --tw: var(--big); } .dg-row.small { --tw: var(--small); }
.dg-group { display: flex; flex-direction: column; margin-left: calc(var(--gap) * var(--tw)); }
.dg-group:first-child { margin-left: 0; }
.dg-cap { font-size: .7rem; color: var(--muted); margin-bottom: 2px; }
.dg-tiles { display: flex; align-items: flex-end; }
.dg-row .tile { width: var(--tw); flex: none; }
/* A tile lying on its side takes the room of a tile turned a quarter. */
.tile.sideways { width: calc(var(--tw) * 4 / 3); height: var(--tw); aspect-ratio: auto; background: none; filter: none; }
.tile .face { position: absolute; left: 50%; top: 50%; width: calc(var(--tw) / 1); height: calc(var(--tw) * 4 / 3);
  background: url("tiles/Front.svg") center / 100% 100% no-repeat; filter: drop-shadow(0 1px 1px rgb(0 0 0 / .35)); }
.turn-l .face { transform: translate(-50%, -50%) rotate(-90deg); }
.turn-r .face { transform: translate(-50%, -50%) rotate(90deg); }
.choice .tile { width: 44px; }
.ranking .tile { width: 32px; margin: 0 auto; display: block; }

/* Offline use, on the https site. */
#offline { max-width: 760px; margin: 0 auto; padding: 0 16px; font-size: .85rem; }
#offline progress { width: 100%; }
.offline-buttons { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }

/* Going through a book in order. */
.reader { border-bottom: 1px solid var(--line); margin-bottom: 12px; padding-bottom: 8px; }
.pager { display: grid; grid-template-columns: 52px minmax(0, 1fr) 52px; gap: 8px; }
.pager button { font-size: 1.5rem; line-height: 1; padding: 0; }
.pager button:disabled, .previous:disabled { opacity: .4; }
.pager select { font: inherit; color: inherit; background: var(--panel); border: 1px solid var(--line); border-radius: 8px;
  padding: 8px 10px; width: 100%; min-width: 0; }
.reader progress { display: block; width: 100%; height: 4px; accent-color: var(--accent); }
.actions { display: flex; gap: 8px; align-items: stretch; }
.actions .next { flex: 1; }
.actions .previous { margin-top: 8px; padding: 0 16px; }

/* Phones, laid out for an iPhone 15 Pro (393 x 852 points, Dynamic Island, home indicator). */
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
button, a, label, select, summary { touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
button:not(:disabled):active, .chip:active, #sections a:active { filter: brightness(.9); }
header { padding-top: env(safe-area-inset-top); }
header, main, footer { padding-left: max(16px, env(safe-area-inset-left)); padding-right: max(16px, env(safe-area-inset-right)); }
footer { padding-bottom: env(safe-area-inset-bottom); }
@media (max-width: 380px) { header, main { padding-left: 8px; padding-right: 8px; } }
@media (pointer: coarse), (max-width: 599px) {
  /* Finger-sized targets, and 16px fields so that Safari does not zoom in on them. */
  button, .chip, .pager select { min-height: 44px; }
  .chip { padding: 8px 14px; }
  #sections a { min-height: 44px; display: flex; align-items: center; justify-content: center; }
  input[type="checkbox"], input[type="radio"] { width: 18px; height: 18px; flex: none; }
  input[type="text"], select, textarea { font-size: 16px; }
}
@media (max-width: 599px) {
  .answers.pending, .actions { padding-left: max(12px, env(safe-area-inset-left)); padding-right: max(12px, env(safe-area-inset-right)); }
  .actions .next, .actions .previous { margin: 0; min-height: 48px; }
  .answers.pending .answer { min-height: 52px; }
  .reader fieldset.books { margin-bottom: 8px; flex-wrap: nowrap; }
  .reader .books .chip { flex: 1 1 auto; justify-content: center; padding: 4px 6px; font-size: .9rem; }
  .reader legend { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
  .reader .help { margin: 2px 0; }
}
