:root {
  --gold: #ffd36b;
  --panel: rgba(14, 12, 24, .94);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; height: 100%; overflow: hidden; background: #d9d2bd; color: #eef;
  font-family: system-ui, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  touch-action: none; user-select: none; -webkit-user-select: none;
}
button { font-family: inherit; }
#game { position: fixed; inset: 0; display: block; touch-action: none; }
.hidden { display: none !important; }

/* ---------- HUD ---------- */
#hud { position: fixed; inset: 0; pointer-events: none; }
#hud button { pointer-events: auto; }

#top {
  position: absolute; top: calc(8px + env(safe-area-inset-top)); left: 10px; right: 10px;
  display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: flex-start;
}
#bars { flex: 1 1 200px; max-width: 320px; display: flex; flex-direction: column; gap: 5px; }
.bar {
  position: relative; height: 18px; border-radius: 9px; background: rgba(0, 0, 0, .55);
  border: 1px solid rgba(255, 255, 255, .18); overflow: hidden; font-size: 11px; font-weight: 700;
}
.bar > div { height: 100%; width: 0; transition: width .12s linear; }
.bar.hp > div { background: linear-gradient(90deg, #ff3b5c, #ff7a6b); }
.bar.xp > div { background: linear-gradient(90deg, #4cc9f0, #8e7dff); }
.bar span { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; text-shadow: 0 1px 2px #000; }

#stats { display: flex; gap: 8px; }
.stat {
  background: rgba(0, 0, 0, .5); border: 1px solid rgba(255, 255, 255, .14); border-radius: 10px;
  padding: 4px 10px; min-width: 64px; text-align: center;
}
.stat .label { display: block; font-size: 10px; opacity: .7; text-transform: uppercase; letter-spacing: .5px; }
.stat b { font-size: 15px; }

#ctrl { margin-left: auto; display: flex; gap: 6px; }
#ctrl button {
  background: rgba(0, 0, 0, .55); color: #fff; border: 1px solid rgba(255, 255, 255, .2);
  border-radius: 10px; padding: 6px 10px; font-size: 13px; cursor: pointer;
}
#btn-auto.on { border-color: var(--gold); color: var(--gold); }

#bossbar {
  position: absolute; top: calc(96px + env(safe-area-inset-top)); left: 50%; transform: translateX(-50%);
  width: min(520px, 80vw); height: 14px; background: rgba(0, 0, 0, .6); border: 1px solid #ff6b6b; border-radius: 7px;
}
#bossbar div { height: 100%; border-radius: 7px; background: linear-gradient(90deg, #b1121f, #ff5e5e); transition: width .1s; }
#bossbar span {
  position: absolute; left: 0; right: 0; top: -19px; text-align: center; font-size: 12px;
  color: #ff8a8a; font-weight: 700; text-shadow: 0 1px 2px #000;
}

#announce {
  position: absolute; top: 24%; left: 0; right: 0; text-align: center; padding: 0 16px;
  font-size: clamp(22px, 4.5vw, 42px); font-weight: 800; letter-spacing: 1px;
  text-shadow: 0 2px 12px #000, 0 0 26px currentColor; opacity: 0;
}
#announce.show { animation: announce 2.4s ease-out forwards; }
@keyframes announce {
  0%   { opacity: 0; transform: scale(.6); }
  12%  { opacity: 1; transform: scale(1.06); }
  25%  { transform: scale(1); }
  75%  { opacity: 1; }
  100% { opacity: 0; transform: translateY(-24px); }
}

/* ---------- Chiêu thức & lướt ---------- */
#skills {
  position: absolute; right: calc(14px + env(safe-area-inset-right)); bottom: calc(16px + env(safe-area-inset-bottom));
  display: flex; gap: 10px;
}
.skill, .act {
  position: relative; width: 64px; height: 64px; border-radius: 50%; padding: 0; overflow: hidden;
  border: 2px solid rgba(255, 255, 255, .35); background: rgba(10, 18, 14, .82); color: #fff; cursor: pointer;
}
.skill .icon, .act .icon { font-size: 25px; line-height: 60px; }
.skill .cd, .act .cd {
  position: absolute; inset: 0; border-radius: 50%;
  background: conic-gradient(rgba(0, 0, 0, .74) var(--p, 0%), transparent 0);
  display: flex; align-items: center; justify-content: center; font-weight: 800; font-size: 18px; text-shadow: 0 1px 3px #000;
}
.skill .key, .act .key { position: absolute; top: 4px; left: 8px; font-size: 10px; opacity: .75; font-weight: 800; }
.skill .name { position: absolute; bottom: 4px; left: 0; right: 0; font-size: 9px; opacity: .85; }
.skill.ready { border-color: var(--gold); box-shadow: 0 0 16px rgba(255, 211, 107, .55); }
.skill.locked { opacity: .4; filter: grayscale(1); }
.skill.locked::after { content: '🔒'; position: absolute; inset: 0; font-size: 22px; line-height: 60px; }

#actions {
  position: absolute; right: calc(14px + env(safe-area-inset-right)); bottom: calc(94px + env(safe-area-inset-bottom));
  display: none; align-items: flex-end; gap: 10px;
}
.act.big { width: 80px; height: 80px; }
.act.big .icon { font-size: 32px; line-height: 76px; }
.act:active { background: rgba(255, 211, 107, .35); }
@media (pointer: coarse) { #actions { display: flex; } }

/* ---------- Joystick ---------- */
#joy {
  position: absolute; width: 124px; height: 124px; margin: -62px 0 0 -62px; border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, .25); background: rgba(255, 255, 255, .06); display: none;
}
#joy.show { display: block; }
#joy-knob {
  position: absolute; left: 50%; top: 50%; width: 54px; height: 54px; margin: -27px 0 0 -27px;
  border-radius: 50%; background: rgba(255, 255, 255, .35);
}

/* ---------- Bảng ---------- */
.overlay {
  position: fixed; inset: 0; background: rgba(4, 10, 6, .72); display: flex; align-items: center; justify-content: center;
  padding: 16px; z-index: 10; backdrop-filter: blur(2px);
}
.panel {
  background: var(--panel); border: 1px solid rgba(255, 255, 255, .14); border-radius: 16px; padding: 22px 24px;
  max-width: 600px; width: 100%; text-align: center; box-shadow: 0 20px 60px rgba(0, 0, 0, .6); max-height: 94vh; overflow: auto;
}
.panel h1 { margin: 0 0 10px; font-size: 32px; color: var(--gold); }
.panel h2 { margin: 0 0 2px; font-size: 24px; color: var(--gold); }
.panel p { line-height: 1.55; opacity: .92; margin: 8px 0; }
.panel p.sub { opacity: .65; font-size: 13px; }
.panel kbd {
  background: rgba(255, 255, 255, .12); border: 1px solid rgba(255, 255, 255, .25); border-bottom-width: 2px;
  border-radius: 5px; padding: 1px 6px; font-size: 12px; font-family: inherit;
}
.primary {
  background: linear-gradient(135deg, #ffd36b, #ff9f43); color: #201300; border: none; border-radius: 12px;
  padding: 12px 28px; font-size: 17px; font-weight: 800; cursor: pointer; margin-top: 8px;
}
.primary:hover { filter: brightness(1.08); }
#ov-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 8px; margin: 10px 0 6px; }
#ov-stats .stat { padding: 8px 6px; }
#ov-stats .stat.rec b { color: var(--gold); }

#cards { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; margin-top: 14px; }
.card {
  flex: 1 1 150px; max-width: 180px; min-height: 176px; position: relative;
  background: linear-gradient(180deg, rgba(255, 255, 255, .08), rgba(255, 255, 255, .03));
  border: 1px solid rgba(255, 211, 107, .35); border-radius: 14px; color: #fff; padding: 14px 10px; cursor: pointer;
  transition: transform .12s, border-color .12s, box-shadow .12s;
}
.card:hover, .card:focus { transform: translateY(-4px); border-color: var(--gold); box-shadow: 0 0 18px rgba(255, 211, 107, .35); outline: none; }
.card .c-icon { font-size: 34px; display: block; }
.card b { display: block; font-size: 15px; margin-top: 6px; color: var(--gold); }
.card small { display: block; opacity: .6; font-size: 11px; min-height: 13px; }
.card p { font-size: 12.5px; margin: 8px 0 0; opacity: .9; line-height: 1.4; }
.card em { position: absolute; top: 6px; left: 9px; font-style: normal; font-size: 11px; opacity: .5; }

#toast {
  position: fixed; left: 50%; bottom: 110px; transform: translateX(-50%); z-index: 11; pointer-events: none;
  background: rgba(0, 0, 0, .78); border: 1px solid rgba(255, 255, 255, .2); padding: 8px 14px; border-radius: 10px;
  font-size: 14px; opacity: 0; transition: opacity .2s; white-space: nowrap;
}
#toast.show { opacity: 1; }

@media (max-width: 640px) {
  #top { gap: 6px 8px; }
  #bars { flex-basis: 140px; }
  #stats .stat { min-width: 50px; padding: 3px 6px; }
  .stat b { font-size: 13px; }
  .stat .label { font-size: 9px; }
  #ctrl button { padding: 5px 8px; font-size: 13px; }
  #btn-auto .lbl { display: none; }
  #bossbar { top: calc(104px + env(safe-area-inset-top)); }
  .skill, .act { width: 56px; height: 56px; }
  .skill .icon, .act .icon { font-size: 22px; line-height: 52px; }
  .skill.locked::after { line-height: 52px; }
  .act.big { width: 72px; height: 72px; }
  .act.big .icon { font-size: 28px; line-height: 68px; }
  #actions { bottom: calc(86px + env(safe-area-inset-bottom)); }
  .panel { padding: 16px 14px; }
  .panel h1 { font-size: 24px; }
  .panel p { font-size: 14px; }
  .card { min-height: 150px; flex-basis: 125px; padding: 10px 8px; }
  .card .c-icon { font-size: 28px; }
}

/* ---------- IV: nền sáng, HUD đậm hơn ---------- */
.stat, #ctrl button { background: rgba(10, 8, 20, .62); }
.bar { background: rgba(10, 8, 20, .62); }
#announce { text-shadow: 0 2px 10px rgba(0,0,0,.6), 0 0 22px currentColor; }

/* ---------- Thủy mặc: HUD kiểu mực ---------- */
html, body { font-family: "Times New Roman", "Noto Serif", Georgia, serif; }
.stat, #ctrl button, .bar, .skill, .act { background: rgba(24, 21, 30, .86); border-color: rgba(10, 8, 14, .7); box-shadow: 0 2px 0 rgba(0,0,0,.35), inset 0 0 0 1px rgba(255,255,255,.06); }
.stat { border-radius: 6px 14px 6px 14px / 14px 6px 14px 6px; }
.stat b, .stat .label { color: #f1e4c2; }
#realm { font-weight: 800; }
.bar.hp > div { background: linear-gradient(90deg, #b8232f, #ff6b5a); }
.bar.xp > div { background: linear-gradient(90deg, #2d7fbf, #8fd0ff); }
#bossbar { border-color: #c8303a; }
#announce { font-family: "Times New Roman", serif; letter-spacing: 1px; }
.panel { background: rgba(24, 21, 30, .95); border: 1px solid rgba(217, 166, 64, .35); }
.panel h1, .panel h2, .card b { color: #e9c56b; }
.primary { background: linear-gradient(135deg, #e9c56b, #c58a2a); }
