:root {
  --paper: #f3ead7;
  --paper-2: #e8dcc0;
  --ink: #2a2118;
  --ink-soft: #5a4a3a;
  --red: #9b2c22;
  --red-dark: #6e1d16;
  --gold: #b8892f;
  --jade: #3f7a5f;
  --blue: #2f5f8a;
  --line: #c9b68e;
  --shadow: 0 2px 10px rgba(42, 33, 24, .18);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--paper) radial-gradient(ellipse at top, #fbf5e6, var(--paper) 70%);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 16px;
}

#app { max-width: 960px; margin: 0 auto; padding: 0 16px 40px; }
.hidden { display: none !important; }

h1, h2, h3 { font-family: var(--font-title); margin: .4em 0; }
h2 { color: var(--red-dark); }

button, .btn {
  font: inherit;
  cursor: pointer;
  background: var(--paper-2);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 14px;
  transition: background .15s, transform .1s;
}
button:hover:not(:disabled) { background: #f9f1de; border-color: var(--gold); }
button:active:not(:disabled) { transform: translateY(1px); }
button:disabled { opacity: .45; cursor: not-allowed; }
button.primary { background: var(--red); color: #fff7e8; border-color: var(--red-dark); }
button.primary:hover:not(:disabled) { background: var(--red-dark); }

/* ---------- Thanh trên cùng ---------- */
#topbar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px;
  padding: 10px 0; border-bottom: 2px solid var(--line); margin-bottom: 16px;
}
#chapter-name { font-weight: 700; color: var(--red-dark); flex: 1; }
#gold { color: var(--gold); font-weight: 700; }
#topbar nav { display: flex; gap: 6px; }
#topbar nav button { padding: 6px 10px; font-size: 14px; }

/* ---------- Màn hình tựa đề ---------- */
.title-screen { text-align: center; padding: 12vh 0 0; }
.title-screen .seal {
  display: inline-grid; place-items: center; width: 96px; height: 96px;
  background: var(--red); color: #fff3df; font-size: 34px; border-radius: 10px;
  box-shadow: var(--shadow); transform: rotate(-4deg);
}
.title-screen h1 { font-size: clamp(36px, 8vw, 64px); margin-top: 20px; letter-spacing: 2px; }
.title-screen p { color: var(--ink-soft); font-style: italic; }
.title-screen .menu { display: flex; flex-direction: column; gap: 10px; width: 240px; margin: 32px auto 0; }

/* ---------- Chân dung ---------- */
.portrait {
  flex: none; display: grid; place-items: center;
  width: 64px; height: 64px; border-radius: 50%;
  color: #fff8ea; font-size: 30px; font-weight: 700;
  border: 3px solid var(--paper); box-shadow: 0 0 0 2px var(--line);
}
.portrait.sm { width: 48px; height: 48px; font-size: 20px; }
.portrait { position: relative; overflow: hidden; }
.portrait img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.dialogue .portrait, .hero-card .portrait { width: 96px; height: 96px; font-size: 42px; }

/* ---------- Hội thoại ---------- */
.dialogue {
  margin-top: 8vh; background: #fffaf0; border: 2px solid var(--line);
  border-radius: 12px; padding: 20px; box-shadow: var(--shadow);
  display: flex; gap: 16px; align-items: flex-start; cursor: pointer; min-height: 160px;
}
.dialogue .speaker { font-weight: 700; color: var(--red-dark); margin-bottom: 6px; }
.dialogue .text { line-height: 1.7; white-space: pre-line; }
.dialogue.narration { font-style: italic; color: var(--ink-soft); }
.dialogue .hint { font-size: 13px; color: var(--ink-soft); margin-top: 12px; }
.choices { display: flex; flex-direction: column; gap: 8px; margin-top: 16px; }
.scene-title { text-align: center; margin-top: 6vh; color: var(--ink-soft); }

/* ---------- Bản đồ ---------- */
.loc-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; }
.loc-card {
  text-align: left; padding: 14px; background: #fffaf0; border: 1px solid var(--line);
  border-radius: 10px; position: relative;
}
.loc-card .name { font-weight: 700; display: block; margin-bottom: 4px; }
.loc-card .desc { font-size: 13px; color: var(--ink-soft); }
.loc-card.current { border: 2px solid var(--red); }
.loc-card .badge {
  position: absolute; top: 8px; right: 8px; background: var(--red); color: #fff;
  font-size: 11px; padding: 2px 6px; border-radius: 10px;
}
.loc-panel {
  margin-top: 20px; padding: 16px; background: #fffaf0; border: 1px solid var(--line); border-radius: 10px;
}
.loc-panel .actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }

/* ---------- Đội hình ---------- */
.hero-card {
  background: #fffaf0; border: 1px solid var(--line); border-radius: 10px;
  padding: 14px; margin-bottom: 12px; display: flex; gap: 14px; flex-wrap: wrap;
}
.hero-card .info { flex: 1; min-width: 220px; }
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 4px 12px; font-size: 14px; }
.skill-list { list-style: none; padding: 0; margin: 8px 0 0; font-size: 14px; }
.skill-list li { padding: 4px 0; border-top: 1px dashed var(--line); }
.skill-list .cost { color: var(--blue); }
.inv { display: flex; flex-wrap: wrap; gap: 8px; }

/* ---------- Thanh máu / nội lực ---------- */
.bar { height: 8px; background: #d9ccb0; border-radius: 4px; overflow: hidden; margin: 3px 0; }
.bar > i { display: block; height: 100%; transition: width .3s; }
.bar.hp > i { background: var(--red); }
.bar.mp > i { background: var(--blue); }
.bar.xp > i { background: var(--gold); }
.bar-label { font-size: 12px; color: var(--ink-soft); }

/* ---------- Chiến đấu ---------- */
.battle { display: flex; flex-direction: column; gap: 14px; }


.log {
  height: 130px; overflow-y: auto; background: #fffaf0; border: 1px solid var(--line);
  border-radius: 8px; padding: 8px 12px; font-size: 14px; line-height: 1.6;
}
.log .crit { color: var(--red); font-weight: 700; }
.battle-actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; min-height: 44px; }
.skill-menu { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 8px; }
.skill-menu button { text-align: left; font-size: 14px; }
.skill-menu small { display: block; color: var(--ink-soft); font-size: 12px; }

/* ---------- Thông báo ---------- */
#toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(100px);
  background: var(--ink); color: var(--paper); padding: 10px 18px; border-radius: 8px;
  opacity: 0; transition: .3s; pointer-events: none; max-width: calc(100% - 32px);
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

@media (max-width: 520px) {
  .portrait { width: 52px; height: 52px; font-size: 24px; }
  .dialogue { flex-direction: column; }
}
