:root {
  color-scheme: dark;
  --bg: #080b12;
  --panel: rgba(12, 16, 27, 0.92);
  --panel-soft: rgba(18, 24, 38, 0.72);
  --line: rgba(220, 183, 102, 0.26);
  --gold: #e0bd73;
  --gold-strong: #f2d698;
  --text: #f5f0e5;
  --muted: #aaa59c;
  --danger: #e88f8f;
  --success: #8fd5ad;
  --shadow: 0 24px 70px rgba(0, 0, 0, 0.52);
}

* { box-sizing: border-box; }

html, body {
  width: 100%;
  min-height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  overscroll-behavior: none;
}

body {
  min-height: 100dvh;
  overflow: hidden;
  background:
    radial-gradient(circle at 50% 18%, rgba(109, 83, 47, 0.28), transparent 32%),
    linear-gradient(160deg, #121827 0%, #080b12 52%, #05070b 100%);
}

button, input { font: inherit; }
button { touch-action: manipulation; }

.app-shell {
  position: relative;
  display: grid;
  place-items: center;
  width: 100%;
  min-height: 100dvh;
  padding: max(14px, env(safe-area-inset-top)) max(14px, env(safe-area-inset-right)) max(14px, env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left));
}

.ambient {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
}

.ambient::before,
.ambient::after {
  content: "";
  position: absolute;
  width: 54vmax;
  height: 54vmax;
  border: 1px solid rgba(224, 189, 115, 0.08);
  border-radius: 44% 56% 58% 42%;
  filter: blur(1px);
  animation: drift 28s linear infinite;
}

.ambient::before { left: -28vmax; top: -32vmax; }
.ambient::after { right: -34vmax; bottom: -36vmax; animation-direction: reverse; animation-duration: 34s; }

@keyframes drift { to { transform: rotate(360deg); } }

.login-panel {
  position: relative;
  z-index: 20;
  width: min(440px, 100%);
  padding: clamp(22px, 5vw, 38px);
  border: 1px solid var(--line);
  border-radius: 24px;
  background: linear-gradient(180deg, rgba(23, 29, 44, 0.96), rgba(8, 11, 18, 0.96));
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.login-panel[hidden] { display: none; }

.brand-mark {
  display: grid;
  place-items: center;
  width: 74px;
  height: 74px;
  margin: 0 auto 18px;
  border: 1px solid rgba(242, 214, 152, 0.6);
  border-radius: 22px 10px 22px 10px;
  background: radial-gradient(circle at 50% 30%, rgba(224, 189, 115, 0.32), rgba(17, 22, 34, 0.8));
  box-shadow: 0 10px 30px rgba(224, 189, 115, 0.12);
  color: var(--gold-strong);
  font-family: Georgia, "Times New Roman", serif;
  font-size: 28px;
  font-weight: 700;
  letter-spacing: 2px;
  transform: rotate(2deg);
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--gold);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.22em;
  text-align: center;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(32px, 7vw, 48px);
  font-weight: 600;
  letter-spacing: 0.04em;
  line-height: 1.05;
  text-align: center;
}

.tagline {
  max-width: 34rem;
  margin: 13px auto 26px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.55;
  text-align: center;
}

.field { display: grid; gap: 8px; }
.field label { color: #d9d1c2; font-size: 13px; font-weight: 650; }

.input-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

.input-wrap span {
  position: absolute;
  left: 15px;
  color: var(--gold);
  font-size: 15px;
  pointer-events: none;
}

input[type="text"],
input[type="password"] {
  width: 100%;
  min-height: 50px;
  padding: 0 15px 0 43px;
  border: 1px solid rgba(224, 189, 115, 0.22);
  border-radius: 14px;
  outline: none;
  background: rgba(3, 6, 11, 0.66);
  color: var(--text);
  transition: border-color .2s ease, box-shadow .2s ease;
}

input[type="text"]:focus,
input[type="password"]:focus {
  border-color: rgba(242, 214, 152, 0.72);
  box-shadow: 0 0 0 4px rgba(224, 189, 115, 0.09);
}

.form-message {
  min-height: 20px;
  margin: 9px 0 2px;
  color: var(--danger);
  font-size: 12px;
}

.primary-button,
.toolbar-button {
  border: 0;
  cursor: pointer;
}

.primary-button {
  width: 100%;
  min-height: 52px;
  border-radius: 14px;
  background: linear-gradient(135deg, #f0d496, #b88743);
  color: #18130c;
  font-weight: 800;
  letter-spacing: 0.02em;
  box-shadow: 0 12px 30px rgba(184, 135, 67, 0.22);
}

.primary-button:hover { filter: brightness(1.05); }
.primary-button:disabled { cursor: not-allowed; filter: grayscale(.65); opacity: .66; }

.server-card {
  display: flex;
  align-items: center;
  gap: 11px;
  margin-top: 18px;
  padding: 12px 14px;
  border: 1px solid rgba(255,255,255,.08);
  border-radius: 13px;
  background: var(--panel-soft);
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.status-dot {
  flex: 0 0 auto;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--danger);
  box-shadow: 0 0 0 5px rgba(232, 143, 143, .08);
}

.build-note {
  margin: 16px 0 0;
  color: #77756f;
  font-size: 11px;
  text-align: center;
}

.runtime-shell {
  position: relative;
  z-index: 10;
  display: grid;
  place-items: center;
  width: 100%;
  min-height: 100dvh;
}

.runtime-shell[hidden] { display: none; }

.game-toolbar {
  position: fixed;
  z-index: 40;
  top: max(8px, env(safe-area-inset-top));
  right: max(8px, env(safe-area-inset-right));
  display: flex;
  gap: 8px;
}

.toolbar-button {
  min-height: 38px;
  padding: 0 13px;
  border: 1px solid rgba(255,255,255,.12);
  border-radius: 11px;
  background: rgba(7, 10, 16, .78);
  color: #ddd7cc;
  font-size: 12px;
  backdrop-filter: blur(12px);
}

.game-stage {
  position: relative;
  width: 800px;
  height: 480px;
  overflow: hidden;
  border: 1px solid rgba(224, 189, 115, .18);
  border-radius: 12px;
  background: #000;
  box-shadow: var(--shadow);
  transform-origin: center center;
}

#gameCanvas {
  display: block;
  width: 800px;
  height: 480px;
  background: #000;
}

#liuYantxt,
#qiHaotxt { display: none; position: absolute; }

#debugPanel {
  position: fixed;
  z-index: 45;
  left: max(8px, env(safe-area-inset-left));
  bottom: max(8px, env(safe-area-inset-bottom));
  width: min(520px, calc(100vw - 16px));
  max-height: 44vh;
  overflow: auto;
  padding: 10px;
  border: 1px solid rgba(255,255,255,.11);
  border-radius: 12px;
  background: rgba(5, 8, 13, .9);
  color: #c8d2c9;
  font: 11px/1.45 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  white-space: pre-wrap;
}

#debugPanel[hidden] { display: none; }
#debugtxt { display: none; }

.loading-layer {
  position: absolute;
  z-index: 30;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(4, 6, 10, .92);
}

.loading-layer[hidden] { display: none; }

.loading-card { width: min(360px, calc(100% - 40px)); text-align: center; }
.loading-title { color: var(--gold-strong); font-family: Georgia, serif; font-size: 24px; }
.loading-text { margin-top: 10px; color: var(--muted); font-size: 13px; }
.progress-track { height: 5px; margin-top: 18px; overflow: hidden; border-radius: 99px; background: rgba(255,255,255,.08); }
.progress-bar { width: 22%; height: 100%; border-radius: inherit; background: linear-gradient(90deg, #8f682f, #f0d496); animation: loading 1.35s ease-in-out infinite alternate; }
@keyframes loading { to { width: 92%; } }

.rotate-notice {
  display: none;
  position: fixed;
  z-index: 60;
  inset: 0;
  place-items: center;
  padding: 30px;
  background: #080b12;
  text-align: center;
}

.rotate-notice strong { display: block; margin-bottom: 8px; color: var(--gold-strong); font-size: 20px; }
.rotate-notice span { color: var(--muted); font-size: 13px; line-height: 1.5; }

@media (orientation: portrait) and (max-width: 760px) {
  .runtime-shell:not([hidden]) + .rotate-notice { display: grid; }
}

@media (max-height: 560px) {
  .login-panel { padding: 18px 24px; }
  .brand-mark { width: 56px; height: 56px; margin-bottom: 10px; font-size: 21px; }
  .tagline { margin-bottom: 16px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; }
}

/* Step 03: tài khoản, nhân vật và trạng thái máy chủ */
#authForm,
#characterForm { display: grid; gap: 14px; }

#authForm .form-message,
#characterForm .form-message { margin: -3px 0 -1px; }

.auth-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin-bottom: 18px;
  padding: 5px;
  border: 1px solid rgba(255,255,255,.07);
  border-radius: 14px;
  background: rgba(2, 5, 9, .48);
}

.auth-tab {
  min-height: 40px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-weight: 700;
}

.auth-tab.is-active {
  background: rgba(224, 189, 115, .13);
  color: var(--gold-strong);
  box-shadow: inset 0 0 0 1px rgba(224, 189, 115, .16);
}

.status-dot.is-online {
  background: var(--success);
  box-shadow: 0 0 0 5px rgba(143, 213, 173, .09), 0 0 18px rgba(143, 213, 173, .45);
}

.status-dot.is-checking {
  background: var(--gold);
  box-shadow: 0 0 0 5px rgba(224, 189, 115, .09);
  animation: pulse-status 1.2s ease-in-out infinite alternate;
}

.status-dot.is-offline { background: var(--danger); }

@keyframes pulse-status { to { opacity: .42; transform: scale(.78); } }

.character-panel {
  width: min(680px, 100%);
  max-height: calc(100dvh - 28px);
  overflow: auto;
}

.panel-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
}

.panel-heading .eyebrow { text-align: left; }

h2, h3 {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-weight: 600;
}

h2 { font-size: clamp(28px, 6vw, 40px); }
h3 { font-size: 28px; }

.character-intro { margin: 9px 0 20px; text-align: left; }

.link-button {
  flex: 0 0 auto;
  min-height: 36px;
  padding: 0 12px;
  border: 1px solid rgba(255,255,255,.1);
  border-radius: 10px;
  background: rgba(0,0,0,.22);
  color: var(--muted);
  cursor: pointer;
}

.path-fieldset {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin: 0;
  padding: 0;
  border: 0;
}

.path-fieldset legend {
  grid-column: 1 / -1;
  width: 100%;
  margin-bottom: 1px;
  color: #d9d1c2;
  font-size: 13px;
  font-weight: 650;
}

.path-option {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 132px;
  padding: 13px 10px;
  border: 1px solid rgba(255,255,255,.09);
  border-radius: 14px;
  background: rgba(3, 6, 11, .54);
  text-align: center;
  cursor: pointer;
  transition: border-color .2s ease, background .2s ease, transform .2s ease;
}

.path-option:hover { transform: translateY(-2px); }
.path-option.is-selected {
  border-color: rgba(242, 214, 152, .58);
  background: linear-gradient(180deg, rgba(224, 189, 115, .14), rgba(3, 6, 11, .62));
  box-shadow: 0 10px 26px rgba(0,0,0,.18);
}
.path-option input { position: absolute; opacity: 0; pointer-events: none; }
.path-icon { color: var(--gold-strong); font: 27px/1 Georgia, serif; }
.path-option strong { margin-top: 7px; color: var(--text); font-size: 14px; }
.path-option small { margin-top: 5px; color: var(--muted); font-size: 10px; line-height: 1.4; }

.character-summary {
  display: flex;
  align-items: center;
  gap: 18px;
  margin: 12px 0 22px;
  padding: 18px;
  border: 1px solid rgba(224, 189, 115, .18);
  border-radius: 18px;
  background: linear-gradient(135deg, rgba(224, 189, 115, .12), rgba(5, 8, 13, .55));
}

.character-summary[hidden],
#characterForm[hidden] { display: none; }

.summary-seal {
  display: grid;
  place-items: center;
  width: 72px;
  height: 72px;
  border: 1px solid rgba(242, 214, 152, .48);
  border-radius: 50%;
  color: var(--gold-strong);
  font: 30px/1 Georgia, serif;
  background: rgba(0,0,0,.23);
}

.character-summary .eyebrow { margin-bottom: 5px; text-align: left; }
.character-summary p:last-child { margin: 7px 0 0; color: var(--muted); font-size: 13px; }

.socket-state {
  margin-top: 13px;
  color: #7f7c75;
  font-size: 11px;
  text-align: center;
}
.socket-state.is-online { color: var(--success); }

@media (max-width: 620px) {
  .path-fieldset { grid-template-columns: 1fr; }
  .path-option { grid-template-columns: 48px 1fr; justify-items: start; min-height: 76px; text-align: left; }
  .path-icon { grid-row: 1 / span 2; }
  .path-option strong { margin-top: 0; }
  .path-option small { margin-top: 2px; }
  .character-panel { padding: 22px; }
}

.field[hidden] { display: none !important; }

/* Step 04: Thanh Vân Thôn gameplay shell */
.world-panel {
  position: relative;
  z-index: 18;
  width: min(1180px, 100%);
  max-height: calc(100dvh - 28px);
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 24px;
  background:
    linear-gradient(180deg, rgba(17, 23, 35, .97), rgba(7, 10, 16, .98)),
    radial-gradient(circle at 80% 5%, rgba(224, 189, 115, .13), transparent 28%);
  box-shadow: var(--shadow);
  scrollbar-width: thin;
  scrollbar-color: rgba(224, 189, 115, .35) transparent;
}

.world-panel[hidden] { display: none; }

.world-header {
  position: sticky;
  top: 0;
  z-index: 5;
  display: grid;
  grid-template-columns: minmax(260px, 1fr) auto auto;
  align-items: center;
  gap: 18px;
  padding: 18px 22px;
  border-bottom: 1px solid rgba(224, 189, 115, .17);
  background: rgba(9, 13, 21, .92);
  backdrop-filter: blur(14px);
}

.world-identity { display: flex; align-items: center; gap: 14px; min-width: 0; }
.world-identity h2 { margin: 0; font: 700 23px/1.15 Georgia, serif; color: var(--gold-strong); }
.world-identity p:last-child { margin: 5px 0 0; color: var(--muted); font-size: 12px; }
.world-seal {
  display: grid;
  place-items: center;
  width: 54px;
  height: 54px;
  flex: 0 0 auto;
  border: 1px solid rgba(242, 214, 152, .5);
  border-radius: 50%;
  background: rgba(224, 189, 115, .1);
  color: var(--gold-strong);
  font: 24px/1 Georgia, serif;
}

.world-resources { display: flex; gap: 10px; }
.world-resources span {
  min-width: 92px;
  padding: 9px 12px;
  border: 1px solid rgba(255,255,255,.07);
  border-radius: 12px;
  background: rgba(0,0,0,.22);
  text-align: right;
}
.world-resources small { display: block; color: var(--muted); font-size: 10px; }
.world-resources strong { display: block; margin-top: 2px; color: var(--gold-strong); font-size: 15px; }
.world-actions { display: flex; gap: 8px; }

.world-grid {
  display: grid;
  grid-template-columns: 1.35fr .9fr;
  gap: 16px;
  padding: 18px;
}

.world-card {
  position: relative;
  min-width: 0;
  padding: 18px;
  border: 1px solid rgba(255,255,255,.075);
  border-radius: 18px;
  background: linear-gradient(180deg, rgba(23, 29, 43, .72), rgba(7, 10, 16, .72));
  overflow: hidden;
}

.location-card { min-height: 260px; padding-top: 126px; }
.location-art {
  position: absolute;
  inset: 0 0 auto;
  height: 118px;
  overflow: hidden;
  background:
    linear-gradient(180deg, rgba(51, 66, 85, .7), rgba(19, 27, 39, .15)),
    radial-gradient(circle at 76% 23%, rgba(242, 214, 152, .5), transparent 12%);
}
.location-art::after {
  content: "";
  position: absolute;
  inset: auto 0 0;
  height: 28px;
  background: linear-gradient(180deg, transparent, rgba(7, 10, 16, .96));
}
.mountain { position: absolute; bottom: 4px; width: 58%; height: 82px; background: rgba(12, 20, 29, .74); clip-path: polygon(0 100%, 29% 42%, 43% 67%, 66% 13%, 100% 100%); }
.mountain-back { left: -2%; opacity: .56; transform: scale(.92); }
.mountain-front { right: -7%; height: 94px; background: rgba(8, 15, 23, .9); }
.village-lantern { position: absolute; right: 11%; bottom: 25px; z-index: 2; color: var(--gold-strong); font-size: 26px; text-shadow: 0 0 18px rgba(242,214,152,.8); }

.card-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.card-heading h3 { margin: 0; color: var(--text); font-size: 17px; }
.world-card > p { color: var(--muted); font-size: 13px; line-height: 1.65; }
.safe-badge, .quest-state {
  flex: 0 0 auto;
  padding: 5px 9px;
  border: 1px solid rgba(143, 213, 173, .25);
  border-radius: 999px;
  color: var(--success);
  background: rgba(143, 213, 173, .08);
  font-size: 10px;
}
.story-marker { display: flex; justify-content: space-between; gap: 16px; margin-top: 14px; padding-top: 12px; border-top: 1px solid rgba(255,255,255,.07); color: var(--muted); font-size: 11px; }
.story-marker strong { color: var(--gold); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }

.stats-grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 9px; margin-top: 14px; }
.stat-item { padding: 11px; border: 1px solid rgba(255,255,255,.06); border-radius: 12px; background: rgba(0,0,0,.18); }
.stat-item small { display: block; color: var(--muted); font-size: 10px; }
.stat-item strong { display: block; margin-top: 4px; color: var(--gold-strong); font-size: 16px; }

.quest-card { grid-column: 1 / -1; }
.quest-progress { height: 7px; margin: 15px 0 10px; overflow: hidden; border-radius: 999px; background: rgba(255,255,255,.08); }
.quest-progress > div { width: 0; height: 100%; border-radius: inherit; background: linear-gradient(90deg, #9f6d31, #f2d698); transition: width .25s ease; }
.quest-reward { min-height: 20px; margin-bottom: 8px; color: var(--gold) !important; }
.quest-action-button { width: auto; min-width: 210px; }

.equipment-list, .inventory-list { display: grid; gap: 9px; margin-top: 14px; }
.equipment-item, .inventory-item {
  display: grid;
  grid-template-columns: 38px minmax(0,1fr) auto;
  align-items: center;
  gap: 10px;
  padding: 10px;
  border: 1px solid rgba(255,255,255,.06);
  border-radius: 12px;
  background: rgba(0,0,0,.18);
}
.item-icon { display: grid; place-items: center; width: 38px; height: 38px; border-radius: 10px; background: rgba(224,189,115,.11); color: var(--gold-strong); font: 18px/1 Georgia, serif; }
.item-copy { min-width: 0; }
.item-copy strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; }
.item-copy small { display: block; margin-top: 3px; color: var(--muted); font-size: 10px; }
.item-quantity { color: var(--gold); font-size: 12px; }
.item-use-button { padding: 6px 8px; border: 1px solid rgba(224,189,115,.24); border-radius: 8px; background: rgba(224,189,115,.08); color: var(--gold-strong); font-size: 10px; cursor: pointer; }
.inventory-card { max-height: 330px; overflow: auto; }
.inventory-card .card-heading > span { color: var(--muted); font-size: 10px; }

.world-footer { display: flex; align-items: center; justify-content: space-between; gap: 18px; padding: 0 18px 18px; color: var(--muted); font-size: 11px; }
.secondary-button {
  min-height: 40px;
  padding: 0 16px;
  border: 1px solid rgba(224,189,115,.25);
  border-radius: 11px;
  background: rgba(224,189,115,.08);
  color: var(--gold-strong);
  cursor: pointer;
}
.secondary-button:disabled, .item-use-button:disabled { opacity: .55; cursor: wait; }

@media (max-width: 860px) {
  body { overflow: auto; }
  .app-shell { align-items: start; }
  .world-panel { max-height: none; border-radius: 18px; }
  .world-header { position: relative; grid-template-columns: 1fr auto; }
  .world-resources { grid-column: 1 / -1; order: 3; }
  .world-actions { align-self: start; }
  .world-grid { grid-template-columns: 1fr; padding: 12px; }
  .quest-card { grid-column: auto; }
  .world-footer { align-items: stretch; flex-direction: column; }
}

@media (max-width: 520px) {
  .world-header { grid-template-columns: 1fr; padding: 15px; }
  .world-actions { position: absolute; top: 14px; right: 14px; }
  .world-actions #refreshStateButton { display: none; }
  .world-resources { display: grid; grid-template-columns: 1fr 1fr; }
  .world-resources span { text-align: left; }
  .world-identity { padding-right: 82px; }
  .world-grid { gap: 11px; }
  .world-card { padding: 15px; }
  .location-card { padding-top: 126px; }
  .quest-action-button { width: 100%; }
}
.safe-badge.is-danger {
  border-color: rgba(232, 143, 143, .3);
  color: var(--danger);
  background: rgba(232, 143, 143, .08);
}

/* Step 05: server-authoritative battle scene */
.battle-panel {
  position: relative;
  z-index: 24;
  width: min(1040px, 100%);
  max-height: calc(100dvh - 28px);
  overflow: auto;
  padding: clamp(14px, 2.5vw, 26px);
  border: 1px solid rgba(224, 189, 115, .32);
  border-radius: 24px;
  background: linear-gradient(180deg, rgba(21, 14, 19, .97), rgba(7, 10, 16, .98));
  box-shadow: var(--shadow);
}

.battle-panel[hidden] { display: none; }

.battle-header,
.battle-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.battle-header h2 { margin: 0; font-family: Georgia, serif; }
.battle-header .eyebrow { text-align: left; }
.battle-turn {
  display: grid;
  place-items: center;
  min-width: 72px;
  padding: 8px 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(0,0,0,.28);
}
.battle-turn small { color: var(--muted); }
.battle-turn strong { color: var(--gold-strong); font-size: 22px; }

.battle-arena {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 90px minmax(0, 1fr);
  align-items: end;
  min-height: 360px;
  margin: 18px 0;
  padding: 24px;
  overflow: hidden;
  border: 1px solid rgba(255,255,255,.08);
  border-radius: 22px;
  background:
    radial-gradient(circle at 72% 30%, rgba(159, 31, 43, .32), transparent 28%),
    linear-gradient(180deg, rgba(74, 34, 48, .42), rgba(17, 17, 24, .84) 54%, rgba(9, 12, 16, .98));
}

.battle-arena::before,
.battle-arena::after {
  content: "";
  position: absolute;
  left: -5%;
  right: -5%;
  height: 110px;
  border-radius: 50%;
  background: rgba(0,0,0,.28);
  filter: blur(18px);
}
.battle-arena::before { bottom: -68px; }
.battle-arena::after { top: -82px; background: rgba(153, 26, 41, .18); }

.battle-combatant { position: relative; z-index: 2; min-width: 0; }
.combatant-name { display: flex; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.combatant-name span { color: #f2b27f; font-size: 12px; }
.enemy-combatant .combatant-name { flex-direction: row-reverse; }
.hp-track {
  height: 14px;
  overflow: hidden;
  border: 1px solid rgba(255,255,255,.14);
  border-radius: 999px;
  background: rgba(0,0,0,.48);
}
.hp-fill {
  width: 100%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #5fb880, #9be0ad);
  transition: width .35s ease;
}
.enemy-hp .hp-fill { background: linear-gradient(90deg, #a52636, #ef6b6b); }
.hp-label { margin-top: 5px; color: var(--muted); font-size: 12px; }
.enemy-combatant .hp-label { text-align: right; }

.fighter-sprite {
  position: relative;
  display: grid;
  place-items: center;
  width: clamp(132px, 24vw, 220px);
  height: clamp(180px, 28vw, 250px);
  margin-top: 18px;
  border: 1px solid rgba(255,255,255,.08);
  border-radius: 48% 48% 20% 20%;
  box-shadow: inset 0 0 50px rgba(255,255,255,.04), 0 24px 45px rgba(0,0,0,.35);
  transition: transform .18s ease, filter .18s ease;
}
.fighter-sprite span { font-family: Georgia, serif; font-size: clamp(48px, 9vw, 92px); text-shadow: 0 8px 30px rgba(0,0,0,.55); }
.player-sprite { margin-left: 8%; background: linear-gradient(160deg, rgba(66, 101, 146, .88), rgba(24, 35, 53, .96)); color: #c9e3ff; }
.enemy-sprite { margin-left: auto; margin-right: 8%; background: linear-gradient(160deg, rgba(137, 41, 48, .9), rgba(43, 17, 22, .98)); color: #ffd0bd; }
.battle-combatant.is-attacking .fighter-sprite { transform: translateX(28px) scale(1.04); filter: brightness(1.35); }
.enemy-combatant.is-attacking .fighter-sprite { transform: translateX(-28px) scale(1.04); }
.battle-combatant.is-hit .fighter-sprite { animation: battle-hit .3s ease; }
@keyframes battle-hit { 25% { transform: translateX(-12px); filter: brightness(1.8); } 70% { transform: translateX(10px); } }

.battle-center-mark { position: relative; z-index: 3; display: grid; place-items: center; align-self: center; }
.battle-center-mark span { color: rgba(242,214,152,.78); font-family: Georgia, serif; font-size: 34px; font-weight: 800; text-shadow: 0 0 24px rgba(226, 91, 71, .35); }

.battle-console { display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(260px, .65fr); gap: 14px; }
.battle-log {
  min-height: 156px;
  max-height: 210px;
  overflow: auto;
  padding: 12px 14px;
  border: 1px solid rgba(255,255,255,.08);
  border-radius: 16px;
  background: rgba(0,0,0,.26);
  color: #d8d1c5;
  font-size: 13px;
  line-height: 1.55;
}
.battle-log p { margin: 0 0 6px; }
.battle-log p:last-child { margin-bottom: 0; }
.battle-log .critical { color: #ffd071; font-weight: 700; }
.battle-log .defeat { color: #f49a9a; font-weight: 700; }
.battle-actions { display: grid; align-content: start; gap: 10px; }
.battle-action-button {
  min-height: 64px;
  padding: 10px 14px;
  border: 1px solid rgba(224,189,115,.28);
  border-radius: 14px;
  background: linear-gradient(135deg, rgba(59,50,37,.9), rgba(20,22,29,.95));
  color: var(--text);
  cursor: pointer;
  text-align: left;
}
.battle-action-button strong,
.battle-action-button small { display: block; }
.battle-action-button small { margin-top: 4px; color: var(--muted); }
.battle-action-button:disabled { cursor: not-allowed; opacity: .5; }
.battle-message { min-height: 22px; color: var(--gold-strong); }
.battle-retry-button { width: auto; min-width: 160px; }

@media (max-width: 760px) {
  body { overflow: auto; }
  .battle-panel { max-height: none; }
  .battle-arena { min-height: 300px; padding: 16px 10px; grid-template-columns: 1fr 52px 1fr; }
  .fighter-sprite { width: min(36vw, 160px); height: min(50vw, 205px); }
  .battle-console { grid-template-columns: 1fr; }
  .battle-header { align-items: flex-start; }
  .battle-footer { position: sticky; bottom: 0; padding-top: 12px; background: linear-gradient(180deg, transparent, rgba(7,10,16,.98) 24%); }
}

/* Step 06: Huyết Vân Cốc, chiến dịch và đội hình đồng hành */
.campaign-card { grid-column: 1 / -1; }
.campaign-progress,
.companions-card .card-heading > span {
  flex: 0 0 auto;
  padding: 5px 9px;
  border: 1px solid rgba(224, 189, 115, .22);
  border-radius: 999px;
  color: var(--gold-strong);
  background: rgba(224, 189, 115, .07);
  font-size: 10px;
}
.campaign-stage-list { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; margin-top: 14px; }
.campaign-stage {
  position: relative;
  display: grid;
  gap: 8px;
  min-height: 154px;
  padding: 13px;
  border: 1px solid rgba(255,255,255,.08);
  border-radius: 14px;
  background: linear-gradient(155deg, rgba(37, 25, 32, .82), rgba(8, 11, 18, .92));
}
.campaign-stage.is-available { border-color: rgba(224, 189, 115, .38); box-shadow: inset 0 0 28px rgba(224, 189, 115, .05); }
.campaign-stage.is-cleared { border-color: rgba(111, 205, 151, .28); background: linear-gradient(155deg, rgba(22, 54, 42, .62), rgba(8, 11, 18, .92)); }
.campaign-stage.is-locked { opacity: .56; filter: saturate(.55); }
.campaign-stage strong { color: var(--text); font-size: 13px; line-height: 1.35; }
.campaign-stage small { color: var(--muted); font-size: 10px; line-height: 1.45; }
.campaign-stage-status { color: var(--gold); font-size: 10px; }
.campaign-stage button {
  align-self: end;
  min-height: 34px;
  border: 1px solid rgba(224,189,115,.25);
  border-radius: 9px;
  background: rgba(224,189,115,.08);
  color: var(--gold-strong);
  cursor: pointer;
}
.campaign-stage button:disabled { cursor: not-allowed; opacity: .55; }

.companions-card { grid-column: 1 / -1; }
.formation-slots { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin: 14px 0; }
.formation-slot {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 66px;
  padding: 9px;
  border: 1px dashed rgba(224,189,115,.24);
  border-radius: 13px;
  color: var(--muted);
  background: rgba(0,0,0,.18);
}
.formation-slot img,
.companion-avatar,
.battle-party-member img { width: 48px; height: 56px; border-radius: 10px; object-fit: cover; }
.formation-slot strong { display: block; color: var(--text); font-size: 12px; }
.formation-slot small { display: block; margin-top: 2px; color: var(--muted); font-size: 10px; }
.companion-roster { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.companion-card {
  display: grid;
  grid-template-columns: 52px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  padding: 10px;
  border: 1px solid rgba(255,255,255,.07);
  border-radius: 13px;
  background: rgba(0,0,0,.18);
}
.companion-card.is-formed { border-color: rgba(224,189,115,.34); background: rgba(224,189,115,.07); }
.companion-copy { min-width: 0; }
.companion-copy strong { display: block; font-size: 12px; }
.companion-copy small { display: block; margin-top: 3px; color: var(--muted); font-size: 10px; line-height: 1.4; }
.companion-toggle {
  min-width: 58px;
  min-height: 32px;
  border: 1px solid rgba(224,189,115,.24);
  border-radius: 9px;
  background: rgba(224,189,115,.08);
  color: var(--gold-strong);
  cursor: pointer;
}
.companion-toggle:disabled { opacity: .55; cursor: wait; }

.fighter-sprite { overflow: hidden; }
.fighter-sprite img { width: 100%; height: 100%; object-fit: cover; border-radius: inherit; filter: drop-shadow(0 18px 24px rgba(0,0,0,.35)); }
.battle-party-strip {
  display: flex;
  gap: 10px;
  margin: -4px 0 14px;
  min-height: 0;
}
.battle-party-strip:empty { display: none; }
.battle-party-member {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr);
  align-items: center;
  gap: 8px;
  min-width: 170px;
  padding: 7px 10px;
  border: 1px solid rgba(224,189,115,.2);
  border-radius: 12px;
  background: rgba(224,189,115,.06);
}
.battle-party-member img { width: 44px; height: 50px; }
.battle-party-member strong { display: block; font-size: 11px; }
.battle-party-member small { display: block; margin-top: 2px; color: var(--muted); font-size: 9px; }
.battle-log .support { color: #9fe5c2; font-weight: 700; }

@media (max-width: 900px) {
  .campaign-stage-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .companion-roster { grid-template-columns: 1fr; }
}

@media (max-width: 520px) {
  .campaign-stage-list { grid-template-columns: 1fr; }
  .formation-slots { grid-template-columns: 1fr; }
  .battle-party-strip { overflow-x: auto; padding-bottom: 4px; }
  .battle-party-member { flex: 0 0 168px; }
}


/* Step 06.1: visual upgrade bằng tài nguyên legacy (UNVERIFIED, nội bộ) */
.path-icon {
  width: 54px;
  height: 62px;
  overflow: hidden;
  border: 1px solid rgba(242, 214, 152, .28);
  border-radius: 12px;
  background: rgba(0,0,0,.28);
  box-shadow: 0 8px 18px rgba(0,0,0,.28);
}
.path-icon img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.summary-seal,
.world-seal {
  overflow: hidden;
  padding: 0;
  background: rgba(0,0,0,.3);
}
.summary-seal img,
.world-seal img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.location-art {
  height: 132px;
  background: #0a0d13;
}
.location-art > img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: 50% 42%;
  filter: saturate(.88) contrast(1.05) brightness(.78);
  transform: scale(1.025);
}
.location-mist {
  position: absolute;
  inset: 0;
  background:
    linear-gradient(180deg, rgba(4,8,12,.05), rgba(7,10,16,.72)),
    radial-gradient(circle at 78% 22%, rgba(242,214,152,.22), transparent 22%);
}
.location-art::after {
  height: 42px;
}
.campaign-stage {
  overflow: hidden;
  min-height: 194px;
  padding-top: 92px;
  isolation: isolate;
}
.campaign-stage-thumb {
  position: absolute;
  z-index: -2;
  inset: 0 0 auto;
  width: 100%;
  height: 86px;
  object-fit: cover;
  filter: saturate(.82) brightness(.68) contrast(1.08);
}
.campaign-stage::before {
  content: "";
  position: absolute;
  z-index: -1;
  inset: 0;
  background: linear-gradient(180deg, rgba(4,7,11,.05) 0, rgba(8,11,18,.92) 47%, rgba(8,11,18,.98) 100%);
}
.campaign-stage.is-cleared .campaign-stage-thumb {
  filter: saturate(.7) brightness(.62) sepia(.18);
}
.campaign-enemy-portrait {
  position: absolute;
  top: 33px;
  right: 9px;
  z-index: 2;
  width: 60px;
  height: 60px;
  object-fit: contain;
  filter: drop-shadow(0 8px 12px rgba(0,0,0,.55));
}
.item-icon {
  overflow: hidden;
  padding: 0;
  background: rgba(0,0,0,.32);
}
.item-icon img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.companion-avatar,
.formation-slot img,
.battle-party-member img {
  object-fit: cover;
  object-position: center top;
  background: rgba(0,0,0,.28);
}
.battle-panel {
  background:
    linear-gradient(180deg, rgba(14,16,22,.98), rgba(5,7,11,.99)),
    radial-gradient(circle at 50% 0, rgba(176,67,55,.12), transparent 34%);
}
.battle-arena {
  position: relative;
  isolation: isolate;
  overflow: hidden;
  min-height: 430px;
  background: #090b0f;
  border-color: rgba(224,189,115,.24);
}
.battle-backdrop {
  position: absolute;
  z-index: -4;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
  filter: saturate(.92) contrast(1.08) brightness(.62);
  transform: scale(1.02);
}
.battle-vignette {
  position: absolute;
  z-index: -3;
  inset: 0;
  background:
    linear-gradient(180deg, rgba(3,5,8,.12), rgba(3,5,8,.48)),
    radial-gradient(circle at 50% 56%, transparent 26%, rgba(2,4,7,.58) 88%);
  pointer-events: none;
}
.battle-arena::before,
.battle-arena::after {
  z-index: -2;
  opacity: .5;
}
.fighter-sprite {
  overflow: visible;
  width: clamp(180px, 28vw, 290px);
  height: clamp(220px, 32vw, 320px);
  border: 0;
  border-radius: 0;
  background: transparent !important;
  box-shadow: none;
}
.fighter-sprite::after {
  content: "";
  position: absolute;
  z-index: -1;
  left: 50%;
  bottom: 9%;
  width: 62%;
  height: 15%;
  border-radius: 50%;
  background: radial-gradient(ellipse, rgba(0,0,0,.55), transparent 72%);
  transform: translateX(-50%);
  filter: blur(4px);
}
.fighter-sprite img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: center bottom;
  border-radius: 0;
  image-rendering: auto;
  filter: drop-shadow(0 18px 20px rgba(0,0,0,.52));
  animation: sprite-breathe 1.8s ease-in-out infinite alternate;
}
.fighter-sprite img[data-scale="small"] {
  transform: scale(1.5);
}
.enemy-sprite img {
  transform: scaleX(-1);
}
.enemy-sprite img[data-scale="small"] {
  transform: scaleX(-1) scale(1.5);
}
@keyframes sprite-breathe {
  from { translate: 0 0; }
  to { translate: 0 -5px; }
}
.battle-combatant.is-attacking .fighter-sprite img {
  animation: none;
}
.battle-combatant.is-hit .fighter-sprite img {
  animation: sprite-flash .28s ease;
}
@keyframes sprite-flash {
  20% { filter: brightness(2.1) saturate(.5) drop-shadow(0 0 16px #fff); }
  70% { filter: brightness(.72) sepia(.6) hue-rotate(-30deg); }
}
.battle-effect-sprite {
  position: absolute;
  z-index: 8;
  left: 50%;
  top: 54%;
  width: min(36vw, 260px);
  height: min(36vw, 260px);
  object-fit: contain;
  pointer-events: none;
  transform: translate(-50%, -50%);
  filter: drop-shadow(0 0 22px rgba(255,194,100,.8));
}
.battle-effect-sprite.is-player-target { left: 25%; }
.battle-effect-sprite.is-enemy-target { left: 75%; }
.battle-action-button {
  position: relative;
  display: grid;
  grid-template-columns: 46px minmax(0,1fr);
  column-gap: 10px;
  align-items: center;
  padding-left: 10px;
}
.battle-action-icon {
  grid-row: 1 / span 2;
  width: 46px;
  height: 46px;
  border: 1px solid rgba(242,214,152,.2);
  border-radius: 10px;
  object-fit: cover;
  box-shadow: 0 6px 14px rgba(0,0,0,.25);
}
.asset-status-pill {
  display: inline-flex;
  margin-left: auto;
  padding: 4px 8px;
  border: 1px solid rgba(232,143,143,.22);
  border-radius: 999px;
  color: #d8a3a3;
  background: rgba(232,143,143,.06);
  font-size: 9px;
  letter-spacing: .04em;
}
.world-footer {
  gap: 10px;
  flex-wrap: wrap;
}
@media (max-width: 760px) {
  .battle-arena { min-height: 340px; }
  .fighter-sprite { width: min(40vw, 180px); height: min(52vw, 220px); }
  .fighter-sprite img[data-scale="small"] { transform: scale(1.42); }
  .enemy-sprite img[data-scale="small"] { transform: scaleX(-1) scale(1.42); }
  .campaign-stage { min-height: 184px; }
}
