
:root {
  --paper: #f3ead6;
  --paper-deep: #e8d5b0;
  --ink: #3a2a1c;
  --ink-soft: #6a5848;
  --seal: #9c2e28;
  --seal-soft: #c45a4c;
  --gold: #b0894a;
  --stage-bg: #1c140c;
  --frame-bg: #2a1f16;
  --shadow: 0 8px 28px #1c140c55;
  --btn-min: 44px;
}

*, *::before, *::after { box-sizing: border-box; }
html, body {
  margin: 0;
  height: 100%;
  background: var(--stage-bg);
  color: var(--ink);
  font-family: var(--font-sans);
  -webkit-text-size-adjust: 100%;
}
button { font: inherit; color: inherit; cursor: pointer; touch-action: manipulation; }
button:disabled { cursor: default; opacity: 0.45; }
img { max-width: 100%; height: auto; display: block; }
[hidden] { display: none !important; }

.app {
  min-height: 100svh;
  height: 100svh;
  max-height: 100svh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background:
    radial-gradient(ellipse at 50% 40%, #3a2a1c55, transparent 60%),
    var(--stage-bg);
}

.skip {
  position: absolute;
  left: -999px;
  top: 0;
}
.skip:focus { left: 8px; z-index: 20; background: var(--paper); padding: 8px; }

.stage {
  flex: 1 1 auto;
  min-height: 0;
  position: relative;
  container-type: size;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.stage-frame {
  position: relative;
  aspect-ratio: 1000 / 640;
  width: min(100cqw, calc(100cqh * 1000 / 640));
  height: auto;
  max-width: 100%;
  max-height: 100%;
  container-type: size;
  background: var(--paper-deep);
  color: var(--ink);
  overflow: hidden;
  box-shadow: var(--shadow);
  isolation: isolate;
}

.scene {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
}

/* HUD inside the 16:10 frame */
.hud {
  position: relative;
  z-index: 5;
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6cqw;
  min-height: max(var(--btn-min), 7.2cqh);
  padding: 0.8cqh 1.4cqw;
  background: linear-gradient(#f6efe0ee, #eadcb8ee);
  border-bottom: 1px solid #3a2a1c33;
}
.brand-title {
  font-size: clamp(15px, 3.2cqw, 22px);
  letter-spacing: 0.18em;
  margin: 0;
  font-weight: 600;
  line-height: 1.2;
}
.chapter-label {
  font-size: clamp(11px, 2cqw, 14px);
  color: var(--ink-soft);
  letter-spacing: 0.08em;
  margin-top: 0.15em;
}
.hud-actions { display: flex; gap: 0.5cqw; align-items: center; }

.btn {
  min-height: max(var(--btn-min), 5.8cqh);
  min-width: max(var(--btn-min), 5.8cqh);
  padding: 0 1.2em;
  border: 1.5px solid var(--ink);
  background: var(--paper);
  color: var(--ink);
  border-radius: 3px;
  letter-spacing: 0.14em;
  font-size: clamp(13px, 2.2cqw, 16px);
  box-shadow: 1px 2px 0 #3a2a1c22;
}
.btn:hover:not(:disabled) { background: #fff8e8; }
.btn:focus-visible { outline: 2px solid var(--seal); outline-offset: 3px; }
.btn.primary {
  background: var(--seal);
  color: #f8efe4;
  border-color: #6e1c18;
}
.btn.primary:hover:not(:disabled) { background: #b03a34; }
.btn.ghost { background: transparent; box-shadow: none; }
.icon-btn {
  padding: 0 0.55em;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35em;
}
.icon-btn img {
  width: 1.4em;
  height: 1.4em;
}
@media (max-width: 520px), (max-height: 420px) {
  .icon-btn .btn-label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
}

/* Gate / title */
.gate, .title-scene {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  background-size: cover;
  background-position: center;
  padding: 4cqh 5cqw;
}
.gate::after, .title-scene::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(#1c140c00, #1c140c66 80%);
  pointer-events: none;
}
.gate > *, .title-scene > * { position: relative; z-index: 1; }
.game-title {
  font-family: var(--font-serif);
  font-size: clamp(36px, 9cqw, 84px);
  letter-spacing: 0.22em;
  margin: 0 0 0.25em;
  font-weight: 700;
  text-shadow: 0 1px 0 #fff6, 0 6px 24px #1c140c33;
}
.game-sub {
  font-family: var(--font-serif);
  font-size: clamp(16px, 3.2cqw, 26px);
  letter-spacing: 0.28em;
  margin: 0 0 1.2em;
  color: var(--ink-soft);
}
.lede {
  max-width: 36em;
  font-size: clamp(13px, 2.2cqw, 16px);
  line-height: 1.85;
  color: var(--ink-soft);
  margin: 0 0 1.6em;
}
.cta-row { display: flex; flex-wrap: wrap; gap: 0.8em; justify-content: center; }
.hint-line { margin-top: 1.4em; color: var(--ink-soft); letter-spacing: 0.16em; font-size: 14px; }
.play-body .draft-ribbon {
  top: 1cqh;
  right: 1cqw;
}
.draft-ribbon {
  position: absolute;
  top: 2.4cqh;
  right: 2cqw;
  z-index: 6;
  background: var(--seal);
  color: #f8efe4;
  font-size: 12px;
  letter-spacing: 0.12em;
  padding: 0.35em 1.2em;
  transform: rotate(6deg);
  box-shadow: var(--shadow);
  pointer-events: none;
}

/* Chapter select */
.chapter-list {
  display: flex;
  flex-direction: column;
  gap: 0.7em;
  width: min(80cqw, 520px);
  margin: 1em auto 0;
  text-align: left;
}
.chapter-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1em;
  width: 100%;
  text-align: left;
  padding: 0.9em 1.1em;
}
.chapter-item .meta { color: var(--ink-soft); font-size: 13px; letter-spacing: 0.08em; }

/* Map play */
.play-body {
  flex: 1 1 auto;
  min-height: 0;
  position: relative;
  display: flex;
}
.map-viewport {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
  position: relative;
  overflow: hidden;
  background: #cbb892;
  touch-action: none;
  cursor: grab;
}
.map-viewport.dragging { cursor: grabbing; }
.map-world {
  position: absolute;
  left: 0;
  top: 0;
  transform-origin: 0 0;
  will-change: transform;
}
.map-world .layer {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  user-select: none;
  -webkit-user-drag: none;
}
.map-world .layer.old { z-index: 1; }
.map-world .layer.new { z-index: 0; }
.hotspot {
  position: absolute;
  z-index: 3;
  border: 2px dashed #9c2e2880;
  background: #f8e7a51a;
  border-radius: 8px;
  transform: translate(-50%, -50%);
  cursor: pointer;
  padding: 0;
  min-width: 0;
  min-height: 0;
  box-shadow: none;
  letter-spacing: 0;
}
.hotspot:hover, .hotspot:focus-visible { background: #f8e7a548; border-color: var(--seal); }
.hotspot .spot-label {
  position: absolute;
  left: 50%;
  bottom: 100%;
  transform: translate(-50%, -4px);
  background: #f6efe0ee;
  border: 1px solid #3a2a1c55;
  padding: 2px 6px;
  font-size: 11px;
  white-space: nowrap;
  letter-spacing: 0.04em;
  pointer-events: none;
  opacity: 0;
  transition: opacity .15s;
}
.hotspot:hover .spot-label, .hotspot:focus-visible .spot-label { opacity: 1; }
.hint-ring {
  position: absolute;
  z-index: 4;
  border: 3px solid var(--seal);
  border-radius: 50%;
  transform: translate(-50%, -50%);
  pointer-events: none;
  animation: pulse 1.6s ease-out infinite;
  box-shadow: 0 0 0 6px #9c2e2833;
}
@keyframes pulse {
  0% { opacity: 0.95; }
  70% { opacity: 0.15; }
  100% { opacity: 0.95; }
}

.map-tools {
  position: absolute;
  z-index: 5;
  left: 1.2cqw;
  bottom: 1.4cqh;
  display: flex;
  flex-direction: column;
  gap: 0.5em;
  align-items: flex-start;
}
.map-tools .row { display: flex; gap: 0.4em; flex-wrap: wrap; align-items: center; }
.compare {
  display: flex;
  align-items: center;
  gap: 0.5em;
  background: #f6efe0ee;
  border: 1px solid #3a2a1c44;
  padding: 0.35em 0.7em;
  border-radius: 3px;
  font-size: clamp(12px, 1.8cqw, 14px);
}
.compare input[type="range"] {
  width: min(28cqw, 180px);
  accent-color: var(--seal);
}
.side-tools {
  position: absolute;
  z-index: 5;
  right: 1.2cqw;
  bottom: 1.4cqh;
  display: flex;
  flex-direction: column;
  gap: 0.45em;
  align-items: stretch;
}
.nudge { animation: glow 1.2s ease-in-out infinite; box-shadow: 0 0 0 3px #9c2e2866; }
@keyframes glow {
  50% { box-shadow: 0 0 0 6px #9c2e2800; }
}

/* overlays */
.overlay {
  position: absolute;
  inset: 0;
  z-index: 8;
  background: #1c140c55;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 3cqh 3cqw;
}
.sheet {
  background: var(--paper);
  border: 1.5px solid var(--ink);
  box-shadow: var(--shadow);
  width: min(92cqw, 620px);
  max-height: 88cqh;
  overflow: hidden;
  padding: 2cqh 3cqw 1.8cqh;
  position: relative;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.sheet .sheet-scroll {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
}
.sheet .cta-row { flex: 0 0 auto; }
.sheet.letter {
  background-size: cover;
  background-position: center;
  width: min(70cqw, 480px);
}
.sheet h2 {
  font-family: var(--font-serif);
  font-weight: 600;
  letter-spacing: 0.16em;
  font-size: clamp(18px, 3.4cqw, 26px);
  margin: 0 0 0.6em;
}
.letter-body, .quote {
  font-family: var(--font-serif);
  font-size: clamp(15px, 2.4cqw, 18px);
  line-height: 1.9;
  letter-spacing: 0.04em;
  white-space: pre-wrap;
}
.draft-note {
  color: var(--seal);
  font-size: 12px;
  letter-spacing: 0.08em;
  margin: 0 0 0.8em;
}
.dialog {
  position: absolute;
  z-index: 9;
  left: 4cqw;
  right: 4cqw;
  bottom: 3cqh;
  display: flex;
  gap: 1cqw;
  align-items: stretch;
  background: #f6efe0f2;
  border: 1.5px solid var(--ink);
  padding: 1.2cqh 1.6cqw;
  box-shadow: var(--shadow);
}
.dialog img.portrait {
  width: max(64px, 12cqh);
  height: max(64px, 12cqh);
  border-radius: 50%;
  border: 2px solid var(--ink);
  object-fit: cover;
  flex: 0 0 auto;
}
.dialog .who { font-weight: 700; letter-spacing: 0.1em; margin-bottom: 0.3em; }
.dialog p { margin: 0; line-height: 1.7; font-size: clamp(14px, 2.2cqw, 17px); }

/* summary */
.summary {
  position: absolute;
  inset: 0;
  z-index: 7;
  display: flex;
  flex-direction: column;
  background-size: cover;
  padding: 2cqh 3cqw 2.2cqh;
}
.summary-maps {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.4cqw;
  margin: 1cqh 0 1.4cqh;
}
.summary-maps figure {
  margin: 0;
  border: 1.5px solid var(--ink);
  overflow: hidden;
  position: relative;
  background: #d9c7a0;
}
.summary-maps figure > img.crop { width: 100%; height: 100%; object-fit: cover; }
.summary-maps .seal {
  position: absolute;
  width: 28% !important;
  height: auto !important;
  max-width: 28%;
  right: 5%;
  top: 14%;
  pointer-events: none;
  z-index: 2;
}
.summary-maps figcaption {
  position: absolute;
  left: 0; right: 0; top: 0;
  padding: 0.4em 0.7em;
  background: #f6efe0cc;
  font-family: var(--font-serif);
  letter-spacing: 0.16em;
  font-size: 13px;
}
.summary .quote {
  text-align: center;
  margin: 0 0 1.2cqh;
}
.summary-actions { display: flex; justify-content: center; flex-wrap: wrap; gap: 0.8em; }

.soon {
  text-align: center;
  padding: 8cqh 5cqw;
}
.soon h2 { margin-bottom: 0.6em; }

.rotate-hint {
  display: none;
  position: absolute;
  left: 50%;
  bottom: 1cqh;
  transform: translateX(-50%);
  font-size: 12px;
  color: var(--ink-soft);
  letter-spacing: 0.1em;
  z-index: 6;
  pointer-events: none;
}
@container (max-height: 380px) {
  .rotate-hint { display: block; }
}

@media (prefers-reduced-motion: reduce) {
  .hint-ring, .nudge { animation: none; }
}

/* landscape phone: keep buttons fat */
@media (orientation: landscape) and (max-height: 500px) {
  .hud { min-height: 44px; }
}

@container (max-height: 420px) {
  .map-tools .row.toggles { display: none; }
  .btn { min-height: 40px; min-width: 40px; font-size: 12px; padding: 0 0.55em; }
  .compare { padding: 0.2em 0.5em; }
  .hud { padding: 0.3cqh 1cqw; }
  .scene > .rotate-hint { display: none; }
}
.app-rotate-hint {
  display: none;
  position: absolute;
  left: 0;
  right: 0;
  bottom: 10px;
  text-align: center;
  color: #d9c7a0;
  letter-spacing: 0.12em;
  font-size: 12px;
  pointer-events: none;
  z-index: 6;
}
@media (max-aspect-ratio: 3/4) {
  .app-rotate-hint { display: block; }
}
