:root {
  --paper: #efede8;
  --paper-light: #f8f6f1;
  --ink: #342721;
  --muted: #71635c;
  --line: #493a33;
  --pink: #d894a7;
  --pink-light: #f1d2db;
  --lemon: #e9d539;
  --navy: #27364d;
  --success: #527a5c;
  --danger: #a34242;
}

* { box-sizing: border-box; }
html, body { min-width: 0; min-height: 100%; margin: 0; }
body {
  min-height: 100dvh;
  overflow-x: hidden;
  background: var(--paper);
  color: var(--ink);
  font-family: Arial, Helvetica, system-ui, sans-serif;
}
button, a { color: inherit; font: inherit; }
button { min-height: 44px; cursor: pointer; }
button:disabled { cursor: default; opacity: .45; }
button:focus-visible, a:focus-visible { outline: 3px solid var(--navy); outline-offset: 3px; }

.game-shell {
  display: grid;
  width: min(100%, 72rem);
  min-height: 100dvh;
  margin: 0 auto;
  padding: max(.4rem, env(safe-area-inset-top)) max(.65rem, env(safe-area-inset-right)) max(.5rem, env(safe-area-inset-bottom)) max(.65rem, env(safe-area-inset-left));
  grid-template-rows: auto auto 1fr auto;
}

.game-header {
  display: grid;
  min-height: 42px;
  grid-template-columns: 4.5rem 1fr 7rem;
  align-items: center;
  border-bottom: 2px solid var(--line);
}
.game-header h1 { margin: 0; font-family: "Arial Black", Arial, sans-serif; font-size: clamp(1rem, 5vw, 1.45rem); letter-spacing: -.04em; text-align: center; }
.home-link, .text-button { display: inline-flex; min-height: 44px; align-items: center; border: 0; background: transparent; font-size: .68rem; font-weight: 900; letter-spacing: .08em; text-decoration: none; }
.text-button { justify-self: end; padding: 0; }

.score-strip { display: grid; min-height: 46px; grid-template-columns: repeat(4, 1fr); border-bottom: 1px solid var(--line); }
.score-strip p { display: flex; margin: 0; padding: .25rem .35rem; flex-direction: column; align-items: center; justify-content: center; border-right: 1px solid color-mix(in srgb, var(--line) 35%, transparent); }
.score-strip p:last-child { border-right: 0; }
.score-strip span { color: var(--muted); font-size: .56rem; font-weight: 900; letter-spacing: .08em; }
.score-strip strong { font-family: "Arial Black", Arial, sans-serif; font-size: 1.05rem; line-height: 1; }

.game-main { display: grid; min-height: 0; padding-top: .45rem; gap: .45rem; grid-template-rows: 26px auto auto minmax(0, 1fr); }
.stage-track { display: grid; margin: 0; padding: 0; grid-template-columns: repeat(3, 1fr); gap: .3rem; list-style: none; }
.stage-track li { display: grid; min-width: 0; place-items: center; border: 1px solid var(--line); border-radius: .3rem; color: var(--muted); font-size: .6rem; font-weight: 900; letter-spacing: .08em; }
.stage-track li.is-current { background: var(--lemon); color: var(--ink); }
.stage-track li.is-done { background: var(--pink-light); color: var(--ink); }

.order-panel { position: relative; min-width: 0; padding: .45rem .55rem .5rem; border: 2px solid var(--line); border-radius: .45rem; background: var(--paper-light); }
.order-heading { display: flex; align-items: center; justify-content: space-between; }
.order-heading h2, .shelf-heading h2 { margin: 0; font-size: .67rem; font-weight: 950; letter-spacing: .08em; }
.order-stamp { color: var(--pink); font-size: 1rem; transform: rotate(9deg); }
.order-cards { display: grid; margin-top: .3rem; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: .35rem; }
.order-card { display: flex; min-width: 0; height: 55px; align-items: end; justify-content: center; overflow: hidden; border: 1px solid var(--line); border-radius: .28rem; background: #e7e1d9; }
.order-card img { width: 100%; height: 100%; object-fit: contain; }
.order-sticker { display: flex; margin: .32rem 0 0; align-items: center; gap: .35rem; color: var(--muted); font-size: .6rem; font-weight: 900; letter-spacing: .07em; }
.order-sticker strong { color: var(--ink); }
.sticker-swatch, .sticker-dot { display: inline-block; border: 1px solid var(--line); border-radius: 50%; background: var(--sticker-color, var(--pink)); }
.sticker-swatch { width: 15px; height: 15px; }

.pack-panel { display: grid; min-width: 0; grid-template-columns: minmax(0, 1fr) minmax(8.4rem, .8fr); gap: .45rem; }
.sleeve-wrap, .action-wrap { min-width: 0; padding: .4rem; border: 1px solid var(--line); border-radius: .45rem; background: #e4ded6; }
.small-label { margin: 0 0 .25rem; color: var(--muted); font-size: .56rem; font-weight: 900; letter-spacing: .08em; }
.sleeves { display: grid; min-height: 68px; padding: .3rem; grid-template-columns: repeat(3, 1fr); gap: .3rem; border: 2px solid color-mix(in srgb, var(--line) 75%, transparent); border-radius: .35rem; background: color-mix(in srgb, var(--paper-light) 70%, transparent); }
.sleeves.is-drop-target { background: var(--pink-light); }
.sleeve-slot { display: grid; min-width: 0; place-items: center; overflow: hidden; border: 1px dashed var(--muted); border-radius: .25rem; color: var(--muted); font-size: .72rem; font-weight: 900; }
.sleeve-slot.is-filled { border-style: solid; background: var(--paper-light); }
.sleeve-slot img { width: 100%; height: 100%; object-fit: contain; }
.action-wrap { display: grid; gap: .35rem; grid-template-rows: 1fr 44px; }
.sticker-buttons { display: grid; grid-template-columns: repeat(3, 1fr); gap: .2rem; }
.sticker-buttons button { display: flex; min-width: 0; min-height: 44px; padding: .15rem; flex-direction: column; align-items: center; justify-content: center; gap: .15rem; border: 1px solid var(--line); border-radius: .3rem; background: var(--paper-light); font-size: .48rem; font-weight: 900; }
.sticker-dot { width: 17px; height: 17px; }
.sticker-pink { --sticker-color: var(--pink); }
.sticker-lemon { --sticker-color: var(--lemon); }
.sticker-navy { --sticker-color: var(--navy); }
.seal-button, .start-button { min-height: 44px; border: 2px solid var(--line); border-radius: .35rem; background: var(--lemon); font-weight: 950; letter-spacing: .04em; }

.shelf { min-height: 0; padding: .4rem; border: 2px solid var(--line); border-radius: .45rem; background: var(--paper-light); }
.shelf-heading { display: flex; min-height: 18px; align-items: baseline; justify-content: space-between; gap: .5rem; }
.shelf-heading p { margin: 0; color: var(--muted); font-size: .48rem; font-weight: 800; text-align: right; }
.card-grid { display: grid; min-height: 0; margin-top: .3rem; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: .32rem; }
.card-choice { position: relative; display: grid; min-width: 0; min-inline-size: 44px; min-height: 68px; padding: 0; place-items: end center; overflow: hidden; touch-action: none; user-select: none; -webkit-user-select: none; border: 1px solid var(--line); border-radius: .32rem; background: #e7e1d9; transition: transform 100ms ease, background-color 100ms ease; }
.card-choice img { width: 100%; height: 100%; object-fit: contain; pointer-events: none; }
.card-choice:active, .card-choice.is-dragging { transform: translateY(2px) scale(.97); background: var(--pink-light); }
.card-choice.is-packed::after { position: absolute; inset: 0; display: grid; place-items: center; background: color-mix(in srgb, var(--success) 68%, transparent); color: var(--paper-light); content: "PACKED"; font-size: .5rem; font-weight: 950; letter-spacing: .06em; }

.live-status { min-height: 22px; margin: .3rem 0 0; padding: .18rem .5rem; border-radius: .3rem; background: var(--ink); color: var(--paper-light); font-size: .65rem; font-weight: 900; letter-spacing: .04em; text-align: center; }
.live-status[data-kind="bad"] { background: var(--danger); }
.live-status[data-kind="good"] { background: var(--success); }
.game-shell.is-rejecting .pack-panel { outline: 3px solid var(--danger); outline-offset: -3px; }
.game-shell.is-success .order-panel { outline: 3px solid var(--success); outline-offset: -3px; }

.screen { position: fixed; z-index: 10; inset: 0; display: flex; padding: max(1rem, env(safe-area-inset-top)) max(1rem, env(safe-area-inset-right)) max(1rem, env(safe-area-inset-bottom)) max(1rem, env(safe-area-inset-left)); flex-direction: column; align-items: center; justify-content: center; background: var(--paper); text-align: center; }
.screen[hidden] { display: none; }
.intro-screen > p, .game-over-screen > p { max-width: 28rem; margin: .45rem 0; font-size: .72rem; font-weight: 900; letter-spacing: .08em; }
.intro-screen h2, .game-over-screen h2 { margin: .3rem 0; font-family: "Arial Black", Arial, sans-serif; font-size: clamp(3.7rem, 18vw, 7rem); letter-spacing: -.08em; line-height: .75; }
.intro-envelope { position: relative; display: grid; width: 118px; height: 82px; place-items: center; border: 3px solid var(--line); background: var(--paper-light); }
.intro-envelope::before { position: absolute; inset: 0; clip-path: polygon(0 0, 50% 62%, 100% 0); background: var(--pink-light); content: ""; }
.intro-envelope span { z-index: 1; color: var(--pink); font-size: 1.5rem; }
.start-button { width: min(17rem, 80vw); min-height: 54px; margin-top: 1.1rem; background: var(--lemon); font-size: 1.05rem; }
.screen-nav { position: absolute; top: max(.25rem, env(safe-area-inset-top)); right: max(1rem, env(safe-area-inset-right)); left: max(1rem, env(safe-area-inset-left)); display: flex; min-height: 48px; align-items: center; justify-content: space-between; }
.screen-nav a, .screen-nav button { display: inline-flex; min-width: 48px; min-height: 48px; padding: 0; align-items: center; border: 0; background: transparent; color: var(--ink); font-size: .68rem; font-weight: 900; letter-spacing: .08em; text-decoration: none; }
.screen-nav button { justify-content: flex-end; }
.final-score { display: grid; width: min(22rem, 90vw); margin: 1rem 0 0; grid-template-columns: repeat(3, 1fr); }
.final-score div { border-right: 1px solid var(--line); }
.final-score div:last-child { border-right: 0; }
.final-score dt { color: var(--muted); font-size: .62rem; font-weight: 900; }
.final-score dd { margin: .25rem 0 0; font-family: "Arial Black", Arial, sans-serif; font-size: 1.7rem; }

.how-dialog { width: min(34rem, calc(100% - 2rem)); max-height: calc(100dvh - 2rem); padding: 1rem; overflow: auto; border: 2px solid var(--line); border-radius: .5rem; background: var(--paper-light); color: var(--ink); }
.how-dialog::backdrop { background: rgb(52 39 33 / .7); }
.dialog-top { display: flex; align-items: center; justify-content: space-between; border-bottom: 2px solid var(--line); }
.dialog-top h2 { margin: 0; font-family: "Arial Black", Arial, sans-serif; font-size: 1.4rem; }
.dialog-top button { border: 0; background: transparent; font-size: .7rem; font-weight: 900; }
.how-dialog ol { margin: 1rem 0; padding: 0; list-style: none; }
.how-dialog li { display: grid; min-height: 58px; grid-template-columns: 5rem 4.5rem 1fr; align-items: center; border-bottom: 1px solid color-mix(in srgb, var(--line) 35%, transparent); }
.how-dialog li b { font-size: .72rem; }
.how-dialog li p, .penalty-note { margin: 0; color: var(--muted); font-size: .8rem; line-height: 1.35; }
.help-cards, .help-sticker, .help-envelope { color: var(--pink); font-size: 1.4rem; }
.penalty-note { font-weight: 700; }

@media (min-width: 48rem) {
  .game-main { grid-template-columns: minmax(13rem, .7fr) minmax(22rem, 1.4fr); grid-template-rows: 28px auto minmax(0, 1fr); }
  .stage-track { grid-column: 1 / -1; }
  .order-panel { grid-column: 1; grid-row: 2 / 4; }
  .order-cards { grid-template-columns: 1fr; }
  .order-card { height: clamp(68px, 10vh, 95px); }
  .pack-panel { grid-column: 2; grid-row: 2; }
  .shelf { grid-column: 2; grid-row: 3; }
  .card-grid { grid-template-columns: repeat(8, 1fr); }
}

@media (orientation: landscape) and (max-height: 30rem) {
  .game-shell { height: 100dvh; padding-top: max(.2rem, env(safe-area-inset-top)); padding-bottom: max(.2rem, env(safe-area-inset-bottom)); overflow: hidden; grid-template-rows: 44px 38px 1fr 20px; }
  .game-header { min-height: 44px; }
  .home-link, .text-button { min-height: 44px; }
  .score-strip { min-height: 38px; }
  .score-strip p { flex-direction: row; gap: .3rem; }
  .game-main { padding-top: .3rem; gap: .3rem; grid-template-columns: 145px minmax(210px, 1fr) 210px; grid-template-rows: 22px minmax(0, 1fr); }
  .stage-track { grid-column: 1 / -1; }
  .order-panel { grid-column: 1; grid-row: 2; padding: .3rem; }
  .order-cards { grid-template-columns: repeat(3, 1fr); gap: .2rem; }
  .order-card { height: 64px; }
  .pack-panel { grid-column: 2; grid-row: 2; grid-template-columns: 1fr; grid-template-rows: 1fr 56px; gap: .25rem; }
  .sleeve-wrap { padding: .28rem; }
  .sleeves { min-height: 75px; height: calc(100% - 14px); }
  .action-wrap { padding: .2rem; grid-template-columns: 1fr 112px; grid-template-rows: 1fr; }
  .sticker-buttons button { min-height: 44px; }
  .seal-button { min-height: 44px; }
  .shelf { grid-column: 3; grid-row: 2; padding: .3rem; }
  .shelf-heading { display: block; }
  .shelf-heading p { margin-top: .1rem; font-size: .42rem; text-align: left; }
  .card-grid { height: calc(100% - 30px); grid-template-columns: repeat(4, 1fr); grid-template-rows: repeat(2, minmax(0, 1fr)); gap: .2rem; }
  .card-choice { min-height: 44px; }
  .live-status { min-height: 20px; margin-top: 0; padding: .1rem; }
  .intro-screen { display: grid; grid-template-columns: 130px 1fr 160px; grid-template-rows: auto auto auto; column-gap: 1rem; }
  .intro-envelope { grid-column: 1; grid-row: 1 / 4; }
  .intro-screen h2 { grid-column: 2; grid-row: 1 / 3; font-size: clamp(3rem, 9vw, 5rem); }
  .intro-screen > p:first-of-type { display: none; }
  .intro-screen > p:last-of-type { grid-column: 2; grid-row: 3; }
  .intro-screen .start-button { grid-column: 3; grid-row: 1 / 4; width: 150px; margin: 0; }
}

@media (max-width: 23rem) {
  .game-shell { padding-right: max(.4rem, env(safe-area-inset-right)); padding-left: max(.4rem, env(safe-area-inset-left)); }
  .pack-panel { grid-template-columns: minmax(0, 1fr) 7.8rem; }
  .order-card { height: 50px; }
  .card-choice { min-height: 62px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; }
}

.sent-splash:not([hidden]) { position: fixed; z-index: 100; inset: 0; display: grid; min-height: 100dvh; place-items: center; align-content: center; gap: 1rem; padding: max(18px, env(safe-area-inset-top)) max(18px, env(safe-area-inset-right)) max(18px, env(safe-area-inset-bottom)) max(18px, env(safe-area-inset-left)); background: var(--paper-light); color: var(--ink); text-align: center; }
.sent-card-art { position: relative; width: min(78vw, 520px); padding: clamp(1rem, 4vw, 2.4rem); border: 3px solid var(--ink); background: var(--paper); transform: rotate(-2deg); }
.sent-splash-cards { display: flex; min-height: clamp(180px, 38vh, 360px); align-items: end; justify-content: center; gap: .4rem; }
.sent-splash-cards img { width: 30%; height: 100%; object-fit: contain; }
.sent-splash-sticker { position: absolute; right: 8%; top: 8%; width: 54px; height: 54px; border: 2px solid var(--ink); border-radius: 50%; background: var(--sticker-color, var(--pink)); }
.sent-splash h2 { margin: 0; font-size: clamp(3rem, 12vw, 8rem); line-height: .8; }
@media (orientation: portrait) {
  .sent-card-art { width: min(92vw, 520px); }
  .sent-splash-cards { min-height: min(44vh, 360px); }
  .sent-splash-cards img { width: 38%; margin-inline: -2.5%; }
}
@media (prefers-reduced-motion: reduce) { .sent-card-art { transform: none; } }
