*,
*::before,
*::after {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  color-scheme: dark;
  background: #000;
}

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  background: #000;
}

body {
  display: grid;
  place-items: center;
  font-family: "Segoe UI", system-ui, sans-serif;
  color: #fff;
  user-select: none;
  -webkit-user-select: none;
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

#app {
  position: relative;
  width: min(100vw, 520px);
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  background: #000;
}

#stage,
.bg,
#flash {
  position: absolute;
  inset: 0;
}

#stage {
  z-index: 0;
}

.bg {
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: center center;
  opacity: 0;
  pointer-events: none;
}

#flash {
  z-index: 1;
  pointer-events: none;
  opacity: 0;
}

#flash.good {
  background: #39ff7a;
  animation: wash 0.45s ease;
}

#flash.bad {
  background: #ff2a2a;
  animation: wash 0.45s ease;
}

@keyframes wash {
  0% { opacity: 0.38; }
  100% { opacity: 0; }
}

#stage.shake {
  animation: shake 0.42s linear;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  15% { transform: translateX(-8px); }
  30% { transform: translateX(7px); }
  45% { transform: translateX(-6px); }
  60% { transform: translateX(4px); }
  75% { transform: translateX(-2px); }
}

#hud {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 4;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: calc(12px + env(safe-area-inset-top)) 18px 28px;
  background: linear-gradient(to bottom, rgba(0, 0, 0, 0.72), rgba(0, 0, 0, 0));
  pointer-events: none;
}

.stat {
  min-width: 0;
}

.stat-right {
  text-align: right;
}

.label {
  display: block;
  margin-bottom: 2px;
  font-family: Impact, "Arial Black", "Segoe UI", sans-serif;
  font-size: 13px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: #ff3b3b;
  text-shadow: 0 2px 6px #000;
}

.stat strong {
  display: inline-block;
  font-family: Impact, "Arial Black", "Segoe UI", sans-serif;
  font-size: clamp(28px, 8vw, 40px);
  font-weight: 400;
  letter-spacing: 0.03em;
  line-height: 1;
  color: #fff;
  font-variant-numeric: tabular-nums;
  text-shadow: 0 2px 0 #000, 0 6px 14px #000;
  transition: color 0.2s ease;
}

.stat-right strong {
  max-width: 62vw;
}

.stat strong.up { color: #3dff7a; }
.stat strong.down { color: #ff4b4b; }

.stat strong.bump {
  animation: bump 0.28s ease;
}

@keyframes bump {
  40% { transform: scale(1.16); }
}

#delta {
  position: absolute;
  left: 50%;
  top: 52%;
  z-index: 3;
  transform: translate(-50%, -50%);
  opacity: 0;
  pointer-events: none;
  font-family: Impact, "Arial Black", "Segoe UI", sans-serif;
  font-size: clamp(52px, 16vw, 84px);
  letter-spacing: 0.02em;
  line-height: 1;
  text-shadow:
    0 3px 0 #000,
    3px 0 0 #000,
    -3px 0 0 #000,
    0 -2px 0 #000,
    0 10px 20px rgba(0, 0, 0, 0.7);
}

#delta.up { color: #3dff7a; }
#delta.down { color: #ff3030; }

#delta.show {
  animation: slam 0.42s cubic-bezier(0.2, 1.4, 0.3, 1) forwards;
}

@keyframes slam {
  0% { opacity: 0; transform: translate(-50%, -42%) scale(0.55); }
  60% { opacity: 1; transform: translate(-50%, -50%) scale(1.08); }
  100% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}

#play {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 4;
  max-height: 48%;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  gap: 8px;
  overflow: hidden;
  padding: 18px 16px calc(36px + env(safe-area-inset-bottom));
  background: linear-gradient(to top, rgba(0, 0, 0, 0.94) 62%, rgba(0, 0, 0, 0));
  transition: opacity 0.25s ease, transform 0.25s ease;
}

#play.out {
  opacity: 0;
  transform: translateY(18px);
}

#scenario-wrap {
  overflow: auto;
  flex: 1 1 auto;
  min-height: 0;
  scrollbar-width: none;
}

#scenario-wrap::-webkit-scrollbar {
  display: none;
}

#day-note,
#scenario-title {
  margin: 0 0 6px;
  text-align: center;
  color: #ff4d4d;
  font-family: Impact, "Arial Black", sans-serif;
  letter-spacing: 0.08em;
  line-height: 1.15;
  text-transform: uppercase;
  text-shadow: 0 2px 6px #000;
}

#day-note { font-size: 13px; }

#scenario-title {
  font-size: clamp(15px, 4vw, 18px);
}

#scenario-text,
#outcome-text {
  margin: 0;
  text-align: center;
  font-size: clamp(15px, 3.8vw, 18px);
  font-weight: 700;
  line-height: 1.35;
  text-shadow: 0 2px 8px #000;
}

#outcome-text { margin-top: 8px; }
#outcome-text.good { color: #b6ffc9; }
#outcome-text.bad { color: #ffc1c1; }

#choices {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.choice {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 46px;
  padding: 8px 10px;
  border-radius: 14px;
  border: 2px solid rgba(255, 255, 255, 0.9);
  background: rgba(16, 16, 16, 0.92);
  color: #fff;
  text-align: left;
  touch-action: manipulation;
}

.choice:focus-visible,
#start-btn:focus-visible,
#next-btn:focus-visible,
#again-btn:focus-visible {
  outline: 3px solid #fff;
  outline-offset: 2px;
}

.choice:active {
  transform: scale(0.985);
}

.choice-key {
  flex: 0 0 28px;
  height: 28px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: #e10600;
  font-family: Impact, "Arial Black", sans-serif;
  font-size: 16px;
  letter-spacing: 0.04em;
}

.choice-text {
  flex: 1;
  font-size: 15px;
  font-weight: 700;
  line-height: 1.25;
}

.choice.win {
  border-color: #3dff7a;
  background: #102616;
}

.choice.win .choice-key { background: #1c8a42; }

.choice.lose {
  border-color: #ff3b3b;
  background: #2c1010;
}

.choice.lose .choice-key { background: #8d1d1d; }

.choice.dim { opacity: 0.38; }

#next-btn,
#again-btn,
#start-btn {
  border: 3px solid #fff;
  background: #ff1a1a;
  color: #fff;
  font-family: Impact, "Arial Black", "Segoe UI", sans-serif;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  box-shadow: 0 5px 0 #6a0000;
  touch-action: manipulation;
}

#next-btn,
#again-btn {
  width: 100%;
  min-height: 52px;
  border-radius: 14px;
  font-size: 22px;
}

#next-btn:active,
#again-btn:active,
#start-btn:active {
  transform: translateY(3px);
  box-shadow: 0 2px 0 #6a0000;
}

#intro {
  position: absolute;
  inset: 0;
  z-index: 5;
  pointer-events: none;
}

.intro-stack {
  position: absolute;
  left: 50%;
  bottom: 11%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  opacity: 0;
  transform: translateX(-50%) translateY(16px);
  transition: opacity 0.45s ease, transform 0.45s ease;
  pointer-events: none;
}

.intro-stack.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
  pointer-events: auto;
}

#intro-best {
  font-family: Impact, "Arial Black", sans-serif;
  font-size: 14px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: #fff;
  text-shadow: 0 2px 8px #000;
}

#start-btn {
  min-width: 190px;
  min-height: 58px;
  padding: 12px 36px;
  border-radius: 999px;
  font-size: 32px;
}


#gameover {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 6;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 0 18px calc(32px + env(safe-area-inset-bottom));
  text-align: center;
  background: linear-gradient(to top, rgba(0, 0, 0, 0.88) 55%, rgba(0, 0, 0, 0));
  opacity: 0;
  transform: translateY(12px);
  transition: opacity 0.45s ease, transform 0.45s ease;
}

#gameover.show {
  opacity: 1;
  transform: none;
}

#gameover h1 {
  margin: 0;
  font-family: Impact, "Arial Black", sans-serif;
  font-size: clamp(28px, 8vw, 36px);
  font-weight: 400;
  letter-spacing: 0.06em;
  line-height: 0.95;
  text-transform: uppercase;
  text-shadow: 0 3px 0 #9d0000, 0 8px 16px #000;
}

#over-days,
#over-best {
  margin: 0;
  font-family: Impact, "Arial Black", sans-serif;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  text-shadow: 0 2px 8px #000;
}

#over-days {
  font-size: clamp(16px, 4.5vw, 22px);
}

#over-story {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 4;
  overflow: hidden;
  margin: 2px 0 0;
  max-width: 36em;
  font-size: 13px;
  font-weight: 700;
  line-height: 1.35;
  color: #ffd0d0;
  text-shadow: 0 2px 8px #000;
}

#over-best {
  font-size: 14px;
  color: #ffe14a;
  letter-spacing: 0.16em;
}

#again-btn {
  margin-top: 4px;
  min-height: 46px;
  font-size: 20px;
}

#announce {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

@media (max-height: 700px) {
  #play { max-height: 46%; }
  .stat strong { font-size: 26px; }
  #delta { font-size: 44px; top: 62%; }
  #gameover h1 { font-size: 36px; }
  #start-btn { min-height: 48px; font-size: 26px; }
}

@media (prefers-reduced-motion: reduce) {
  .bg,
  #play,
  #gameover,
  .intro-stack,
  .stat strong {
    transition: none !important;
    animation: none !important;
  }

  #delta.show,
  #flash.good,
  #flash.bad,
  #stage.shake,
  .stat strong.bump {
    animation: none !important;
  }

  #delta.show { opacity: 1; }
}

body.spectator button {
  pointer-events: none;
  cursor: default;
}

#credit {
  position: fixed;
  left: 50%;
  bottom: 0;
  z-index: 50;
  width: min(100vw, 520px);
  margin: 0;
  padding: 6px 12px calc(8px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  text-align: center;
  pointer-events: auto;
}

#credit a {
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  line-height: 1.3;
  text-decoration: none;
  text-shadow: 0 1px 6px #000;
}

#credit a:hover,
#credit a:focus-visible {
  color: #ff4d4d;
  text-decoration: underline;
}

#gate,
#watch-wait {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  background: #000;
  padding: 24px;
}

.gate-card {
  width: min(100%, 340px);
  text-align: center;
}

.gate-kicker,
.gate-card h1,
.gate-label {
  font-family: Impact, "Arial Black", "Segoe UI", sans-serif;
  font-weight: 400;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.gate-kicker {
  margin: 0 0 8px;
  color: #ff3b3b;
  font-size: 14px;
}

.gate-card h1 {
  margin: 0;
  font-size: 48px;
  text-shadow: 0 3px 0 #9d0000;
}

.gate-label {
  display: block;
  margin-top: 18px;
  color: #fff;
  font-size: 13px;
}

#gate-pass {
  display: block;
  width: 100%;
  margin: 12px 0 14px;
  padding: 14px 16px;
  border: 2px solid #fff;
  border-radius: 14px;
  background: #111;
  color: #fff;
  font-size: 18px;
  letter-spacing: 0.18em;
  text-align: center;
  user-select: text;
  -webkit-user-select: text;
}

#gate-pass:focus-visible {
  outline: 3px solid #ff1a1a;
  outline-offset: 2px;
}

#gate-go {
  width: 100%;
  min-height: 52px;
  border: 3px solid #fff;
  border-radius: 14px;
  background: #ff1a1a;
  color: #fff;
  font-family: Impact, "Arial Black", "Segoe UI", sans-serif;
  font-size: 22px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  box-shadow: 0 5px 0 #6a0000;
}

#gate-go:active {
  transform: translateY(3px);
  box-shadow: 0 2px 0 #6a0000;
}

#gate-error,
.gate-wait {
  margin: 14px 0 0;
  font-weight: 700;
}

#gate-error { color: #ff4d4d; }

.gate-wait {
  color: #fff;
  line-height: 1.4;
}

#gate.deny .gate-card {
  animation: shake 0.42s linear;
}

#home-nav {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 2;
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: calc(10px + env(safe-area-inset-top)) 10px 0;
  pointer-events: none;
}

#home-nav a {
  flex: 1 1 0;
  display: grid;
  place-items: center;
  min-height: 40px;
  padding: 8px 10px;
  border: 2px solid #fff;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.78);
  color: #fff;
  font-family: Impact, "Arial Black", "Segoe UI", sans-serif;
  font-size: 13px;
  font-weight: 400;
  letter-spacing: 0.06em;
  line-height: 1.05;
  text-align: center;
  text-decoration: none;
  text-transform: uppercase;
  pointer-events: auto;
}

#home-nav a:active {
  transform: translateY(2px);
}

#score-box {
  width: min(100%, 280px);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

#name-btn,
#share-x,
#name-save {
  width: 100%;
  min-height: 40px;
  border: 3px solid #fff;
  border-radius: 14px;
  background: #ff1a1a;
  color: #fff;
  font-family: Impact, "Arial Black", "Segoe UI", sans-serif;
  font-size: 18px;
  letter-spacing: 0.08em;
  text-align: center;
  text-decoration: none;
  text-transform: uppercase;
  box-shadow: 0 4px 0 #6a0000;
}

#share-x {
  display: grid;
  place-items: center;
}

#name-form {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

#name-input {
  width: 100%;
  padding: 12px 14px;
  border: 2px solid #fff;
  border-radius: 14px;
  background: #111;
  color: #fff;
  font-size: 16px;
  text-align: center;
  user-select: text;
  -webkit-user-select: text;
}

#name-note {
  margin: 0;
  font-size: 13px;
  font-weight: 700;
  color: #b6ffc9;
}

#name-error {
  margin: 0;
  font-size: 13px;
  font-weight: 700;
  color: #ffb4b4;
}

body.spectator #score-box {
  display: none !important;
}

html:has(body.page),
html:has(body.page) body {
  height: auto;
  overflow: auto;
}

body.page {
  display: block;
  min-height: 100%;
  user-select: text;
  -webkit-user-select: text;
}

body.page #credit {
  position: static;
  left: auto;
  bottom: auto;
  width: 100%;
  transform: none;
  padding: 8px 12px calc(16px + env(safe-area-inset-bottom));
}

.sheet {
  width: min(100%, 640px);
  margin: 0 auto;
  padding: calc(18px + env(safe-area-inset-top)) 16px calc(64px + env(safe-area-inset-bottom));
}

.page-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 18px;
}

.page-nav a,
.page-btn {
  display: inline-grid;
  place-items: center;
  min-height: 36px;
  padding: 8px 12px;
  border: 2px solid #fff;
  border-radius: 999px;
  color: #fff;
  font-family: Impact, "Arial Black", "Segoe UI", sans-serif;
  font-size: 13px;
  letter-spacing: 0.06em;
  text-align: center;
  text-decoration: none;
  text-transform: uppercase;
}

.page-nav a[aria-current="page"] {
  background: #ff1a1a;
}

.page-kicker,
.sheet h1,
fieldset legend,
.rank {
  font-family: Impact, "Arial Black", "Segoe UI", sans-serif;
  font-weight: 400;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.page-kicker {
  margin: 0;
  color: #ff3b3b;
  font-size: 14px;
}

.sheet h1 {
  margin: 6px 0 0;
  font-size: clamp(36px, 10vw, 56px);
  line-height: 0.95;
  text-shadow: 0 3px 0 #9d0000;
}

.page-lead {
  margin: 12px 0 18px;
  color: #ddd;
  font-weight: 700;
  line-height: 1.4;
}

#scenario-form,
.card,
#board-list li {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

#scenario-form label,
.choice-block {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

#scenario-form input,
#scenario-form textarea,
#name-input {
  font-family: "Segoe UI", system-ui, sans-serif;
  text-transform: none;
  letter-spacing: 0;
  font-weight: 600;
}

#scenario-form input,
#scenario-form textarea {
  width: 100%;
  padding: 12px 14px;
  border: 2px solid #fff;
  border-radius: 14px;
  background: #111;
  color: #fff;
  font-size: 16px;
}

#scenario-form textarea {
  min-height: 96px;
  resize: vertical;
}

fieldset {
  margin: 0;
  padding: 12px;
  border: 2px solid rgba(255, 255, 255, 0.35);
  border-radius: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

fieldset legend {
  padding: 0 6px;
  color: #ff3b3b;
}

#submit-scenario,
.page-btn {
  min-height: 52px;
  border: 3px solid #fff;
  border-radius: 14px;
  background: #ff1a1a;
  box-shadow: 0 5px 0 #6a0000;
  font-size: 22px;
}

.page-btn {
  color: #fff;
}

.form-note {
  margin: 0;
  font-weight: 700;
  color: #b6ffc9;
}

.form-note.is-error {
  color: #ffb4b4;
}

.card {
  margin-bottom: 14px;
  padding: 14px;
  border: 2px solid rgba(255, 255, 255, 0.4);
  border-radius: 16px;
  background: #0c0c0c;
}

.card h2,
.rank {
  margin: 0;
}

.card h2 {
  font-size: 22px;
}

.card p,
.choice-block p {
  margin: 0;
  font-weight: 700;
  line-height: 1.35;
  text-transform: none;
  letter-spacing: 0;
}

.choice-block strong,
.card .rank {
  color: #ff3b3b;
}

.votes {
  display: flex;
  gap: 8px;
}

.vote {
  flex: 1;
  min-height: 42px;
  border: 2px solid #fff;
  border-radius: 12px;
  background: #161616;
  font-family: Impact, "Arial Black", "Segoe UI", sans-serif;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.vote.is-on {
  background: #ff1a1a;
}

#board-list {
  margin: 0;
  padding: 0;
  list-style: none;
}

#board-list li {
  padding: 12px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.18);
}

#board-list strong {
  font-family: Impact, "Arial Black", "Segoe UI", sans-serif;
  font-size: 22px;
  font-weight: 400;
  letter-spacing: 0.04em;
}

#board-list span {
  color: #ddd;
  font-weight: 700;
}
