:root {
  color-scheme: dark;
  font-family: system-ui, sans-serif;
  color: #f7eee7;
  background: #100c0d;
  --ink: #100c0d;
  --panel: #1c1517;
  --muted: #c5aeb0;
  --red: #ff6359;
  --red-hover: #ff8376;
  --line: #584047;
  --paper: #f3e6d7;
  --display: Impact, Haettenschweiler, "Avenir Next Condensed", "Arial Narrow", system-ui, sans-serif;
  --mono: ui-monospace, "Cascadia Mono", Menlo, monospace;
  --hazard: repeating-linear-gradient(128deg, var(--red) 0 10px, #2e191d 10px 20px);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  min-height: 100vh;
  background: radial-gradient(ellipse at 74% 24%, #2b1216 0%, transparent 57%), var(--ink);
}

game-navigation { --game-nav-padding: 12px 24px; }

main {
  width: min(1120px, 100% - 40px);
  margin-inline: auto;
  padding-block: clamp(22px, 5vw, 76px);
}

.front {
  display: grid;
  grid-template: "headline art" 1fr "controls art" 1fr / minmax(0, 1.18fr) minmax(0, 1fr);
  position: relative;
  overflow: hidden;
  isolation: isolate;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: linear-gradient(140deg, #24171b, #171113 62%);
  box-shadow: 0 24px 65px #0008;
}

.front::before {
  content: "";
  position: absolute;
  z-index: 2;
  inset: 0 0 auto;
  height: 5px;
  background: linear-gradient(90deg, var(--red) 0 22%, transparent 22%), var(--hazard);
  pointer-events: none;
}

.masthead {
  grid-area: headline;
  align-self: end;
  padding: clamp(25px, 5vw, 66px) clamp(20px, 4vw, 48px) 0;
}

h1, .room-brand {
  margin: 0;
  font-family: var(--display);
  font-stretch: condensed;
  font-weight: 800;
  text-transform: uppercase;
}

h1 {
  font-size: clamp(2.2rem, 6.5vw, 5.85rem);
  line-height: .95;
  letter-spacing: .005em;
}

h1 span, .room-brand span { color: var(--red); }
h2 { margin: 0 0 10px; font-size: clamp(1.22rem, 2.6vw, 1.65rem); line-height: 1.15; letter-spacing: -.035em; overflow-wrap: anywhere; }
.masthead p { margin: 14px 0 0; font-size: clamp(.95rem, 2.2vw, 1.13rem); color: var(--muted); }

.deck-art {
  grid-area: art;
  position: relative;
  min-height: 100%;
  background: #1d0f10;
  border-left: 1px solid #7a3d3c;
  overflow: hidden;
}

.deck-art img { position: absolute; width: 100%; height: 100%; object-fit: cover; object-position: center; }

.deck-art::after {
  content: "";
  position: absolute;
  inset: 0;
  box-shadow: inset 0 0 30px #100c0d55;
  pointer-events: none;
}

.home { grid-area: controls; min-width: 0; padding: 22px clamp(20px, 4vw, 48px) clamp(25px, 5vw, 62px); }
#menu { display: grid; gap: 10px; max-width: 390px; }

#menu button {
  position: relative;
  min-height: 55px;
  padding-inline: 16px 44px;
  text-align: left;
}

#menu button::after {
  content: "";
  position: absolute;
  right: 18px;
  top: calc(50% - 5px);
  width: 9px;
  height: 9px;
  border-top: 2px solid currentColor;
  border-right: 2px solid currentColor;
  transform: rotate(45deg);
}

#home form { display: grid; gap: 11px; }
#home h2 { margin-bottom: 0; }
label { display: grid; gap: 5px; min-width: 0; color: #f7eee7; font-size: .9rem; font-weight: 650; }

input, select, button {
  min-height: 46px;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 9px 12px;
  font: inherit;
}

input, select { width: 100%; min-width: 0; background: #130e10; color: #f7eee7; border-color: #77575d; font-size: 1rem; }

button {
  cursor: pointer;
  background: var(--red);
  color: var(--ink);
  font-weight: 800;
  box-shadow: 0 2px 0 #0005;
  transition: background-color 150ms, border-color 150ms, box-shadow 150ms;
}

button:hover:enabled { background: var(--red-hover); }
button:active:enabled { box-shadow: inset 0 2px 2px #0004; }
button:disabled { cursor: default; background: #3b292c; color: #d1b6b7; box-shadow: none; }

button:focus-visible, input:focus-visible, select:focus-visible {
  outline: 2px solid #ffad9f;
  outline-offset: 3px;
}

#menu #open-join, .back-to-menu, .secondary {
  border-color: #77575d;
  background: #25191d;
  color: #f7eee7;
}

#menu #open-join:hover, .back-to-menu:hover, .secondary:hover:enabled { background: #3b2428; }

#room {
  width: min(100%, 960px);
  margin-inline: auto;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: radial-gradient(ellipse at 50% 15%, #27171b, #1b1416 70%);
  box-shadow: 0 20px 50px #0008;
  padding: 0 clamp(12px, 3.5vw, 32px) clamp(15px, 3.5vw, 32px);
}

.room-top {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 3px 14px;
  padding-block: 15px 11px;
  border-bottom: 1px solid var(--line);
}

.room-brand { font-size: 1.35rem; letter-spacing: .035em; line-height: 1; }
.meta { color: var(--muted); font: 650 .78rem/1.25 var(--mono); overflow-wrap: anywhere; }

.scores {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  list-style: none;
  padding: 0;
  margin: 10px 0 16px;
}

.score {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 4px 9px;
  max-width: 100%;
  padding: 5px 8px;
  border: 1px solid #64474e;
  border-radius: 6px;
  background: #24191d;
}

.your-score { border-color: #ac625f; background: #332024; }
.score-name { color: #eddbd9; font-size: .81rem; overflow-wrap: anywhere; }
.score-value { color: #ff9788; font: 800 .85rem/1 var(--mono); }
.score .meter { grid-column: 1 / -1; }
.meter { display: block; height: 3px; overflow: hidden; border-radius: 3px; background: #62434b; }
.meter::before { content: ""; display: block; width: var(--fill); height: 100%; border-radius: inherit; background: var(--red); }

#stage > p { margin: 9px 0; color: var(--muted); }
#room[data-phase="lobby"] #stage { text-align: center; }

.room-share {
  display: grid;
  grid-template-columns: 46px minmax(0, auto) 46px;
  justify-content: center;
  align-items: stretch;
  gap: 6px 8px;
  margin-top: 14px;
  text-align: center;
}

.room-code-label, #stage .copy-status { grid-column: 1 / -1; margin: 0; color: var(--muted); font-size: .82rem; }
.room-code, .copy-link { border-color: #a65b59; background: #321c22; color: #fff0e9; }
.room-code:hover:enabled, .copy-link:hover:enabled { background: #482429; }

.room-code {
  grid-column: 2;
  padding: 9px 13px;
  color: #fff1e8;
  font: 800 clamp(1.55rem, 7vw, 2.9rem)/1 var(--mono);
  letter-spacing: .12em;
}

.copy-link { display: grid; place-items: center; padding: 0; }
.copy-status input { width: min(100%, 350px); }
.start-game { margin-top: 15px; min-width: min(180px, 100%); }
.secondary { margin-top: 12px; }

.prompt {
  position: relative;
  display: grid;
  align-content: center;
  width: 100%;
  min-height: 86px;
  padding: 16px 19px;
  border: 1px solid #b25759;
  border-radius: 10px;
  color: #fff3ea;
  background: linear-gradient(125deg, #51242a, #2f181e);
  box-shadow: 0 3px 0 #100a0e;
  font-size: clamp(1.17rem, 3.2vw, 1.95rem);
  font-weight: 800;
  line-height: 1.22;
  overflow-wrap: anywhere;
}

.prompt-cover, .prompt-opened::before {
  padding-block: 16px;
  border: 0;
  border-block: 7px solid transparent;
  border-image: var(--hazard) 1;
  background: radial-gradient(ellipse at 53% 52%, #3c1b21, #221318 72%);
  text-align: center;
}

.prompt-cover { place-content: center; gap: 7px; min-height: clamp(150px, 27vh, 240px); }
button.prompt-cover:hover:enabled { background: radial-gradient(ellipse at 53% 52%, #552329, #2b171c 72%); }
.cover-title, .prompt-opened::before {
  color: var(--red);
  font: 800 clamp(2.75rem, 9vw, 6rem)/1 var(--display);
  letter-spacing: .09em;
  text-shadow: 2px 3px #14090c, 0 0 28px #ff625a49;
}

.cover-caption { color: #f6e4de; font-size: clamp(.85rem, 2.5vw, 1rem); font-weight: 650; }
.prompt-opened { animation: card-turn 470ms ease-in-out both; }
.prompt-opened::before {
  content: "KEEP OUT" / "";
  position: absolute;
  inset: -1px;
  display: grid;
  place-content: center;
  border-block-width: 4px;
  padding: 0;
  font-size: clamp(1.65rem, 5vw, 3rem);
  pointer-events: none;
  animation: uncover 470ms step-end both;
}

.submission-progress {
  display: grid;
  grid-template-columns: auto minmax(35px, 1fr);
  align-items: center;
  gap: 8px;
  max-width: 245px;
  margin-block: 12px 4px;
  font-size: .82rem;
  font-weight: 750;
  color: var(--muted);
}

.submission-progress .meter { height: 5px; }

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 142px), 1fr));
  gap: 10px;
  margin: 12px 0;
}

.cards:empty { display: none; }

.card {
  position: relative;
  display: grid;
  align-content: center;
  min-height: 90px;
  padding: 13px 14px;
  border: 1px solid #e4beab;
  border-radius: 8px;
  color: #2c171b;
  background: linear-gradient(145deg, #fff4e8, var(--paper));
  box-shadow: 0 3px 0 #a7877c, 0 5px 9px #0a060650;
  font-size: 1rem;
  font-weight: 800;
  line-height: 1.17;
  text-align: left;
  overflow-wrap: anywhere;
}

button.card:hover:enabled { background: #fff4eb; border-color: #fa8f84; }

.card.selected, button.card.selected:hover:enabled {
  color: #2a1014;
  background: #ffb6a6;
  border-color: #ff8073;
  box-shadow: 0 3px 0 #923f43, inset 0 0 0 2px #b74549;
}

.card.back, .flip::before {
  display: grid;
  place-items: center;
  color: #ff9d8f;
  background:
    linear-gradient(125deg, transparent 43%, #9e353b67 43% 51%, transparent 51% 56%, #9e353b50 56% 60%, transparent 60%),
    linear-gradient(155deg, #32191e, #211316);
  border-color: #945052;
  font: 850 clamp(.68rem, 1.9vw, .87rem)/1.12 var(--mono);
  letter-spacing: .12em;
  text-align: center;
}

.card.back { animation: seal 210ms ease-out both; }
@keyframes seal { from { opacity: 0; transform: translateY(4px) scale(.97); } }

.flip { animation: card-turn 570ms ease-in-out both; }
.flip::before {
  content: "SEALED" / "";
  position: absolute;
  inset: -1px;
  border: 1px solid #a05252;
  border-radius: inherit;
  pointer-events: none;
  animation: uncover 570ms step-end both;
}

@keyframes card-turn {
  from, to { transform: perspective(750px) rotateY(0); }
  49% { transform: perspective(750px) rotateY(90deg); }
  50% { transform: perspective(750px) rotateY(-90deg); }
}
@keyframes uncover { 50%, to { visibility: hidden; } }

.card.winning-card { animation: verdict-glow 750ms ease-out; }

.winner-stamp {
  justify-self: start;
  max-width: 100%;
  margin-top: 7px;
  padding: 4px 5px;
  border: 2px solid currentColor;
  border-radius: 2px;
  color: #8d222a;
  font: 900 .72rem/1 var(--mono);
  letter-spacing: .06em;
  text-align: center;
  animation: stamp 330ms cubic-bezier(.17, .9, .4, 1.2) both;
}

@keyframes stamp {
  from { opacity: 0; transform: scale(1.38) rotate(-11deg); }
  to { opacity: 1; transform: scale(1) rotate(-3deg); }
}
@keyframes verdict-glow { from { box-shadow: 0 0 28px #fb625b9e, inset 0 0 0 2px #b74549; } }
body:has(#final-result[open]) .winning-card,
body:has(#final-result[open]) .winner-stamp { animation-play-state: paused; }

#error { margin: 10px 0 0; color: #ff9d90; font-weight: 700; }
#error:empty { display: none; }

#final-result {
  --verdict-accent: var(--red);
  width: min(475px, 100% - 26px);
  max-height: calc(100dvh - 20px);
  overflow: auto;
  padding: clamp(17px, 4.5vw, 31px);
  border: 1px solid #a45b5b;
  border-top: 5px solid var(--verdict-accent);
  border-radius: 9px;
  color: #f7eee7;
  background: radial-gradient(ellipse at top right, #482028, #24171b 70%);
  box-shadow: 0 15px 80px #000a;
}

#final-result[open] { animation: verdict-in 280ms cubic-bezier(.2, .8, .25, 1) both; }
#final-result[data-outcome="win"] { --verdict-accent: #ffd0aa; box-shadow: 0 0 55px #f0464145, 0 16px 80px #000a; }
#final-result[data-outcome="reader"] { --verdict-accent: #ef9c8b; }
#final-result::backdrop { background: #0d080be0; backdrop-filter: blur(4px); }

#final-result h2 { margin: 0; font-size: clamp(1.64rem, 7vw, 2.8rem); line-height: 1.02; }
#final-result p { margin: 12px 0 16px; font-size: clamp(.96rem, 3vw, 1.14rem); overflow-wrap: anywhere; }
#final-result #result-detail { color: var(--verdict-accent); font-weight: 750; margin-bottom: 0; }
#final-result button { width: 100%; }
@keyframes verdict-in { from { opacity: 0; transform: translateY(8px) scale(.96); } }

@media (min-width: 900px) {
  .front { min-height: 490px; }
  #create, #join { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  #home h2, #create label:first-of-type { grid-column: 1 / -1; }
}

@media (max-width: 690px) {
  main { width: min(100% - 26px, 540px); }
  .front { grid-template: "headline" auto "art" auto "controls" auto / minmax(0, 1fr); }
  .masthead { padding-bottom: 15px; }
  h1 { font-size: clamp(2.35rem, 11vw, 5rem); }
  .masthead p { margin-top: 7px; }
  .deck-art { min-height: 0; height: min(68vw, 290px); border: 0; border-block: 1px solid #7a3d3c; }
  .home { padding-top: 15px; }
  #menu { max-width: none; }
  .front:has(#menu[hidden]) .deck-art { display: none; }
}

@media (orientation: landscape) and (min-width: 568px) {
  .cards { grid-template-columns: repeat(auto-fit, minmax(95px, 1fr)); }
  .answer-controls .cards { grid-template-columns: repeat(5, minmax(0, 1fr)); }
}

@media (orientation: landscape) and (min-width: 568px) and (max-height: 500px) {
  game-navigation { --game-nav-padding: 2px 16px; }
  main { width: min(960px, 100% - 28px); padding-block: 8px; }
  .front { min-height: 0; grid-template: "headline art" 1fr "controls art" 1fr / minmax(0, 1.2fr) minmax(0, 1fr); border-radius: 11px; }
  .front:has(#menu[hidden]) { grid-template: "headline" auto "controls" auto / minmax(0, 1fr); }
  .front:has(#menu[hidden]) .deck-art { display: none; }
  .masthead { padding: 13px 14px 0; }
  h1 { font-size: clamp(1.6rem, 5vw, 2.7rem); }
  .masthead p { margin-top: 4px; font-size: .86rem; }
  .home { padding: 9px 14px 13px; }
  .deck-art { min-height: 100%; height: auto; border: 0; border-left: 1px solid #7a3d3c; }
  #menu { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; }
  #menu button { min-height: 46px; padding-inline: 8px 20px; font-size: .86rem; }
  #menu button::after { right: 9px; height: 6px; width: 6px; }
  #home form { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 5px 8px; }
  #home #create { grid-template-columns: minmax(0, 1fr) minmax(0, 1.5fr) minmax(0, .7fr); }
  #home h2 { grid-column: 1 / -1; }
  #create label:first-of-type { grid-column: auto; }
  #create .back-to-menu { grid-column: 2 / -1; }
  #home label { gap: 2px; }
  #room { border-radius: 10px; padding: 0 9px 8px; }
  .room-top { padding-block: 5px; }
  .room-brand { font-size: .95rem; }
  .meta { font-size: .72rem; }
  #stage h2, #home h2 { margin-bottom: 4px; font-size: 1.05rem; }
  #stage > p { margin-block: 4px; font-size: .86rem; }
  .scores { flex-wrap: nowrap; gap: 4px; margin: 3px 0 5px; overflow-x: auto; }
  .score { flex: 0 0 auto; max-width: 142px; padding: 3px 5px; gap: 1px 5px; }
  .score-name { font-size: .72rem; }
  .score-value { font-size: .75rem; }
  .prompt { min-height: 46px; padding: 6px 9px; font-size: 1.06rem; line-height: 1.15; }
  .prompt-cover { min-height: 98px; border-block-width: 5px; gap: 3px; }
  .cover-title { font-size: clamp(1.9rem, 7vw, 3.5rem); }
  .submission-progress { margin-block: 4px 3px; }
  .cards { grid-template-columns: repeat(auto-fit, minmax(82px, 1fr)); gap: 5px; margin: 5px 0 7px; }
  .card { min-height: 46px; padding: 5px; font-size: .88rem; line-height: 1.1; }
  .answer-controls { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: start; gap: 6px; margin-top: 4px; }
  .answer-controls .cards { margin: 0 0 4px; }
  .answer-controls > button { font-size: .85rem; padding-inline: 7px; }
  .room-share { margin-top: 7px; }
  .room-code { font-size: 1.6rem; }
  .start-game, .secondary { margin-top: 8px; }
  #final-result p { margin-block: 7px 10px; }
}

@media (orientation: landscape) and (min-width: 568px) and (max-width: 650px) and (max-height: 500px) {
  .answer-controls .card { padding-inline: 4px; font-size: .8rem; font-weight: 750; hyphens: auto; }
  .answer-controls > button { max-width: 70px; }
}

@media (prefers-reduced-motion: reduce) {
  .card, .winner-stamp, .prompt-opened, #final-result[open] { animation: none; }
  .flip::before, .prompt-opened::before { display: none; }
  button { transition: none; }
}
