/* =====================================================================
   Archangel Michael: Blade of Light — UI styles
   Palette: Celestial Gold & Radiant Light vs. Deep Obsidian & Hellfire Crimson
   ===================================================================== */
:root {
  --gold: #ffd36a;
  --gold-2: #e0a21f;
  --gold-3: #8a5a0a;
  --light: #fff6d6;
  --obsidian: #0b0710;
  --obsidian-2: #190f22;
  --crimson: #c2262e;
  --crimson-2: #7a0f18;
  --ink: #f4e9cf;
  --font-display: 'Cinzel', 'Trajan Pro', 'Cormorant Garamond', Georgia, 'Times New Roman', serif;
  --font-body: 'Segoe UI', system-ui, -apple-system, Roboto, 'Helvetica Neue', Arial, sans-serif;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
}

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

html, body {
  margin: 0; padding: 0; width: 100%; height: 100%;
  overflow: hidden; background: var(--obsidian); color: var(--ink);
  font-family: var(--font-body);
  touch-action: none; user-select: none; -webkit-user-select: none;
  -webkit-touch-callout: none; overscroll-behavior: none;
}

#game { position: fixed; inset: 0; width: 100vw; height: 100vh; height: 100dvh; display: block; }

.hidden { display: none !important; }

/* ---------------------------------------------------------------- HUD */
#hud {
  position: fixed; inset: 0; pointer-events: none; z-index: 10;
  padding: calc(8px + var(--safe-t)) calc(10px + var(--safe-r)) 0 calc(10px + var(--safe-l));
  display: flex; justify-content: space-between; align-items: flex-start; gap: 8px;
}
.hud-left { width: min(260px, 36vw); display: flex; flex-direction: column; gap: 5px; }
.hud-center { display: flex; flex-direction: column; align-items: center; gap: 4px; text-align: center; flex: 1; min-width: 0; }
.hud-right { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; pointer-events: none; }

.bar { display: flex; align-items: center; gap: 6px; font-family: var(--font-display); font-size: clamp(9px, 1.5vw, 12px); letter-spacing: .08em; }
.bar-label { width: 56px; white-space: nowrap; color: var(--gold); text-shadow: 0 0 6px #000; font-weight: 700; }
.bar-num { min-width: 22px; text-align: right; color: var(--light); text-shadow: 0 0 6px #000; font-weight: 700; }
.bar-track {
  flex: 1; height: clamp(10px, 1.9vw, 15px); border-radius: 8px; position: relative; overflow: hidden;
  background: linear-gradient(#050207, #170c1c); border: 1.5px solid var(--gold-2);
  box-shadow: 0 0 8px rgba(255, 211, 106, .25), inset 0 0 6px #000;
}
.bar-fill { height: 100%; width: 100%; transition: width .12s linear; border-radius: 6px; }
.bar.hp .bar-fill { background: linear-gradient(#ff7a7a, #c2262e 60%, #7a0f18); }
.bar.ult .bar-fill { background: linear-gradient(#fff6d6, #ffd36a 50%, #e0a21f); }
.bar.chain .bar-fill { background: linear-gradient(#fff, #9fd3ff 40%, #4a8fe0); transition: none; }
.bar.ult.ready .bar-track { animation: pulse 0.9s ease-in-out infinite; border-color: #fff6d6; }
.bar.chain.ready .bar-track { border-color: #cfe9ff; }
@keyframes pulse { 0%, 100% { box-shadow: 0 0 8px rgba(255,211,106,.4), inset 0 0 6px #000; } 50% { box-shadow: 0 0 22px rgba(255,236,160,.95), inset 0 0 6px #000; } }

.badge {
  font-family: var(--font-display); font-weight: 700; letter-spacing: .14em; font-size: clamp(11px, 2vw, 15px);
  padding: 3px 14px; border-radius: 14px; color: var(--obsidian);
  background: linear-gradient(#fff2bd, var(--gold) 50%, var(--gold-2)); box-shadow: 0 0 14px rgba(255, 211, 106, .5);
}
.saved { font-family: var(--font-display); font-weight: 700; font-size: clamp(14px, 2.6vw, 22px); color: var(--light); text-shadow: 0 0 10px rgba(255, 211, 106, .9), 0 2px 3px #000; letter-spacing: .06em; }
.saved.bump { animation: bump .5s ease; }
@keyframes bump { 40% { transform: scale(1.35); color: #fff; } }
.lost { font-size: clamp(10px, 1.6vw, 12px); color: #ff8e8e; text-shadow: 0 1px 3px #000; letter-spacing: .08em; min-height: 1em; }
.boss { width: min(440px, 90%); margin-top: 4px; }
.boss-name { font-family: var(--font-display); font-size: clamp(9px, 1.6vw, 12px); letter-spacing: .2em; color: #ff9a8a; text-shadow: 0 0 8px #c2262e; }
.boss-track { height: 12px; border-radius: 7px; border: 1.5px solid #ff6a4a; background: #1a0508; overflow: hidden; box-shadow: 0 0 12px rgba(255, 60, 40, .5); }
#boss-fill { height: 100%; width: 100%; background: linear-gradient(#ff9a6a, #d3281a 60%, #6a0a0a); transition: width .15s linear; }

.score { font-family: var(--font-display); font-weight: 700; color: var(--gold); font-size: clamp(12px, 2.2vw, 18px); text-shadow: 0 0 8px #000, 0 0 12px rgba(255, 211, 106, .4); }
.icon-btn {
  pointer-events: auto; width: clamp(32px, 5vw, 42px); height: clamp(32px, 5vw, 42px); border-radius: 50%;
  border: 2px solid var(--gold-2); color: var(--gold); font-family: var(--font-display); font-weight: 900; font-size: 14px; letter-spacing: 1px;
  background: radial-gradient(#2a1838, #0b0710); cursor: pointer; box-shadow: 0 0 10px rgba(255, 211, 106, .3);
}
.icon-btn:active { transform: scale(.92); }

.banner { position: fixed; top: 24%; left: 0; right: 0; text-align: center; pointer-events: none; z-index: 12; opacity: 0; transition: opacity .5s; padding: 0 12px; }
.banner.show { opacity: 1; }
#banner-title { font-family: var(--font-display); font-weight: 900; font-size: clamp(22px, 5.2vw, 46px); letter-spacing: .1em; color: var(--light); text-shadow: 0 0 18px var(--gold), 0 0 40px rgba(255, 160, 40, .8), 0 3px 4px #000; }
#banner-sub { margin-top: 6px; font-size: clamp(12px, 2.2vw, 18px); letter-spacing: .18em; color: var(--gold); text-shadow: 0 2px 4px #000; text-transform: uppercase; }
.toast { position: fixed; top: calc(122px + var(--safe-t)); left: 50%; transform: translateX(-50%); z-index: 12; pointer-events: none; font-family: var(--font-display); font-size: clamp(12px, 2.2vw, 17px); letter-spacing: .1em; color: var(--light); padding: 6px 16px; border-radius: 16px; background: rgba(11, 7, 16, .72); border: 1px solid var(--gold-2); opacity: 0; transition: opacity .3s; white-space: nowrap; }
.toast.show { opacity: 1; }
.toast.bad { color: #ffb0b0; border-color: var(--crimson); }

/* ---------------------------------------------------------- TOUCH UI */
#touch { position: fixed; inset: 0; z-index: 11; pointer-events: none; }
.tbtn {
  position: absolute; pointer-events: auto; display: flex; flex-direction: column; align-items: center; justify-content: center;
  border-radius: 50%; color: var(--gold); border: 2px solid rgba(255, 211, 106, .7);
  background: radial-gradient(circle at 35% 30%, rgba(255, 211, 106, .28), rgba(20, 10, 30, .55));
  box-shadow: 0 0 14px rgba(255, 211, 106, .3), inset 0 0 12px rgba(0, 0, 0, .4);
  touch-action: none; user-select: none; opacity: .82; backdrop-filter: blur(2px);
}
.tbtn.down { background: radial-gradient(circle at 35% 30%, rgba(255, 236, 160, .75), rgba(120, 70, 10, .65)); transform: scale(.94); opacity: 1; }
.tbtn svg { width: 46%; height: 46%; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; pointer-events: none; }
.tbtn span { font-family: var(--font-display); font-size: clamp(7px, 1.9vmin, 10px); letter-spacing: .1em; font-weight: 700; margin-top: -2px; pointer-events: none; }
#dpad { position: absolute; left: calc(2.5vmin + var(--safe-l)); bottom: calc(3vmin + var(--safe-b)); width: 38vmin; max-width: 230px; height: 19vmin; max-height: 115px; pointer-events: auto; touch-action: none; }
.tbtn.dp { width: 48%; height: 100%; border-radius: 28px; }
.tbtn.dp.left { left: 0; } .tbtn.dp.right { right: 0; }
.tbtn.act { width: 17vmin; height: 17vmin; max-width: 104px; max-height: 104px; }
#t-jump   { right: calc(2.5vmin + var(--safe-r)); bottom: calc(3vmin + var(--safe-b)); width: 20vmin; height: 20vmin; max-width: 120px; max-height: 120px; }
#t-attack { right: calc(24vmin + var(--safe-r)); bottom: calc(2vmin + var(--safe-b)); }
#t-chain  { right: calc(3vmin + var(--safe-r)); bottom: calc(25vmin + var(--safe-b)); }
#t-ult    { right: calc(21vmin + var(--safe-r)); bottom: calc(20vmin + var(--safe-b)); border-color: rgba(255, 246, 214, .9); }
#t-ult.ready { animation: pulse 0.9s ease-in-out infinite; background: radial-gradient(circle at 35% 30%, rgba(255, 246, 214, .7), rgba(224, 162, 31, .5)); }
#t-chain.cooling { opacity: .4; }

/* ----------------------------------------------------------- SCREENS */
.screen { position: fixed; inset: 0; z-index: 20; display: flex; align-items: center; justify-content: center; padding: calc(10px + var(--safe-t)) calc(10px + var(--safe-r)) calc(10px + var(--safe-b)) calc(10px + var(--safe-l)); }
.screen.dim { background: radial-gradient(ellipse at center, rgba(11, 7, 16, .78), rgba(5, 2, 8, .92)); backdrop-filter: blur(3px); }
#screen-levels, #screen-armory, #screen-howto { background: linear-gradient(rgba(8, 4, 14, .82), rgba(8, 4, 14, .9)); backdrop-filter: blur(4px); }

h1, h2, h3 { font-family: var(--font-display); margin: 0; }

.menu-wrap { display: flex; flex-direction: column; align-items: center; justify-content: flex-start; gap: clamp(10px, 3vh, 26px); width: 100%; height: 100%; padding-top: clamp(4px, 3vh, 36px); overflow: hidden; }
@media (min-aspect-ratio: 5/4) {
  /* landscape: Michael stands on the left, title + buttons stack on the right */
  .menu-wrap { flex-direction: column; justify-content: center; align-items: center; padding-top: 0; padding-left: 44vw; gap: clamp(10px, 3vh, 24px); }
  .title-block { text-align: center; }
}
@media (min-aspect-ratio: 5/4) and (max-height: 520px) {
  .menu-wrap { flex-direction: row; padding-left: 30vw; gap: 4vw; }
  .title { font-size: clamp(26px, 8vmin, 44px); }
  .title-block { text-align: center; }
.title-pre { display: none; }
}
.title-pre { font-family: var(--font-display); letter-spacing: .4em; font-size: clamp(9px, 1.6vw, 13px); color: var(--gold); opacity: .85; }
.title {
  font-size: clamp(34px, 9vmin, 84px); line-height: .98; letter-spacing: .1em; font-weight: 900; margin: 6px 0 4px;
  background: linear-gradient(#fffbe8 10%, #ffd36a 45%, #c27b10 80%); -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 0 16px rgba(255, 190, 70, .65)) drop-shadow(0 4px 3px rgba(0, 0, 0, .8));
}
.title-sub { font-family: var(--font-display); font-size: clamp(16px, 3.8vmin, 32px); letter-spacing: .34em; color: #ff9a7a; text-shadow: 0 0 14px #c2262e, 0 0 26px rgba(194, 38, 46, .7); font-style: italic; }
.menu-buttons { display: flex; flex-direction: column; gap: clamp(7px, 1.6vh, 12px); width: min(300px, 80vw); }
.foot-note { position: absolute; bottom: calc(6px + var(--safe-b)); left: 0; right: 0; text-align: center; font-size: 10px; letter-spacing: .2em; opacity: .4; pointer-events: none; text-transform: uppercase; }

.btn {
  position: relative; font-family: var(--font-display); font-weight: 700; letter-spacing: .16em; text-transform: uppercase;
  font-size: clamp(13px, 2.2vmin, 17px); padding: clamp(10px, 1.9vh, 14px) 18px; color: var(--light); cursor: pointer;
  background: linear-gradient(rgba(60, 30, 80, .85), rgba(14, 6, 22, .95)); border: 2px solid var(--gold-2); border-radius: 6px;
  box-shadow: 0 0 12px rgba(255, 211, 106, .18), inset 0 0 14px rgba(255, 211, 106, .08); transition: transform .1s, box-shadow .15s, border-color .15s;
  touch-action: manipulation;
}
.btn:hover { border-color: var(--gold); box-shadow: 0 0 22px rgba(255, 211, 106, .55), inset 0 0 18px rgba(255, 211, 106, .18); transform: translateY(-1px); }
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .4; cursor: not-allowed; filter: grayscale(.6); transform: none; box-shadow: none; }
.btn.primary { color: var(--obsidian); background: linear-gradient(#fff2bd, var(--gold) 45%, var(--gold-2)); border-color: #fff6d6; box-shadow: 0 0 20px rgba(255, 211, 106, .6); }
.btn.primary:hover { box-shadow: 0 0 34px rgba(255, 220, 130, .95); }
.btn.small { font-size: clamp(10px, 1.7vmin, 13px); padding: 8px 10px; letter-spacing: .1em; }
.btn-row { display: flex; gap: 8px; } .btn-row .btn { flex: 1; }
.grace-chip { display: inline-block; margin-left: 8px; padding: 1px 8px; border-radius: 10px; background: var(--gold); color: var(--obsidian); font-size: .8em; letter-spacing: 0; }

.panel {
  width: min(720px, 100%); max-height: 100%; display: flex; flex-direction: column; border-radius: 10px;
  background: linear-gradient(rgba(34, 18, 48, .94), rgba(12, 6, 20, .97)); border: 2px solid var(--gold-2);
  box-shadow: 0 0 40px rgba(255, 211, 106, .25), 0 0 0 1px #000, inset 0 0 30px rgba(255, 211, 106, .06); padding: clamp(10px, 2.4vmin, 20px);
}
.panel.wide { width: min(980px, 100%); }
.panel.narrow { width: min(460px, 100%); }
.panel.center { text-align: center; align-items: center; overflow-y: auto; touch-action: pan-y; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
.panel-head h2 { font-size: clamp(16px, 3.4vmin, 26px); letter-spacing: .16em; color: var(--gold); text-shadow: 0 0 12px rgba(255, 190, 70, .6); text-transform: uppercase; }
.panel-body { overflow-y: auto; overflow-x: hidden; touch-action: pan-y; -webkit-overflow-scrolling: touch; padding-right: 4px; }
.star-total, .grace-total { font-family: var(--font-display); color: var(--gold); font-size: clamp(11px, 2vmin, 15px); white-space: nowrap; }
.grace-total b { font-size: 1.3em; color: var(--light); }
.hint { font-size: 12px; opacity: .6; text-align: center; margin: 10px 0 0; }

/* Level select */
.chapter-head { font-family: var(--font-display); color: var(--gold); letter-spacing: .14em; margin: 12px 0 8px; font-size: clamp(12px, 2.2vmin, 16px); display: flex; justify-content: space-between; border-bottom: 1px solid rgba(255, 211, 106, .3); padding-bottom: 4px; }
.chapter-head small { color: #ff9a7a; letter-spacing: .08em; font-style: italic; }
.lvl-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: clamp(6px, 1.4vmin, 12px); }
.lvl { aspect-ratio: 1.15; border-radius: 8px; border: 2px solid var(--gold-2); cursor: pointer; font-family: var(--font-display); color: var(--light);
  background: linear-gradient(rgba(70, 36, 90, .9), rgba(20, 8, 30, .95)); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font-size: clamp(14px, 3vmin, 22px); font-weight: 900; position: relative; touch-action: pan-y; }
.lvl:hover { box-shadow: 0 0 18px rgba(255, 211, 106, .6); border-color: var(--gold); }
.lvl .stars { font-size: clamp(9px, 1.8vmin, 14px); letter-spacing: 1px; color: #5a4a3a; }
.lvl .stars i { font-style: normal; } .lvl .stars i.on { color: var(--gold); text-shadow: 0 0 6px var(--gold); }
.lvl.locked { opacity: .45; cursor: not-allowed; border-color: #4a3a5a; filter: grayscale(.8); }
.lvl.boss { border-color: #ff6a4a; box-shadow: 0 0 12px rgba(255, 80, 50, .5); }
.lvl.current { animation: pulse 1.2s infinite; border-color: #fff6d6; }

/* Armory */
.up-card { display: grid; grid-template-columns: 52px 1fr auto; gap: 12px; align-items: center; padding: 10px; margin-bottom: 8px; border-radius: 8px; border: 1px solid rgba(255, 211, 106, .35); background: rgba(255, 255, 255, .03); }
.up-icon { width: 52px; height: 52px; border-radius: 50%; border: 2px solid var(--gold-2); background: radial-gradient(#3b2250, #120a1a); display: flex; align-items: center; justify-content: center; }
.up-icon svg { width: 60%; height: 60%; fill: none; stroke: var(--gold); stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.up-name { font-family: var(--font-display); color: var(--gold); letter-spacing: .1em; font-size: clamp(13px, 2.4vmin, 17px); font-weight: 700; }
.up-desc { font-size: clamp(11px, 1.9vmin, 13px); opacity: .75; margin: 2px 0 5px; }
.pips { display: flex; gap: 4px; }
.pip { width: 18px; height: 7px; border-radius: 4px; background: #2a1a38; border: 1px solid #5a4a3a; }
.pip.on { background: linear-gradient(var(--light), var(--gold-2)); border-color: var(--gold); box-shadow: 0 0 6px rgba(255, 211, 106, .7); }

/* How to play */
.howto h3 { color: var(--gold); letter-spacing: .12em; font-size: 15px; margin: 12px 0 4px; text-transform: uppercase; }
.howto p { margin: 4px 0; font-size: 14px; line-height: 1.5; opacity: .92; }
.keys { width: 100%; border-collapse: collapse; font-size: 14px; }
.keys td { padding: 4px 6px; border-bottom: 1px solid rgba(255, 211, 106, .15); }
.keys td:first-child { opacity: .85; width: 45%; }
kbd { display: inline-block; min-width: 24px; text-align: center; padding: 1px 6px; margin: 0 2px; border: 1px solid var(--gold-2); border-radius: 4px; background: #1a0f24; color: var(--gold); font-family: var(--font-display); font-size: 12px; box-shadow: 0 2px 0 #5a3a08; }

/* Result */
.res-title { font-family: var(--font-display); font-size: clamp(24px, 6vmin, 42px); letter-spacing: .14em; font-weight: 900; margin-bottom: 4px; }
.res-title.win { color: var(--gold); text-shadow: 0 0 24px rgba(255, 190, 70, .9); }
.res-title.lose { color: #ff6a5a; text-shadow: 0 0 24px rgba(194, 38, 46, .9); }
.res-sub { font-size: 13px; letter-spacing: .14em; opacity: .75; text-transform: uppercase; margin-bottom: 8px; }
.res-stars { font-size: clamp(34px, 9vmin, 56px); letter-spacing: 6px; margin: 4px 0 8px; }
.res-stars span { display: inline-block; color: #3a2a40; transform: scale(.4); opacity: 0; }
.res-stars span.on { color: var(--gold); text-shadow: 0 0 22px var(--gold); animation: starpop .55s cubic-bezier(.2, 1.6, .4, 1) forwards; }
.res-stars span.off { transform: scale(1); opacity: 1; }
@keyframes starpop { to { transform: scale(1); opacity: 1; } }
.res-table { width: 100%; border-collapse: collapse; font-size: clamp(12px, 2.1vmin, 15px); margin-bottom: 10px; }
.res-table td { padding: 4px 6px; border-bottom: 1px solid rgba(255, 211, 106, .15); text-align: left; }
.res-table td:last-child { text-align: right; color: var(--gold); font-weight: 700; }
.res-table tr.total td { font-family: var(--font-display); font-size: 1.15em; color: var(--light); border-top: 2px solid var(--gold-2); border-bottom: none; }
.res-table tr.total td:last-child { color: var(--gold); }
.res-btns { display: flex; flex-direction: column; gap: 8px; width: 100%; }
.res-btns .btn-row { width: 100%; }

#rotate-hint { position: fixed; inset: 0; z-index: 50; }

@media (max-height: 520px) {
  .hud-left { width: min(210px, 30vw); }
  .banner { top: 18%; }
  .panel { padding: 8px; }
  .menu-buttons { gap: 5px; }
  .btn { padding: 7px 14px; }
}
@media (prefers-reduced-motion: reduce) { .bar.ult.ready .bar-track, #t-ult.ready, .lvl.current { animation: none; } }
