* { margin: 0; padding: 0; box-sizing: border-box; }
html, body {
  width: 100%; height: 100%;
  overflow: hidden;
  background: #05060e;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  color: #f5e9c8;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}
#game-canvas, canvas {
  position: fixed; inset: 0;
  width: 100% !important; height: 100% !important;
  display: block;
}

/* ---------- shared overlay scaffolding ---------- */
.overlay {
  position: fixed; inset: 0;
  display: none;
  align-items: center; justify-content: center;
  flex-direction: column;
  z-index: 20;
  background: radial-gradient(ellipse at 50% 35%, rgba(24, 18, 48, 0.82), rgba(4, 4, 12, 0.94));
  backdrop-filter: blur(3px);
  padding: 16px;
  text-align: center;
}
.overlay.visible { display: flex; }
.panel {
  max-width: 640px; width: 100%;
  background: rgba(10, 10, 26, 0.88);
  border: 1px solid rgba(240, 200, 110, 0.35);
  border-radius: 16px;
  padding: 28px 30px;
  box-shadow: 0 0 60px rgba(255, 200, 90, 0.12), inset 0 0 40px rgba(80, 60, 160, 0.08);
  max-height: 92vh; overflow-y: auto;
}
h1.title {
  font-size: clamp(34px, 7vw, 58px);
  letter-spacing: 6px;
  font-weight: 800;
  background: linear-gradient(180deg, #ffe9a8, #e8b34b 60%, #a06a1e);
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent;
  text-shadow: 0 0 30px rgba(255, 200, 90, 0.25);
  margin-bottom: 4px;
}
.subtitle {
  color: #b9a8e8; letter-spacing: 3px; font-size: 13px;
  text-transform: uppercase; margin-bottom: 20px;
}
.btn {
  display: inline-block;
  padding: 12px 34px;
  margin: 6px;
  font-size: 16px; font-weight: 700; letter-spacing: 2px;
  color: #1a1206;
  background: linear-gradient(180deg, #ffd977, #e0a535);
  border: none; border-radius: 10px;
  cursor: pointer;
  text-transform: uppercase;
  box-shadow: 0 4px 18px rgba(230, 170, 60, 0.35);
  transition: transform 0.12s, box-shadow 0.12s;
}
.btn:hover { transform: translateY(-2px) scale(1.03); box-shadow: 0 6px 26px rgba(255, 200, 90, 0.5); }
.btn:active { transform: scale(0.97); }
.btn.secondary {
  background: rgba(60, 50, 120, 0.6);
  color: #ded2ff;
  border: 1px solid rgba(160, 140, 255, 0.4);
  box-shadow: none;
}
.btn.small { padding: 8px 18px; font-size: 12px; }

/* difficulty selector */
.diff-row { display: flex; justify-content: center; gap: 8px; margin: 14px 0; flex-wrap: wrap; }
.diff-btn {
  padding: 9px 20px; border-radius: 8px; cursor: pointer;
  background: rgba(30, 26, 60, 0.8); color: #a99ad8;
  border: 1px solid rgba(140, 120, 220, 0.3);
  font-weight: 700; letter-spacing: 1px; font-size: 13px;
  transition: all 0.15s;
}
.diff-btn.active {
  background: linear-gradient(180deg, #6d5bd0, #4a3aa0);
  color: #fff; border-color: #b9a8ff;
  box-shadow: 0 0 18px rgba(120, 100, 255, 0.45);
}

.stats-row {
  display: flex; justify-content: center; gap: 26px;
  margin: 16px 0 6px; flex-wrap: wrap;
}
.stat { text-align: center; }
.stat .v { font-size: 22px; font-weight: 800; color: #ffd977; }
.stat .k { font-size: 10px; letter-spacing: 2px; text-transform: uppercase; color: #8f83bd; }

.howto {
  text-align: left; font-size: 13px; line-height: 1.75; color: #cfc4ee;
  background: rgba(20, 16, 44, 0.6); border-radius: 10px;
  padding: 14px 18px; margin: 12px 0;
  border: 1px solid rgba(120, 100, 200, 0.2);
}
.howto b { color: #ffd977; }
.hidden { display: none !important; }

/* lore card */
#lore-card .panel { border-color: rgba(140, 220, 255, 0.35); }
#lore-domain { font-size: 30px; font-weight: 800; letter-spacing: 4px; color: #ffe9a8; margin-bottom: 2px; }
#lore-epithet { font-size: 13px; letter-spacing: 3px; text-transform: uppercase; color: #9fd8ff; margin-bottom: 14px; }
#lore-text { font-size: 15px; line-height: 1.8; color: #e4dcff; font-style: italic; margin-bottom: 18px; }
#lore-timer-wrap { height: 6px; background: rgba(255,255,255,0.08); border-radius: 3px; overflow: hidden; margin-bottom: 14px; }
#lore-timer-bar { height: 100%; width: 100%; background: linear-gradient(90deg, #ffd977, #7de3ff); border-radius: 3px; }

/* ---------- HUD ---------- */
#hud {
  position: fixed; inset: 0; z-index: 10;
  pointer-events: none; display: none;
}
#hud.visible { display: block; }
#hud-top {
  position: absolute; top: 0; left: 0; right: 0;
  display: flex; justify-content: space-between; align-items: flex-start;
  padding: 10px 16px; gap: 10px;
}
.hud-box {
  background: rgba(8, 8, 22, 0.55);
  border: 1px solid rgba(240, 200, 110, 0.22);
  border-radius: 10px; padding: 6px 14px;
  backdrop-filter: blur(2px);
}
#hud-score { font-size: 22px; font-weight: 800; color: #ffe9a8; letter-spacing: 1px; }
#hud-hiscore { font-size: 10px; color: #8f83bd; letter-spacing: 2px; }
#hud-domain { font-size: 13px; font-weight: 700; color: #9fd8ff; letter-spacing: 3px; text-transform: uppercase; text-align: center; }
#hud-lives { font-size: 18px; letter-spacing: 3px; text-align: right; color: #ffd977; }
#hud-graze { font-size: 10px; color: #b9a8e8; letter-spacing: 1px; text-align: right; }

#btn-pause {
  position: absolute; top: 10px; right: 16px;
  pointer-events: auto;
  width: 40px; height: 40px; border-radius: 10px;
  background: rgba(8, 8, 22, 0.6); color: #ffd977;
  border: 1px solid rgba(240, 200, 110, 0.35);
  font-size: 16px; cursor: pointer; display: none;
  align-items: center; justify-content: center;
}
#btn-pause.visible { display: flex; }

/* boss bar */
#boss-bar-wrap {
  position: absolute; top: 64px; left: 50%; transform: translateX(-50%);
  width: min(560px, 82vw); display: none;
}
#boss-bar-wrap.visible { display: block; }
#boss-name { font-size: 12px; letter-spacing: 3px; text-transform: uppercase; color: #ff9f9f; text-align: center; margin-bottom: 4px; text-shadow: 0 0 8px rgba(255,80,80,0.6); }
#boss-bar-outer { height: 12px; background: rgba(10, 6, 20, 0.75); border: 1px solid rgba(255, 120, 120, 0.45); border-radius: 6px; overflow: hidden; }
#boss-bar-inner { height: 100%; width: 100%; background: linear-gradient(90deg, #b03050, #ff6060, #ffb060); border-radius: 6px; transition: width 0.15s; }

/* chi burst gauge */
#chi-wrap {
  position: absolute; bottom: 18px; left: 50%; transform: translateX(-50%);
  width: min(360px, 70vw); text-align: center;
}
#chi-label { font-size: 10px; letter-spacing: 3px; color: #8fe8ff; text-transform: uppercase; margin-bottom: 4px; }
#chi-outer { height: 14px; background: rgba(6, 10, 24, 0.75); border: 1px solid rgba(120, 220, 255, 0.4); border-radius: 7px; overflow: hidden; }
#chi-inner { height: 100%; width: 0%; background: linear-gradient(90deg, #2a7fd0, #66e0ff, #d8ff9f); border-radius: 7px; transition: width 0.1s; }
#chi-wrap.ready #chi-outer { box-shadow: 0 0 22px rgba(110, 230, 255, 0.8); border-color: #d8ff9f; }
#chi-wrap.ready #chi-label { color: #d8ff9f; animation: chipulse 0.7s infinite alternate; }
@keyframes chipulse { from { opacity: 0.6; } to { opacity: 1; } }
#btn-burst {
  pointer-events: auto; margin-top: 8px;
  padding: 8px 26px; border-radius: 20px; cursor: pointer;
  background: rgba(20, 60, 110, 0.7); color: #9fd8ff;
  border: 1px solid rgba(120, 220, 255, 0.5);
  font-weight: 800; letter-spacing: 2px; font-size: 12px;
  display: none;
}
#btn-burst.visible { display: inline-block; }
#btn-burst.ready { background: linear-gradient(180deg, #7de3ff, #2a9fd0); color: #04222e; box-shadow: 0 0 24px rgba(110, 230, 255, 0.7); }

/* warning banner */
#warn-banner {
  position: absolute; top: 38%; left: 0; right: 0;
  text-align: center; font-size: clamp(22px, 5vw, 40px); font-weight: 900;
  letter-spacing: 8px; color: #ff5f5f; text-transform: uppercase;
  text-shadow: 0 0 24px rgba(255, 40, 40, 0.9);
  display: none; animation: warnblink 0.45s infinite alternate;
}
#warn-banner.visible { display: block; }
@keyframes warnblink { from { opacity: 0.35; } to { opacity: 1; } }

/* ritual flash */
#flash {
  position: fixed; inset: 0; z-index: 30; pointer-events: none;
  background: radial-gradient(ellipse at center, #fffbe8, #ffe9a8 45%, rgba(255, 220, 140, 0) 80%);
  opacity: 0; transition: opacity 0.3s;
}

/* stage clear summary */
#summary-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 20px; margin: 14px 0; text-align: left; font-size: 14px; }
#summary-grid .k { color: #8f83bd; letter-spacing: 1px; text-transform: uppercase; font-size: 11px; }
#summary-grid .v { color: #ffe9a8; font-weight: 800; font-size: 18px; }
#summary-quote { font-style: italic; color: #b9a8e8; font-size: 13px; line-height: 1.7; margin: 10px 0 16px; }

#gameover-title { font-size: 40px; font-weight: 900; letter-spacing: 6px; color: #ff7f7f; text-shadow: 0 0 30px rgba(255, 60, 60, 0.5); margin-bottom: 8px; }
#victory-title { font-size: 40px; font-weight: 900; letter-spacing: 6px; background: linear-gradient(180deg, #fffbe8, #ffd977, #e0a535); -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent; margin-bottom: 8px; }

.touch-hint { font-size: 11px; color: #6f649e; letter-spacing: 1px; margin-top: 10px; }

/* ---------- boot / loading splash ---------- */
#boot-overlay {
  z-index: 40;
  background: radial-gradient(ellipse at 50% 40%, #14102a 0%, #05060e 75%);
  transition: opacity 0.45s ease;
}
#boot-overlay.fade-out { opacity: 0; pointer-events: none; }
.boot-content { text-align: center; width: min(420px, 84vw); }
.boot-title {
  font-size: 42px; font-weight: 900; letter-spacing: 8px;
  background: linear-gradient(180deg, #fffbe8, #ffd977, #e0a535);
  -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent;
  animation: bootpulse 1.6s ease-in-out infinite alternate;
}
@keyframes bootpulse { from { filter: brightness(0.85); } to { filter: brightness(1.15); } }
.boot-sub { font-size: 12px; letter-spacing: 3px; color: #8f83bd; margin: 8px 0 26px; text-transform: uppercase; }
.boot-bar-outer {
  width: 100%; height: 8px; border-radius: 4px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(240, 200, 110, 0.35);
  overflow: hidden;
}
#boot-bar {
  height: 100%; width: 0%;
  background: linear-gradient(90deg, #7de3ff, #ffd977);
  box-shadow: 0 0 12px rgba(255, 217, 119, 0.8);
  transition: width 0.15s ease;
}
#boot-status { margin-top: 14px; font-size: 12px; letter-spacing: 2px; color: #b9a8e8; }