:root {
  --bg: #0a0706;
  --ink: #d8cfbd;
  --ink-dim: #9a8f7c;
  --ink-faint: #5d5449;
  --line: rgba(216, 207, 189, 0.26);
  --line-strong: rgba(216, 207, 189, 0.5);
  --brass: #a88a52;
  --red: #8e2318;
  --red-hi: #cf4a35;
  --green: #4c5a3e;
  --serif: 'Shippori Mincho B1', 'Hiragino Mincho ProN', 'Yu Mincho', 'YuMincho', serif;
  --type: 'Special Elite', 'Courier New', monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--serif);
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
}

body {
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  overflow: hidden;
}

/* ---- 3D layer ---- */
#gl {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  height: 100lvh;
  display: block;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

.no-gl body {
  background:
    radial-gradient(ellipse at 50% 28%, #3a2418 0%, #140c09 45%, #070504 80%);
}
.no-gl #gl { display: none; }

/* 文字の視認性のための下部シェード */
.shade {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background: linear-gradient(to bottom,
    rgba(10, 7, 6, 0) 34%,
    rgba(10, 7, 6, 0.78) 50%,
    rgba(10, 7, 6, 0.94) 66%);
  transition: background 0.6s;
}
[data-mood="trap"] .shade,
[data-mood="dead"] .shade {
  background: linear-gradient(to bottom,
    rgba(18, 5, 4, 0) 34%,
    rgba(22, 6, 5, 0.8) 50%,
    rgba(20, 6, 5, 0.95) 66%);
}

/* ---- screens ---- */
.screen {
  position: fixed;
  inset: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.45s ease, visibility 0s linear 0.45s;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
.screen.is-active {
  opacity: 1;
  visibility: visible;
  transition: opacity 0.6s ease 0.1s;
}

.frame {
  width: 100%;
  max-width: 460px;
  min-height: 100%;
  margin: 0 auto;
  padding: 0 24px;
  display: flex;
  flex-direction: column;
}

.hud {
  height: 56px;
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--type);
  font-size: 14px;
  letter-spacing: 0.32em;
  color: var(--ink-dim);
  border-bottom: 1px solid var(--line);
  margin: 0 -4px;
}
[data-screen="result"][data-variant="trap"] .hud,
[data-screen="end"][data-variant="dead"] .hud { color: var(--red-hi); border-color: rgba(207, 74, 53, 0.4); }
[data-screen="result"][data-variant="item"] .hud,
[data-screen="end"][data-variant="clear"] .hud { color: var(--brass); }

.gap { flex: 1 0 34vh; }
.gap--short { flex-basis: 28vh; }

.panel {
  padding: 8px 0 28px;
}

.eyebrow, .kicker {
  margin: 0 0 6px;
  font-family: var(--type);
  font-size: 12px;
  letter-spacing: 0.34em;
  color: var(--ink-dim);
}
.kicker { text-align: center; }

.title {
  margin: 0 0 18px;
  font-size: 44px;
  font-weight: 700;
  letter-spacing: 0.14em;
  line-height: 1.2;
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.6);
}
.title--end { text-align: center; font-size: 34px; margin-top: 4px; }
[data-variant="dead"] .title--end { color: var(--red-hi); }
[data-variant="clear"] .title--end { color: #e4d3a8; }

.heading {
  margin: 0 0 16px;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: 0.1em;
  color: #d9c9a8;
}
.heading--center { text-align: center; }
[data-variant="trap"] .heading { color: var(--red-hi); }

.body {
  margin: 0 0 26px;
  font-size: 15.5px;
  line-height: 2;
  color: #c9bfac;
  white-space: pre-line;
  min-height: 2em;
}
.body--riddle {
  padding-left: 14px;
  border-left: 1px solid var(--brass);
  font-size: 16.5px;
  min-height: 4em;
}
.body--riddle.is-typing::after {
  content: '▌';
  margin-left: 2px;
  color: var(--brass);
  animation: caret 1s steps(1) infinite;
}
@keyframes caret { 50% { opacity: 0; } }
.body--center { text-align: center; }

.delta {
  margin: -6px 0 22px;
  text-align: center;
  font-family: var(--type);
  font-size: 30px;
  letter-spacing: 0.08em;
  color: var(--red-hi);
}
.delta:empty { display: none; }

.note {
  margin: 18px 0 0;
  font-size: 11.5px;
  line-height: 1.8;
  color: var(--ink-faint);
}
.note--center { text-align: center; }

/* ---- buttons: 角ばった細線。丸みやカード感は出さない ---- */
.btn {
  appearance: none;
  -webkit-appearance: none;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  min-height: 56px;
  padding: 12px 16px;
  border: 1px solid var(--line-strong);
  border-radius: 0;
  background: rgba(10, 7, 6, 0.55);
  color: var(--ink);
  font: inherit;
  font-size: 16px;
  letter-spacing: 0.22em;
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s, color 0.2s;
  touch-action: manipulation;
}
.btn:active { background: rgba(216, 207, 189, 0.14); }
.btn:focus-visible { outline: 1px solid var(--brass); outline-offset: 3px; }
[data-variant="trap"] .btn { border-color: rgba(207, 74, 53, 0.55); }

.btn--primary, .btn--scan {
  border-color: rgba(168, 138, 82, 0.7);
  background:
    linear-gradient(var(--brass), var(--brass)) left top / 12px 2px no-repeat,
    linear-gradient(var(--brass), var(--brass)) left top / 2px 12px no-repeat,
    linear-gradient(var(--brass), var(--brass)) right top / 12px 2px no-repeat,
    linear-gradient(var(--brass), var(--brass)) right top / 2px 12px no-repeat,
    linear-gradient(var(--brass), var(--brass)) left bottom / 12px 2px no-repeat,
    linear-gradient(var(--brass), var(--brass)) left bottom / 2px 12px no-repeat,
    linear-gradient(var(--brass), var(--brass)) right bottom / 12px 2px no-repeat,
    linear-gradient(var(--brass), var(--brass)) right bottom / 2px 12px no-repeat,
    rgba(10, 7, 6, 0.6);
}
.btn--scan {
  flex-direction: column;
  gap: 8px;
  min-height: 96px;
  font-size: 17px;
}
.btn--scan svg { color: var(--brass); }
.btn--scan::after {
  content: '';
  position: absolute;
  inset: -1px;
  border: 1px solid var(--brass);
  opacity: 0;
  animation: breathe 3.2s ease-in-out infinite;
  pointer-events: none;
}
@keyframes breathe { 50% { opacity: 0.55; } }

/* ---- meter ---- */
.meter { margin-top: 26px; }
.meter__row {
  display: flex;
  justify-content: space-between;
  font-family: var(--type);
  font-size: 13px;
  letter-spacing: 0.18em;
  color: var(--ink-dim);
  margin-bottom: 8px;
}
.meter__bar {
  position: relative;
  height: 6px;
  background: rgba(216, 207, 189, 0.08);
  border: 1px solid rgba(216, 207, 189, 0.12);
}
.meter__bar::after {
  content: '';
  position: absolute;
  left: 50%;
  top: -3px;
  bottom: -3px;
  width: 1px;
  background: rgba(216, 207, 189, 0.25);
}
.meter__bar i {
  display: block;
  height: 100%;
  width: calc(var(--v, 0) * 100%);
  background: var(--green);
  transition: width 1.2s ease, background 0.6s;
}
.meter.is-danger .meter__row span:last-child { color: var(--red-hi); }
.meter.is-danger .meter__bar i { background: var(--red-hi); }

/* ---- end ---- */
.stats {
  margin: 0 0 8px;
  border-top: 1px solid var(--line);
}
.stats div {
  display: flex;
  justify-content: space-between;
  padding: 11px 2px;
  border-bottom: 1px solid var(--line);
  font-size: 14px;
}
.stats dt { color: var(--ink-dim); letter-spacing: 0.1em; }
.stats dd { margin: 0; font-family: var(--type); letter-spacing: 0.1em; }

.staff {
  margin: 28px 0 0;
  padding: 10px 0;
  text-align: center;
  font-family: var(--type);
  font-size: 10px;
  letter-spacing: 0.3em;
  color: #3a332c;
  -webkit-touch-callout: none;
}
.staff.is-holding { color: var(--red-hi); }

/* ---- sound toggle ---- */
.sound {
  position: fixed;
  z-index: 20;
  top: calc(env(safe-area-inset-top) + 64px);
  right: calc(env(safe-area-inset-right) + 12px);
  padding: 6px 4px;
  border: 0;
  background: none;
  color: var(--ink-faint);
  font-family: var(--type);
  font-size: 10px;
  letter-spacing: 0.2em;
  cursor: pointer;
}

/* ---- scanner ---- */
.scanner {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: #000;
}
.scanner[hidden] { display: none; }
.scanner video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.scanner__mask {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}
.scanner__frame {
  width: min(70vw, 300px);
  aspect-ratio: 1;
  box-shadow: 0 0 0 200vmax rgba(0, 0, 0, 0.5);
  --c: var(--ink);
  background:
    linear-gradient(var(--c), var(--c)) left top / 28px 2px no-repeat,
    linear-gradient(var(--c), var(--c)) left top / 2px 28px no-repeat,
    linear-gradient(var(--c), var(--c)) right top / 28px 2px no-repeat,
    linear-gradient(var(--c), var(--c)) right top / 2px 28px no-repeat,
    linear-gradient(var(--c), var(--c)) left bottom / 28px 2px no-repeat,
    linear-gradient(var(--c), var(--c)) left bottom / 2px 28px no-repeat,
    linear-gradient(var(--c), var(--c)) right bottom / 28px 2px no-repeat,
    linear-gradient(var(--c), var(--c)) right bottom / 2px 28px no-repeat;
}
.scanner__hint {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(env(safe-area-inset-top) + 9vh);
  margin: 0;
  padding: 0 24px;
  text-align: center;
  font-size: 15px;
  letter-spacing: 0.08em;
  text-shadow: 0 1px 3px #000;
}
.scanner__error {
  position: absolute;
  left: 24px;
  right: 24px;
  top: 50%;
  transform: translateY(-50%);
  padding: 22px 18px;
  border: 1px solid rgba(207, 74, 53, 0.6);
  background: rgba(12, 6, 5, 0.94);
  text-align: center;
  font-size: 14.5px;
  line-height: 1.9;
  white-space: pre-line;
}
.scanner__error p { margin: 0; }
.scanner:has(.scanner__error:not([hidden])) .scanner__mask { display: none; }
.scanner__close {
  position: absolute;
  left: 24px;
  right: 24px;
  bottom: calc(env(safe-area-inset-bottom) + 28px);
  width: auto;
  background: rgba(0, 0, 0, 0.6);
}

/* ---- dev panel (?dev) ---- */
.dev {
  position: fixed;
  z-index: 60;
  left: 8px;
  bottom: 8px;
  max-width: 280px;
  padding: 8px;
  background: rgba(0, 0, 0, 0.85);
  border: 1px dashed #666;
  font: 11px/1.5 monospace;
  color: #ccc;
}
.dev summary { cursor: pointer; }
.dev button, .dev input {
  font: 11px monospace;
  margin: 2px 0;
  width: 100%;
  padding: 6px;
  background: #222;
  color: #ddd;
  border: 1px solid #555;
  border-radius: 0;
  text-align: left;
}

.noscript { padding: 40px 24px; text-align: center; }

@media (prefers-reduced-motion: reduce) {
  .btn--scan::after, .body--riddle.is-typing::after { animation: none; }
  .screen, .screen.is-active { transition: none; }
}

@media (max-height: 640px) {
  .gap { flex-basis: 30vh; }
  .title { font-size: 36px; }
  .body { line-height: 1.85; margin-bottom: 20px; }
  .meter { margin-top: 20px; }
}
