:root {
  --paper-cream: #f4efe1;
  --paper-edge: #fbf8ee;
  --paper-shadow: rgba(34, 52, 30, 0.20);
  --ink-primary: #2a3322;
  --ink-muted: #55644a;
  --accent-forest: #497542;
  --accent-terra: #be6040;
  --accent-danger: #9f2d3f;
  --border-crease: rgba(62, 86, 52, 0.28);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html,
body,
#app {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #a9bd82;
  font-family: "Hiragino Mincho ProN", "Yu Mincho", "Georgia", "Times New Roman", serif;
  color: var(--ink-primary);
  user-select: none;
}

#scene-canvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: grab;
  touch-action: none;
}

#scene-canvas:active {
  cursor: grabbing;
}

.miniature-vignette {
  pointer-events: none;
  position: fixed;
  inset: 0;
  background: radial-gradient(
    ellipse at center,
    rgba(245, 237, 224, 0) 58%,
    rgba(30, 46, 26, 0.22) 100%
  );
}

/* Top-left title + quest stack */
.title-stack {
  position: fixed;
  top: 16px;
  left: 18px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
  z-index: 10;
}

.title-bookmark {
  padding: 9px 16px 10px;
  background: rgba(246, 243, 231, 0.90);
  border: 1px solid var(--border-crease);
  border-radius: 3px;
  box-shadow:
    0 3px 0 rgba(182, 194, 156, 0.85),
    0 8px 20px var(--paper-shadow);
  backdrop-filter: blur(6px);
}

.title-bookmark h1 {
  font-size: 1.1rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  line-height: 1.15;
  color: var(--ink-primary);
}

.title-bookmark .subtitle {
  margin-top: 2px;
  font-size: 0.70rem;
  letter-spacing: 0.12em;
  color: var(--ink-muted);
  font-family: "Hiragino Kaku Gothic ProN", "Yu Gothic", system-ui, sans-serif;
}

/* Retro-styled quest & score card */
.quest-card {
  padding: 8px 13px 9px;
  background: rgba(16, 20, 24, 0.88);
  color: #f6f4ea;
  border: 2px solid #f6f4ea;
  outline: 2px solid #101418;
  border-radius: 2px;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.30);
  font-family: "Courier New", "Hiragino Kaku Gothic ProN", monospace;
  max-width: 285px;
}

.quest-card.is-danger {
  border-color: #f07b88;
  background: rgba(24, 12, 22, 0.92);
}

.quest-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  font-size: 0.82rem;
  letter-spacing: 0.06em;
}

.quest-score {
  white-space: nowrap;
}

.quest-score strong {
  color: #f7d76d;
  font-size: 1.02rem;
}

.key-badge {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 2px 7px;
  background: rgba(235, 192, 74, 0.22);
  border: 1px solid #f3cd67;
  color: #fae193;
  border-radius: 2px;
  font-size: 0.70rem;
  white-space: nowrap;
}

.compass-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 7px;
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.35);
  border-radius: 2px;
  font-size: 0.70rem;
  white-space: nowrap;
}

.key-badge[hidden],
.compass-pill[hidden],
.bark-bubble[hidden],
.fc-dialog[hidden] {
  display: none !important;
}

.compass-arrow {
  display: inline-block;
  color: #f7d76d;
  font-size: 0.78rem;
  transition: transform 0.08s linear;
}

.quest-card.is-danger .compass-arrow {
  color: #ff7c8a;
}

.quest-hint {
  margin-top: 5px;
  font-size: 0.73rem;
  line-height: 1.4;
  color: #dfe6d5;
}

.quest-card.is-danger .quest-hint {
  color: #ffbec6;
}

/* Top-right paper tab controls */
.toolbar {
  position: fixed;
  top: 16px;
  right: 18px;
  display: flex;
  gap: 8px;
  z-index: 10;
}

.paper-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 8px 12px;
  font-family: "Hiragino Kaku Gothic ProN", "Yu Gothic", system-ui, sans-serif;
  font-size: 0.76rem;
  font-weight: 500;
  letter-spacing: 0.04em;
  color: var(--ink-primary);
  background: rgba(248, 245, 234, 0.92);
  border: 1px solid var(--border-crease);
  border-radius: 3px;
  box-shadow:
    0 2px 0 rgba(176, 190, 152, 0.9),
    0 6px 14px var(--paper-shadow);
  cursor: pointer;
  transition: transform 0.14s ease, background 0.16s ease, color 0.16s ease;
}

.paper-btn:hover {
  background: var(--paper-edge);
  transform: translateY(-1px);
}

.paper-btn:active {
  transform: translateY(1px);
}

.paper-btn.is-active {
  background: var(--accent-forest);
  color: #faf9f2;
  border-color: rgba(42, 74, 38, 0.55);
  box-shadow:
    0 2px 0 #2e5229,
    0 6px 14px rgba(34, 66, 30, 0.28);
}

.paper-btn .btn-icon {
  font-size: 0.88rem;
  line-height: 1;
}

/* Tactile Zoom + / - Buttons (stacked cleanly above Dash button) */
.zoom-controls {
  position: fixed;
  right: 22px;
  bottom: 114px;
  z-index: 15;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.zoom-btn {
  width: 44px;
  height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: "Hiragino Kaku Gothic ProN", "Yu Gothic", system-ui, sans-serif;
  font-size: 1.25rem;
  font-weight: 700;
  line-height: 1;
  color: var(--ink-primary);
  background: rgba(249, 245, 233, 0.94);
  border: 2px solid rgba(72, 92, 60, 0.36);
  border-radius: 50%;
  box-shadow:
    0 3px 0 rgba(154, 170, 134, 0.9),
    0 6px 14px var(--paper-shadow);
  cursor: pointer;
  transition: transform 0.12s ease, background 0.14s ease;
}

.zoom-btn:hover {
  background: var(--paper-edge);
  transform: translateY(-1px);
}

.zoom-btn:active {
  transform: translateY(1px);
}

/* Tactile Dash Mode Button (bottom-right, easy thumb reach on mobile & click on PC) */
.dash-btn {
  position: fixed;
  right: 22px;
  bottom: 58px;
  z-index: 15;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 11px 16px;
  font-family: "Hiragino Kaku Gothic ProN", "Yu Gothic", system-ui, sans-serif;
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: #2b241c;
  background: rgba(249, 245, 233, 0.94);
  border: 2px solid rgba(72, 92, 60, 0.36);
  border-radius: 999px;
  box-shadow:
    0 3px 0 rgba(154, 170, 134, 0.9),
    0 8px 18px var(--paper-shadow);
  cursor: pointer;
  transition: transform 0.12s ease, background 0.15s ease, color 0.15s ease;
}

.dash-btn.is-active {
  background: #c85c3b;
  color: #fffdf5;
  border-color: #f6e7c8;
  box-shadow:
    0 3px 0 #8a3a22,
    0 8px 20px rgba(180, 74, 42, 0.42);
}

.dash-btn.is-urgent {
  border-color: #ff6e82;
  animation: dashPulse 0.85s ease-in-out infinite;
}

@keyframes dashPulse {
  0%, 100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(255, 110, 130, 0.55); }
  50% { transform: scale(1.06); box-shadow: 0 0 0 10px rgba(255, 110, 130, 0); }
}

/* Floating Dog Bark Bubble ("ワン！") */
.bark-bubble {
  position: fixed;
  z-index: 14;
  transform: translate(-50%, -100%);
  padding: 4px 10px;
  background: #101418;
  color: #fffdf5;
  border: 2px solid #fffdf5;
  border-radius: 3px;
  font-family: "Courier New", "Hiragino Kaku Gothic ProN", monospace;
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  pointer-events: none;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.32);
}

/* Auto-Disappearing Famicom Retro Comment Window */
.fc-dialog {
  position: fixed;
  left: 50%;
  bottom: 54px;
  transform: translateX(-50%);
  width: min(580px, calc(100vw - 28px));
  z-index: 30;
  cursor: pointer;
  transition: opacity 0.25s ease;
}

.fc-dialog-inner {
  background: rgba(13, 15, 22, 0.94);
  color: #fcfaf2;
  border: 3px solid #fcfaf2;
  outline: 3px solid #0d0f16;
  border-radius: 4px;
  padding: 14px 18px 15px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.48);
  font-family: "Courier New", "Hiragino Kaku Gothic ProN", "Yu Gothic", monospace;
}

.fc-dialog.is-phantom .fc-dialog-inner {
  background: rgba(22, 10, 24, 0.95);
  border-color: #e47486;
  color: #f9e6ea;
}

.fc-speaker {
  display: inline-block;
  margin-bottom: 7px;
  padding: 2px 10px;
  background: #fcfaf2;
  color: #0d0f16;
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0.10em;
}

.fc-dialog.is-phantom .fc-speaker {
  background: #d85268;
  color: #fff6f8;
}

.fc-text {
  min-height: 2.6em;
  font-size: 0.94rem;
  line-height: 1.65;
  letter-spacing: 0.06em;
}

/* Retro Clear / Game Over Modal */
.end-overlay {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(12, 14, 18, 0.66);
  padding: 20px;
}

.end-overlay[hidden] {
  display: none;
}

.end-box {
  width: min(460px, 100%);
  background: #0d0f16;
  color: #fcfaf2;
  border: 4px solid #fcfaf2;
  outline: 4px solid #0d0f16;
  border-radius: 4px;
  padding: 26px 24px 24px;
  text-align: center;
  font-family: "Courier New", "Hiragino Kaku Gothic ProN", monospace;
  box-shadow: 0 18px 46px rgba(0, 0, 0, 0.58);
}

.end-box.is-gameover {
  border-color: #df5c6e;
  background: #170a14;
}

.end-icon {
  font-size: 2.1rem;
  margin-bottom: 8px;
}

.end-title {
  font-size: 1.55rem;
  letter-spacing: 0.14em;
  color: #f7d76d;
  margin-bottom: 12px;
}

.end-box.is-gameover .end-title {
  color: #ff6e82;
}

.end-desc {
  font-size: 0.88rem;
  line-height: 1.78;
  letter-spacing: 0.05em;
  margin-bottom: 22px;
  color: #e8ece2;
  text-align: left;
  white-space: pre-line;
}

.fc-retry-btn {
  display: inline-block;
  padding: 12px 24px;
  background: #fcfaf2;
  color: #0d0f16;
  border: none;
  border-radius: 2px;
  font-family: inherit;
  font-size: 0.94rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  cursor: pointer;
}

.fc-retry-btn:hover {
  background: #f7d76d;
}

/* Bottom subtle hint bar */
.hint-strip {
  position: fixed;
  bottom: 14px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 6px 14px;
  background: rgba(246, 243, 231, 0.84);
  border: 1px solid var(--border-crease);
  border-radius: 3px;
  box-shadow: 0 4px 12px var(--paper-shadow);
  font-family: "Hiragino Kaku Gothic ProN", "Yu Gothic", system-ui, sans-serif;
  font-size: 0.72rem;
  letter-spacing: 0.03em;
  color: var(--ink-muted);
  white-space: nowrap;
  backdrop-filter: blur(5px);
  pointer-events: none;
  z-index: 9;
}

.hint-mobile {
  display: none;
}

.telemetry {
  font-variant-numeric: tabular-nums;
  opacity: 0.78;
  padding-left: 10px;
  border-left: 1px solid var(--border-crease);
}

/* Mobile Touch Joystick */
.touch-joystick {
  display: none;
  position: fixed;
  bottom: 52px;
  left: 18px;
  z-index: 12;
  touch-action: none;
}

.joy-base {
  width: 92px;
  height: 92px;
  border-radius: 50%;
  background: rgba(244, 240, 228, 0.56);
  border: 1.5px solid rgba(54, 78, 46, 0.42);
  box-shadow: 0 4px 14px var(--paper-shadow);
  position: relative;
}

.joy-knob {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--accent-terra);
  border: 2px solid var(--paper-edge);
  box-shadow: 0 3px 8px rgba(42, 56, 36, 0.35);
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

@media (hover: none) and (pointer: coarse), (max-width: 768px) {
  .title-stack {
    top: 10px;
    left: 10px;
    gap: 6px;
  }
  .title-bookmark {
    padding: 5px 10px;
  }
  .title-bookmark h1 {
    font-size: 0.90rem;
  }
  .title-bookmark .subtitle {
    font-size: 0.60rem;
  }
  .quest-card {
    padding: 6px 9px;
    max-width: 225px;
  }
  .quest-top {
    font-size: 0.74rem;
  }
  .quest-hint {
    font-size: 0.66rem;
  }
  .toolbar {
    top: 10px;
    right: 10px;
    flex-direction: column;
    gap: 5px;
  }
  .paper-btn {
    padding: 5px 8px;
    font-size: 0.68rem;
  }
  .zoom-controls {
    right: 16px;
    bottom: 124px;
    gap: 7px;
  }
  .zoom-btn {
    width: 42px;
    height: 42px;
    font-size: 1.15rem;
  }
  .dash-btn {
    right: 16px;
    bottom: 64px;
    padding: 13px 16px;
    font-size: 0.80rem;
  }
  .fc-dialog {
    bottom: 158px;
  }
  .fc-dialog-inner {
    padding: 11px 14px;
  }
  .fc-text {
    font-size: 0.82rem;
  }
  .hint-desktop {
    display: none;
  }
  .hint-mobile {
    display: inline;
  }
  .hint-strip {
    bottom: 10px;
    padding: 5px 10px;
    font-size: 0.66rem;
  }
  .telemetry {
    display: none;
  }
  .touch-joystick {
    display: block;
  }
}
