:root {
  color-scheme: dark;
  --background: #152527;
  --surface: #203739;
  --accent: #8bd8c8;
  --text: #f6f0e6;
  --muted: #d3cabb;
  --ink: #181613;
  --serif: "Noto Serif KR", "AppleMyungjo", "Batang", serif;
  font-family: Pretendard, -apple-system, BlinkMacSystemFont, "Malgun Gothic", sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  min-width: 0;
  color: var(--text);
  background: radial-gradient(ellipse at 50% 28%, #324b48, #142322 51%, #0b1517 100%);
}
button { color: inherit; font: inherit; cursor: pointer; }
button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
button:disabled { cursor: default; }
p, h1, h2 { margin: 0; }

/* One continuous room: the canvas behind the page draws the wall under the title and the
   table under the cards and seats, so no section gets its own band or border. */
.shell {
  position: relative;
  isolation: isolate;
  max-width: 480px;
  min-height: 100svh;
  margin-inline: auto;
  padding-bottom: max(10px, env(safe-area-inset-bottom));
  background: #1d1922;
  box-shadow: 0 0 70px #0711149c;
}
.room-layer {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}
#room { z-index: -2; }
#hand { z-index: 3; }
/* Shade the top of the wall so the title reads without a header bar. */
.shell::before {
  content: "";
  position: absolute;
  z-index: -1;
  inset: 0 0 auto;
  height: 150px;
  background: linear-gradient(#0d0a10d9, #0d0a1080 55%, #0d0a1000);
  pointer-events: none;
}
.masthead, .intro { position: relative; z-index: 4; text-shadow: 0 1px 6px #0a080dcc; }
.masthead {
  min-height: 50px;
  padding: max(2px, env(safe-area-inset-top)) 16px 2px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.brand { font-family: var(--serif); font-weight: 700; font-size: 19px; letter-spacing: .08em; }
.quiet {
  min-height: 44px;
  padding: 0 6px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  font-size: .8125rem;
  color: var(--muted);
}
.quiet:hover { color: var(--text); }
.intro { padding: 9px 16px 10px; }
.master { color: var(--accent); font-size: .75rem; letter-spacing: .055em; font-weight: 650; }
h1 { margin-top: 2px; font: 700 clamp(1.5rem, 6vw, 1.875rem)/1.2 var(--serif); }
.prompt { margin-top: 4px; font-size: .875rem; line-height: 1.35; color: var(--muted); }

.tableau {
  position: relative;
  height: clamp(144px, 26svh, 196px);
}
.tableau[data-layout="floor"] { height: clamp(108px, 20svh, 172px); }
.deck {
  touch-action: none;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  position: absolute;
  z-index: 2;
  top: 49%;
  left: 50%;
  translate: -50% -50%;
  display: grid;
  place-items: center;
  width: 66px;
  height: 69px;
}
.deck, .candidate, .picked {
  padding: 0;
  border: none;
  background: transparent;
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
}
.card-art {
  display: block;
  position: relative;
  flex: none;
  aspect-ratio: 11 / 14;
  border: 1px solid #d7ad7c;
  border-radius: 9%;
  box-shadow: 0 4px 10px #080a0ad6, inset 0 0 0 2px #211920;
  overflow: hidden;
}
.back {
  background:
    radial-gradient(circle at 26% 23%, #f2d5a0 0 1px, transparent 1.7px),
    radial-gradient(circle at 73% 23%, #b4d6bc 0 1px, transparent 1.7px),
    radial-gradient(circle at 26% 76%, #b4d6bc 0 1px, transparent 1.7px),
    radial-gradient(circle at 73% 76%, #f2d5a0 0 1px, transparent 1.7px),
    linear-gradient(145deg, transparent 40%, #459285 41% 43%, #255952 44% 47%, #b57a68 48% 49%, transparent 50%),
    linear-gradient(35deg, transparent 41%, #b57a68 42% 43%, #2b5d58 45% 53%, #459285 54% 56%, transparent 57%),
    radial-gradient(ellipse at 45% 40%, #562c47, #321d35 73%);
}
.back::after {
  content: "";
  position: absolute;
  inset: 8%;
  border: 1px solid #d7ad7c8a;
  border-radius: 8%;
}
.deck-card {
  width: 45px;
  height: auto;
  transform: rotate(-12deg) skewX(-8deg) scaleY(.8);
  transition: transform .18s ease;
  box-shadow: 2px 3px #a88d6f, 4px 6px #4d3444, 5px 8px #a88d6f, 0 12px 14px #150d12bb;
}
.deck[data-holding] .deck-card { transform: translateY(-5px) rotate(-8deg) skewX(-4deg) scaleY(.93); }
.tableau[data-phase="shuffling"] .deck-card { animation: shuffle .31s ease-in-out both; }
@keyframes shuffle {
  25% { transform: translate(-8px, -6px) rotate(-28deg); }
  60% { transform: translate(7px, -10px) rotate(14deg); }
  100% { transform: translateY(-2px) rotate(-5deg); }
}

.fan {
  position: absolute;
  z-index: 2;
  inset: auto clamp(6px, calc(10vw - 26px), 12px) 0;
  display: grid;
  grid-template-columns: repeat(7, minmax(44px, 1fr));
  height: 84px;
  overflow-x: clip;
  overflow-y: visible;
}
@media (max-width: 319px) { .fan { overflow-x: auto; } }
.candidate {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 84px;
  isolation: isolate;
  touch-action: manipulation;
}
.candidate .card-art {
  width: 47px;
  transform: translateY(var(--drop)) rotate(var(--turn));
  transition: transform .18s ease;
  pointer-events: none;
}
.candidate:is(:focus-visible, [data-preview]) { z-index: 1; outline-offset: -2px; border-radius: 6px; }
.candidate[data-preview] { outline: 2px solid var(--accent); }
.candidate:is(:focus-visible, [data-preview]) .card-art { transform: translateY(-7px); }

.shell[data-full-deck] {
  height: 100dvh;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-rows: auto minmax(0, 1fr) auto;
  padding-bottom: max(2px, env(safe-area-inset-bottom));
}
.shell[data-full-deck] .masthead {
  grid-area: 1 / 1 / 2 / -1;
  min-height: 44px;
  padding: env(safe-area-inset-top) 10px 0;
  justify-content: flex-end;
}
.shell[data-full-deck] .brand { display: none; }
.shell[data-full-deck] .intro {
  grid-area: 1 / 1 / 2 / -1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 2px;
  padding: env(safe-area-inset-top) 108px 0 10px;
  pointer-events: none;
}
.shell[data-full-deck] .intro h1 { font-size: 1.125rem; line-height: 1.1; margin: 0; }
.shell[data-full-deck] .intro .master { order: 1; font-size: .6875rem; }
.shell[data-full-deck] .prompt, .shell[data-full-deck] footer { display: none; }
.shell[data-full-deck] .tableau {
  --portrait-height: clamp(28px, 5svh, 42px);
  grid-area: 2 / 1 / 3 / -1;
  height: auto;
}
.shell[data-view="staggered"][data-full-deck] .fan {
  inset: var(--portrait-height) 3px 0;
  height: auto;
  padding: 2px 0;
  grid-template-columns: repeat(14, minmax(0, 1fr));
  grid-template-rows: repeat(12, minmax(0, 1fr));
  gap: 1px;
  overflow: clip;
}
.shell[data-view="staggered"] .tableau[data-count="3"] .candidate {
  grid-column: span 2;
  min-width: 0;
  min-height: 0;
  grid-template: minmax(0, 1fr) / minmax(0, 1fr);
}
/* Every pair has a centered six-card row followed by a full seven-card row. */
.shell[data-view="staggered"] .tableau[data-count="3"] .candidate:nth-child(13n + 1) { grid-column: 2 / span 2; }
.shell[data-view="staggered"] .tableau[data-count="3"] .candidate .card-art {
  width: auto;
  max-width: calc(100% - 2px);
  height: calc(100% - 2px);
  transform: none;
}
.shell[data-view="staggered"] .tableau[data-count="3"] .candidate[data-taken] {
  opacity: .35;
  border: 1px dashed #d3cabb6b;
  border-radius: 8px;
}

/* Ribbon spread: 78 cards laid in three overlapping arcs on the master's table. */
.shell[data-view="ribbon"][data-full-deck] .tableau { --portrait-height: clamp(64px, 17svh, 150px); }
.shell[data-view="ribbon"][data-full-deck] .intro .master { display: none; }
.shell[data-view="ribbon"][data-full-deck] .prompt {
  display: block;
  margin: 0;
  font-size: .75rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.shell[data-view="ribbon"][data-full-deck] .fan {
  inset: var(--portrait-height) 0 0;
  height: auto;
  display: block;
  overflow: clip;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}
.shell[data-view="ribbon"] .tableau[data-count="3"] .candidate {
  position: absolute;
  display: block;
  min-height: 0;
  rotate: var(--rot, 0deg);
  transform-origin: 50% 100%;
  touch-action: none;
}
.shell[data-view="ribbon"] .tableau[data-count="3"] .candidate .card-art {
  width: 100%;
  height: 100%;
  aspect-ratio: auto;
  border-radius: 5px;
  box-shadow: -1px 2px 4px #0b090dbb, inset 0 0 0 2px #211920;
  transition: transform .12s ease-out;
}
.shell[data-view="ribbon"] .tableau[data-count="3"] .back::after { border-radius: 3px; inset: 7% 9%; }
.shell[data-view="ribbon"] .tableau[data-count="3"] .candidate:is([data-preview], :focus-visible) {
  z-index: 100;
  outline: none;
}
.shell[data-view="ribbon"] .tableau[data-count="3"] .candidate:is([data-preview], :focus-visible) .card-art {
  transform: translateY(-22%) scale(1.16);
  border-color: var(--accent);
  box-shadow: 0 10px 16px #07080ad9, inset 0 0 0 2px #211920, 0 0 0 2px var(--accent);
}
.ribbon-hint {
  position: absolute;
  z-index: 4;
  top: calc(var(--portrait-height) + 6px);
  inset-inline: 16px;
  font-size: .75rem;
  line-height: 1.3;
  text-align: center;
  color: var(--muted);
  text-shadow: 0 1px 4px #0a080dcc;
  pointer-events: none;
  transition: opacity .2s ease;
}
.ribbon-hint[data-faded], .tableau[data-dealing] .ribbon-hint { opacity: 0; }

/* The guest's seats are spots on the same table, nearest the guest. */
.landing {
  height: 126px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  position: relative;
  z-index: 5;
}
.tableau[data-phase="intro"] + .landing { display: none; }
.seat { position: relative; display: grid; justify-items: center; align-content: start; width: min(27%, 92px); height: 111px; }
.seat-label { margin-top: 3px; font-size: .6875rem; text-align: center; line-height: 1.15; color: var(--muted); }
.seat[data-active] .seat-label { color: var(--accent); }
.seat[data-active] .place { border-color: var(--accent); }
.place {
  display: grid;
  place-items: center;
  width: 72px;
  height: 92px;
  border: 1px solid #e3b79147;
  border-radius: 7px;
  color: var(--muted);
  background: radial-gradient(ellipse, #f6dcb514, #f6dcb505 70%);
  box-shadow: inset 0 0 12px #0b080e66;
  font-size: .75rem;
}
.picked {
  position: absolute;
  inset: 0 auto auto 50%;
  translate: -50% 0;
  display: grid;
  place-items: center;
  width: 78px;
  height: 92px;
  z-index: 2;
  border-radius: 8px;
  perspective: 450px;
}
.picked .card-art { width: 72px; transform: translateZ(0); }
.picked .front {
  background:
    linear-gradient(#1d4148 10%, #38565a 45%, #873d57 46%, #53263f 86%);
  display: grid;
  place-items: center;
}
.front::before {
  content: "";
  position: absolute;
  inset: 9%;
  border: 1px solid #f8d4ab75;
  background:
    linear-gradient(72deg, #132733 0 27%, transparent 28%) bottom right / 45% 38% no-repeat,
    linear-gradient(107deg, #162d36 0 39%, transparent 40%) bottom left / 48% 51% no-repeat;
}
.face-symbol { position: relative; color: #f5d4a2; font: 2rem/1 Georgia, serif; align-self: start; margin-top: 23%; }
.face-name { position: absolute; bottom: 9%; font: 700 .75rem/1 var(--serif); color: #f6f0e6; }

.controls { padding: 8px 16px 0; }
.instruction {
  display: grid;
  align-content: center;
  min-height: 34px;
  margin-bottom: 6px;
  font-size: .8125rem;
  line-height: 1.3;
  color: var(--muted);
}
.primary {
  width: 100%;
  min-height: 48px;
  padding: 6px 12px;
  color: var(--ink);
  font-size: .9375rem;
  font-weight: 750;
  border: 1px solid transparent;
  border-radius: 9px;
  background: var(--accent);
}
.primary:hover:enabled { background: #a1e2d5; }
.primary:disabled { border-color: #8bd8c85c; color: var(--text); background: #1d1922cc; }
.action-row { display: flex; gap: 8px; }
.alternate { background: transparent; border-color: var(--accent); color: var(--accent); }
.alternate:hover:enabled { color: var(--ink); }
.shell[data-full-deck] .landing {
  grid-area: 3 / 1;
  height: 70px;
  gap: 2px;
  justify-content: space-evenly;
}
.shell[data-full-deck] .seat { height: 66px; width: min(31%, 82px); }
.shell[data-full-deck] .picked, .shell[data-full-deck] .place { height: 48px; width: 38px; }
.shell[data-full-deck] .picked .card-art { width: 36px; }
.shell[data-full-deck] .seat-label { font-size: .625rem; white-space: nowrap; }
.shell[data-full-deck] .controls {
  grid-area: 3 / 2;
  display: flex;
  align-items: center;
  min-width: 90px;
  padding: 0 6px;
}
.shell[data-full-deck] .instruction {
  position: absolute;
  width: 1px;
  height: 1px;
  min-height: 0;
  overflow: hidden;
  clip-path: inset(50%);
}
.shell[data-full-deck] .primary { min-height: 44px; white-space: nowrap; padding-inline: 8px; font-size: .8125rem; }
.shell[data-full-deck] .controls:has(.primary:disabled) .instruction {
  position: static;
  clip-path: none;
  width: min(24vw, 90px);
  height: auto;
  margin: 0;
  font-size: .75rem;
}
.shell[data-full-deck] .controls:has(.primary:disabled) .action-row { display: none; }
.result { padding: 12px 16px 0; font-size: .875rem; line-height: 1.5; }
.result h2 { font: 700 1.375rem/1.2 var(--serif); color: var(--accent); margin-bottom: 4px; }
.result .next { margin-top: 4px; color: var(--muted); }
.result .reset { margin-top: 3px; text-decoration: underline; text-underline-offset: 3px; }
footer { padding: 10px 16px 0; font-size: .6875rem; color: var(--muted); text-align: center; }
.tableau[data-phase="result"], .tableau[data-count="3"][data-phase="result"] { height: 92px; }

.shell[data-still] *, .shell[data-still] *::before, .shell[data-still] *::after {
  animation-duration: 0s !important;
  transition-duration: 0s !important;
}
@media (max-height: 620px) {
  .shell { padding-bottom: max(6px, env(safe-area-inset-bottom)); }
  .intro {
    display: grid;
    grid-template-columns: 1fr auto;
    align-items: baseline;
    padding-block: 5px;
  }
  .intro h1 { grid-area: 1 / 1; }
  .intro .master { grid-area: 1 / 2; }
  .intro .prompt { grid-column: 1 / -1; }
  .landing { height: 105px; }
  .seat { height: 98px; }
  .picked, .place { height: 81px; }
  .picked .card-art, .place { width: 63px; }
  .controls { padding-top: 4px; }
  .tableau[data-phase="result"], .tableau[data-count="3"][data-phase="result"] { height: 62px; }
  .result { padding-top: 8px; }
  footer { padding-top: 4px; }
}
