:root {
  color-scheme: light;
  --paper: #faf6eb;
  --surface: #fffdf8;
  --ink: #203c30;
  --muted: #56685e;
  --line: #ddd7c8;
  --green: #195640;
  --green-pale: #e9f2e9;
  --red: #ae3d2c;
  --red-pale: #f9e9e1;
  --gold: #ffdc87;
  --shadow: 0 4px 16px #493d2110;
  font: 15px/1.45 "DM Sans", system-ui, "Microsoft YaHei", sans-serif;
}
* { box-sizing: border-box; }
body { margin: 0; min-height: 100dvh; color: var(--ink); background: var(--paper); }
button, a, summary { -webkit-tap-highlight-color: transparent; }
button, select { font: inherit; color: inherit; cursor: pointer; }
button:disabled { cursor: default; opacity: .52; }
:where(button, a, select, summary, input):focus-visible { outline: 3px solid #b26021; outline-offset: 3px; }
a { color: var(--green); }
[hidden] { display: none !important; }

.top, main { width: min(100%, 1192px); margin-inline: auto; padding-inline: 24px; }
.top { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding-block: 18px; }
.brand { display: flex; align-items: center; gap: 11px; color: var(--ink); font-size: 25px; font-weight: 850; white-space: nowrap; text-decoration: none; }
.brand-mark { position: relative; display: grid; place-items: center; width: 39px; height: 39px; flex: none; border-radius: 13px; background: var(--red); }
.brand-mark::before { content: ""; position: absolute; width: 16px; height: 22px; border: 1px solid #ffe5b4; border-radius: 4px; transform: translate(-3px, -1px) rotate(-20deg); }
.brand-mark span { display: grid; place-items: center; width: 16px; height: 22px; border-radius: 4px; background: #fff7de; color: var(--red); font: 700 11px/1 Georgia, serif; transform: translate(3px, 0) rotate(12deg); }
.top-actions, .controls, .dialog-actions { display: flex; align-items: center; gap: 8px; }
.ghost, .primary {
  min-height: 38px;
  padding: 6px 15px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  font-weight: 700;
  white-space: nowrap;
}
.ghost:hover:enabled { border-color: #8fa997; background: var(--green-pale); }
.primary { border-color: var(--red); background: var(--red); color: #fffaf3; }
.primary:hover:enabled { border-color: #903120; background: #903120; }
.primary:disabled { opacity: 1; border-color: #e5c9bd; background: #f2ded5; color: #7b4d40; }
.difficulty { display: flex; align-items: center; gap: 5px; padding: 0 7px 0 11px; min-height: 38px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); }
.difficulty label { color: var(--muted); font-size: 12px; white-space: nowrap; }
#difficulty { padding: 5px 2px; border: 0; background: transparent; font-weight: 700; }

main { padding-bottom: 24px; }
.scoreboard {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  max-width: 480px;
  margin: 0 auto 14px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
  box-shadow: var(--shadow);
}
.team, .round { display: flex; align-items: center; justify-content: center; gap: 10px; padding: 7px 18px; white-space: nowrap; }
.team small, .round small { font-size: 13px; font-weight: 650; color: var(--muted); }
.team b { min-width: 1.25em; font: 700 29px/1 Georgia, serif; text-align: center; color: var(--green); }
.team.away b { color: var(--red); }
.round { border-inline: 1px solid var(--line); background: #f5f0e4; }
.round strong { font-size: 16px; color: var(--ink); }

.table {
  position: relative;
  isolation: isolate;
  display: grid;
  grid-template: minmax(72px, auto) minmax(80px, auto) minmax(79px, auto) / minmax(110px, 1fr) minmax(0, 3fr) minmax(110px, 1fr);
  align-items: center;
  justify-items: center;
  gap: 0 8px;
  padding: 10px 25px 18px;
  min-height: 276px;
  border: 6px solid #204e3c;
  border-radius: 36px;
  color: #fff9e9;
  background: radial-gradient(ellipse at 50% 15%, #33785b, #205d46 62%, #184b39);
  box-shadow: inset 0 0 0 1px #a5d0a56e, inset 0 0 26px #102f2260, 0 6px 17px #153b2a29;
}
.table-line {
  position: absolute;
  inset: 9px;
  z-index: -1;
  border: 1px solid #d2e7ba3b;
  border-radius: 24px;
  pointer-events: none;
  background: repeating-linear-gradient(130deg, transparent 0 3px, #152f2111 3px 4px);
}
.table-line::before, .table-line::after { position: absolute; inset-block-end: 12px; color: #dbedcb42; font: 27px/1 Georgia, serif; }
.table-line::before { content: "♣"; inset-inline-start: 18px; }
.table-line::after { content: "♦"; inset-inline-end: 18px; }
.north { grid-area: 1 / 2; }
.east { grid-area: 2 / 3; justify-self: end; }
.west { grid-area: 2 / 1; justify-self: start; }
.player {
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: 100%;
  min-width: 102px;
  padding: 6px 10px 6px 6px;
  border: 1px solid #b5dab35b;
  border-radius: 14px;
  background: #143f33;
  box-shadow: 0 3px 6px #102d2050;
}
.player.north { background: #20533d; }
.player.turn { border-color: var(--gold); box-shadow: 0 0 0 2px #ffdc8740; }
.player.turn small { color: #ffebac; }
.player .portrait { display: block; width: 36px; height: 36px; object-fit: contain; padding: 3px; border-radius: 10px; background: #f2e7cb; }
.player strong, .player small { display: block; white-space: nowrap; }
.player small { font-size: 12px; color: #d7ebdc; font-variant-numeric: tabular-nums; }
.center { grid-area: 2 / 2; min-width: 0; width: 100%; text-align: center; }
.call { color: #ffebaa; font-size: 12px; font-weight: 750; }
.current { font-size: clamp(18px, 2.35vw, 29px); font-weight: 800; }
.passes { color: #e1efdd; font-size: 12px; }
.passes:empty { display: none; }
.table-cards {
  grid-area: 3 / 1 / 4 / 4;
  align-self: start;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 5px 8px;
  max-width: 100%;
  padding: 3px 0;
}
.played-hand { display: grid; justify-items: center; gap: 3px; padding: 3px 5px 5px; border: 1px solid transparent; border-radius: 9px; }
.played-hand.leading { border-color: #ffe3a584; background: #10392d7a; }
.played-hand small { color: #f2f6e9; font-size: 11px; }
.played-row { display: flex; gap: 2px; }

.rack { margin-top: 13px; padding: 15px 17px 14px; border: 1px solid var(--line); border-radius: 18px; background: var(--surface); box-shadow: var(--shadow); }
.rack-top { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 8px; margin-bottom: 11px; }
.rack-title { white-space: nowrap; font-size: 16px; font-weight: 800; }
.rack-title span { font-size: 12px; font-weight: 600; color: var(--muted); }
.status { padding: 4px 10px; border-radius: 999px; background: var(--green-pale); color: #235440; text-align: center; font-size: 12px; font-weight: 750; }
.your-turn .status { background: var(--red-pale); color: #943320; }
.rack-tools { display: flex; justify-content: flex-end; gap: 6px; }
.sort { min-height: 33px; padding: 3px 9px; font-size: 12px; }
.rack-tools button[aria-pressed=true], .choices button[aria-pressed=true] { border-color: #78a087; background: var(--green-pale); color: var(--green); }
.hand { display: flex; flex-wrap: wrap; align-items: end; gap: 10px 11px; min-height: 85px; user-select: none; }
.hand-group { display: grid; justify-items: start; align-content: end; gap: 4px; }
.group-label { min-height: 17px; padding: 0 2px; border: 0; background: transparent; color: var(--green); font-size: 11px; font-weight: 700; }
.group-cards { display: flex; gap: 2px; }
.card {
  position: relative;
  display: grid;
  grid-template-rows: 1fr 1fr;
  place-items: center;
  min-width: 0;
  padding: 4px 0;
  border: 1px solid #dbd2be;
  border-radius: 7px;
  background: linear-gradient(#fffef9, #f5edda);
  box-shadow: 0 2px 3px #30291a25;
  color: #263b32;
  font: 700 17px/1 Georgia, "Microsoft YaHei", serif;
}
.group-cards .card { width: 35px; height: 67px; touch-action: none; }
.card.red { color: #ab362f; }
.card .suit { font-size: 23px; }
.card.level::after { content: ""; position: absolute; inset-block-end: 3px; width: 10px; height: 2px; border-radius: 2px; background: #866227; }
.card.wild { border-color: #cf9d4e; background: linear-gradient(#fff2cb, #ffdb94); }
.card.wild::after { width: 55%; background: #a63d38; }
button.card { transition: transform .13s ease, box-shadow .13s ease; }
button.card:disabled { opacity: 1; }
button.card.ineligible { opacity: .5; }
button.card[aria-pressed=true] { z-index: 1; transform: translateY(-4px); box-shadow: 0 0 0 2px #bd5941, 0 4px 9px #43332345; }
.card.mini { width: 27px; height: 42px; border-radius: 5px; font-size: 13px; }
.card.mini .suit { font-size: 16px; }
.card.joker { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; overflow: hidden; }
.joker-art { width: 100%; height: 70%; min-height: 0; object-fit: contain; pointer-events: none; }
.joker-art.mono { filter: grayscale(1); }
.joker-mark { font: 750 9px/1.1 system-ui, sans-serif; white-space: nowrap; }
.card.mini .joker-mark { font-size: 8px; }
.wild-as { position: absolute; inset: 2px 1px auto auto; padding: 1px; border-radius: 2px; color: #982733; background: #fff6d9; font: 750 8px/1 system-ui, sans-serif; }
.hand.dragging .card { cursor: grabbing; }
.group-cards .card.drag-source { opacity: .35; }
.card.drag-preview { position: fixed; inset: 0 auto auto 0; z-index: 30; pointer-events: none; box-shadow: 0 5px 15px #0008; }
.insert-marker { position: fixed; z-index: 29; width: 3px; transform: translateX(-50%); border-radius: 3px; background: var(--red); pointer-events: none; }

.note { min-height: 28px; padding-block: 5px; color: var(--muted); text-align: center; font-size: 12px; }
.live-coach { max-width: 640px; margin: 0 auto 10px; padding: 10px 14px; border: 1px solid currentColor; border-radius: 10px; font-size: 13px; line-height: 1.5; }
.live-coach p, .live-coach ul { margin: 4px 0 0; }
.live-coach ul { padding-inline-start: 1.4em; color: var(--muted); }
.live-coach ul:empty { display: none; }
.controls { justify-content: center; }
.controls button { min-width: 87px; min-height: 43px; }
.controls .primary { min-width: 128px; }
.choices { display: flex; flex-wrap: wrap; justify-content: center; gap: 5px; padding-top: 9px; }
.choices button { min-height: 33px; padding: 4px 8px; font-size: 12px; }

.game-tools { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-top: 12px; }
.review-entry { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 13px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); }
.review-entry small { display: block; color: var(--muted); font-size: 12px; }
.review-entry button { min-height: 35px; padding: 4px 9px; font-size: 13px; }
.history { margin-top: 7px; color: var(--muted); font-size: 13px; }
.history summary { width: max-content; padding: 7px 2px; cursor: pointer; }
.history ol { max-height: 220px; overflow: auto; margin: 2px 0; padding: 10px 12px 10px 34px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); }

dialog {
  width: min(580px, calc(100vw - 28px));
  max-height: calc(100dvh - 24px);
  overflow: auto;
  padding: 19px;
  border: 1px solid var(--line);
  border-radius: 17px;
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 15px 60px #10251c66;
}
dialog::backdrop { background: #142b22ad; }
dialog h2 { margin: 0; font-size: 20px; }
dialog li { margin: 8px 0; }
.dialog-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.dialog-actions { justify-content: flex-end; flex-wrap: wrap; }
#replay-dialog { width: min(680px, calc(100vw - 28px)); }
.review-picker, .review-nav { display: flex; align-items: end; gap: 7px; margin-top: 12px; }
.review-picker > label:first-child { display: grid; gap: 4px; min-width: 0; flex: 1; color: var(--muted); font-size: 13px; }
.review-check { display: flex; align-items: center; min-height: 35px; white-space: nowrap; font-size: 13px; }
.review-picker select, .review-nav select { width: 100%; min-width: 0; min-height: 35px; padding: 5px; border: 1px solid var(--line); border-radius: 7px; background: var(--surface); }
.review-nav select { flex: 1; }
.review-nav button, .training-actions button { min-height: 35px; padding: 4px 9px; font-size: 13px; }
.review-meta, .review-hand { color: var(--muted); font-size: 13px; }
.review-meta { margin: 5px 0; }
.review-context { margin: 10px 0 5px; font-weight: 750; }
.review-hand { padding: 4px 0 8px; }
.review-hand p { margin: 5px 0; color: var(--ink); }
.review-card { margin: 6px 0; padding: 8px 11px; border: 1px solid var(--line); border-radius: 9px; background: #f8f4e9; }
.review-card h3 { margin: 0 0 3px; color: var(--green); font-size: 14px; }
.review-card p { margin: 3px 0; }
.review-card p:empty, #review-empty:empty { display: none; }
.review-card ul { margin: 4px 0; padding-left: 18px; color: var(--muted); font-size: 13px; }
.review-card li { margin: 3px 0; }
.review-action { font-weight: 750; }
.review-coach { background: var(--green-pale); }
.review-foot { margin-top: 10px; }
#review-highlights-title { margin: 12px 0 5px; font-size: 15px; }
.review-highlight-list { display: flex; flex-wrap: wrap; gap: 6px; }
.review-highlight-list button { min-height: 35px; padding: 4px 8px; font-size: 13px; }
#review-highlight-reason { margin: 6px 0; font-size: 13px; }
.review-comparison { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 7px; }
.review-comparison:has(#review-coach[hidden]) { grid-template-columns: minmax(0, 1fr); }
.review-comparison .review-card { min-width: 0; overflow-wrap: anywhere; }
.training-auto { display: flex; align-items: center; gap: 6px; padding: 7px 0; }
.training-actions { display: flex; gap: 7px; flex-wrap: wrap; }
.training-status { min-height: 18px; margin: 8px 0; color: var(--green); font-size: 13px; }
#training-history { max-height: 150px; overflow: auto; padding-left: 22px; color: var(--muted); font-size: 13px; }

@media (max-width: 820px) {
  .top, main { padding-inline: 16px; }
  .group-cards .card { width: 30px; height: 61px; }
}
@media (max-width: 560px) {
  .top, main { padding-inline: 8px; }
  .top { gap: 6px; padding-block: 10px; }
  .brand { gap: 6px; font-size: 19px; }
  .brand-mark { width: 29px; height: 29px; border-radius: 9px; }
  .brand-mark::before, .brand-mark span { width: 12px; height: 17px; border-radius: 3px; }
  .brand-mark span { font-size: 9px; }
  .top-actions { gap: 4px; }
  .top-actions button { min-height: 35px; padding: 4px 7px; font-size: 12px; }
  .difficulty { min-height: 35px; padding-inline: 4px; }
  .difficulty label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
  #difficulty { font-size: 12px; }
  .scoreboard { max-width: 390px; margin-bottom: 8px; border-radius: 12px; }
  .team, .round { gap: 6px; padding: 5px 9px; }
  .team b { font-size: 25px; }
  .team small, .round small { font-size: 11px; }
  .round strong { font-size: 14px; }
  .table {
    grid-template: 53px minmax(66px, auto) minmax(60px, auto) / minmax(70px, 1fr) minmax(0, 2fr) minmax(70px, 1fr);
    gap: 0 4px;
    min-height: 205px;
    padding: 5px 8px 10px;
    border-width: 4px;
    border-radius: 23px;
  }
  .table-line { inset: 4px; border-radius: 16px; }
  .table-line::before, .table-line::after { display: none; }
  .player { min-width: 0; gap: 4px; padding: 4px; border-radius: 9px; }
  .player .portrait { width: 25px; height: 25px; padding: 2px; border-radius: 7px; }
  .player strong { font-size: 12px; }
  .player small, .call, .passes { font-size: 11px; }
  .table-cards { gap: 2px 4px; }
  .played-hand { gap: 2px; padding: 2px 3px 3px; }
  .card.mini { width: 21px; height: 35px; font-size: 11px; }
  .card.mini .suit { font-size: 14px; }
  .rack { margin-top: 8px; padding: 9px 8px; border-radius: 13px; }
  .rack-top { grid-template-columns: minmax(0, 1fr) auto; gap: 5px; margin-bottom: 7px; }
  .rack-title { font-size: 14px; }
  .rack-title span { font-size: 11px; }
  .rack-tools { grid-column: 1 / -1; }
  .rack-tools .sort { min-height: 31px; }
  .hand { gap: 8px 8px; min-height: 72px; }
  .group-cards .card { width: 25px; height: 53px; border-radius: 5px; font-size: 15px; }
  .group-cards .card .suit { font-size: 20px; }
  .joker-mark { font-size: 8px; }
  .card.mini .joker-mark { font-size: 7px; }
  .controls { gap: 5px; }
  .controls button { min-width: 73px; }
  .controls .primary { min-width: 110px; }
  .game-tools { grid-template-columns: 1fr; gap: 6px; margin-top: 8px; }
  .review-entry { padding: 7px 9px; }
  dialog { padding: 13px; }
}
@media (prefers-reduced-motion: reduce) {
  button.card { transition: none; }
}

.ai-status { margin: 0 auto; padding: 2px 16px 0; text-align: center; font-size: 12px; color: #647a6c; }

#practice-panel { margin-bottom: 10px; }
#practice-panel .review-highlight-list { margin-top: 6px; }
#practice-panel .review-comparison { color: var(--muted); overflow-wrap: anywhere; }
#review-practice { min-height: 35px; padding: 4px 9px; font-size: 13px; }
