:root {
  --ink: #172d45;
  --ink-soft: #274763;
  --cream: #fff7df;
  --paper: #fffaf0;
  --rice: #fffdf4;
  --red: #d94b42;
  --red-dark: #a93535;
  --gold: #f5bd4f;
  --green: #4e8a61;
  --shadow: rgba(11, 28, 42, .2);
}

* { box-sizing: border-box; }

html { background: var(--ink); color-scheme: light; }

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  color: var(--ink);
  background:
    radial-gradient(circle at 8% 6%, rgba(245, 189, 79, .22), transparent 28rem),
    linear-gradient(145deg, #17334c 0%, #0f2437 65%, #122034 100%);
  font-family: "Yu Gothic", "Hiragino Kaku Gothic ProN", system-ui, sans-serif;
  overscroll-behavior: none;
}

button, a { -webkit-tap-highlight-color: transparent; }
button { font: inherit; }

.topbar {
  height: 62px;
  padding: max(9px, env(safe-area-inset-top)) max(14px, env(safe-area-inset-right)) 9px max(14px, env(safe-area-inset-left));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: var(--cream);
}

.brand { display: flex; align-items: baseline; gap: 7px; color: inherit; text-decoration: none; letter-spacing: .08em; }
.brand span { font-size: 11px; font-weight: 800; opacity: .74; }
.brand b { color: var(--gold); font-size: 19px; }
.top-actions { display: flex; gap: 8px; }

.small-button, .ghost-button, .primary-button, .control-button, .pause-button, .close-button, .upgrade-button {
  border: 0;
  cursor: pointer;
  touch-action: manipulation;
}

.small-button {
  min-height: 38px;
  padding: 0 13px;
  border: 1px solid rgba(255,255,255,.27);
  border-radius: 999px;
  color: var(--cream);
  background: rgba(255,255,255,.08);
  font-size: 12px;
  font-weight: 800;
}

.page-shell {
  width: min(1380px, 100%);
  margin: 0 auto;
  padding: 0 22px 30px;
  display: grid;
  grid-template-columns: minmax(250px, 350px) minmax(560px, 900px);
  justify-content: center;
  align-items: center;
  gap: clamp(22px, 4vw, 62px);
}

.story-panel { color: var(--cream); padding: 24px 0; }
.eyebrow { margin: 0 0 8px; color: var(--gold); font-size: 11px; font-weight: 900; letter-spacing: .17em; }
.story-panel h1 { margin: 0; font-size: clamp(34px, 4.2vw, 58px); line-height: 1.02; letter-spacing: -.06em; text-wrap: balance; }
.story-panel h1 span { color: #f2c15d; font-size: .72em; letter-spacing: .02em; }
.story-lead { margin: 22px 0; color: rgba(255,255,255,.78); line-height: 1.9; font-size: 14px; }
.feature-strip { display: grid; grid-template-columns: repeat(3, 1fr); border: 1px solid rgba(255,255,255,.14); border-radius: 18px; overflow: hidden; }
.feature-strip span { padding: 12px 7px; text-align: center; font-size: 10px; color: rgba(255,255,255,.65); border-right: 1px solid rgba(255,255,255,.12); }
.feature-strip span:last-child { border: 0; }
.feature-strip b { display: block; color: var(--cream); font-size: 14px; }
.record-card { margin-top: 16px; padding: 16px 18px; border-radius: 18px; color: var(--ink); background: linear-gradient(135deg, #fff8e7, #f0ddad); box-shadow: 0 18px 50px rgba(0,0,0,.18); }
.record-card > span { display: block; font-size: 11px; font-weight: 800; color: #89643a; }
.record-card > strong { font-size: 30px; font-weight: 1000; }
.record-card small { font-weight: 800; }
.record-card p { margin: 6px 0 0; font-size: 12px; }
.copyright-note { color: rgba(255,255,255,.42); font-size: 10px; line-height: 1.6; }

.game-column { min-width: 0; }
.game-frame {
  position: relative;
  width: 100%;
  aspect-ratio: 10 / 9;
  max-height: calc(100dvh - 190px);
  min-height: 470px;
  overflow: hidden;
  border: 5px solid #f2dfb7;
  border-radius: 28px;
  background: #8cc8c0;
  box-shadow: 0 30px 90px rgba(2, 14, 25, .52), inset 0 0 0 2px #9d7746;
  isolation: isolate;
}

#game-canvas { width: 100%; height: 100%; display: block; touch-action: none; outline: none; }

.hud {
  position: absolute;
  z-index: 6;
  left: 12px;
  right: 58px;
  top: 12px;
  display: grid;
  grid-template-columns: .65fr 1.2fr .85fr .8fr 1fr;
  gap: 6px;
  pointer-events: none;
}

.hud > div {
  min-width: 0;
  padding: 7px 9px 6px;
  border: 1px solid rgba(255,255,255,.38);
  border-radius: 12px;
  color: #fff;
  background: rgba(13, 37, 54, .72);
  backdrop-filter: blur(8px);
  text-shadow: 0 2px 2px rgba(0,0,0,.28);
}
.hud small { display: block; font-size: 8px; font-weight: 900; letter-spacing: .09em; color: #f6d882; white-space: nowrap; }
.hud strong { display: block; overflow: hidden; font-size: clamp(13px, 2.3vw, 20px); text-overflow: ellipsis; white-space: nowrap; }
.heart-cell strong { color: #ff8177; letter-spacing: .06em; }

.mission-chip {
  position: absolute;
  z-index: 6;
  left: 12px;
  right: 58px;
  top: 72px;
  min-height: 35px;
  padding: 6px 10px;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  border: 1px solid rgba(255,255,255,.36);
  border-radius: 11px;
  color: #fff;
  background: rgba(51, 42, 31, .78);
  box-shadow: 0 5px 16px rgba(0,0,0,.16);
  pointer-events: none;
}
.mission-chip span { color: #f5cc69; font-size: 9px; font-weight: 1000; letter-spacing: .08em; white-space: nowrap; }
.mission-chip strong { overflow: hidden; font-size: 11px; text-overflow: ellipsis; white-space: nowrap; }
.mission-chip em { padding: 3px 6px; border-radius: 999px; color: #21364a; background: #fff0a8; font-size: 9px; font-style: normal; font-weight: 1000; white-space: nowrap; }
.mission-chip.complete { background: rgba(37, 91, 55, .84); }
.mission-chip.failed { background: rgba(105, 48, 48, .8); }

.pause-button {
  position: absolute;
  z-index: 7;
  top: 12px;
  right: 12px;
  width: 38px;
  height: 38px;
  border: 1px solid rgba(255,255,255,.4);
  border-radius: 50%;
  color: white;
  background: rgba(13,37,54,.78);
  font-weight: 1000;
}
.pause-button:disabled { opacity: .38; cursor: default; }

.toast {
  position: absolute;
  z-index: 9;
  left: 50%;
  top: 116px;
  min-width: 140px;
  transform: translate(-50%, -14px) scale(.9);
  padding: 9px 16px;
  border-radius: 999px;
  color: #fff;
  background: rgba(19, 43, 61, .88);
  text-align: center;
  font-size: 13px;
  font-weight: 900;
  opacity: 0;
  pointer-events: none;
  transition: .18s ease;
}
.toast.show { opacity: 1; transform: translate(-50%, 0) scale(1); }

.screen { position: absolute; z-index: 8; inset: 0; }
.screen[hidden] { display: none !important; }
.cover-screen { display: flex; align-items: flex-end; background: url("thumbnail.png") center / cover no-repeat; }
.cover-shade { position: absolute; inset: 0; background: linear-gradient(180deg, rgba(10,24,41,.05) 10%, rgba(10,24,41,.16) 42%, rgba(10,24,41,.92) 100%); }
.cover-content { position: relative; width: min(520px, 92%); margin: 0 auto; padding: 0 20px clamp(24px, 6vh, 62px); color: white; text-align: center; text-shadow: 0 3px 14px rgba(0,0,0,.46); }
.cover-content h2 { margin: 4px 0 10px; font-size: clamp(30px, 6vw, 52px); line-height: 1.02; letter-spacing: -.05em; }
.cover-content p:not(.eyebrow) { margin: 0 0 18px; font-size: 13px; line-height: 1.75; }

.primary-button, .ghost-button {
  width: min(320px, 92%);
  min-height: 48px;
  margin: 5px auto;
  border-radius: 14px;
  font-weight: 900;
}
.primary-button { color: white; background: linear-gradient(180deg, #ef6a55, #bd3f3b); box-shadow: 0 6px 0 #7c2f34, 0 12px 22px rgba(93,35,36,.28); }
.primary-button:active { transform: translateY(4px); box-shadow: 0 2px 0 #7c2f34; }
.ghost-button { border: 1px solid rgba(23,45,69,.2); color: var(--ink); background: rgba(255,255,255,.74); }
.cover-content .ghost-button { color: white; border-color: rgba(255,255,255,.4); background: rgba(10,30,44,.45); }

.dialog-screen { display: grid; place-items: center; padding: 18px; background: rgba(10,29,43,.72); backdrop-filter: blur(5px); }
.paper-card {
  position: relative;
  width: min(500px, 100%);
  max-height: calc(100% - 18px);
  overflow: auto;
  padding: clamp(22px, 5vw, 38px);
  border: 2px solid #c9a66b;
  border-radius: 24px;
  color: var(--ink);
  background: radial-gradient(circle at 80% 12%, rgba(226,191,111,.2), transparent 14rem), var(--paper);
  box-shadow: 0 24px 70px rgba(0,0,0,.38);
  text-align: center;
}
.paper-card h2 { margin: 4px 0 9px; font-size: clamp(25px, 5vw, 38px); line-height: 1.12; }
.paper-card > p:not(.eyebrow) { color: #526474; line-height: 1.7; font-size: 13px; }
.ingredient-medal { width: 74px; height: 74px; margin: 0 auto 5px; display: grid; place-items: center; border-radius: 50%; background: #f6d889; font-size: 38px; box-shadow: 0 7px 0 #bf8b47; }
.choose-label { margin: 16px 0 8px !important; font-weight: 800; color: #8a603a !important; }
.upgrade-list { display: grid; gap: 8px; }
.upgrade-button { display: grid; grid-template-columns: 44px 1fr; align-items: center; min-height: 58px; padding: 9px 12px; border: 1px solid #d7c092; border-radius: 15px; color: var(--ink); background: #fff; text-align: left; }
.upgrade-button:hover, .upgrade-button:focus-visible { border-color: var(--red); transform: translateY(-1px); box-shadow: 0 8px 20px rgba(112,70,43,.13); }
.upgrade-button > b { grid-row: 1 / span 2; font-size: 26px; }
.upgrade-button strong { font-size: 14px; }
.upgrade-button small { color: #65727d; font-size: 11px; }

.result-screen { padding: 12px; overflow: auto; background: rgba(10,29,43,.76); backdrop-filter: blur(6px); }
.result-card { margin: 0 auto; max-height: none; min-height: 100%; }
.result-score { margin: 12px auto; padding: 12px; border-radius: 18px; background: #f6e5b8; }
.result-score strong { display: block; font-size: clamp(36px, 8vw, 58px); line-height: 1; }
.result-score span { font-size: 11px; font-weight: 900; color: #8a603a; }
.result-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 5px; }
.result-grid span { padding: 9px 3px; border: 1px solid #e2d5b8; border-radius: 12px; color: #74654f; font-size: 10px; }
.result-grid strong { display: block; color: var(--ink); font-size: 19px; }
.result-note { min-height: 44px; }
.ranking { margin-top: 16px; text-align: left; }

.how-card { text-align: left; }
.how-card h2 { text-align: center; }
.how-card .eyebrow { text-align: center; }
.how-card ol { margin: 18px 0 0; padding: 0; list-style: none; display: grid; gap: 9px; }
.how-card li { padding: 10px 12px; border-left: 4px solid var(--red); border-radius: 0 12px 12px 0; background: #f5edd9; }
.how-card li b, .how-card li span { display: block; }
.how-card li span { margin-top: 2px; color: #63717a; font-size: 11px; }
.close-button { width: 40px; height: 40px; border-radius: 50%; color: var(--ink); background: #eee2c9; font-size: 22px; font-weight: 900; }
.how-card > .close-button { position: absolute; top: 12px; right: 12px; }

.touch-controls { margin-top: 12px; display: flex; justify-content: space-between; align-items: center; gap: 18px; touch-action: none; overscroll-behavior: contain; }
.move-buttons { display: grid; grid-template-columns: repeat(2, 78px); gap: 10px; }
.action-buttons { display: flex; align-items: center; gap: 10px; }
.control-button {
  height: 62px;
  border: 2px solid rgba(255,255,255,.21);
  border-radius: 19px;
  color: white;
  background: linear-gradient(180deg, #365a75, #19364e);
  box-shadow: 0 7px 0 #081b2a;
  font-size: 24px;
  font-weight: 1000;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
}
.control-button.pressed, .control-button:active { transform: translateY(5px); box-shadow: 0 2px 0 #081b2a; filter: brightness(1.15); }
.attack-button { width: 96px; color: #fff8d5; background: linear-gradient(180deg, #50785e, #294839); box-shadow: 0 7px 0 #132d25; }
.attack-button small, .jump-button small { display: block; margin-top: -4px; font-size: 8px; letter-spacing: .12em; }
.jump-button { width: 116px; color: white; background: linear-gradient(180deg, #ef6652, #ad3737); box-shadow: 0 7px 0 #661e2a; }
.control-hint { margin: 12px 0 0; color: rgba(255,255,255,.56); text-align: center; font-size: 10px; }
.control-hint span { color: #f0cc77; }

.book-dialog { width: min(760px, calc(100% - 28px)); max-height: calc(100dvh - 36px); border: 2px solid #c7a264; border-radius: 24px; color: var(--ink); background: var(--paper); box-shadow: 0 25px 90px rgba(0,0,0,.45); }
.book-dialog::backdrop { background: rgba(8,22,34,.78); backdrop-filter: blur(5px); }
.book-head { display: flex; align-items: center; justify-content: space-between; gap: 14px; }
.book-head h2 { margin: 0; }
.book-dialog > p { color: #66727a; font-size: 13px; line-height: 1.7; }
.book-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.ingredient-card { min-height: 128px; padding: 12px 7px; border: 1px solid #dfcfad; border-radius: 16px; text-align: center; background: #fffdf7; }
.ingredient-card.locked { filter: grayscale(1); opacity: .46; }
.ingredient-card span { display: block; font-size: 34px; }
.ingredient-card strong { display: block; margin-top: 4px; font-size: 13px; }
.ingredient-card small { display: block; margin-top: 5px; color: #6d7a82; font-size: 9px; line-height: 1.45; }
.outfit-row { margin-top: 18px; padding-top: 15px; border-top: 1px dashed #cdbb97; }
.outfit-row > span { display: block; margin-bottom: 8px; font-weight: 900; }
#outfit-list { display: flex; flex-wrap: wrap; gap: 8px; }
.outfit-choice { min-height: 38px; padding: 0 12px; border: 1px solid #ccb98f; border-radius: 999px; background: white; color: var(--ink); font-weight: 800; }
.outfit-choice.selected { color: white; border-color: var(--red-dark); background: var(--red); }
.outfit-choice:disabled { opacity: .45; }
.sr-only { position: fixed; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

@media (max-width: 900px) {
  .topbar { height: 54px; }
  .page-shell { display: block; padding: 0 12px max(18px, env(safe-area-inset-bottom)); }
  .story-panel { display: none; }
  .game-column { width: min(720px, 100%); margin: 0 auto; }
  .game-frame { min-height: 0; max-height: none; border-width: 3px; border-radius: 20px; }
}

@media (max-width: 560px) {
  .brand span { display: none; }
  .small-button { min-height: 34px; padding: 0 10px; font-size: 11px; }
  .game-frame { aspect-ratio: 10 / 9.4; }
  .hud { left: 7px; top: 7px; right: 45px; gap: 3px; }
  .hud > div { padding: 5px 6px; border-radius: 9px; }
  .hud small { font-size: 7px; letter-spacing: .04em; }
  .hud strong { font-size: 12px; }
  .heart-cell small { display: none; }
  .mission-chip { left: 7px; right: 45px; top: 54px; min-height: 31px; padding: 5px 7px; gap: 5px; }
  .mission-chip span { display: none; }
  .mission-chip strong { font-size: 9px; }
  .mission-chip em { font-size: 8px; }
  .toast { top: 91px; max-width: calc(100% - 24px); font-size: 11px; }
  .pause-button { top: 7px; right: 7px; width: 34px; height: 34px; }
  .cover-content { padding-bottom: 22px; }
  .cover-content h2 { font-size: 32px; }
  .cover-content p:not(.eyebrow) { font-size: 11px; }
  .primary-button, .ghost-button { min-height: 44px; }
  .paper-card { padding: 22px 16px; border-radius: 18px; }
  .result-grid span { font-size: 8px; }
  .result-grid strong { font-size: 15px; }
  .touch-controls { margin-top: 9px; }
  .move-buttons { grid-template-columns: repeat(2, min(22vw, 74px)); gap: 8px; }
  .action-buttons { gap: 7px; }
  .control-button { height: 56px; border-radius: 16px; }
  .attack-button { width: min(20vw, 82px); }
  .jump-button { width: min(25vw, 102px); }
  .control-hint { display: none; }
  .book-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-height: 720px) and (min-width: 901px) {
  .page-shell { align-items: start; }
  .story-panel { padding-top: 0; }
  .story-lead { margin: 12px 0; }
  .game-frame { min-height: 440px; }
  .touch-controls { margin-top: 8px; }
  .control-button { height: 52px; }
}

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