:root {
  --bg-plum: #130f1c;
  --clay-cream: #f5eadb;
  --clay-soft: #dfd0c0;
  --coral-felt: #cf443e;
  --coral-deep: #9f2d2a;
  --amber-lamp: #f2bc72;
  --emerald-soft: #4ec47d;
  --card-surface: rgba(28, 22, 42, 0.80);
  --card-border: rgba(245, 234, 219, 0.20);
  --font-ui: 'SF Pro Rounded', 'Nunito', 'Fredoka', ui-rounded, system-ui, -apple-system, sans-serif;
  --font-story: 'Iowan Old Style', 'Lora', 'Georgia', serif;
}

* {
  box-sizing: border-box;
  user-select: none;
  -webkit-user-select: none;
}

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg-plum);
  color: var(--clay-cream);
  font-family: var(--font-ui);
}

button:focus-visible {
  outline: 2.5px solid var(--amber-lamp);
  outline-offset: 2px;
}

#app {
  position: fixed;
  inset: 0;
}

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

/* Warm handcrafted Splash Loader */
#splash {
  position: fixed;
  inset: 0;
  z-index: 80;
  background: radial-gradient(circle at 50% 45%, #231a34 0%, #130f1c 75%);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  transition: opacity 0.42s ease;
}
#splash.done {
  opacity: 0;
  pointer-events: none;
}
.splash-icon {
  width: 58px;
  height: 58px;
  animation: floatBob 1.8s ease-in-out infinite;
}
.splash-text {
  font-family: var(--font-story);
  font-size: 16px;
  color: var(--clay-soft);
  letter-spacing: 0.02em;
}
.splash-card {
  max-width: 360px;
  padding: 24px 26px;
  border-radius: 24px;
  background: rgba(28, 22, 42, 0.9);
  border: 1px solid var(--card-border);
  text-align: center;
}
.splash-card h2 {
  margin: 0 0 8px;
  font-family: var(--font-story);
}
.splash-card p {
  margin: 0;
  font-size: 14px;
  color: var(--clay-soft);
}
@keyframes floatBob {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-7px); }
}

/* Velvet cross-fade curtain (blocks stray clicks during transitions!) */
#curtain {
  position: fixed;
  inset: 0;
  background: #130f1c;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.34s ease;
  z-index: 60;
}
#curtain.show {
  opacity: 1;
  pointer-events: auto;
}

/* Corner minimal nav */
#top-nav {
  position: fixed;
  top: max(14px, env(safe-area-inset-top));
  right: max(16px, env(safe-area-inset-right));
  z-index: 40;
}

.nav-cluster {
  display: flex;
  gap: 8px;
  align-items: center;
}

.mini-pill {
  appearance: none;
  border: 1px solid var(--card-border);
  background: rgba(26, 20, 38, 0.80);
  color: var(--clay-cream);
  font-family: var(--font-ui);
  font-size: 13px;
  font-weight: 600;
  padding: 8px 13px;
  border-radius: 999px;
  cursor: pointer;
  backdrop-filter: blur(12px);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  box-shadow: inset 0 1px 0 rgba(255, 245, 235, 0.16), 0 6px 18px rgba(10, 6, 18, 0.38);
  transition: transform 0.14s ease, background 0.14s ease;
}
.mini-pill.icon-only {
  padding: 8px 10px;
}
.mini-pill:hover {
  transform: translateY(-1px);
  background: rgba(46, 36, 64, 0.90);
}
.lang-pill .on {
  color: #fff8ef;
  font-weight: 800;
}
.lang-pill .off {
  color: rgba(245, 234, 219, 0.45);
}
.lang-pill .sep {
  color: rgba(245, 234, 219, 0.3);
}

.chapter-wrap {
  position: relative;
}

.chapter-menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  min-width: 224px;
  padding: 8px;
  border-radius: 20px;
  background: rgba(26, 20, 38, 0.95);
  border: 1px solid var(--card-border);
  backdrop-filter: blur(16px);
  box-shadow: 0 16px 40px rgba(8, 5, 16, 0.58);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.chapter-item {
  appearance: none;
  border: none;
  background: transparent;
  color: var(--clay-soft);
  font-family: var(--font-ui);
  font-size: 13.5px;
  font-weight: 600;
  text-align: left;
  padding: 9px 12px;
  border-radius: 12px;
  cursor: pointer;
  transition: background 0.14s ease, color 0.14s ease;
}
.chapter-item:hover {
  background: rgba(245, 234, 219, 0.11);
  color: var(--clay-cream);
}
.chapter-item.active {
  background: rgba(207, 68, 62, 0.30);
  color: #fff6ec;
}

/* Main HUD Overlay */
#overlay {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 20;
}

#overlay button,
.title-card,
.story-card,
.table-bottom-dock,
.doom-hud,
.ending-dock,
.touch-controls {
  pointer-events: auto;
}

/* Act 0 Title Card */
.title-wrap {
  position: absolute;
  left: 34px;
  bottom: 42px;
  max-width: 430px;
}

.title-card {
  padding: 24px 26px 22px;
  border-radius: 28px;
  background: rgba(24, 18, 36, 0.78);
  border: 1px solid var(--card-border);
  backdrop-filter: blur(14px);
  box-shadow: inset 0 1.5px 0 rgba(255, 245, 235, 0.18), 0 22px 50px rgba(8, 5, 16, 0.55);
}

.game-title {
  margin: 0 0 8px;
  font-family: var(--font-story);
  font-size: 33px;
  font-weight: 700;
  line-height: 1.1;
  color: #fff3e6;
  text-shadow: 0 3px 16px rgba(207, 68, 62, 0.35);
}

.game-sub {
  margin: 0 0 18px;
  font-size: 14.5px;
  line-height: 1.45;
  color: var(--clay-soft);
}

.btn-row {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.keepsake-badge {
  font-size: 12.5px;
  font-weight: 700;
  color: var(--amber-lamp);
  padding: 6px 12px;
  border-radius: 999px;
  background: rgba(242, 188, 114, 0.14);
  border: 1px solid rgba(242, 188, 114, 0.30);
}

/* Tactile Soft-3D Pill Buttons */
.pill-btn {
  appearance: none;
  border: none;
  font-family: var(--font-ui);
  font-size: 14.5px;
  font-weight: 700;
  padding: 11px 22px;
  border-radius: 999px;
  cursor: pointer;
  color: #fff8f0;
  transition: transform 0.14s ease, filter 0.14s ease, opacity 0.14s ease;
  box-shadow:
    inset 0 2px 1px rgba(255, 255, 255, 0.28),
    inset 0 -3px 0 rgba(0, 0, 0, 0.22),
    0 10px 24px rgba(12, 6, 20, 0.42);
}
.pill-btn:hover:not(:disabled) {
  transform: translateY(-2px);
  filter: brightness(1.06);
}
.pill-btn:active:not(:disabled) {
  transform: translateY(1px);
}
.pill-btn:disabled {
  opacity: 0.40;
  cursor: default;
}
.pill-btn.primary {
  background: linear-gradient(180deg, #de524b 0%, #b53230 100%);
}
.pill-btn.danger {
  background: linear-gradient(180deg, #d64545 0%, #9c252c 100%);
}
.pill-btn.warm {
  background: linear-gradient(180deg, #5d7ba8 0%, #3d547a 100%);
}
.pill-btn.dawn {
  background: linear-gradient(180deg, #e8ad5c 0%, #c47d35 100%);
}
.pill-btn.ghost {
  background: rgba(245, 234, 219, 0.13);
  color: var(--clay-cream);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.16);
}

/* Story Intro & Finale Bar */
.intro-bar {
  position: absolute;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%);
  width: min(620px, calc(100vw - 32px));
}

.story-card {
  padding: 20px 26px;
  border-radius: 26px;
  background: rgba(24, 18, 36, 0.84);
  border: 1px solid var(--card-border);
  backdrop-filter: blur(14px);
  box-shadow: inset 0 1px 0 rgba(255, 245, 235, 0.16), 0 18px 42px rgba(8, 4, 15, 0.55);
}

.story-text {
  margin: 0 0 16px;
  font-family: var(--font-story);
  font-size: 19px;
  line-height: 1.5;
  color: #fff4e8;
  text-align: center;
}

.story-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}
.story-actions.center {
  justify-content: center;
}

/* Top HUD Pills */
.hud-top {
  position: absolute;
  top: max(14px, env(safe-area-inset-top));
  left: max(16px, env(safe-area-inset-left));
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  max-width: calc(100vw - 260px);
}

.hud-pill {
  padding: 8px 14px;
  border-radius: 999px;
  background: rgba(24, 18, 36, 0.78);
  border: 1px solid var(--card-border);
  backdrop-filter: blur(12px);
  font-size: 13px;
  font-weight: 600;
  color: var(--clay-cream);
  box-shadow: inset 0 1px 0 rgba(255, 245, 235, 0.14), 0 6px 18px rgba(8, 5, 16, 0.34);
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.hud-pill.warn {
  border-color: rgba(232, 92, 92, 0.55);
  background: rgba(78, 22, 34, 0.82);
}
.accent {
  color: var(--amber-lamp);
}

.dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
}
.dot.live {
  background: #e84b4b;
  box-shadow: 0 0 8px #e84b4b;
}
.dot.blank {
  background: transparent;
  border: 2px solid #efe7dc;
}

.hud-bottom-hint {
  position: absolute;
  bottom: max(10px, env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  padding: 5px 15px;
  border-radius: 999px;
  background: rgba(18, 13, 28, 0.66);
  font-size: 12px;
  color: rgba(245, 234, 219, 0.86);
  white-space: nowrap;
  max-width: calc(100vw - 24px);
  overflow: hidden;
  text-overflow: ellipsis;
}

.center-toast {
  position: absolute;
  top: 72px;
  left: 50%;
  transform: translateX(-50%);
  padding: 9px 20px;
  border-radius: 16px;
  background: rgba(28, 20, 42, 0.88);
  border-left: 3px solid var(--amber-lamp);
  color: #fff3de;
  font-weight: 600;
  font-size: 14px;
  box-shadow: 0 12px 28px rgba(8, 4, 16, 0.48);
  max-width: min(520px, calc(100vw - 32px));
  text-align: center;
}

/* Act II Table Bottom Dock */
.table-bottom-dock {
  position: absolute;
  bottom: max(16px, env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  width: min(640px, calc(100vw - 28px));
  padding: 15px 18px;
  border-radius: 26px;
  background: rgba(24, 18, 36, 0.84);
  border: 1px solid var(--card-border);
  backdrop-filter: blur(14px);
  box-shadow: inset 0 1px 0 rgba(255, 245, 235, 0.15), 0 16px 40px rgba(6, 4, 12, 0.55);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 11px;
}

.table-status {
  font-size: 14px;
  font-weight: 600;
  color: #ffefd8;
  text-align: center;
  min-height: 20px;
}

.table-actions {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: center;
}

.item-bar {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
}

.item-chip {
  appearance: none;
  border: 1px solid rgba(245, 234, 219, 0.24);
  background: rgba(54, 43, 72, 0.74);
  color: var(--clay-cream);
  font-family: var(--font-ui);
  padding: 7px 13px;
  border-radius: 16px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.18), 0 4px 12px rgba(8, 4, 15, 0.35);
  transition: transform 0.14s ease, background 0.14s ease;
}
.item-chip:hover:not(:disabled) {
  transform: translateY(-2px);
  background: rgba(84, 65, 108, 0.90);
}
.item-chip:disabled {
  opacity: 0.36;
  cursor: default;
}

/* Act III Minimap, Hurt Vignette, High-Contrast Crosshair & Soft-Ceramic Portrait HUD */
.hurt-vignette {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(circle at 50% 50%, transparent 48%, rgba(214, 48, 56, 0.72) 100%);
  transition: opacity 0.08s linear;
}

.minimap-box {
  position: absolute;
  top: 64px;
  right: 18px;
  padding: 8px;
  border-radius: 18px;
  background: rgba(22, 17, 34, 0.78);
  border: 1px solid var(--card-border);
  backdrop-filter: blur(10px);
  box-shadow: 0 10px 26px rgba(8, 4, 16, 0.45);
  display: flex;
}

.crosshair {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 14px;
  height: 14px;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  border: 2px solid #fff7eb;
  box-shadow: 0 0 0 1.5px rgba(18, 12, 26, 0.75), 0 0 10px rgba(255, 190, 120, 0.55);
  transition: transform 0.14s ease, border-color 0.14s ease;
}
.crosshair.shield {
  transform: translate(-50%, -50%) scale(2.2);
  border-color: #6ce89c;
}

.doom-hud {
  position: absolute;
  bottom: 40px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 9px 20px;
  border-radius: 26px;
  max-width: calc(100vw - 20px);
  background: linear-gradient(180deg, rgba(58, 49, 76, 0.90) 0%, rgba(34, 28, 48, 0.95) 100%);
  border: 2px solid rgba(245, 234, 219, 0.24);
  box-shadow:
    inset 0 2px 0 rgba(255, 245, 235, 0.22),
    inset 0 -3px 0 rgba(0, 0, 0, 0.30),
    0 14px 34px rgba(8, 4, 16, 0.6);
}

.doom-stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 56px;
}
.doom-stat span {
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: 0.05em;
  color: rgba(245, 234, 219, 0.70);
}
.doom-stat strong {
  font-size: 19px;
  font-weight: 800;
  color: #fff4e4;
}

.doom-portrait {
  padding: 4px;
  border-radius: 18px;
  background: rgba(20, 15, 30, 0.82);
  border: 1.5px solid rgba(245, 210, 168, 0.32);
  display: flex;
}

/* Mobile Touch Controls (Act III on touchscreens) */
.touch-controls {
  position: fixed;
  inset: 0;
  pointer-events: none;
}
.touch-stick {
  position: absolute;
  left: 22px;
  bottom: 120px;
  width: 96px;
  height: 96px;
  border-radius: 50%;
  background: rgba(28, 22, 42, 0.62);
  border: 2px solid rgba(245, 234, 219, 0.28);
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: auto;
  touch-action: none;
}
.touch-knob {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: rgba(245, 234, 219, 0.82);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}
.touch-btns {
  position: absolute;
  right: 20px;
  bottom: 126px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  pointer-events: auto;
}

/* Act IV Ending Dock — framed bottom-left so the hero umbrella on the golden table stays 100% visible! */
.ending-dock {
  position: absolute;
  left: 34px;
  bottom: 34px;
  width: min(440px, calc(100vw - 32px));
  padding: 24px 26px;
  border-radius: 28px;
  background: rgba(24, 18, 36, 0.84);
  border: 1px solid var(--card-border);
  backdrop-filter: blur(16px);
  box-shadow: inset 0 1.5px 0 rgba(255, 245, 235, 0.18), 0 20px 50px rgba(8, 4, 16, 0.55);
}
.ending-dock.dawn {
  background: rgba(54, 34, 42, 0.74);
  border-color: rgba(255, 232, 194, 0.42);
}
.ending-dock h2 {
  margin: 0 0 10px;
  font-family: var(--font-story);
  font-size: 26px;
  color: #fff6e9;
}
.ending-dock p {
  margin: 0 0 18px;
  font-size: 14.5px;
  line-height: 1.55;
  color: var(--clay-cream);
}

@media (max-width: 640px) {
  .title-wrap, .ending-dock {
    left: 16px;
    right: 16px;
    bottom: 44px;
    width: auto;
  }
  .game-title {
    font-size: 25px;
  }
  .hud-top {
    top: 60px;
    left: 12px;
    max-width: calc(100vw - 116px);
  }
  .center-toast {
    top: 112px;
  }
  .minimap-box {
    top: 60px;
    bottom: auto;
    right: 12px;
    transform: scale(0.82);
    transform-origin: top right;
  }
  .doom-hud {
    gap: 8px;
    padding: 7px 12px;
    bottom: 34px;
  }
  .doom-stat {
    min-width: 44px;
  }
  .doom-stat strong {
    font-size: 15px;
  }
}
