:root {
  --bg-deep: #0b0907;
  --bg-panel: rgba(20, 17, 14, 0.92);
  --gold: #d9aa4b;
  --gold-bright: #f7d782;
  --crimson: #a8241d;
  --crimson-bright: #d9382e;
  --parchment: #f2e8d5;
  --text-muted: #b5a68e;
  --border-gold: rgba(217, 170, 75, 0.42);
}

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

html,
body {
  width: 100%;
  height: 100%;
  height: 100dvh;
  overflow: hidden;
  background: radial-gradient(circle at 50% 38%, #221c15 0%, #100d0a 65%, #070605 100%);
  color: var(--parchment);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
}

#canvas-container {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
  touch-action: none;
}

/* Top HUD */
.hud-top {
  position: fixed;
  top: env(safe-area-inset-top, 10px);
  left: 12px;
  right: 12px;
  z-index: 10;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.hud-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-panel);
  border: 1px solid var(--border-gold);
  border-radius: 14px;
  padding: 10px 14px;
  backdrop-filter: blur(10px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.55);
  pointer-events: auto;
}

.hud-title-group {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.chapter-pill {
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--gold);
}

.level-title {
  font-family: 'Cinzel', serif;
  font-size: 1.02rem;
  font-weight: 700;
  color: var(--parchment);
}

.hud-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.icon-btn {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border-gold);
  color: var(--gold-bright);
  border-radius: 10px;
  padding: 7px 10px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.12s, background 0.15s;
}

.icon-btn:active {
  transform: scale(0.93);
  background: rgba(217, 170, 75, 0.22);
}

.hud-stats-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: rgba(15, 12, 10, 0.82);
  border: 1px solid rgba(217, 170, 75, 0.25);
  border-radius: 10px;
  padding: 6px 12px;
  pointer-events: auto;
}

.stat-item {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.stat-item strong {
  color: var(--gold-bright);
  font-weight: 700;
}

.progress-track {
  flex: 1;
  height: 7px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 99px;
  overflow: hidden;
  max-width: 160px;
}

.progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--crimson-bright), var(--gold-bright));
  transition: width 0.25s ease-out;
}

/* Floating helper instruction + combo toast */
.gesture-hint {
  position: fixed;
  bottom: calc(env(safe-area-inset-bottom, 12px) + 92px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 8;
  font-size: 0.75rem;
  color: rgba(242, 232, 213, 0.65);
  background: rgba(11, 9, 7, 0.65);
  padding: 5px 14px;
  border-radius: 99px;
  border: 1px solid rgba(217, 170, 75, 0.2);
  pointer-events: none;
  white-space: nowrap;
}

.floating-toast {
  position: fixed;
  top: 128px;
  left: 50%;
  transform: translateX(-50%) translateY(-10px);
  z-index: 25;
  background: linear-gradient(135deg, #8e1f1b, #4a0e0b);
  border: 1.5px solid var(--gold-bright);
  color: var(--gold-bright);
  font-family: 'Cinzel', serif;
  font-weight: 700;
  font-size: 0.85rem;
  padding: 8px 18px;
  border-radius: 99px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.65);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  white-space: nowrap;
}

.floating-toast.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* Bottom Tactical Abilities Bar */
.hud-bottom {
  position: fixed;
  bottom: env(safe-area-inset-bottom, 14px);
  left: 12px;
  right: 12px;
  z-index: 10;
  display: flex;
  justify-content: center;
  gap: 10px;
  pointer-events: none;
}

.ability-btn {
  pointer-events: auto;
  flex: 1;
  max-width: 145px;
  background: var(--bg-panel);
  border: 1.5px solid var(--border-gold);
  border-radius: 14px;
  padding: 9px 10px;
  color: var(--parchment);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  cursor: pointer;
  backdrop-filter: blur(10px);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.55);
  transition: transform 0.12s, border-color 0.2s, background 0.2s;
}

.ability-btn:active {
  transform: scale(0.95);
}

.ability-btn.armed {
  background: linear-gradient(135deg, rgba(168, 36, 29, 0.9), rgba(90, 16, 12, 0.95));
  border-color: var(--gold-bright);
  box-shadow: 0 0 18px rgba(247, 215, 130, 0.55);
}

.ability-left {
  display: flex;
  align-items: center;
  gap: 7px;
  text-align: left;
}

.ability-icon {
  font-size: 1.25rem;
}

.ability-name {
  font-size: 0.74rem;
  font-weight: 700;
  line-height: 1.15;
  color: var(--parchment);
}

.ability-sub {
  font-size: 0.62rem;
  color: var(--text-muted);
}

.ability-badge {
  background: rgba(217, 170, 75, 0.22);
  border: 1px solid var(--gold);
  color: var(--gold-bright);
  font-size: 0.74rem;
  font-weight: 800;
  min-width: 24px;
  height: 24px;
  border-radius: 99px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Title / Campaign Overlay Screen */
.overlay-screen {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: radial-gradient(circle at 50% 25%, rgba(28, 22, 16, 0.94), rgba(8, 6, 5, 0.98));
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  overflow-y: auto;
}

.hidden {
  display: none !important;
}

.title-card {
  width: 100%;
  max-width: 440px;
  background: linear-gradient(180deg, #1b1612 0%, #0f0c09 100%);
  border: 1.5px solid var(--gold);
  border-radius: 20px;
  overflow: hidden;
  box-shadow: 0 22px 60px rgba(0, 0, 0, 0.85);
  text-align: center;
}

.title-hero-banner {
  position: relative;
  width: 100%;
  height: 220px;
  overflow: hidden;
  border-bottom: 1.5px solid var(--border-gold);
}

.title-hero-banner img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center 20%;
}

.title-hero-gradient {
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(11, 9, 7, 0.1) 0%, rgba(15, 12, 9, 0.95) 100%);
}

.title-emblem {
  position: absolute;
  bottom: 12px;
  left: 16px;
  right: 16px;
}

.jp-watermark {
  font-size: 0.78rem;
  letter-spacing: 0.22em;
  color: var(--gold-bright);
  text-transform: uppercase;
  margin-bottom: 2px;
}

.main-game-title {
  font-family: 'Cinzel', serif;
  font-size: 2.1rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  color: #fff;
  text-shadow: 0 4px 16px rgba(0, 0, 0, 0.9);
}

.main-game-subtitle {
  font-size: 0.85rem;
  color: var(--gold);
  font-weight: 600;
}

.title-body {
  padding: 18px 20px 22px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.rank-banner {
  background: rgba(217, 170, 75, 0.12);
  border: 1px solid var(--border-gold);
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--gold-bright);
}

.title-desc {
  font-size: 0.84rem;
  line-height: 1.48;
  color: var(--text-muted);
}

.primary-gold-btn {
  background: linear-gradient(135deg, #e0b354 0%, #b07d23 100%);
  color: #120d07;
  font-family: 'Cinzel', serif;
  font-size: 1rem;
  font-weight: 800;
  padding: 14px 18px;
  border: none;
  border-radius: 12px;
  cursor: pointer;
  box-shadow: 0 6px 20px rgba(217, 170, 75, 0.35);
  transition: transform 0.12s;
}

.primary-gold-btn:active {
  transform: scale(0.97);
}

.secondary-btn-row {
  display: flex;
  gap: 10px;
}

.secondary-btn {
  flex: 1;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border-gold);
  color: var(--parchment);
  font-weight: 600;
  font-size: 0.84rem;
  padding: 11px 12px;
  border-radius: 11px;
  cursor: pointer;
}

.install-pwa-btn {
  background: linear-gradient(135deg, #8e1f1b 0%, #59110e 100%);
  border: 1px solid var(--gold);
  color: var(--gold-bright);
  font-weight: 700;
  font-size: 0.84rem;
  padding: 11px 14px;
  border-radius: 11px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

/* Chapter Story Modal & Victory Modal */
.modal-card {
  width: 100%;
  max-width: 460px;
  max-height: 90dvh;
  background: linear-gradient(180deg, #1b1612 0%, #100d0a 100%);
  border: 1.5px solid var(--gold);
  border-radius: 20px;
  overflow-y: auto;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.9);
  display: flex;
  flex-direction: column;
}

.chapter-tabs {
  display: flex;
  gap: 6px;
  padding: 10px 14px;
  background: rgba(0, 0, 0, 0.4);
  border-bottom: 1px solid rgba(217, 170, 75, 0.2);
  overflow-x: auto;
}

.chapter-tab-btn {
  flex: 1;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(217, 170, 75, 0.3);
  color: var(--text-muted);
  font-size: 0.74rem;
  font-weight: 700;
  padding: 6px 8px;
  border-radius: 8px;
  cursor: pointer;
  white-space: nowrap;
}

.chapter-tab-btn.active {
  background: var(--gold);
  color: #120d07;
  border-color: var(--gold-bright);
}

.chapter-tab-btn.locked {
  opacity: 0.5;
}

.chapter-art-wrap {
  width: 100%;
  aspect-ratio: 16 / 9;
  background: #000;
  overflow: hidden;
  border-bottom: 1px solid var(--border-gold);
}

.chapter-art-wrap img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.chapter-content {
  padding: 16px 20px 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.chapter-meta-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--gold);
}

.chapter-title {
  font-family: 'Cinzel', serif;
  font-size: 1.38rem;
  font-weight: 800;
  color: #fff;
}

.chapter-jp {
  font-size: 0.8rem;
  color: var(--gold-bright);
  margin-top: -4px;
}

.chapter-quote {
  font-style: italic;
  font-size: 0.84rem;
  color: var(--parchment);
  background: rgba(217, 170, 75, 0.09);
  border-left: 3px solid var(--gold);
  padding: 8px 12px;
  border-radius: 0 8px 8px 0;
}

.chapter-story {
  font-size: 0.86rem;
  line-height: 1.56;
  color: #d6cabc;
  user-select: text;
}

/* Level Select Grid */
.level-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  padding: 14px 18px;
  max-height: 60dvh;
  overflow-y: auto;
}

.level-card {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-gold);
  border-radius: 12px;
  padding: 11px 14px;
  text-align: left;
  color: var(--parchment);
  cursor: pointer;
}

.level-card.current {
  border-color: var(--gold-bright);
  background: rgba(217, 170, 75, 0.16);
}

.level-card.locked {
  opacity: 0.45;
  cursor: not-allowed;
}

.level-card-top {
  display: flex;
  justify-content: space-between;
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--gold);
  margin-bottom: 3px;
}

.level-card-name {
  font-family: 'Cinzel', serif;
  font-size: 0.96rem;
  font-weight: 700;
}

.level-card-sub {
  font-size: 0.74rem;
  color: var(--text-muted);
  margin-top: 2px;
}
