:root {
  color-scheme: dark;
  --ink: #f4e8ca;
  --muted: #a9a0b6;
  --night: #080b1c;
  --amber: #f3b23c;
}

* { box-sizing: border-box; }

html, body {
  width: 100%;
  min-height: 100%;
}

body {
  display: grid;
  margin: 0;
  overflow: hidden;
  place-items: center;
  color: var(--ink);
  background:
    radial-gradient(circle at 50% 25%, rgba(88, 54, 112, .3), transparent 34rem),
    repeating-linear-gradient(0deg, rgba(255,255,255,.012) 0 1px, transparent 1px 4px),
    #070918;
  font-family: "Courier New", ui-monospace, monospace;
  overscroll-behavior: none;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: .2;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 160 160' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.2'/%3E%3C/svg%3E");
  mix-blend-mode: soft-light;
}

button { -webkit-tap-highlight-color: transparent; }

.game-shell {
  width: min(100vw, 56.25svh);
  height: 100svh;
}

.game-frame {
  position: relative;
  overflow: hidden;
  width: 100%;
  height: 100%;
  background: #11142d;
  border-inline: 1px solid rgba(218, 194, 170, .22);
  box-shadow: 0 0 70px rgba(0,0,0,.72);
}

.game-frame::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 4;
  pointer-events: none;
  background: repeating-linear-gradient(0deg, transparent 0 3px, rgba(6,8,20,.1) 3px 4px);
  box-shadow: inset 0 0 65px rgba(3,4,14,.42);
}

#game {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

.screen {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: max(30px, env(safe-area-inset-top)) 28px max(90px, env(safe-area-inset-bottom));
  text-align: center;
  background: linear-gradient(180deg, rgba(8,9,26,.42), rgba(8,9,26,.72) 42%, rgba(8,9,26,.46));
  transition: opacity .22s ease, visibility .22s ease;
}

.screen.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.eyebrow {
  display: flex;
  align-items: center;
  gap: 10px;
  color: #d9bc8f;
  font-size: clamp(7px, 1.7vw, 10px);
  letter-spacing: .2em;
  white-space: nowrap;
}

.eyebrow span { width: 28px; height: 1px; background: #8d704e; }
.eyebrow.danger { color: #df7585; }

.start-screen h1 {
  margin: 12px 0 10px;
  color: #f5e9d0;
  font-size: clamp(52px, 15vw, 82px);
  line-height: .88;
  letter-spacing: -.09em;
  text-shadow: 5px 5px 0 #30203b, 8px 8px 0 rgba(0,0,0,.3);
}

.start-screen h1 span,
.game-over h2 span { color: var(--amber); }

.tagline {
  margin: 5px 0 28px;
  color: #b8afbd;
  font-size: clamp(8px, 2.15vw, 11px);
  line-height: 1.75;
  letter-spacing: .06em;
}

.hero-card {
  display: flex;
  align-items: center;
  width: min(310px, 84%);
  padding: 10px 15px 10px 10px;
  margin-bottom: 24px;
  text-align: left;
  background: rgba(15,18,39,.84);
  border: 1px solid rgba(229,202,162,.22);
  clip-path: polygon(8px 0, 100% 0, 100% calc(100% - 8px), calc(100% - 8px) 100%, 0 100%, 0 8px);
}

.hero-portrait {
  flex: 0 0 auto;
  width: 62px;
  height: 58px;
  margin-right: 14px;
  background: url('assets/kai-chibi-lowres-sheet-v2.png') left 18.8% center / 800% auto no-repeat;
  image-rendering: pixelated;
  filter: saturate(.85) contrast(1.08);
  clip-path: inset(2px);
}

.hero-card small,
.hero-card span {
  display: block;
  color: #8b8497;
  font-size: 7px;
  letter-spacing: .16em;
}

.hero-card strong {
  display: block;
  margin: 4px 0;
  font-size: 18px;
  letter-spacing: .08em;
}

.hero-card span { color: #c0a477; }

.pixel-button {
  position: relative;
  width: min(285px, 84%);
  min-height: 48px;
  padding: 14px 20px;
  border: 0;
  color: var(--ink);
  background: #22253f;
  box-shadow: inset 0 0 0 2px rgba(255,255,255,.12), 4px 4px 0 rgba(5,6,16,.55);
  clip-path: polygon(8px 0, 100% 0, 100% calc(100% - 8px), calc(100% - 8px) 100%, 0 100%, 0 8px);
  font: 700 11px/1 "Courier New", monospace;
  letter-spacing: .11em;
  cursor: pointer;
  transition: transform .12s ease, filter .12s ease;
}

.pixel-button.primary {
  color: #201825;
  background: var(--amber);
  box-shadow: inset 0 -5px 0 #bd762d, 4px 4px 0 rgba(5,6,16,.55);
}

.pixel-button.ghost {
  margin-top: 10px;
  background: rgba(25,27,51,.82);
  border: 1px solid rgba(244,232,202,.2);
}

.pixel-button:active { transform: translate(2px, 2px); }
.pixel-button span { margin-right: 8px; }

.auto-hint {
  display: flex;
  align-items: center;
  gap: 9px;
  margin-top: 19px;
  color: #aaa36e;
  font-size: 8px;
  letter-spacing: .17em;
}

.auto-dot {
  width: 7px;
  height: 7px;
  background: #a8b75d;
  box-shadow: 0 0 9px #a8b75d;
  animation: pulse 1.3s steps(2, end) infinite;
}

@keyframes pulse { 50% { opacity: .35; } }

.icon-button {
  position: absolute;
  top: max(16px, env(safe-area-inset-top));
  z-index: 5;
  width: 38px;
  height: 38px;
  color: #d4c8bd;
  background: rgba(12,14,33,.78);
  border: 1px solid rgba(244,232,202,.24);
  font: bold 15px monospace;
  cursor: pointer;
}

.sound-button { right: 62px; }
.pause-button { right: 16px; }
.icon-button:active { color: #211927; background: var(--amber); }

.pause-screen h2,
.game-over h2 {
  margin: 15px 0 34px;
  font-size: clamp(48px, 14vw, 72px);
  line-height: .9;
  letter-spacing: -.06em;
  text-shadow: 5px 5px 0 #2d213b;
}

.game-over h2 {
  margin-bottom: 28px;
  font-size: clamp(40px, 11vw, 60px);
}

.result-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  width: min(430px, 94%);
  margin-bottom: 30px;
  background: rgba(15,18,39,.88);
  border: 1px solid rgba(244,232,202,.18);
}

.result-grid div {
  min-width: 0;
  padding: 15px 5px;
  border-right: 1px solid rgba(244,232,202,.12);
}

.result-grid div:last-child { border: 0; }
.result-grid small { display: block; color: #898296; font-size: 7px; letter-spacing: .1em; }
.result-grid strong { display: block; margin-top: 6px; color: var(--amber); font-size: clamp(15px, 4.4vw, 22px); }

@media (max-width: 700px) {
  .game-shell { width: 100vw; height: 100svh; }
  .game-frame { border: 0; box-shadow: none; }
}

@media (max-height: 660px) {
  .screen { padding-bottom: 30px; }
  .hero-card { display: none; }
  .tagline { margin-bottom: 18px; }
}

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