:root {
  color-scheme: dark;
  --ink: #edf0d5;
  --gold: #e9bd62;
  --blue: #5b81bc;
  --night: #090b14;
  --panel: rgba(12, 18, 35, .94);
  --line: #9baed0;
}

* { box-sizing: border-box; }

html, body {
  min-height: 100%;
  margin: 0;
  background:
    radial-gradient(circle at 50% 15%, #222943 0, #0d101c 38%, #05060b 100%);
  color: var(--ink);
  font-family: Georgia, "Times New Roman", serif;
  overflow-x: hidden;
}

body {
  display: grid;
  place-items: center;
  padding: 24px;
}

button { font: inherit; }

#game-shell {
  width: min(1120px, 100%);
}

.game-frame {
  position: relative;
  aspect-ratio: 5 / 3;
  overflow: hidden;
  border: 2px solid #485570;
  border-radius: 4px;
  background: #05070e;
  box-shadow: 0 28px 80px #000, inset 0 0 0 2px #111827;
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
}

.scanlines {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 20;
  opacity: .13;
  background: repeating-linear-gradient(to bottom, transparent 0 3px, #000 4px 5px);
  mix-blend-mode: multiply;
}

.screen {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 8%;
  text-align: center;
}

.title-screen {
  background:
    linear-gradient(to bottom, rgba(7, 10, 22, .28), rgba(5, 6, 12, .96)),
    radial-gradient(ellipse at center 34%, rgba(67, 93, 139, .42), transparent 42%);
}

.title-mark {
  position: relative;
  width: 126px;
  height: 108px;
  margin-bottom: 4px;
  filter: drop-shadow(0 0 18px rgba(128, 197, 255, .35));
}

.crystal {
  position: absolute;
  left: 50%;
  bottom: 8px;
  width: 32px;
  height: 88px;
  clip-path: polygon(50% 0, 100% 28%, 82% 88%, 50% 100%, 18% 88%, 0 28%);
  background: linear-gradient(100deg, #26385b 0 25%, #a8d2d8 26% 44%, #5075a7 45% 72%, #16233e 73%);
  transform-origin: 50% 100%;
}

.crystal-a { transform: translateX(-50%); }
.crystal-b { transform: translateX(-50%) rotate(-31deg) scale(.72); }
.crystal-c { transform: translateX(-50%) rotate(34deg) scale(.62); }

.eyebrow {
  margin: 0 0 12px;
  color: var(--gold);
  font: 700 12px/1.2 system-ui, sans-serif;
  letter-spacing: .24em;
  text-transform: uppercase;
}

h1 { margin: 0; font-weight: 400; text-shadow: 0 3px 0 #000; }
h1 span { display: block; font-size: clamp(28px, 5.3vw, 64px); letter-spacing: .05em; }
h1 strong {
  display: block;
  margin-top: -2px;
  color: #cfd9e7;
  font-size: clamp(20px, 3.8vw, 47px);
  font-weight: 400;
  letter-spacing: .32em;
  text-transform: uppercase;
  transform: translateX(.17em);
}

.subtitle {
  max-width: 580px;
  margin: 18px 0 24px;
  color: #b8c1d0;
  font-size: clamp(14px, 1.6vw, 19px);
  font-style: italic;
}

.title-actions { display: grid; gap: 8px; min-width: 220px; }

.menu-button {
  border: 1px solid transparent;
  padding: 10px 26px;
  background: transparent;
  color: #aab3c4;
  cursor: pointer;
  font: 700 14px/1 system-ui, sans-serif;
  letter-spacing: .12em;
  text-transform: uppercase;
}

.menu-button.active, .menu-button:hover:not(:disabled), .menu-button:focus-visible {
  border-color: #8295b9;
  outline: none;
  background: linear-gradient(90deg, transparent, rgba(80, 108, 158, .35), transparent);
  color: #fff;
}

.menu-button:disabled { opacity: .28; cursor: default; }

.start-hint {
  position: absolute;
  bottom: 20px;
  margin: 0;
  color: #778197;
  font: 11px/1.4 system-ui, sans-serif;
  letter-spacing: .06em;
}

.dialogue {
  position: absolute;
  z-index: 30;
  left: 5%;
  right: 5%;
  bottom: 5%;
  min-height: 132px;
  display: flex;
  border: 3px double var(--line);
  border-radius: 5px;
  background: linear-gradient(135deg, rgba(16, 31, 68, .98), rgba(8, 14, 31, .98));
  box-shadow: 0 7px 0 rgba(0,0,0,.55), inset 0 0 30px rgba(71, 104, 175, .13);
}

.portrait {
  flex: 0 0 114px;
  margin: 9px;
  border: 1px solid #7386aa;
  background-color: #121827;
  image-rendering: pixelated;
}

.dialogue-copy { position: relative; flex: 1; padding: 16px 42px 18px 8px; text-align: left; }
.speaker { margin: 0 0 8px; color: var(--gold); font: 800 14px/1 system-ui, sans-serif; letter-spacing: .08em; text-transform: uppercase; }
.dialogue-text { margin: 0; color: #fff; font-size: clamp(16px, 2vw, 22px); line-height: 1.4; text-shadow: 0 2px #000; }
.continue-caret { position: absolute; right: 18px; bottom: 13px; color: var(--gold); animation: bob .8s steps(2) infinite; }

.objective {
  position: absolute;
  z-index: 8;
  top: 18px;
  left: 18px;
  max-width: 340px;
  border-left: 3px solid var(--gold);
  padding: 8px 12px;
  background: rgba(5, 8, 16, .8);
  text-align: left;
}

.objective span { display: block; color: var(--gold); font: 700 9px/1 system-ui, sans-serif; letter-spacing: .18em; text-transform: uppercase; }
.objective strong { font-size: 14px; font-weight: 400; }

.battle-ui { position: absolute; inset: 0; z-index: 9; pointer-events: none; }
.boss-panel { position: absolute; top: 22px; left: 50%; width: min(390px, 48%); transform: translateX(-50%); }
.boss-name-row { display: flex; justify-content: space-between; margin-bottom: 5px; color: #fff; font: 700 13px/1 system-ui, sans-serif; letter-spacing: .07em; text-transform: uppercase; text-shadow: 0 2px #000; }
.boss-name-row span { color: #d8b478; font-size: 10px; }
.bar { height: 10px; border: 1px solid #a9b5c9; padding: 2px; background: #090b13; box-shadow: 0 2px #000; }
.bar i { display: block; height: 100%; width: 100%; background: #c54c56; transition: width .3s; }
.party-panel { position: absolute; right: 20px; bottom: 20px; width: min(390px, 43%); display: grid; gap: 6px; }
.party-row { display: grid; grid-template-columns: 68px 1fr 104px; align-items: center; gap: 7px; padding: 7px 9px; border: 1px solid #7182a3; background: rgba(9, 16, 35, .9); font: 12px/1 system-ui, sans-serif; }
.party-row.active { border-color: var(--gold); box-shadow: 0 0 12px rgba(233,189,98,.3); }
.party-row .name { font-weight: 800; color: #fff; }
.party-row .stats { text-align: right; color: #c4cad6; font-variant-numeric: tabular-nums; }
.party-row .atb { height: 7px; border: 1px solid #44536f; padding: 1px; background: #090b12; }
.party-row .atb i { display:block; height:100%; background:#55b8b1; }
.party-row.ko { opacity: .45; filter: grayscale(1); }
.party-row.ko .name::after { content: "  KO"; color: #db6a6a; }
.command-panel { position: absolute; left: 20px; bottom: 20px; width: min(390px, 44%); grid-template-columns: repeat(2, 1fr); gap: 6px; padding: 10px; border: 3px double #93a6c9; background: rgba(10, 19, 43, .96); pointer-events: auto; }
.command-panel button { border: 1px solid #526583; padding: 10px 8px; background: #111d38; color: #fff; cursor: pointer; font: 700 12px/1 system-ui, sans-serif; letter-spacing: .06em; text-transform: uppercase; }
.command-panel button:hover, .command-panel button:focus-visible, .command-panel button.selected { border-color: var(--gold); background: #273c61; outline: none; }
.battle-log { position:absolute; left:20px; top:20px; width:31%; min-height:42px; padding:9px 12px; border-left:2px solid var(--gold); background:rgba(4,7,15,.7); color:#e6e9ef; font:italic 13px/1.35 Georgia,serif; }

.ending { background: rgba(5, 7, 14, .94); }
.ending h2 { margin: 0; color: #eff0e0; font-size: clamp(28px, 5vw, 60px); font-weight: 400; line-height: 1.08; text-shadow: 0 3px #000; }
.ending p:not(.eyebrow) { max-width: 610px; color: #aeb8c9; font-size: clamp(15px, 1.8vw, 20px); line-height: 1.5; }

.mute { position: absolute; z-index: 40; top: 12px; right: 12px; width: 34px; height: 34px; border: 1px solid #57647c; border-radius: 50%; background: rgba(5,8,16,.65); color: #b7c2d3; cursor: pointer; }
.mute.off { color: #697183; text-decoration: line-through; }

.touch-controls { display: none; }
.rotate-notice { display: none; }
.hidden { display: none !important; }

footer { display: flex; justify-content: space-between; gap: 20px; padding: 10px 4px 0; color: #697285; font: 9px/1.4 system-ui, sans-serif; letter-spacing: .09em; }

@keyframes bob { 50% { transform: translateY(4px); } }

@media (max-width: 700px), (pointer: coarse) {
  body { padding: 0; align-items: start; background: #05060b; }
  #game-shell { width: 100vw; }
  .game-frame { width: 100vw; height: 100svh; aspect-ratio: auto; border: 0; border-radius: 0; }
  canvas { object-fit: contain; }
  footer { display: none; }
  .touch-controls { position: absolute; z-index: 25; inset: auto 18px 18px 18px; display: flex; justify-content: space-between; align-items: end; pointer-events: none; }
  .touch-controls button { pointer-events: auto; touch-action: manipulation; border: 1px solid rgba(177,194,220,.5); background: rgba(15,25,48,.64); color: rgba(255,255,255,.9); }
  .dpad { display: grid; grid-template-columns: repeat(3, 46px); grid-template-rows: repeat(2, 46px); gap: 4px; }
  .dpad button:nth-child(1) { grid-column: 2; }
  .dpad button:nth-child(2) { grid-column: 1; grid-row: 2; }
  .dpad button:nth-child(3) { grid-column: 2; grid-row: 2; }
  .dpad button:nth-child(4) { grid-column: 3; grid-row: 2; }
  .action-button { width: 58px; height: 58px; margin: 0 5px 4px 0; border-radius: 50%; font-weight: 900; }
  .dialogue { left: 3%; right: 3%; bottom: 100px; min-height: 118px; }
  .portrait { display: none; }
  .dialogue-copy { padding: 13px 34px 15px 14px; }
  .dialogue-text { font-size: 16px; }
  .objective { top: 10px; left: 10px; max-width: 65%; }
  .battle-log { top: 12px; left: 12px; width: 45%; font-size: 11px; }
  .boss-panel { top: 15px; left: auto; right: 12px; width: 46%; transform: none; }
  .party-panel { right: 12px; bottom: 106px; width: 52%; }
  .party-row { grid-template-columns: 56px 1fr; padding: 5px; font-size: 10px; }
  .party-row .atb { grid-column: 1 / -1; }
  .command-panel { left: 12px; bottom: 106px; width: 43%; grid-template-columns: 1fr; padding: 6px; }
  .command-panel button { padding: 8px 5px; font-size: 10px; }
}

@media (max-width: 700px) and (orientation: portrait) {
  #game-shell.playing .rotate-notice {
    position: absolute;
    z-index: 60;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: rgba(5, 7, 14, .96);
    color: #fff;
    text-align: center;
  }

  .rotate-notice strong {
    margin-top: 22px;
    color: var(--gold);
    font: 800 18px/1 system-ui, sans-serif;
    letter-spacing: .1em;
    text-transform: uppercase;
  }

  .rotate-notice p { margin: 9px 0 0; color: #aeb8c9; font-style: italic; }

  .phone-icon {
    width: 42px;
    height: 70px;
    border: 3px solid #a9bad2;
    border-radius: 7px;
    box-shadow: inset 0 -8px #1b2942;
    transform: rotate(90deg);
  }
}

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