:root {
  color-scheme: light;
  --paper: #f5f2e9;
  --panel: #fffcf4;
  --ink: #1c322b;
  --muted: #53635a;
  --line: #ded9ca;
  --green: #185241;
  --dark: #10392f;
  --mint: #c4dacb;
  --gold: #f0d185;
  --red: #a02f40;
  --card-width: 3rem;
  font-family: Inter, system-ui, -apple-system, "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
  color: var(--ink);
  background: var(--paper);
  line-height: 1.5;
}
* { box-sizing: border-box; }
body { margin: 0; }
[hidden] { display: none !important; }
h1, h2, h3, p { margin: 0; }
a { color: inherit; }
button, input { font: inherit; }
button, input {
  min-height: 2.65rem;
  padding: .5rem .85rem;
  border: 1px solid var(--line);
  border-radius: .65rem;
  color: var(--ink);
  background: var(--panel);
}
button { cursor: pointer; font-weight: 650; }
button:not(:disabled):hover { background: #eeeade; border-color: #a8ac9f; }
button:disabled { opacity: .56; cursor: default; }
:focus-visible { outline: 2px solid var(--red); outline-offset: 3px; }
button.primary, button.match-button { color: #fffdf5; background: var(--green); border-color: var(--green); }
button.primary:not(:disabled):hover,
button.match-button:not(:disabled):hover { color: #fffdf5; background: var(--dark); border-color: var(--dark); }
button.match-button:disabled { background: #e9ede4; color: #596b61; border-color: #dce4d9; opacity: 1; }

.masthead, main {
  max-width: 74rem;
  margin-inline: auto;
  padding-inline: clamp(.9rem, 4.5vw, 3.5rem);
}
.masthead {
  min-height: 4.6rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: .6rem;
  font: 700 1.38rem/1 Georgia, serif;
  letter-spacing: -.04em;
  text-decoration: none;
}
.seal {
  display: grid;
  place-items: center;
  border-radius: .6rem;
  width: 2rem;
  height: 2rem;
  background: var(--green);
  color: var(--gold);
  font: 1.5rem/1 Georgia, serif;
}
.header-controls, .language-picker { display: flex; align-items: center; }
.header-controls { flex-wrap: wrap; justify-content: flex-end; gap: clamp(.45rem, 2vw, 1.3rem); font-size: .82rem; }
.header-controls a { padding-block: .55rem; font-weight: 650; text-decoration: none; }
.header-controls a:hover { text-decoration: underline; }
.quiet { background: transparent; }
.language-picker { gap: .15rem; padding: .22rem; border: 1px solid var(--line); border-radius: .6rem; }
.language-picker button { min-height: 2rem; padding: .23rem .5rem; border: 0; border-radius: .42rem; background: transparent; }
.language-picker button[aria-pressed="true"] { background: #e0e8dc; }

main { padding-bottom: 2.5rem; }
.intro {
  min-height: 14.4rem;
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: center;
  padding: 1.65rem clamp(.1rem, 2vw, 1.4rem) 2rem;
  border-top: 1px solid var(--line);
}
.intro h1 {
  font: 700 clamp(4rem, 9vw, 7rem)/.94 Georgia, serif;
  letter-spacing: -.085em;
  margin: 0 0 .8rem -.045em;
}
.intro h1 span { color: var(--red); }
.intro p { max-width: 34rem; color: var(--muted); font-size: clamp(.92rem, 1.5vw, 1.08rem); font-weight: 500; }
.intro-actions { display: flex; flex-wrap: wrap; gap: .45rem; margin-top: 1rem; }
.intro-actions .primary { padding-inline: 1.15rem; }
.sample-hand {
  position: relative;
  flex: 0 0 clamp(9rem, 25vw, 16rem);
  margin-inline-end: clamp(.3rem, 4vw, 2.8rem);
  height: clamp(7rem, 15vw, 10rem);
}
.sample-hand img {
  position: absolute;
  top: 8%;
  left: 50%;
  width: clamp(3.4rem, 8.5vw, 6rem);
  height: auto;
  border-radius: 7%;
  box-shadow: 0 .6rem 1.2rem #322a2035;
}
.sample-hand img:nth-child(1) { transform: translateX(-114%) rotate(-19deg); }
.sample-hand img:nth-child(2) { transform: translate(-55%, -7%) rotate(-2deg); }
.sample-hand img:nth-child(3) { transform: translateX(8%) rotate(17deg); }

.workspace { display: grid; grid-template-columns: minmax(0, 1fr) minmax(15rem, 19rem); align-items: start; gap: 1rem; }
.table-panel {
  padding: clamp(.6rem, 2.2vw, 1.3rem);
  border-radius: 1.1rem;
  background: radial-gradient(ellipse at 30% 0%, #225947, var(--dark) 82%);
  color: #fffbec;
  box-shadow: 0 7px 24px #233b2b24;
}
.table-head, .gallery-head { display: flex; justify-content: space-between; align-items: center; gap: .65rem; }
.table-head { padding: 0 .22rem .82rem; }
.table-head h2 { font-size: clamp(1.13rem, 2vw, 1.38rem); letter-spacing: -.04em; }
#next-stack { color: var(--mint); font-size: .82rem; margin-top: .13rem; }
.remaining {
  padding: .26rem .7rem;
  border: 1px solid #78998a;
  border-radius: 2rem;
  color: #f9e4aa;
  white-space: nowrap;
  font-weight: 690;
  font-size: .78rem;
  font-variant-numeric: tabular-nums;
}
.board { display: grid; gap: .35rem; }
.board-row {
  display: grid;
  grid-template-columns: 4.4rem minmax(0, 1fr);
  gap: .25rem;
  align-items: center;
  padding: .2rem .24rem;
  border: 1px solid #f4f9e51f;
  border-radius: .65rem;
  background: #092f284f;
}
.board-row.is-next { border-color: #d4b871; background: #123b2d; }
.board-row.is-complete { background: #245341; }
.row-title { padding-inline-start: .3rem; color: var(--mint); font-size: .75rem; font-weight: 650; white-space: nowrap; }
.row-title::before {
  display: inline-block;
  content: "";
  width: .34rem;
  height: .34rem;
  margin-right: .3rem;
  vertical-align: .1em;
  border-radius: 50%;
  background: #829f9180;
}
.is-next .row-title { color: #f9e4aa; }
.is-next .row-title::before { background: var(--gold); }
.is-complete .row-title::before { background: #a4d3b6; }
.stack {
  display: flex;
  gap: .35rem;
  align-items: center;
  overflow-x: auto;
  padding: .28rem;
  scrollbar-width: thin;
  scrollbar-color: #82a998 #164739;
  min-height: calc(var(--card-width) * 10 / 7 + .56rem);
}
.card, .empty-slot {
  flex: 0 0 var(--card-width);
  aspect-ratio: 7 / 10;
  border-radius: .3rem;
}
.card {
  position: relative;
  display: block;
  min-height: 0;
  padding: 0;
  border: 0;
  background: #fffaf0;
  box-shadow: 0 2px 5px #061c15a0;
}
.card img { display: block; width: 100%; height: auto; }
.card:disabled { opacity: 1; }
.card:not(:disabled):hover { background: #fffaf0; transform: translateY(-.13rem); }
.card:focus-visible { outline-color: white; outline-offset: 2px; }
.card.is-selected { box-shadow: 0 0 0 2px var(--gold), 0 2px 5px #061c15a0; }
.card.is-hinted { box-shadow: 0 0 0 2px #9fe8ba, 0 2px 5px #061c15a0; }
.card.is-dealt { animation: reveal-card 150ms ease-out; }
@keyframes reveal-card {
  from { opacity: .36; transform: translateX(-.3rem) scale(.92); }
  to { opacity: 1; transform: none; }
}
@media (prefers-reduced-motion: reduce) {
  .card.is-dealt { animation: none; }
}
.project-links { display: flex; flex-wrap: wrap; gap: .6rem 1.2rem; margin-top: 1.15rem; }
.project-links a { color: var(--green); text-underline-offset: .2em; }
.empty-slot { border: 1px dashed #819e8f86; }
.complete-label {
  color: #cbedd6;
  font-size: .85rem;
  font-weight: 700;
}
.complete-label::before { content: "✓"; margin-right: .4rem; }

.control-panel { display: grid; gap: .7rem; }
.panel, .rulebook {
  border: 1px solid var(--line);
  border-radius: .95rem;
  background: var(--panel);
  padding: 1rem;
}
.panel h2 { font-size: 1rem; font-weight: 750; }
.hand-deck {
  display: flex;
  align-items: center;
  gap: .8rem;
}
.hand-deck img { width: 2.5rem; height: auto; filter: drop-shadow(.13rem .15rem 0 #99916e54); }
.hand-deck p { color: var(--muted); font-size: .87rem; font-variant-numeric: tabular-nums; }
.hand-deck button { min-height: 2rem; margin-left: auto; padding: .2rem .45rem; font-size: .76rem; }
.selection {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .5rem;
  min-height: 4.15rem;
  margin: .65rem 0;
  padding: .43rem .65rem;
  border-radius: .55rem;
  background: #f1eee4;
}
.selection p { font-size: .79rem; color: var(--muted); }
.selection p:first-child { font-weight: 700; color: var(--ink); }
.selection output { font: 700 2rem/1 Georgia, serif; color: var(--muted); font-variant-numeric: lining-nums tabular-nums; }
.selection .is-target { color: var(--green); }
#match { width: 100%; }
.button-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .4rem; margin-top: .45rem; }
.button-grid button { padding-inline: .3rem; font-size: .86rem; }
.replay-progress { margin-top: .6rem; color: var(--green); font-size: .8rem; font-weight: 700; }
.feedback { color: var(--muted); font-size: .81rem; margin-top: .65rem; }
.feedback:empty { display: none; }
.feedback.error, #age-error { color: var(--red); }
.auto-choices { margin-top: .65rem; }
.auto-choices h3 { font-size: .88rem; }
.auto-choice-list { display: grid; gap: .35rem; max-height: 12rem; overflow: auto; padding: .3rem; }
.auto-choice-list button { text-align: left; font-size: .8rem; }
.auto-choice-list button[aria-pressed="true"] { border-color: var(--green); background: #e5eee2; }
.auto-choice-list span { display: block; color: var(--muted); font-size: .78rem; }

.rulebook { margin-top: 1rem; }
.rulebook summary { cursor: pointer; font-weight: 700; }
.rulebook ol { margin-bottom: .1rem; padding-left: 1.35rem; color: var(--muted); font-size: .92rem; }
.rulebook li + li { margin-top: .4rem; }
dialog {
  width: min(26rem, calc(100% - 1.5rem));
  max-height: 88vh;
  border: 1px solid var(--line);
  border-radius: .95rem;
  background: var(--panel);
  color: var(--ink);
  padding: clamp(.9rem, 3vw, 1.45rem);
  box-shadow: 0 1rem 5rem #142c2252;
}
dialog::backdrop { background: #0c261ec4; }
#age-form { display: grid; gap: .65rem; }
#age-help { color: var(--muted); }
#age-error { font-size: .9rem; }
#age-input[aria-invalid="true"] { border-color: var(--red); }
.dialog-actions { display: flex; justify-content: flex-end; gap: .5rem; margin-top: .35rem; }
#gallery { width: min(55rem, calc(100% - 1.5rem)); }
.gallery-head { position: sticky; top: -1.45rem; padding: .7rem 0; background: var(--panel); border-bottom: 1px solid var(--line); }
.gallery-head p { color: var(--muted); font-size: .85rem; }
.gallery-suit { padding: .8rem 0; }
.gallery-suit + .gallery-suit { border-top: 1px solid var(--line); }
.gallery-suit[data-suit="hearts"] h3, .gallery-suit[data-suit="diamonds"] h3 { color: var(--red); }
.gallery-row { display: grid; grid-template-columns: repeat(10, minmax(0, 1fr)); gap: .38rem; margin-top: .45rem; }
.gallery-row img { display: block; width: 100%; height: auto; border-radius: .28rem; box-shadow: 0 2px 4px #2c211720; }

@media (max-width: 740px) {
  .workspace { grid-template-columns: minmax(0, 1fr); }
  .control-panel { grid-template-columns: minmax(0, 1fr) minmax(0, 2fr); align-items: start; }
  .hand-deck { flex-wrap: wrap; }
  .hand-deck button { margin-left: 0; }
  .gallery-row { grid-template-columns: repeat(5, minmax(0, 1fr)); }
}
@media (max-width: 510px) {
  .masthead { padding-block: .55rem; gap: .4rem; }
  .header-controls > a { order: 1; }
  .header-controls .quiet { padding-inline: .42rem; min-height: 2rem; }
  .intro { min-height: 11rem; padding-block: 1.15rem; gap: .2rem; }
  .intro h1 { font-size: clamp(3.1rem, 13vw, 4.6rem); }
  .sample-hand { flex-basis: 6.2rem; height: 5rem; margin-inline-end: .25rem; }
  .sample-hand img { width: 2.85rem; }
  .board-row { grid-template-columns: 3.4rem minmax(0, 1fr); }
  .row-title { padding-inline-start: .17rem; }
  .row-title::before { margin-right: .22rem; }
  .control-panel { grid-template-columns: minmax(0, 1fr); }
  .hand-deck button { margin-left: auto; }
}
