/* =====================================================================
   Archangel Michael: Blade of Light
   Global stylesheet - Celestial Gold vs Obsidian & Hellfire Crimson
   ===================================================================== */

:root {
  --gold: #ffd777;
  --gold-deep: #d99b2b;
  --gold-soft: #ffe9b0;
  --obsidian: #08060f;
  --obsidian-2: #120d20;
  --crimson: #ff3b52;
  --crimson-deep: #8d1024;
  --azure: #79c7ff;
  --text: #f3ecdf;
  --text-dim: #a89e8c;
  --panel: rgba(14, 10, 26, 0.88);
  --panel-line: rgba(255, 215, 119, 0.28);
  --shadow-gold: 0 0 18px rgba(255, 200, 90, 0.45);
  --font-display: "Cinzel", "Trajan Pro", Georgia, "Times New Roman", serif;
  --font-ui: "Segoe UI", system-ui, -apple-system, Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #05040a;
  color: var(--text);
  font-family: var(--font-ui);
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  touch-action: none;
  overscroll-behavior: none;
}

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

canvas#game {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  background: #05040a;
}

.hidden { display: none !important; }
.grow { flex: 1 1 auto; }

/* ============================== HUD ============================== */
#hud {
  position: absolute;
  inset: 0;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: max(10px, env(safe-area-inset-top)) 14px max(12px, env(safe-area-inset-bottom)) 14px;
  font-family: var(--font-ui);
}

.hud-row { display: flex; align-items: center; gap: 8px; }
.hud-top { gap: 10px; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 999px;
  background: linear-gradient(180deg, rgba(30, 22, 50, 0.9), rgba(12, 9, 22, 0.9));
  border: 1px solid var(--panel-line);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--gold-soft);
  backdrop-filter: blur(6px);
  text-shadow: 0 0 10px rgba(255, 200, 90, 0.35);
  white-space: nowrap;
}
.chip.ghost { color: var(--text-dim); font-weight: 600; border-color: rgba(255,255,255,0.12); background: rgba(8,6,15,0.6); }
.chip .ico { color: var(--gold); }

.icon-btn {
  pointer-events: auto;
  width: 40px; height: 40px;
  border-radius: 12px;
  border: 1px solid var(--panel-line);
  background: rgba(12, 9, 22, 0.82);
  color: var(--gold);
  font-size: 13px;
  letter-spacing: 1px;
  cursor: pointer;
  transition: transform .12s ease, background .2s;
}
.icon-btn:active { transform: scale(.92); }

/* Vitals */
.vitals { display: flex; align-items: flex-end; gap: 10px; }
.portrait {
  width: 56px; height: 56px;
  border-radius: 14px;
  border: 1px solid var(--panel-line);
  background: radial-gradient(circle at 50% 35%, rgba(255,215,119,.22), rgba(10,7,18,.95));
  box-shadow: 0 0 22px rgba(255,200,90,.25);
  overflow: hidden;
  flex: 0 0 auto;
}
.portrait canvas { width: 100%; height: 100%; display: block; }

.bars { display: flex; flex-direction: column; gap: 6px; width: min(38vw, 300px); }
.bar {
  position: relative;
  height: 18px;
  border-radius: 10px;
  background: rgba(6, 5, 12, 0.8);
  border: 1px solid var(--panel-line);
  overflow: hidden;
}
.bar .fill {
  position: absolute; inset: 0 auto 0 0;
  width: 100%;
  border-radius: 9px;
  transition: width .18s ease-out;
}
.bar.health .fill { background: linear-gradient(90deg, #8b1226, #ff5a6e 60%, #ffb3b8); box-shadow: 0 0 14px rgba(255,80,100,.6); }
.bar.ult { height: 14px; }
.bar.ult .fill { width: 0%; background: linear-gradient(90deg, #2b6fb8, #79c7ff 40%, #ffe9b0); box-shadow: 0 0 16px rgba(150,210,255,.7); }
.bar.ult.full .fill { animation: pulseUlt 1s infinite alternate; }
@keyframes pulseUlt { from { filter: brightness(1); } to { filter: brightness(1.5); } }

.bar-label {
  position: absolute;
  inset: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 10px; font-weight: 800; letter-spacing: .12em;
  text-shadow: 0 1px 3px #000;
  color: #fff;
}

/* Ability icons */
.abilities { display: flex; gap: 8px; align-items: flex-end; }
.ab {
  position: relative;
  width: 62px; height: 62px;
  border-radius: 14px;
  border: 1px solid var(--panel-line);
  background: linear-gradient(180deg, rgba(38,28,60,.9), rgba(10,7,18,.92));
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px;
  overflow: hidden;
  box-shadow: inset 0 0 18px rgba(255,200,90,.12);
}
.ab-key { font-size: 11px; font-weight: 800; color: var(--gold); letter-spacing: .08em; }
.ab-name { font-size: 9px; font-weight: 700; letter-spacing: .1em; color: var(--text-dim); }
.ab-cd {
  position: absolute; left: 0; right: 0; bottom: 0;
  height: 0%;
  background: rgba(0, 0, 0, 0.66);
  border-top: 1px solid rgba(255,215,119,.35);
  transition: height .08s linear;
  pointer-events: none;
}
.ab.ready { box-shadow: 0 0 20px rgba(255,215,119,.5), inset 0 0 18px rgba(255,215,119,.25); }
.ab.charged { border-color: var(--azure); box-shadow: 0 0 22px rgba(121,199,255,.6), inset 0 0 18px rgba(121,199,255,.2); }

/* ============================== TOUCH CONTROLS ============================== */
#touch {
  position: absolute;
  inset: 0;
  pointer-events: none;
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  padding: 0 max(14px, env(safe-area-inset-left)) max(16px, env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-right));
  z-index: 30;
}
.tc-side { display: flex; align-items: flex-end; gap: 12px; pointer-events: none; }
.tc-right { display: grid; grid-template-columns: repeat(2, auto); gap: 10px; align-items: end; justify-items: end; }

.tbtn {
  pointer-events: auto;
  border: 1px solid rgba(255, 215, 119, 0.35);
  background: radial-gradient(circle at 50% 30%, rgba(255,255,255,.14), rgba(12,9,22,.42));
  color: var(--gold-soft);
  font-family: var(--font-ui);
  font-weight: 800;
  letter-spacing: .06em;
  border-radius: 50%;
  width: 74px; height: 74px;
  font-size: 20px;
  display: flex; align-items: center; justify-content: center;
  backdrop-filter: blur(3px);
  touch-action: none;
  transition: transform .06s ease, background .1s;
}
.tbtn.move { width: 86px; height: 86px; font-size: 24px; }
.tbtn.act { font-size: 12px; }
.tbtn:active, .tbtn.held {
  transform: scale(.94);
  background: radial-gradient(circle at 50% 30%, rgba(255,215,119,.5), rgba(140,90,10,.5));
  box-shadow: 0 0 24px rgba(255,200,90,.5);
}
.tbtn.jump { background: radial-gradient(circle at 50% 30%, rgba(180,230,255,.18), rgba(12,9,22,.45)); border-color: rgba(140,210,255,.45); color: #d9f0ff; }
.tbtn.smite { border-color: rgba(140,210,255,.5); color: #cfe9ff; }
.tbtn.chain { border-color: rgba(255,215,119,.6); }

/* ============================== SCREENS ============================== */
.screen {
  position: absolute;
  inset: 0;
  z-index: 40;
  display: flex;
  flex-direction: column;
  background:
    radial-gradient(120% 90% at 50% 0%, rgba(58, 38, 100, 0.55), transparent 60%),
    radial-gradient(100% 100% at 80% 100%, rgba(140, 30, 40, 0.22), transparent 65%),
    linear-gradient(180deg, #0a0713 0%, #0f0a1c 45%, #07050d 100%);
  overflow: hidden;
}
.screen.overlay { background: rgba(4, 3, 8, 0.76); backdrop-filter: blur(8px); align-items: center; justify-content: center; z-index: 50; }

/* Main menu */
.menu-bg-glow {
  position: absolute; inset: -20% -10% auto -10%;
  height: 80%;
  background: radial-gradient(50% 50% at 50% 40%, rgba(255, 214, 130, 0.22), transparent 70%);
  animation: breathe 7s ease-in-out infinite alternate;
  pointer-events: none;
}
@keyframes breathe { from { opacity: .55; transform: scale(1); } to { opacity: 1; transform: scale(1.08); } }

.menu-inner {
  position: relative;
  margin: auto;
  padding: 24px;
  width: min(760px, 94vw);
  text-align: center;
  display: flex; flex-direction: column; align-items: center; gap: 18px;
  max-height: 100vh;
  overflow-y: auto;
  scrollbar-width: thin;
}
.title { margin: 0; line-height: .96; font-family: var(--font-display); }
.title .t-small {
  display: block;
  font-size: clamp(15px, 3.1vw, 26px);
  letter-spacing: .42em;
  text-transform: uppercase;
  color: var(--gold-soft);
  opacity: .92;
  text-shadow: 0 0 18px rgba(255,200,90,.5);
}
.title .t-big {
  display: block;
  margin-top: 6px;
  font-size: clamp(30px, 7.4vw, 68px);
  letter-spacing: .06em;
  font-weight: 900;
  background: linear-gradient(180deg, #fff8e2 0%, #ffd777 42%, #c8860f 78%, #ffe9b0 100%);
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent;
  filter: drop-shadow(0 0 22px rgba(255, 190, 60, .55));
}
.tagline { margin: 0; color: var(--text-dim); font-size: clamp(12px, 1.7vw, 15px); letter-spacing: .04em; }
.tagline em { color: var(--gold); font-style: normal; }

.menu-actions { display: flex; flex-direction: column; gap: 12px; width: min(360px, 86vw); margin-top: 6px; }

.btn {
  pointer-events: auto;
  font-family: var(--font-ui);
  cursor: pointer;
  padding: 13px 22px;
  border-radius: 14px;
  font-size: 15px;
  font-weight: 800;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--gold-soft);
  background: linear-gradient(180deg, rgba(46, 34, 74, .95), rgba(14, 10, 26, .95));
  border: 1px solid var(--panel-line);
  transition: transform .12s ease, box-shadow .2s, background .2s, color .2s;
  box-shadow: 0 6px 18px rgba(0,0,0,.5);
}
.btn:hover { background: linear-gradient(180deg, rgba(66, 48, 104, .98), rgba(20, 14, 36, .98)); box-shadow: 0 0 22px rgba(255,200,90,.3); }
.btn:active { transform: scale(.97); }
.btn.primary {
  background: linear-gradient(180deg, #ffe08a, #e2a521 55%, #a86f08);
  color: #2a1a02;
  border-color: #ffeec0;
  text-shadow: 0 1px 0 rgba(255,255,255,.4);
  box-shadow: 0 0 26px rgba(255, 190, 60, .5);
}
.btn.primary:hover { filter: brightness(1.08); }
.btn.back { padding: 9px 16px; font-size: 12px; }
.btn:disabled { opacity: .4; cursor: not-allowed; box-shadow: none; }
.btn.gold-outline { border-color: var(--gold); }

.settings-bar { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; align-items: center; }
.settings-bar.center { justify-content: center; }
.toggle {
  pointer-events: auto;
  cursor: pointer;
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .06em;
  color: var(--text-dim);
  background: rgba(10, 7, 18, .8);
  border: 1px solid rgba(255,255,255,.12);
  transition: all .18s;
}
.toggle.on { color: #1d1204; background: linear-gradient(180deg, #ffe08a, #d99b2b); border-color: #ffeec0; box-shadow: 0 0 16px rgba(255,200,90,.4); }
.grace-badge {
  padding: 8px 14px; border-radius: 999px; font-size: 12px; font-weight: 700;
  color: var(--gold-soft); background: rgba(10,7,18,.8); border: 1px solid var(--panel-line);
}
.grace-badge b { color: var(--gold); }
.credits { margin: 4px 0 0; font-size: 11px; color: #5d5470; letter-spacing: .12em; text-transform: uppercase; }

/* Screen head */
.screen-head {
  display: flex; align-items: center; gap: 14px;
  padding: max(12px, env(safe-area-inset-top)) 18px 12px;
  border-bottom: 1px solid rgba(255,215,119,.14);
  background: linear-gradient(180deg, rgba(20,14,36,.95), rgba(10,7,18,.6));
  flex: 0 0 auto;
}
.screen-head h2 { margin: 0; font-family: var(--font-display); font-size: clamp(18px, 3.2vw, 26px); letter-spacing: .1em; color: var(--gold-soft); text-shadow: 0 0 16px rgba(255,200,90,.35); }
.screen-head .grow { flex: 1; }

/* Level select */
.chapter-filter { display: flex; gap: 8px; padding: 12px 18px 4px; overflow-x: auto; flex: 0 0 auto; }
.chapter-filter .cf {
  cursor: pointer; white-space: nowrap;
  padding: 7px 14px; border-radius: 999px; font-size: 12px; font-weight: 700;
  letter-spacing: .06em; color: var(--text-dim);
  background: rgba(10,7,18,.8); border: 1px solid rgba(255,255,255,.1);
}
.chapter-filter .cf.active { color: #1d1204; background: linear-gradient(180deg,#ffe08a,#d99b2b); border-color:#ffeec0; }

.level-grid {
  flex: 1 1 auto;
  overflow-y: auto;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(92px, 1fr));
  gap: 10px;
  padding: 14px 18px calc(28px + env(safe-area-inset-bottom));
}
.lvl {
  position: relative;
  aspect-ratio: 1 / 1;
  border-radius: 14px;
  border: 1px solid rgba(255,215,119,.18);
  background: linear-gradient(180deg, rgba(36,26,58,.9), rgba(10,7,18,.92));
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  cursor: pointer;
  transition: transform .12s, box-shadow .2s, border-color .2s;
  overflow: hidden;
}
.lvl:hover { transform: translateY(-3px); border-color: var(--gold); box-shadow: 0 0 20px rgba(255,200,90,.3); }
.lvl .num { font-family: var(--font-display); font-size: clamp(18px, 3.4vw, 26px); font-weight: 900; color: var(--gold-soft); }
.lvl .lstars { font-size: 11px; letter-spacing: 2px; color: #4a425c; }
.lvl .lstars .s-on { color: var(--gold); text-shadow: 0 0 8px rgba(255,200,90,.8); }
.lvl.locked { cursor: not-allowed; filter: grayscale(.85) brightness(.55); }
.lvl.locked .num { color: #4b4460; }
.lvl .lock { position: absolute; font-size: 20px; color: #6b6280; }
.lvl.boss { border-color: rgba(255,59,82,.7); box-shadow: 0 0 18px rgba(255,59,82,.28) inset; }
.lvl.boss .num { color: #ffb2bd; }
.lvl .chapline { position: absolute; bottom: 0; left: 0; right: 0; height: 3px; }

/* Upgrades */
.upgrade-grid {
  flex: 1 1 auto; overflow-y: auto;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 14px; padding: 16px 18px calc(28px + env(safe-area-inset-bottom));
}
.upg {
  border-radius: 16px; padding: 16px;
  background: linear-gradient(180deg, rgba(34,25,56,.92), rgba(10,7,18,.94));
  border: 1px solid rgba(255,215,119,.16);
  display: flex; flex-direction: column; gap: 10px;
}
.upg h3 { margin: 0; font-family: var(--font-display); font-size: 16px; letter-spacing: .06em; color: var(--gold-soft); }
.upg p { margin: 0; font-size: 12.5px; color: var(--text-dim); line-height: 1.45; }
.upg .pips { display: flex; gap: 4px; }
.upg .pip { flex: 1 1 auto; height: 8px; border-radius: 4px; background: rgba(255,255,255,.09); }
.upg .pip.on { background: linear-gradient(90deg, #ffe08a, #d99b2b); box-shadow: 0 0 10px rgba(255,200,90,.6); }
.upg .row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.upg .cost { font-size: 12px; font-weight: 800; color: var(--gold); letter-spacing: .06em; }
.upg .btn { padding: 9px 16px; font-size: 12px; }
.upg.maxed .cost { color: var(--azure); }

/* Help */
.help-scroll { flex: 1 1 auto; overflow-y: auto; padding: 18px 18px calc(28px + env(safe-area-inset-bottom)); }
.help-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 14px; max-width: 1100px; margin: 0 auto; }
.card {
  border-radius: 16px; padding: 16px;
  background: linear-gradient(180deg, rgba(30,22,50,.9), rgba(10,7,18,.94));
  border: 1px solid rgba(255,215,119,.16);
}
.card h3 { margin: 0 0 8px; font-family: var(--font-display); font-size: 15px; letter-spacing: .06em; color: var(--gold); }
.card p { margin: 0 0 8px; font-size: 13px; color: var(--text-dim); line-height: 1.5; }
.card p:last-child { margin-bottom: 0; }
.card b { color: var(--gold-soft); }
.card.highlight { border-color: rgba(121,199,255,.35); box-shadow: inset 0 0 26px rgba(121,199,255,.08); }
.mobile-note { max-width: 1100px; margin: 16px auto 0; font-size: 12px; color: #6b6280; text-align: center; }

/* ============================== MODALS ============================== */
.modal {
  width: min(480px, 92vw);
  border-radius: 20px;
  padding: 26px;
  text-align: center;
  background: linear-gradient(180deg, rgba(26,19,44,.98), rgba(9,7,16,.98));
  border: 1px solid var(--panel-line);
  box-shadow: 0 0 60px rgba(0,0,0,.75), 0 0 50px rgba(255,190,60,.12) inset;
  display: flex; flex-direction: column; gap: 16px; align-items: center;
  max-height: 92vh; overflow-y: auto;
}
.modal.wide { width: min(620px, 94vw); }
.modal h2 {
  margin: 0; font-family: var(--font-display); font-size: clamp(24px, 5vw, 38px);
  letter-spacing: .12em; text-transform: uppercase;
  background: linear-gradient(180deg, #fff8e2, #ffd777 45%, #c8860f);
  -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent;
  filter: drop-shadow(0 0 16px rgba(255,190,60,.45));
}
#screen-result.defeat h2 { background: linear-gradient(180deg, #ffd0d6, #ff3b52 55%, #7a0d1c); -webkit-background-clip: text; background-clip: text; filter: drop-shadow(0 0 16px rgba(255,59,82,.5)); }
.modal-actions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; width: 100%; }
.modal-actions .btn { flex: 1 1 140px; }

.stars { display: flex; gap: 12px; font-size: clamp(30px, 8vw, 46px); line-height: 1; }
.star { color: #332c46; transition: color .3s, transform .3s; }
.star.on { color: var(--gold); text-shadow: 0 0 22px rgba(255,200,90,.9); transform: scale(1.12); animation: starPop .5s ease-out; }
@keyframes starPop { 0% { transform: scale(.2) rotate(-40deg); } 70% { transform: scale(1.3) rotate(6deg); } 100% { transform: scale(1.12) rotate(0); } }

.breakdown { width: 100%; display: flex; flex-direction: column; gap: 6px; }
.breakdown .brow { display: flex; justify-content: space-between; font-size: 13.5px; padding: 7px 12px; border-radius: 10px; background: rgba(255,255,255,.045); }
.breakdown .brow span:first-child { color: var(--text-dim); letter-spacing: .04em; }
.breakdown .brow span:last-child { color: var(--gold-soft); font-weight: 800; }
.breakdown .brow.total { background: rgba(255,200,90,.12); border: 1px solid var(--panel-line); }
.breakdown .brow.total span:last-child { color: var(--gold); font-size: 16px; }
.grace-earned { font-size: 15px; font-weight: 800; letter-spacing: .1em; color: var(--azure); text-shadow: 0 0 16px rgba(121,199,255,.6); }

/* ============================== TOAST / HINT ============================== */
.toast {
  position: absolute; left: 50%; top: 14%; transform: translateX(-50%);
  z-index: 60; padding: 10px 20px; border-radius: 999px;
  background: rgba(12,9,22,.92); border: 1px solid var(--panel-line);
  color: var(--gold-soft); font-size: 13px; font-weight: 700; letter-spacing: .08em;
  text-transform: uppercase; box-shadow: 0 0 26px rgba(0,0,0,.6);
  animation: toastIn .3s ease-out;
  white-space: nowrap; pointer-events: none;
}
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, -12px); } to { opacity: 1; transform: translate(-50%, 0); } }

.hint {
  position: absolute; left: 50%; bottom: 20%; transform: translateX(-50%);
  z-index: 20; font-size: 13px; color: rgba(255, 233, 176, .85);
  text-shadow: 0 2px 8px #000; letter-spacing: .06em; pointer-events: none;
  text-align: center; padding: 0 16px;
}

/* Scrollbars */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: rgba(255,255,255,.04); }
::-webkit-scrollbar-thumb { background: rgba(255,215,119,.28); border-radius: 6px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,215,119,.5); }

/* Small screens */
@media (max-width: 520px) {
  .chip { font-size: 11px; padding: 5px 9px; }
  .chip.ghost.hide-small { display: none; }
  .bars { width: 42vw; }
  .ab { width: 52px; height: 52px; }
  .ab-key { font-size: 9px; }
  .portrait { width: 44px; height: 44px; }
  .tbtn.move { width: 74px; height: 74px; }
  .tbtn { width: 62px; height: 62px; font-size: 16px; }
  .tbtn.act { font-size: 10px; }
}
