/* ============================================================
   THE GREAT ROSTAM — UI stylesheet (mobile-first)
   Palette: night desert + Persian gold + crimson blood accents
   Layout: full-viewport stage, adaptive canvas, thumb controls
   ============================================================ */
:root {
  --gold: #e8b64c;
  --gold-bright: #ffd700;
  --gold-dim: #8a6a2a;
  --night: #0d0a14;
  --panel: #17101f;
  --panel-2: #1f1529;
  --blood: #b03030;
  --ink: #efe6d0;
  --ink-dim: #b5a888;
  --green: #7bc47f;
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
  --sar: env(safe-area-inset-right, 0px);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  height: 100%;
  background: #060409;
  font-family: 'Vazirmatn', 'Segoe UI', Tahoma, sans-serif;
  color: var(--ink);
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

#stage {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  background: var(--night);
}

canvas#game {
  width: 100%; height: 100%;
  display: block;
  image-rendering: auto;
  background: #0d0a14;
}

.layer {
  position: absolute; inset: 0;
  pointer-events: none;
  user-select: none;
}
.hidden { display: none !important; }

/* ============================== HUD ============================== */
#hud { padding: calc(10px + var(--sat)) calc(12px + var(--sar)) 10px calc(12px + var(--sal)); }

#hearts { display: flex; gap: 5px; }
.heart {
  width: 24px; height: 22px;
  background: var(--blood);
  clip-path: path('M15 27 C 4 18, 0 12, 0 8 C 0 3, 4 0, 8 0 C 11 0, 14 2, 15 5 C 16 2, 19 0, 22 0 C 26 0, 30 3, 30 8 C 30 12, 26 18, 15 27 Z');
  filter: drop-shadow(0 0 4px rgba(176,48,48,0.8));
  transition: opacity .25s, transform .25s;
}
.heart.empty { background: #3a2a30; opacity: .45; filter: none; transform: scale(.85); }

#resources {
  position: absolute; top: calc(10px + var(--sat)); right: calc(12px + var(--sar));
  display: flex; gap: 10px; align-items: center;
  font-weight: 700; text-shadow: 0 2px 4px #000;
}
#arrows { font-size: 17px; color: var(--ink); }
#arrows span { color: var(--gold-bright); }

#rakhsh-cd {
  position: relative; width: 38px; height: 38px;
  border-radius: 50%;
  background: conic-gradient(var(--gold) var(--cd, 0%), #2a2233 0);
  display: grid; place-items: center;
  font-size: 17px;
  border: 2px solid var(--gold-dim);
}
#rakhsh-cd span { filter: grayscale(var(--gray, 1)); }

#boss-bar {
  position: absolute; top: calc(10px + var(--sat)); left: 50%;
  transform: translateX(-50%);
  width: min(560px, 62vw);
  text-align: center;
  transition: top .3s;
}
#boss-name {
  font-size: 13px; font-weight: 700;
  color: var(--gold-bright);
  text-shadow: 0 2px 6px #000;
  margin-bottom: 4px;
  letter-spacing: 1px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
#boss-track {
  height: 11px;
  background: #241018;
  border: 2px solid var(--gold-dim);
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 0 18px rgba(0,0,0,.7);
}
#boss-fill {
  height: 100%; width: 100%;
  background: linear-gradient(90deg, #7a1f1f, var(--blood) 60%, #d8503f);
  transition: width .18s ease-out;
}

#trial-label {
  position: absolute; bottom: calc(10px + var(--sab)); left: calc(12px + var(--sal));
  font-size: 11px; color: var(--ink-dim);
  letter-spacing: 2px; text-shadow: 0 2px 4px #000;
}

/* ========================= Touch controls ======================== */
#touch-ui { z-index: 20; display: none; }
body.touch #touch-ui.on { display: block; }

.tbtn {
  pointer-events: auto;
  width: 60px; height: 60px;
  border-radius: 50%;
  background: rgba(23,16,31,0.5);
  border: 2px solid rgba(232,182,76,0.55);
  color: var(--ink);
  font-size: 24px;
  line-height: 1;
  display: grid; place-items: center;
  touch-action: none;
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  text-shadow: 0 2px 4px #000;
}
.tbtn.big { width: 74px; height: 74px; font-size: 30px; }
.tbtn:active, .tbtn.pressed {
  background: rgba(232,182,76,0.35);
  border-color: var(--gold-bright);
  transform: scale(0.93);
}

.tc-left {
  position: absolute;
  left: calc(14px + var(--sal));
  bottom: calc(20px + var(--sab));
  display: flex; gap: 14px;
}
.tc-right {
  position: absolute;
  right: calc(14px + var(--sar));
  bottom: calc(20px + var(--sab));
  width: 184px; height: 224px;
}
#tb-attack{ position: absolute; right: 0;    bottom: 0; }
#tb-jump  { position: absolute; right: 98px; bottom: 10px; }
#tb-roll  { position: absolute; right: 8px;  bottom: 96px; }
#tb-bow   { position: absolute; right: 104px;bottom: 102px; }
#tb-mount { position: absolute; right: 52px; bottom: 184px; }

#tc-sys {
  position: absolute;
  top: calc(10px + var(--sat));
  right: calc(12px + var(--sar));
  display: flex; gap: 8px;
}
.sysbtn {
  pointer-events: auto;
  width: 38px; height: 38px;
  border-radius: 10px;
  border: 1.5px solid rgba(232,182,76,0.4);
  background: rgba(23,16,31,0.55);
  color: var(--ink);
  font-size: 17px;
  touch-action: none;
  display: grid; place-items: center;
}
.sysbtn:active { background: rgba(232,182,76,0.3); }

/* shift HUD aside when touch controls own the corners */
body.touch.on-play #resources { right: calc(12px + var(--sar)); top: calc(56px + var(--sat)); }

/* ======================= Finisher offer UI ======================= */
#finish-offer { z-index: 30; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; padding-bottom: calc(140px + var(--sab)); }
#finish-banner {
  text-align: center;
  animation: offerPulse 0.9s ease-in-out infinite;
  margin-bottom: 18px;
}
.fb-main {
  font-size: clamp(24px, 6vw, 40px); font-weight: 900;
  color: var(--gold-bright);
  text-shadow: 0 0 26px rgba(255,215,0,0.55), 0 3px 10px #000;
  letter-spacing: 1px;
}
.fb-sub {
  font-size: clamp(13px, 3vw, 17px);
  color: var(--ink);
  letter-spacing: 2px;
  text-shadow: 0 2px 6px #000;
  margin-top: 4px;
}
#finish-btn {
  pointer-events: auto;
  font-family: inherit;
  font-size: clamp(18px, 4.5vw, 26px);
  font-weight: 900;
  color: #1a0e04;
  background: linear-gradient(180deg, #ffe08a, var(--gold-bright) 55%, #b8860b);
  border: 3px solid #fff3c4;
  border-radius: 16px;
  padding: 14px 42px;
  box-shadow: 0 0 40px rgba(255,215,0,0.5), 0 6px 0 #7a5a10;
  cursor: pointer;
  animation: offerPulse 0.55s ease-in-out infinite;
  touch-action: none;
}
#finish-btn:active { transform: translateY(3px); box-shadow: 0 0 30px rgba(255,215,0,0.4), 0 3px 0 #7a5a10; }
@keyframes offerPulse { 0%,100% { transform: scale(1); } 50% { transform: scale(1.07); } }

/* ========================== QTE overlay ========================== */
#qte-overlay { z-index: 40; }
.qte-vignette {
  position: absolute; inset: 0;
  background: radial-gradient(ellipse at center, rgba(0,0,0,0.12) 34%, rgba(4,2,8,0.82) 100%);
  animation: vigIn .35s ease-out;
}
@keyframes vigIn { from { opacity: 0; } to { opacity: 1; } }

#qte-stage {
  position: absolute; left: 50%; top: 40%;
  transform: translate(-50%, -50%);
  width: 0; height: 0;
}
#qte-ring {
  position: absolute; left: 50%; top: 50%;
  transform: translate(-50%, -50%);
  border: 5px solid var(--gold-bright);
  border-radius: 50%;
  box-shadow: 0 0 24px rgba(255,215,0,0.5), inset 0 0 18px rgba(255,215,0,0.25);
  width: 200px; height: 200px;
}
#qte-target {
  position: absolute; left: 50%; top: 50%;
  transform: translate(-50%, -50%);
  width: 104px; height: 104px;
  border: 3px dashed rgba(239,230,208,0.75);
  border-radius: 50%;
  background: rgba(23,16,31,0.55);
  display: grid; place-items: center;
}
#qte-icon { font-size: 52px; line-height: 1; filter: drop-shadow(0 2px 6px #000); }
#qte-feedback {
  position: absolute; left: 50%; top: 50%;
  transform: translate(-50%, -50%);
  font-size: clamp(22px, 5vw, 34px); font-weight: 900;
  white-space: nowrap;
  text-shadow: 0 3px 12px #000;
  opacity: 0;
}
#qte-feedback.pop { animation: fbPop .7s ease-out; }
@keyframes fbPop {
  0% { opacity: 0; transform: translate(-50%,-50%) scale(0.5); }
  18% { opacity: 1; transform: translate(-50%,-50%) scale(1.18); }
  32% { transform: translate(-50%,-50%) scale(1); }
  75% { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%,-62%) scale(1); }
}

#qte-dots {
  position: absolute; left: 50%; top: calc(40% + 130px);
  transform: translateX(-50%);
  display: flex; gap: 12px;
}
#qte-dots i {
  width: 13px; height: 13px; border-radius: 50%;
  background: rgba(239,230,208,0.25);
  border: 1.5px solid rgba(232,182,76,0.6);
}
#qte-dots i.done { background: var(--gold-bright); box-shadow: 0 0 10px rgba(255,215,0,0.7); }
#qte-dots i.fail { background: var(--blood); border-color: #e05545; }

#qte-hint {
  position: absolute; left: 50%; bottom: calc(16px + var(--sab));
  transform: translateX(-50%);
  font-size: clamp(11px, 2.6vw, 14px);
  color: var(--ink-dim);
  white-space: nowrap;
  text-shadow: 0 2px 4px #000;
}
#qte-btns {
  position: absolute; left: 50%; bottom: calc(48px + var(--sab));
  transform: translateX(-50%);
  display: flex; gap: 18px;
}
#qte-btns button {
  pointer-events: auto;
  width: 84px; height: 84px;
  border-radius: 20px;
  background: rgba(23,16,31,0.72);
  border: 2.5px solid rgba(232,182,76,0.65);
  color: var(--ink);
  font-size: 38px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  touch-action: none;
  cursor: pointer;
}
#qte-btns button small { font-size: 12px; color: var(--ink-dim); letter-spacing: 1px; margin-top: 2px; }
#qte-btns button:active, #qte-btns button.match {
  background: rgba(232,182,76,0.4);
  border-color: var(--gold-bright);
  box-shadow: 0 0 22px rgba(255,215,0,0.45);
}

/* ========================= Big banner ============================ */
#big-banner {
  position: absolute; left: 50%; top: 26%;
  transform: translate(-50%, -50%);
  z-index: 45;
  pointer-events: none;
  animation: bannerIn 2.2s ease-out forwards;
}
#big-banner span {
  font-size: clamp(26px, 7vw, 54px);
  font-weight: 900;
  color: var(--gold-bright);
  text-shadow: 0 0 34px rgba(255,215,0,0.6), 0 4px 14px #000;
  white-space: nowrap;
}
#big-banner.rage span { color: #ff5f4a; text-shadow: 0 0 34px rgba(255,80,40,0.7), 0 4px 14px #000; }
@keyframes bannerIn {
  0% { opacity: 0; transform: translate(-50%,-50%) scale(0.4); }
  14% { opacity: 1; transform: translate(-50%,-50%) scale(1.12); }
  24% { transform: translate(-50%,-50%) scale(1); }
  78% { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%,-64%) scale(1.02); }
}

/* ========================= Screen flash ========================== */
#flash {
  position: absolute; inset: 0;
  z-index: 44;
  pointer-events: none;
  background: radial-gradient(ellipse at center, rgba(255,246,214,0.95) 0%, rgba(255,215,0,0.55) 45%, rgba(255,150,50,0.15) 100%);
  animation: flashOut 0.5s ease-out forwards;
}
@keyframes flashOut { from { opacity: 1; } to { opacity: 0; } }

/* ======================= Hurt vignette =========================== */
#hurt-vignette {
  position: absolute; inset: 0;
  z-index: 43;
  pointer-events: none;
  opacity: 0;
  background: radial-gradient(ellipse at center, rgba(176,48,48,0) 52%, rgba(150,20,20,0.55) 100%);
}
#hurt-vignette.hit { animation: hurtPulse 0.42s ease-out; }
@keyframes hurtPulse { 0% { opacity: 0; } 16% { opacity: 1; } 100% { opacity: 0; } }

/* ======================== Combo counter ========================== */
#combo {
  position: absolute; left: 50%; top: calc(84px + var(--sat));
  transform: translateX(-50%);
  z-index: 20; pointer-events: none;
  text-align: center;
  opacity: 0;
}
#combo.show { animation: comboPop 1.5s ease-out forwards; }
#combo b {
  display: block;
  font-size: clamp(30px, 7vw, 46px); font-weight: 900;
  color: var(--gold-bright);
  text-shadow: 0 0 22px rgba(255,215,0,0.55), 0 3px 10px #000;
  line-height: 1;
}
#combo span { font-size: 12px; letter-spacing: 3px; color: var(--ink); text-shadow: 0 2px 6px #000; }
@keyframes comboPop {
  0% { opacity: 0; transform: translateX(-50%) scale(0.5); }
  10% { opacity: 1; transform: translateX(-50%) scale(1.15); }
  18% { transform: translateX(-50%) scale(1); }
  72% { opacity: 1; }
  100% { opacity: 0; transform: translateX(-50%) scale(1); }
}

/* ======================= Rotate toast ============================ */
#rotate-toast {
  position: absolute; left: 50%; bottom: calc(84px + var(--sab));
  transform: translateX(-50%);
  z-index: 46;
  background: rgba(23,16,31,0.92);
  border: 1.5px solid var(--gold-dim);
  border-radius: 12px;
  padding: 10px 18px;
  font-size: 14px;
  pointer-events: none;
  animation: toastIn .3s ease-out;
}
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, 12px); } to { opacity: 1; transform: translate(-50%, 0); } }

/* =========================== Dialogue ============================ */
#dialogue {
  z-index: 25;
  display: flex; align-items: flex-end; justify-content: center;
  padding-bottom: calc(26px + var(--sab));
  pointer-events: auto;
}
#dialogue-portrait {
  position: absolute; bottom: calc(26px + var(--sab));
  left: max(calc(50% - 400px), calc(10px + var(--sal)));
  width: 66px; height: 66px;
  border: 3px solid var(--gold-dim);
  border-radius: 50%;
  background: var(--panel);
  box-shadow: 0 6px 20px rgba(0,0,0,.8), inset 0 0 24px rgba(0,0,0,.6);
  image-rendering: pixelated;
  z-index: 1;
}
#dialogue-box {
  width: 720px; max-width: calc(96% - 2 * max(84px, 8%));
  min-height: 128px;
  background: linear-gradient(180deg, rgba(31,21,41,0.97), rgba(23,16,31,0.97));
  border: 2px solid var(--gold-dim);
  border-radius: 14px;
  padding: 12px 18px 30px;
  position: relative;
  box-shadow: 0 10px 40px rgba(0,0,0,.85), inset 0 0 40px rgba(232,182,76,0.05);
}
#dialogue-box::before, #dialogue-box::after {
  content: '❖'; position: absolute; top: 7px;
  color: var(--gold-dim); font-size: 12px;
}
#dialogue-box::before { left: 10px; }
#dialogue-box::after { right: 10px; }

#dialogue-speaker {
  color: var(--gold-bright);
  font-weight: 900; font-size: 13.5px;
  letter-spacing: 1px;
  margin-bottom: 5px;
}
#dialogue-fa {
  font-size: 17px; line-height: 1.85;
  font-weight: 700;
  min-height: 36px;
  text-align: right;
  text-shadow: 0 1px 3px #000;
}
#dialogue-en {
  font-size: 13px; line-height: 1.5;
  color: var(--ink-dim);
  min-height: 20px;
}
#dialogue-hint {
  position: absolute; bottom: 7px; right: 14px;
  font-size: 11px; color: var(--gold-dim);
  animation: blink 1.4s step-end infinite;
}

/* ============================= Menus ============================= */
.menu {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 12px;
  background: radial-gradient(ellipse at center, rgba(13,10,20,0.25) 0%, rgba(6,4,9,0.88) 100%);
  pointer-events: auto;
  text-align: center;
  padding: 20px;
}
.menu h2 {
  font-family: 'Cinzel', serif;
  font-size: clamp(34px, 8vw, 64px); letter-spacing: 6px;
  color: var(--ink);
  text-shadow: 0 4px 24px #000;
}
.menu h2.gold { color: var(--gold-bright); text-shadow: 0 0 34px rgba(255,215,0,0.35), 0 4px 24px #000; }
.menu h2.blood { color: var(--blood); text-shadow: 0 0 30px rgba(176,48,48,0.4), 0 4px 24px #000; }
.menu-hint { color: var(--ink-dim); font-size: 14px; letter-spacing: 2px; }

#title-ornament {
  font-size: 34px; color: var(--gold-dim);
  animation: float 3.4s ease-in-out infinite;
}
@keyframes float { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-8px); } }

#title-main {
  font-family: 'Cinzel', serif;
  font-size: clamp(34px, 9vw, 74px); font-weight: 800;
  letter-spacing: clamp(3px, 1.4vw, 10px);
  background: linear-gradient(180deg, #fff3c4 0%, var(--gold-bright) 45%, #9c6f1c 100%);
  -webkit-background-clip: text; background-clip: text;
  color: transparent;
  filter: drop-shadow(0 4px 18px rgba(0,0,0,0.9)) drop-shadow(0 0 26px rgba(232,182,76,0.25));
  animation: titleGlow 4s ease-in-out infinite;
}
@keyframes titleGlow {
  0%,100% { filter: drop-shadow(0 4px 18px rgba(0,0,0,0.9)) drop-shadow(0 0 18px rgba(232,182,76,0.2)); }
  50%     { filter: drop-shadow(0 4px 18px rgba(0,0,0,0.9)) drop-shadow(0 0 42px rgba(232,182,76,0.45)); }
}
#title-fa {
  font-size: clamp(22px, 5vw, 30px); font-weight: 900; color: var(--gold);
  text-shadow: 0 2px 10px #000;
}
#title-sub { color: var(--ink-dim); font-size: clamp(12px, 3vw, 15px); letter-spacing: 3px; }
#title-trial {
  margin-top: 8px; font-size: clamp(14px, 3.4vw, 17px); color: var(--ink);
  border-top: 1px solid var(--gold-dim);
  border-bottom: 1px solid var(--gold-dim);
  padding: 7px 22px;
}
#title-start { font-size: clamp(17px, 4vw, 21px); font-weight: 700; color: var(--green); margin-top: 12px; }
.blink { animation: blink 1.4s step-end infinite; }
@keyframes blink { 50% { opacity: 0.15; } }

#title-controls {
  position: absolute; bottom: calc(14px + var(--sab));
  display: flex; gap: 8px; flex-wrap: wrap; justify-content: center;
  padding: 0 12px;
  font-size: 11.5px; color: var(--ink-dim); letter-spacing: 1px;
  max-width: 96vw;
}
#title-controls span { border: 1px solid #3a2f44; padding: 3px 9px; border-radius: 6px; background: rgba(23,16,31,0.6); }
body.touch #title-controls .kb-only { display: none; }
body:not(.touch) #title-controls .touch-only { display: none; }

#victory-stats {
  display: flex; gap: 22px; flex-wrap: wrap; justify-content: center;
  font-size: 15px; color: var(--ink);
  margin-top: 4px;
}
#victory-stats b { color: var(--gold-bright); }

#mute-indicator {
  position: absolute; top: calc(10px + var(--sat)); left: 50%; transform: translateX(-50%);
  font-size: 12px; color: var(--ink-dim);
  background: rgba(23,16,31,0.8);
  padding: 4px 12px; border-radius: 6px;
  z-index: 50;
  pointer-events: none;
}

/* ======================= Desktop enhancement ===================== */
@media (min-width: 900px) and (min-height: 620px) {
  #hud { padding: 16px 22px; }
  .heart { width: 30px; height: 27px; }
  #arrows { font-size: 20px; }
  #rakhsh-cd { width: 44px; height: 44px; font-size: 20px; }
  #boss-bar { top: 18px; width: min(560px, 60vw); }
  #boss-name { font-size: 15px; }
  #boss-track { height: 14px; }
  #trial-label { font-size: 13px; }
  .tbtn { width: 68px; height: 68px; }
  .tbtn.big { width: 84px; height: 84px; font-size: 34px; }
  #dialogue-box { min-height: 150px; padding: 16px 26px 34px; }
  #dialogue-fa { font-size: 19px; }
  #dialogue-en { font-size: 14px; }
  #dialogue-portrait { width: 84px; height: 84px; }
  #qte-btns button { width: 96px; height: 96px; font-size: 44px; }
  #qte-hint { bottom: 22px; }
  #qte-btns { bottom: 58px; }
}

/* landscape phones: compress HUD, keep controls reachable */
@media (max-height: 480px) {
  .tbtn { width: 52px; height: 52px; font-size: 20px; }
  .tbtn.big { width: 64px; height: 64px; font-size: 26px; }
  .tc-right { width: 168px; height: 196px; }
  #tb-attack { right: 0; bottom: 0; }
  #tb-jump { right: 86px; bottom: 8px; }
  #tb-roll { right: 6px; bottom: 84px; }
  #tb-bow { right: 92px; bottom: 90px; }
  #tb-mount { right: 46px; bottom: 158px; }
  #hearts { gap: 4px; }
  .heart { width: 19px; height: 17px; }
  #boss-bar { width: min(420px, 52vw); }
  #trial-label { display: none; }
  #dialogue-box { min-height: 104px; padding-bottom: 24px; }
  #dialogue-fa { font-size: 15px; line-height: 1.6; }
  #qte-btns button { width: 70px; height: 70px; font-size: 30px; }
  #qte-btns { bottom: calc(40px + var(--sab)); }
}

/* very narrow portrait phones: shrink QTE ring furniture */
@media (max-width: 420px) {
  #qte-btns { gap: 12px; }
  #qte-btns button { width: 76px; height: 76px; font-size: 34px; }
}
