:root {
  color-scheme: light;
  --ink: #102c25;
  --green: #167a4d;
  --green-dark: #0f6840;
  --green-soft: #dff3e6;
  --paper: #f7fbf7;
  --card-w: 1fr;
  --card-rank: clamp(10px, 1.45cqi, 22px);
  --card-suit: clamp(17px, 2.4cqi, 36px);
}
* { box-sizing: border-box; }
html { min-width: 320px; background: #edf5ef; }
body {
  margin: 0;
  padding: max(8px, env(safe-area-inset-top)) 8px max(24px, env(safe-area-inset-bottom));
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
}
button, select { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }
.page { width: 100%; display: flex; flex-direction: column; align-items: center; gap: 22px; }
.game-board {
  --board-size: 100cqi;
  container-type: inline-size;
  position: relative;
  isolation: isolate;
  width: min(96vw, calc(100dvh - 40px), 1000px);
  aspect-ratio: 1 / 1;
  overflow: hidden;
  border-radius: clamp(12px, 1.8cqi, 22px);
  background: #29a56b url("assets/table-felt.webp") center / cover no-repeat;
  box-shadow: 0 16px 44px rgba(20, 76, 48, .16), inset 0 0 0 1px rgba(255,255,255,.16);
  flex: 0 0 auto;
}
.leaf { position: absolute; z-index: 0; width: 23%; height: auto; pointer-events: none; opacity: .9; }
.leaf-tl { left: -1.5%; top: -1.5%; }
.leaf-bl { left: -1.5%; bottom: -1.5%; transform: scaleY(-1); }
.leaf-br { right: -1.5%; bottom: -1.5%; transform: rotate(180deg); }
.brand-row, .stats-bar, .action-row, .tableau, .bottom-bar { position: absolute; z-index: 2; }
.brand-row {
  top: 1.7%; left: 4%; width: 92%; height: 8%;
  display: flex; align-items: center; justify-content: center;
}
.brand-lockup { display: flex; align-items: center; justify-content: center; gap: clamp(7px, 1.3cqi, 15px); min-width: 0; }
.brand-logo { width: clamp(34px, 6.5cqi, 66px); height: auto; display: block; filter: drop-shadow(0 1px 1px rgba(0,0,0,.08)); }
h1 { margin: 0; color: #fff; font-size: clamp(19px, 4.0cqi, 43px); line-height: 1; font-weight: 800; letter-spacing: -.045em; text-shadow: 0 1px 2px rgba(0,0,0,.12); white-space: nowrap; }
.mode-select-wrap {
  position: absolute; right: 0; top: 50%; transform: translateY(-50%);
  display: flex; align-items: center; justify-content: center;
  width: 15.6%; min-width: 76px; height: 73%;
  background: rgba(255,255,255,.96); border: 1px solid rgba(11,73,47,.13); border-radius: 999px;
  box-shadow: 0 2px 5px rgba(10,78,48,.08); color: #102c25;
}
.mode-select-wrap select { width: 100%; height: 100%; padding: 0 18% 0 12%; appearance: none; border: 0; outline: 0; background: transparent; color: inherit; font-size: clamp(10px, 1.55cqi, 16px); font-weight: 750; cursor: default; text-align: center; }
.select-chevron { position: absolute; right: 13%; pointer-events: none; font-size: clamp(11px, 1.5cqi, 16px); }
.stats-bar {
  top: 11.1%; left: 5.5%; width: 89%; height: 6.1%;
  display: flex; align-items: center; justify-content: space-evenly;
  padding: 0 1.2%; border-radius: 999px;
  background: rgba(255,255,255,.96); border: 1px solid rgba(14,66,45,.09);
  box-shadow: 0 3px 9px rgba(7,78,44,.09);
}
.stat-item { min-width: 0; display: flex; align-items: center; justify-content: center; gap: clamp(3px, .75cqi, 9px); color: #112e26; white-space: nowrap; }
.stat-item img { width: clamp(13px, 2.4cqi, 24px); height: clamp(13px, 2.4cqi, 24px); object-fit: contain; }
.stat-label { font-size: clamp(9px, 1.65cqi, 17px); font-weight: 700; }
.stat-item strong { font-size: clamp(10px, 1.75cqi, 18px); font-weight: 850; font-variant-numeric: tabular-nums; }
.stat-divider { width: 1px; height: 48%; background: #d4e5da; flex: 0 0 1px; }
.completed-stat { gap: clamp(4px, .7cqi, 8px); }
.action-row {
  top: 19.4%; left: 50%; transform: translateX(-50%);
  display: flex; align-items: center; justify-content: center; gap: clamp(8px, 1.6cqi, 16px);
  width: 69%; height: 7.8%;
}
.control-button {
  display: inline-flex; align-items: center; justify-content: center; gap: clamp(5px, .95cqi, 10px);
  min-width: 0; height: 100%; padding: 0 clamp(10px, 2.2cqi, 22px);
  border: 1.5px solid rgba(19,64,45,.16); border-radius: 999px;
  background: rgba(255,255,255,.96); color: #142d27;
  box-shadow: 0 3px 8px rgba(12,78,48,.1);
  font-weight: 750; font-size: clamp(10px, 1.7cqi, 18px); white-space: nowrap;
  cursor: pointer; transition: transform .12s ease, box-shadow .12s ease, background .12s ease;
}
.control-button:hover:not(:disabled) { transform: translateY(-1px); box-shadow: 0 5px 12px rgba(12,78,48,.15); }
.control-button:active:not(:disabled) { transform: translateY(1px); }
.control-button:focus-visible, .stock-pile:focus-visible, .mode-select-wrap:focus-within { outline: 3px solid #0b4e32; outline-offset: 3px; }
.control-button:disabled { opacity: .42; cursor: not-allowed; box-shadow: none; }
.control-button img { width: clamp(14px, 2cqi, 22px); height: clamp(14px, 2cqi, 22px); object-fit: contain; }
.primary-button { background: #118047; border-color: rgba(255,255,255,.95); outline: 1px solid rgba(8,93,49,.15); color: white; min-width: 33%; }
.primary-button img { filter: brightness(0) invert(1); }
.tableau {
  top: 29.2%; left: 2%; width: 96%; height: 54.8%;
  display: grid; grid-template-columns: repeat(10, minmax(0, 1fr));
  gap: .48%; align-items: start;
}
.column { position: relative; min-width: 0; height: 100%; border-radius: 8px; }
.column.empty-target { background: rgba(255,255,255,.07); outline: 1px dashed rgba(255,255,255,.34); }
.playing-card {
  position: absolute; left: 0; width: 100%; aspect-ratio: 5 / 7;
  border-radius: clamp(4px, .85cqi, 9px); overflow: hidden;
  user-select: none; -webkit-user-select: none; touch-action: manipulation;
  box-shadow: 0 2px 4px rgba(0,0,0,.15);
  transition: outline-color .12s ease, filter .12s ease, transform .12s ease;
}
.playing-card.face-down { border: 1px solid rgba(255,255,255,.95); background: #1768b3; }
.playing-card.face-down img { width: 100%; height: 100%; display: block; object-fit: fill; }
.playing-card.face-up {
  background: #fffefa; border: 1px solid #d9e0dc; color: #101b18; cursor: pointer;
  font-family: Georgia, "Times New Roman", serif;
}
.playing-card.face-up .rank-corner { position: absolute; top: 5%; left: 8%; z-index: 2; display: flex; flex-direction: column; align-items: center; line-height: .92; }
.rank-corner .rank { font-size: clamp(10px, 1.65cqi, 18px); font-weight: 800; }
.rank-corner .suit-small { font-size: clamp(9px, 1.45cqi, 16px); margin-top: 2px; }
.center-suit { position: absolute; left: 50%; top: 51%; transform: translate(-50%,-50%); font-size: clamp(24px, 4.1cqi, 43px); line-height: 1; }
.face-up .portrait { position: absolute; left: 9%; right: 9%; bottom: 0; height: 76%; background-image: url("assets/court-cards-sprite.png"); background-repeat: no-repeat; background-size: 300% 100%; background-position-y: center; }
.face-up.rank-11 .portrait { background-position-x: 0%; }
.face-up.rank-12 .portrait { background-position-x: 50%; }
.face-up.rank-13 .portrait { background-position-x: 100%; }
.face-up .portrait + .rank-corner { background: rgba(255,255,255,.9); border-radius: 0 0 5px 0; padding: 0 2px 2px 0; }
.playing-card.selectable { cursor: grab; }
.playing-card.selected { outline: 3px solid #fff; outline-offset: -3px; filter: drop-shadow(0 0 5px rgba(255,255,255,.9)); transform: translateY(-3px); z-index: 5; }
.playing-card.hint-source { outline: 3px solid #ffe56e; outline-offset: -3px; z-index: 6; }
.column.hint-target { outline: 3px solid #ffe56e; outline-offset: 2px; border-radius: 9px; background: rgba(255,239,134,.12); }
.bottom-bar { left: 3.2%; right: 3.2%; bottom: 3.1%; height: 13.2%; display: flex; align-items: end; justify-content: space-between; }
.goal-pill {
  display: inline-flex; align-items: center; gap: clamp(5px, 1cqi, 11px);
  max-width: 48%; min-height: 43%; padding: 0 clamp(9px, 1.8cqi, 19px);
  border: 1.5px solid rgba(255,255,255,.78); border-radius: 999px;
  background: rgba(14,111,67,.25); color: white; font-size: clamp(8px, 1.5cqi, 16px); font-weight: 700;
  text-shadow: 0 1px 2px rgba(0,0,0,.12); white-space: nowrap;
}
.goal-pill img { width: clamp(15px, 2.6cqi, 27px); height: clamp(15px, 2.6cqi, 27px); filter: brightness(0) invert(1); }
.stock-area { display: flex; align-items: end; justify-content: end; gap: clamp(5px, 1.6cqi, 16px); height: 100%; }
.stock-pile.hint-source { filter: drop-shadow(0 0 7px #ffe56e); }
.stock-pile { position: relative; width: clamp(38px, 9.2cqi, 92px); height: 93%; border: 0; padding: 0; background: transparent; cursor: pointer; }
.stock-card { position: absolute; width: 77%; height: 88%; left: 0; bottom: 0; border: 1px solid white; border-radius: 7px; background: #1268af url("assets/card-back.webp") center / 100% 100% no-repeat; box-shadow: 0 2px 4px rgba(0,0,0,.2); }
.stock-card-1 { transform: translateX(0); }
.stock-card-2 { transform: translateX(12%); }
.stock-card-3 { transform: translateX(24%); }
.stock-card-4 { transform: translateX(36%); }
.stock-count { position: absolute; right: -7%; top: -5%; min-width: 25px; padding: 2px 5px; border-radius: 99px; color: #14553a; background: white; font: 800 clamp(8px, 1.1cqi, 12px)/1.3 system-ui,sans-serif; box-shadow: 0 1px 4px rgba(0,0,0,.15); }
.deal-button { height: 44%; min-width: clamp(72px, 15.2cqi, 150px); padding-inline: clamp(9px, 1.8cqi, 19px); }
.toast { position: absolute; z-index: 10; left: 50%; bottom: 17%; transform: translate(-50%, 8px); max-width: 84%; padding: 9px 15px; border-radius: 999px; color: #153c2c; background: rgba(255,255,255,.96); box-shadow: 0 4px 16px rgba(0,0,0,.16); font-size: clamp(11px, 1.45cqi, 15px); font-weight: 700; text-align: center; opacity: 0; pointer-events: none; transition: opacity .16s, transform .16s; }
.toast.visible { opacity: 1; transform: translate(-50%, 0); }
.modal-backdrop { position: absolute; inset: 0; z-index: 20; display: grid; place-items: center; padding: 18px; background: rgba(10,42,29,.42); backdrop-filter: blur(3px); }
.modal-backdrop[hidden] { display: none; }
.confirm-dialog { width: min(88%, 370px); border-radius: 18px; padding: 24px; background: #fbfffc; box-shadow: 0 14px 45px rgba(0,0,0,.22); color: #15382a; }
.confirm-dialog h2 { margin: 0 0 8px; font-size: 21px; }
.confirm-dialog p { margin: 0 0 20px; color: #587066; font-size: 14px; }
.dialog-actions { display: flex; justify-content: end; gap: 9px; height: 44px; }
.dialog-actions .control-button { font-size: 14px; }
.instructions { width: min(96vw, 1000px); background: #fff; border: 1px solid #dce8df; border-radius: 18px; padding: clamp(16px, 3vw, 26px); box-shadow: 0 8px 24px rgba(30,90,52,.07); }
.instructions-head { margin-bottom: 15px; }
.eyebrow { display: inline-block; padding: 4px 9px; border-radius: 999px; background: #e8f5ec; color: #18724a; font-size: 10px; font-weight: 850; letter-spacing: .12em; }
.instructions h2 { margin: 8px 0 0; font-size: clamp(20px,3vw,27px); letter-spacing: -.035em; color: #153b2b; }
.instruction-grid { display: grid; grid-template-columns: repeat(4,minmax(0,1fr)); gap: 12px; }
.instruction-grid article { padding: 13px; border-radius: 12px; background: #f5faf6; border: 1px solid #e1eee4; }
.instruction-grid h3 { margin: 0 0 6px; color: #176342; font-size: 13px; }
.instruction-grid p { margin: 0; color: #52665b; font-size: 12px; line-height: 1.55; }
.help-line { margin: 14px 0 0; color: #52665b; font-size: 12px; line-height: 1.5; }
@container (max-width: 560px) {
  .brand-row { top: 2%; }
  .brand-logo { width: 6cqi; }
  h1 { font-size: 3.65cqi; }
  .mode-select-wrap { min-width: 0; width: 15%; }
  .mode-select-wrap select { font-size: 1.7cqi; }
  .stat-label { font-size: 1.65cqi; }
  .stat-item strong { font-size: 1.8cqi; }
  .action-row { width: 76%; }
  .control-button { font-size: 1.8cqi; padding-inline: 1.6cqi; }
  .control-button img { width: 2.5cqi; height: 2.5cqi; }
  .goal-pill { font-size: 1.5cqi; }
  .instruction-grid { grid-template-columns: repeat(2,minmax(0,1fr)); }
}
@media (max-width: 520px) {
  body { padding-inline: 2px; }
  .page { gap: 12px; }
  .game-board { width: min(99vw, calc(100dvh - 12px)); border-radius: 10px; }
  .instructions { width: 99vw; border-radius: 12px; }
  .instruction-grid { gap: 7px; }
  .instruction-grid article { padding: 9px; }
  .instruction-grid h3 { font-size: 12px; }
  .instruction-grid p,.help-line { font-size: 11px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: .01ms !important; animation-duration: .01ms !important; scroll-behavior: auto !important; }
}
