@font-face { font-family: "Press Start 2P"; src: url("assets/fonts/press-start-2p.ttf") format("truetype"); font-style: normal; font-weight: 400; font-display: swap; }
@font-face { font-family: "Space Mono"; src: url("assets/fonts/space-mono-regular.ttf") format("truetype"); font-style: normal; font-weight: 400; font-display: swap; }
@font-face { font-family: "Space Mono"; src: url("assets/fonts/space-mono-bold.ttf") format("truetype"); font-style: normal; font-weight: 700; font-display: swap; }

:root {
  --ink: #f7f0d5;
  --dark: #120b24;
  --purple: #2b1745;
  --green: #76ff8a;
  --pink: #ff4f9a;
  --gold: #ffd166;
  --cyan: #44d7e8;
}

* { box-sizing: border-box; }
html { max-width: 100%; overflow-x: hidden; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    radial-gradient(circle at 50% 8%, #40245e 0, transparent 28rem),
    linear-gradient(180deg, #120b24, #090612);
  font-family: "Space Mono", monospace;
  overflow-x: hidden;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

button { font: inherit; }

.crt {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 20;
  opacity: .18;
  background: repeating-linear-gradient(0deg, transparent 0 3px, #000 3px 4px);
  mix-blend-mode: multiply;
}

.start-screen {
  width: 100%;
  max-width: none;
  height: 100%;
  max-height: none;
  margin: 0;
  padding: max(28px, env(safe-area-inset-top)) 24px max(28px, env(safe-area-inset-bottom));
  border: 0;
  color: var(--ink);
  background:
    linear-gradient(rgba(18,11,36,.25), rgba(18,11,36,.9)),
    repeating-linear-gradient(90deg, transparent 0 47px, rgba(118,255,138,.06) 48px 49px),
    repeating-linear-gradient(0deg, transparent 0 47px, rgba(118,255,138,.06) 48px 49px),
    radial-gradient(circle at 50% 32%, #58306f, #120b24 55%);
  text-align: center;
}
.start-screen[open] { display: grid; place-items: center; }
.start-screen::backdrop { background: var(--dark); }
.start-content { position: relative; z-index: 2; width: min(620px, 100%); }
.start-logo { margin: 12px 0 24px; font-size: clamp(35px, 8vw, 74px); line-height: 1.2; text-shadow: 6px 6px 0 var(--pink), 11px 11px 0 #000; }
.start-logo span { color: var(--cyan); }
.start-tagline { color: var(--gold); font-weight: 700; letter-spacing: .12em; line-height: 1.8; }
.start-actions { width: min(330px, 100%); margin: 34px auto 0; display: grid; gap: 14px; }
.start-actions .button { width: 100%; }
.text-button { border: 0; padding: 12px; color: var(--green); background: transparent; cursor: pointer; font-weight: 700; text-decoration: underline; text-underline-offset: 5px; }
.start-version { margin-top: 34px; color: #8f79a3; font-size: 11px; letter-spacing: .12em; }
.prototype-badge { display: inline-block; margin: 0; padding: 7px 10px; color: #120b24; background: var(--green); font-weight: 800; letter-spacing: .1em; }
.prototype-note { max-width: 500px; margin: 18px auto 0; color: #d7cce0; font-size: 13px; line-height: 1.5; }
.start-art { position: fixed; inset: 0; pointer-events: none; overflow: hidden; }
.pixel-card { position: absolute; display: grid; place-items: center; width: 110px; height: 155px; border: 5px solid #18101d; color: #c71959; background: var(--ink); box-shadow: 10px 10px 0 rgba(0,0,0,.45); font-family: "Press Start 2P"; font-size: 24px; }
.card-one { left: 8%; top: 18%; transform: rotate(-14deg); }
.card-two { right: 8%; top: 23%; transform: rotate(12deg); }
.card-three { right: 14%; bottom: 10%; transform: rotate(-7deg); }

.cabinet { width: min(1120px, calc(100% - 32px)); margin: 0 auto; padding: max(28px, env(safe-area-inset-top)) 0 max(48px, env(safe-area-inset-bottom)); }
.topbar { display: flex; align-items: end; justify-content: space-between; padding-bottom: 20px; }
.header-actions { display: flex; gap: 10px; }
.eyebrow { color: var(--green); letter-spacing: .18em; font-weight: 700; margin: 0 0 8px; }
h1, h2 { font-family: "Press Start 2P", monospace; }
h1 { margin: 0; font-size: clamp(28px, 6vw, 58px); line-height: 1; text-shadow: 4px 4px 0 var(--pink); }
h1 span { color: var(--cyan); }
.icon-button, .button {
  border: 3px solid var(--ink);
  color: var(--ink);
  background: var(--purple);
  box-shadow: 5px 5px 0 #000;
  cursor: pointer;
  font-weight: 700;
  letter-spacing: .05em;
}
.icon-button { padding: 10px 12px; }
.button { padding: 14px 20px; min-width: 150px; }
.button:hover:not(:disabled), .icon-button:hover { transform: translate(2px, 2px); box-shadow: 3px 3px 0 #000; }
.button:disabled { opacity: .35; cursor: not-allowed; }
.button.primary { background: var(--pink); color: #140814; }
.button.quiet { border-color: #947fa8; }
.button.danger { color: var(--ink); background: #8f173f; border-color: var(--pink); }
.feedback-button { position: fixed; right: max(14px, env(safe-area-inset-right)); bottom: max(14px, env(safe-area-inset-bottom)); z-index: 15; padding: 10px 12px; border: 3px solid var(--dark); color: var(--dark); background: var(--green); box-shadow: 5px 5px 0 #000; cursor: pointer; font: 700 11px "Press Start 2P", monospace; }
.feedback-button:hover { transform: translate(2px, 2px); box-shadow: 3px 3px 0 #000; }
body:has(#startDialog[open]) > .feedback-button, body:has(#pauseDialog[open]) > .feedback-button { display: none; }

.hud {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  border: 4px solid var(--ink);
  box-shadow: 8px 8px 0 #000;
  background: #160d2a;
}
.hud div { padding: 13px 16px; border-right: 2px solid #5b4770; }
.hud div:last-child { border: 0; }
.hud span { display: block; color: #a892b6; font-size: 12px; }
.hud strong { display: block; color: var(--gold); font-family: "Press Start 2P"; margin-top: 7px; }
.target-meter { height: 13px; margin: 0 8px; border: 3px solid var(--ink); border-top: 0; background: #160d2a; box-shadow: 6px 6px 0 #000; }
.target-meter span { display: block; width: 0; height: 100%; background: linear-gradient(90deg, var(--pink), var(--gold)); transition: width .2s ease; }

.table {
  margin-top: 20px;
  min-height: 390px;
  padding: 28px;
  border: 4px solid #319260;
  background:
    linear-gradient(90deg, rgba(255,255,255,.025) 50%, transparent 50%) 0 0 / 12px 12px,
    #164d38;
  box-shadow: inset 0 0 0 8px #0d2f23, 8px 8px 0 #000;
}
.table-copy { display: flex; justify-content: space-between; gap: 24px; color: #b8e7c7; font-size: 13px; }
.hand-score { color: var(--gold); font-weight: 700; text-align: right; }
.piles { display: flex; justify-content: center; gap: 28px; min-height: 126px; padding-top: 12px; }
.pile { position: relative; width: 82px; height: 112px; border: 4px solid #18101d; color: #18101d; background: var(--ink); box-shadow: 6px 7px 0 rgba(0,0,0,.4); cursor: pointer; }
.pile span { display: grid; place-items: center; height: 75px; font-family: "Press Start 2P"; font-size: 15px; }
.pile small { display: block; font-size: 9px; font-weight: 700; }
.stock-pile { color: var(--green); background: repeating-linear-gradient(45deg, #25143c 0 7px, #3a2059 7px 14px); }
.discard-pile span { color: #c71959; font-size: 22px; }
.pile:disabled { opacity: .4; cursor: not-allowed; }
.pile:not(:disabled):hover { transform: translateY(-5px); }
.turn-banner { display: flex; justify-content: center; align-items: center; gap: 18px; margin: 12px auto; }
.turn-banner span { padding: 6px 9px; color: #120b24; background: var(--green); font-family: "Press Start 2P"; font-size: 10px; }
.turn-banner small { color: #b8e7c7; font-weight: 700; }
.meld-area { min-height: 74px; padding: 10px 14px; border: 2px dashed rgba(184,231,199,.4); }
.meld-area > p { margin: 0 0 8px; color: #b8e7c7; font-size: 9px; }
.laid-melds { display: flex; gap: 12px; flex-wrap: wrap; }
.meld-group { display: flex; align-items: center; gap: 3px; padding: 5px 7px; color: #18101d; background: rgba(247,240,213,.9); border-left: 5px solid var(--cyan); box-shadow: 3px 3px 0 rgba(0,0,0,.3); }
.meld-group b { color: #7a1644; font-family: "Press Start 2P"; font-size: 10px; }
.meld-group small { margin-left: 5px; color: #164d38; font-weight: 700; }
.empty-melds { color: rgba(184,231,199,.5); font-size: 10px; }
.hand { width: 100%; max-width: 100%; min-height: 205px; display: flex; justify-content: center; align-items: end; padding-top: 34px; contain: inline-size; }
.card {
  position: relative;
  width: 116px;
  height: 166px;
  margin-left: -28px;
  padding: 11px;
  border: 4px solid #1c1323;
  border-radius: 4px;
  color: #18101d;
  background: var(--ink);
  box-shadow: 7px 8px 0 rgba(0,0,0,.4);
  cursor: pointer;
  transition: transform .12s ease, filter .12s ease;
  text-align: left;
}
.card:first-child { margin-left: 0; }
.card:hover { transform: translateY(-8px); }
.card.selected { transform: translateY(-24px); background: #fff7b8; outline: 4px solid var(--pink); z-index: 2; }
.card.red { color: #c71959; }
.card-rank { font-family: "Press Start 2P"; font-size: 20px; }
.card-suit { font-size: 30px; line-height: 1.1; }
.card-center { position: absolute; inset: 0; display: grid; place-content: center; font-size: 54px; }
.card-value { position: absolute; right: 8px; bottom: 7px; font-size: 11px; font-weight: 700; }
.card-perk { position: absolute; left: 7px; bottom: 7px; max-width: 72px; padding: 3px 5px; color: #120b24; background: var(--cyan); font-size: 8px; font-weight: 700; box-shadow: 2px 2px 0 #18101d; }
.card.perk-wild { background: linear-gradient(135deg, #f7f0d5 55%, #76ff8a); }
.card.perk-foil { background: linear-gradient(135deg, #f7f0d5 35%, #86eff7 50%, #f7f0d5 65%); }
.card.perk-charged { box-shadow: 0 0 0 4px var(--gold), 7px 8px 0 rgba(0,0,0,.4); }
.card.perk-charged .card-perk { background: var(--gold); }
.card.perk-battery .card-perk { color: #f7f0d5; background: #7d47cf; }
.hand-scroll-hint { display: none; }
.perk-legend { display: flex; justify-content: center; gap: 16px; margin-top: 24px; color: #b8e7c7; font-size: 10px; flex-wrap: wrap; }
.perk-legend span { display: inline-flex; align-items: center; gap: 6px; }
.perk-dot { width: 9px; height: 9px; border: 1px solid var(--ink); }
.wild-dot { background: var(--green); }
.foil-dot { background: var(--cyan); }
.charged-dot { background: var(--gold); }
.battery-dot { background: #9a5ced; }

.controls { display: flex; justify-content: center; gap: 14px; padding: 24px 0; flex-wrap: wrap; }
.buff-strip { border-top: 2px solid #5b4770; padding-top: 15px; display: flex; gap: 18px; align-items: center; }
.buff-strip > p { color: #a892b6; font-size: 12px; white-space: nowrap; }
.buffs { display: flex; gap: 9px; flex-wrap: wrap; }
.buff-chip { padding: 8px 10px; color: var(--dark); background: var(--cyan); border: 2px solid var(--ink); font-size: 12px; font-weight: 700; }
.empty-buff { color: #786688; font-size: 13px; }

.modal { border: 0; padding: 0; background: transparent; color: var(--ink); max-width: 950px; width: calc(100% - 32px); }
.modal::backdrop { background: rgba(8, 4, 16, .88); backdrop-filter: blur(4px); }
.modal-panel { padding: 32px; border: 5px solid var(--ink); background: var(--purple); box-shadow: 12px 12px 0 #000; }
.modal h2 { line-height: 1.4; color: var(--gold); }
.choices { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; margin-top: 24px; }
.choice { min-height: 190px; padding: 18px; border: 3px solid var(--cyan); background: #160d2a; color: var(--ink); text-align: left; cursor: pointer; box-shadow: 6px 6px 0 #000; }
.choice:hover { background: #301955; transform: translateY(-4px); }
.choice-icon { display: block; font-size: 34px; color: var(--green); }
.choice strong { display: block; font-family: "Press Start 2P"; font-size: 13px; line-height: 1.5; margin: 14px 0 10px; color: var(--gold); }
.choice small { color: #d2c4dd; font-size: 13px; line-height: 1.5; }
.end-panel { max-width: 600px; margin: auto; text-align: center; }
.end-panel .button { margin-top: 18px; }
.pause-actions { display: grid; width: min(360px, 100%); margin: 12px auto 0; gap: 2px; }
.pause-actions .button { width: 100%; text-decoration: none; }
.confirm-actions { display: flex; justify-content: center; gap: 12px; flex-wrap: wrap; }
.help-panel { max-width: 650px; margin: auto; }
.help-panel li { margin: 14px 0; line-height: 1.5; }
.help-panel strong { color: var(--gold); }
.fine-print { color: #a892b6; font-size: 12px; }
.feedback-panel { max-width: 680px; margin: auto; }
.feedback-panel fieldset { margin: 20px 0; padding: 0; border: 0; }
.feedback-panel legend, .form-field { color: var(--gold); font-weight: 700; font-size: 12px; letter-spacing: .05em; }
.rating-row { display: flex; gap: 9px; margin-top: 10px; }
.rating-row input { position: absolute; opacity: 0; }
.rating-row span { display: grid; place-items: center; width: 44px; height: 44px; border: 3px solid #947fa8; color: var(--ink); background: #160d2a; cursor: pointer; }
.rating-row input:checked + span { color: #120b24; background: var(--green); border-color: var(--ink); }
.form-field { display: grid; gap: 7px; margin: 16px 0; }
.form-field select, .form-field textarea { width: 100%; border: 3px solid #947fa8; padding: 10px; color: var(--ink); background: #160d2a; font: 400 16px "Space Mono", monospace; resize: vertical; }

button:focus-visible { outline: 4px solid var(--green); outline-offset: 4px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; animation: none !important; }
  .crt { display: none; }
}

@media (max-width: 740px) {
  .pixel-card { opacity: .22; width: 86px; height: 124px; }
  .card-one { left: -20px; top: 12%; }
  .card-two { right: -25px; top: 17%; }
  .card-three { right: 8%; bottom: 4%; }
  .cabinet { width: min(100% - 20px, 1120px); }
  .topbar { align-items: center; gap: 8px; }
  .header-actions { gap: 6px; }
  .icon-button { padding: 9px; }
  .hud { grid-template-columns: repeat(2, 1fr); }
  .hud div { border-bottom: 2px solid #5b4770; }
  .hud div:last-child { grid-column: 1 / -1; }
  .table { padding: 18px 10px; min-height: 330px; }
  .table-copy { display: block; padding: 0 8px; }
  .hand-score { text-align: left; }
  .hand { overflow-x: auto; overflow-y: hidden; justify-content: flex-start; padding-left: 22px; padding-right: 22px; }
  .card { min-width: 90px; width: 90px; height: 140px; margin-left: -31px; }
  .card:first-child { margin-left: 0; }
  .hand-scroll-hint {
    display: flex;
    justify-content: center;
    gap: 10px;
    margin: 10px 0 0;
    color: var(--green);
    font: 9px "Press Start 2P", monospace;
    letter-spacing: .04em;
    text-align: center;
  }
  .hand-scroll-hint span { color: var(--gold); }
  .choices { grid-template-columns: 1fr; }
  .buff-strip { align-items: start; }
}

@media (max-width: 460px) {
  .topbar { align-items: stretch; flex-direction: column; }
  .topbar h1 { font-size: 20px; text-shadow: 3px 3px 0 var(--pink); }
  .header-actions { align-self: flex-end; flex-shrink: 0; }
  .icon-button { min-width: 38px; padding: 8px 6px; font-size: 11px; }
  .table-copy p { overflow-wrap: anywhere; }
}

@media (max-height: 700px) {
  .cabinet { padding-top: 10px; }
  .topbar { padding-bottom: 10px; }
  .topbar .eyebrow { display: none; }
  h1 { font-size: 26px; }
  .hud div { padding: 8px 10px; }
  .hud strong { margin-top: 4px; font-size: 11px; }
  .table { margin-top: 10px; min-height: 0; padding-top: 12px; }
  .table-copy { font-size: 10px; }
  .piles { min-height: 90px; padding-top: 0; }
  .pile { width: 64px; height: 86px; }
  .pile span { height: 55px; font-size: 11px; }
  .meld-area { min-height: 52px; }
  .hand { min-height: 145px; padding-top: 22px; }
  .card { min-width: 82px; width: 82px; height: 128px; }
  .perk-legend { margin-top: 12px; }
  .controls { padding: 12px 0; }
  .buff-strip { padding-top: 8px; }
  .feedback-panel { max-height: 94vh; overflow-y: auto; padding: 20px; }
}
