/* English City 3D — giao diện. Tầng: #game (canvas + lớp cảm ứng) < #ui (HUD, màn hình, thông báo). */
:root {
  --bg: #0f172a;
  --panel: rgba(15, 23, 42, 0.78);
  --panel-solid: #111c33;
  --line: rgba(148, 163, 184, 0.28);
  --text: #f1f5f9;
  --muted: #94a3b8;
  --accent: #38bdf8;
  --accent-2: #6366f1;
  --good: #34d399;
  --warn: #fbbf24;
  --bad: #f87171;
  --radius: 14px;
  --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);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--text); overscroll-behavior: none; }
body { -webkit-tap-highlight-color: transparent; -webkit-user-select: none; user-select: none; touch-action: none; }
input, select, textarea { -webkit-user-select: text; user-select: text; touch-action: auto; }
.hidden { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; }
kbd { display: inline-block; min-width: 1.6em; padding: 1px 6px; border-radius: 6px; background: #e2e8f0; color: #0f172a; font: 700 0.82em/1.5 ui-monospace, SFMono-Regular, Menlo, monospace; text-align: center; box-shadow: 0 2px 0 #94a3b8; }

#game { position: fixed; inset: 0; background: radial-gradient(ellipse at 50% 30%, #1e3a5f, #0f172a 70%); }
.game-canvas { position: absolute; inset: 0; width: 100% !important; height: 100% !important; display: block; outline: none; touch-action: none; }
#ui { position: fixed; inset: 0; pointer-events: none; z-index: 10; }
#ui > * { pointer-events: auto; }

/* ───────── Màn hình phủ ───────── */
.screen { position: absolute; inset: 0; display: grid; place-items: center; padding: calc(16px + var(--safe-t)) 16px calc(16px + var(--safe-b)); overflow: auto; z-index: 30; }
.auth-screen { background: radial-gradient(ellipse at 30% 20%, rgba(56, 189, 248, 0.25), transparent 55%), radial-gradient(ellipse at 80% 90%, rgba(99, 102, 241, 0.3), transparent 55%), var(--bg); }
.map-screen, .settings-screen { background: rgba(2, 6, 23, 0.6); backdrop-filter: blur(4px); }
.card { width: min(440px, 100%); background: var(--panel-solid); border: 1px solid var(--line); border-radius: 20px; padding: 26px; box-shadow: 0 24px 60px rgba(0, 0, 0, 0.45); }
.card h2 { margin: 0 0 6px; font-size: 1.35rem; }
.card h3 { margin: 20px 0 8px; font-size: 0.82rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }
.card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.card-head h2 { margin: 0; }
.sub, .hint, .muted { color: var(--muted); font-size: 0.86rem; }
.hint { margin: 14px 0 0; line-height: 1.45; }
.brand { display: flex; gap: 14px; align-items: center; margin-bottom: 20px; }
.brand-logo { font-size: 2.6rem; }
.brand h1 { margin: 0; font-size: 1.5rem; letter-spacing: -0.01em; }
.brand p { margin: 2px 0 0; color: var(--muted); font-size: 0.88rem; }
.tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; padding: 4px; background: rgba(148, 163, 184, 0.12); border-radius: 12px; margin-bottom: 16px; }
.tab { border: 0; background: transparent; padding: 9px; border-radius: 9px; font-weight: 600; color: var(--muted); }
.tab.active { background: #1e293b; color: var(--text); box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4); }
.field { display: block; margin-bottom: 14px; }
.field > span:first-child { display: block; margin-bottom: 6px; font-size: 0.82rem; font-weight: 600; color: #cbd5e1; }
.field input, .country-select { width: 100%; padding: 12px 14px; border-radius: 11px; border: 1px solid var(--line); background: #0b1324; color: var(--text); font: inherit; font-size: 16px; outline: none; }
.field input:focus, .country-select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.2); }
.field-status { min-height: 1.2em; margin-top: 5px; font-size: 0.8rem; color: var(--muted); }
.field-status.good { color: var(--good); }
.field-status.bad, .form-error { color: var(--bad); }
.form-error { min-height: 1.3em; font-size: 0.86rem; margin-bottom: 8px; }
.form-notice { padding: 10px 12px; margin-bottom: 14px; border-radius: 10px; background: rgba(251, 191, 36, 0.14); border: 1px solid rgba(251, 191, 36, 0.4); color: #fde68a; font-size: 0.86rem; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 12px 18px; border-radius: 12px; border: 0; font-weight: 700; }
.btn-primary { width: 100%; background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff; }
.btn-primary:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-danger { background: rgba(248, 113, 113, 0.16); color: #fecaca; border: 1px solid rgba(248, 113, 113, 0.4); padding: 8px 14px; }
.btn.loading::after { content: ""; width: 14px; height: 14px; border: 2px solid rgba(255, 255, 255, 0.5); border-top-color: #fff; border-radius: 50%; animation: spin 0.7s linear infinite; }
.link { background: none; border: 0; padding: 0; color: var(--accent); font-size: 0.85rem; text-decoration: underline; }
.logout-link { display: block; margin: 12px auto 0; color: var(--muted); }
.icon-btn { width: 34px; height: 34px; border-radius: 10px; border: 1px solid var(--line); background: transparent; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Onboarding: panel bên phải, cảnh 3D xem trước nhân vật phía sau */
.onboarding-screen { pointer-events: none !important; place-items: center end; padding-right: max(5vw, 16px); }
.onboarding-card { pointer-events: auto; width: min(400px, 100%); background: rgba(17, 28, 51, 0.92); backdrop-filter: blur(8px); }
.avatar-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.avatar-option { display: grid; gap: 3px; place-items: center; padding: 9px 4px; border-radius: 12px; border: 1.5px solid var(--line); background: #0b1324; font-size: 0.76rem; color: #cbd5e1; }
.avatar-option.active { border-color: var(--accent); background: rgba(56, 189, 248, 0.14); color: #fff; }
.avatar-emoji { width: 30px; height: 30px; display: grid; place-items: center; border-radius: 50%; background: linear-gradient(135deg, #38bdf8, #6366f1); font-weight: 800; color: #fff; }
.country-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 10px 12px; border-radius: 11px; background: #0b1324; border: 1px solid var(--line); }
.flag { font-size: 1.4rem; line-height: 1; }
.country-name { font-weight: 600; }
.country-source { color: var(--muted); font-size: 0.74rem; flex: 1; }
.country-select { margin-top: 8px; }

/* Chọn map */
.map-card { width: min(720px, 100%); }
.map-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; }
.map-option { display: grid; gap: 5px; text-align: left; padding: 16px; border-radius: 16px; border: 1.5px solid var(--line); background: linear-gradient(160deg, #16233f, #0b1324); transition: transform 0.12s, border-color 0.12s; }
.map-option:hover { transform: translateY(-2px); border-color: var(--accent); }
.map-option.current { border-color: var(--good); }
.map-icon { font-size: 2rem; }
.map-name { font-weight: 700; }
.map-blurb { color: var(--muted); font-size: 0.82rem; line-height: 1.35; }
.map-meta { margin-top: 4px; font-size: 0.74rem; color: var(--accent); font-weight: 600; }
.map-option.current .map-meta { color: var(--good); }

/* Cài đặt */
.settings-card { width: min(640px, 100%); max-height: 100%; overflow: auto; }
.account-row { display: flex; align-items: center; gap: 12px; padding: 12px; border-radius: 14px; background: #0b1324; border: 1px solid var(--line); }
.account-row > div:nth-child(2) { flex: 1; min-width: 0; }
.account-avatar { font-size: 1.9rem; }
.segmented { display: flex; gap: 4px; padding: 3px; border-radius: 10px; background: rgba(148, 163, 184, 0.14); }
.seg { flex: 1; padding: 6px 4px; border: 0; border-radius: 8px; background: transparent; font-size: 0.8rem; font-weight: 600; color: var(--muted); }
.seg.active { background: var(--accent); color: #06283d; }
.table-wrap { max-height: 220px; overflow: auto; border: 1px solid var(--line); border-radius: 12px; -webkit-user-select: text; user-select: text; touch-action: pan-y; }
.history { width: 100%; border-collapse: collapse; font-size: 0.8rem; }
.history th, .history td { padding: 8px 10px; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
.history th { position: sticky; top: 0; background: #16233f; color: var(--muted); font-weight: 600; }
.controls-help { display: grid; gap: 7px; font-size: 0.84rem; color: #cbd5e1; line-height: 1.7; }

/* Loading */
.loading-screen { background: radial-gradient(ellipse at 50% 35%, #1e3a5f, #0b1120 70%); z-index: 60; transition: opacity 0.35s; }
.loading-screen.fade-out { opacity: 0; pointer-events: none !important; }
.loading-box { width: min(380px, 86vw); text-align: center; }
.loading-icon { font-size: 3.2rem; animation: bob 1.6s ease-in-out infinite; }
.loading-title { margin: 10px 0 18px; font-size: 1.2rem; font-weight: 700; }
.loading-bar { height: 8px; border-radius: 99px; background: rgba(148, 163, 184, 0.2); overflow: hidden; }
.loading-bar-fill { height: 100%; width: 0; border-radius: 99px; background: linear-gradient(90deg, var(--accent), var(--accent-2)); transition: width 0.25s ease-out; }
.loading-label { margin-top: 10px; font-size: 0.85rem; color: var(--muted); min-height: 1.2em; }
.loading-tip { margin-top: 18px; font-size: 0.8rem; color: #64748b; }
@keyframes bob { 50% { transform: translateY(-8px); } }

/* Lớp phủ chặn */
.block-screen { background: rgba(2, 6, 23, 0.88); backdrop-filter: blur(6px); z-index: 80; }
.block-card { text-align: center; }
.block-icon { font-size: 3rem; margin-bottom: 8px; }
.block-card p { color: #cbd5e1; line-height: 1.5; margin: 8px 0 20px; }

/* Toast */
.toast-host { position: absolute; top: calc(14px + var(--safe-t)); left: 50%; transform: translateX(-50%); display: grid; gap: 8px; z-index: 70; pointer-events: none !important; width: min(92vw, 460px); }
.toast { padding: 11px 16px; border-radius: 12px; background: var(--panel-solid); border: 1px solid var(--line); box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4); font-size: 0.9rem; text-align: center; animation: toast-in 0.3s ease-out; }
.toast.success { border-color: rgba(52, 211, 153, 0.6); }
.toast.error { border-color: rgba(248, 113, 113, 0.7); }
.toast.out { opacity: 0; transform: translateY(-8px); transition: 0.3s; }
@keyframes toast-in { from { opacity: 0; transform: translateY(-10px); } }

/* ───────── HUD ───────── */
.hud { position: absolute; inset: 0; pointer-events: none !important; }
.hud > * { pointer-events: auto; }
.hud-top-left { position: absolute; top: calc(10px + var(--safe-t)); left: calc(10px + var(--safe-l)); display: flex; flex-direction: column; gap: 6px; align-items: flex-start; pointer-events: none; }
.hud-top-left > * { pointer-events: auto; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 5px 11px; border-radius: 99px; background: var(--panel); border: 1px solid var(--line); font-size: 0.82rem; font-weight: 600; backdrop-filter: blur(6px); max-width: 60vw; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chip-dim { font-weight: 500; color: #cbd5e1; }
.chip-online .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--good); box-shadow: 0 0 0 3px rgba(52, 211, 153, 0.25); }
.chip-online b { color: var(--good); font-variant-numeric: tabular-nums; }
.chip-online .sep { color: var(--muted); }
.hud-buttons { display: flex; gap: 6px; }
.hud-btn { padding: 7px 12px; border-radius: 11px; border: 1px solid var(--line); background: var(--panel); font-size: 0.82rem; font-weight: 600; backdrop-filter: blur(6px); }
.hud-btn:hover { border-color: var(--accent); }
.hud-top-right { position: absolute; top: calc(10px + var(--safe-t)); right: calc(10px + var(--safe-r)); }
.minimap { position: relative; border-radius: 50%; box-shadow: 0 6px 22px rgba(0, 0, 0, 0.45); cursor: pointer; line-height: 0; }
.minimap canvas { border-radius: 50%; }
.minimap-badge { position: absolute; right: 0; bottom: 0; padding: 2px 6px; border-radius: 8px; background: var(--panel-solid); border: 1px solid var(--line); font-size: 0.66rem; font-weight: 700; line-height: 1.4; }
.center-hint { position: absolute; left: 50%; top: 22%; transform: translateX(-50%); padding: 8px 14px; border-radius: 99px; background: var(--panel); border: 1px solid var(--line); font-size: 0.84rem; pointer-events: none; animation: pulse 2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.55; } }
.prompt { position: absolute; left: 50%; bottom: calc(22% + var(--safe-b)); transform: translateX(-50%); padding: 9px 16px; border-radius: 12px; background: var(--panel); border: 1px solid var(--accent); font-size: 0.92rem; font-weight: 600; pointer-events: none; white-space: nowrap; backdrop-filter: blur(6px); }

/* Hội thoại */
.dialogue { position: absolute; left: 50%; bottom: calc(26px + var(--safe-b)); transform: translateX(-50%); width: min(680px, 94vw); padding: 14px 18px; border-radius: 16px; background: rgba(15, 23, 42, 0.92); border: 1px solid var(--accent); box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5); cursor: pointer; z-index: 5; }
.dlg-head { display: flex; justify-content: space-between; font-size: 0.74rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }
.dlg-speaker { margin-top: 6px; font-weight: 800; font-size: 0.9rem; }
.dlg-speaker.npc { color: var(--warn); }
.dlg-speaker.you { color: var(--accent); }
.dlg-text { min-height: 2.8em; margin-top: 4px; font-size: 1.12rem; line-height: 1.4; }
.dlg-next { text-align: right; font-size: 0.76rem; color: var(--muted); opacity: 0.35; }
.dlg-next.ready { opacity: 1; color: var(--accent); animation: pulse 1.2s infinite; }

/* Bảng debug */
.debug { position: absolute; left: calc(10px + var(--safe-l)); bottom: calc(10px + var(--safe-b)); width: 268px; max-height: calc(100vh - 190px); display: flex; flex-direction: column; border-radius: 12px; background: rgba(2, 6, 23, 0.82); border: 1px solid var(--line); font: 11.5px/1.45 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; backdrop-filter: blur(6px); overflow: hidden; }
.dbg-head { display: flex; align-items: center; gap: 4px; width: 100%; padding: 7px 10px; border: 0; background: transparent; text-align: left; font: inherit; white-space: nowrap; overflow: hidden; }
.dbg-fps { font-size: 13px; min-width: 2ch; }
.dbg-fps.good { color: var(--good); } .dbg-fps.ok { color: var(--warn); } .dbg-fps.bad { color: var(--bad); }
.dbg-line { color: #cbd5e1; flex: 1; overflow: hidden; text-overflow: ellipsis; }
.dbg-caret { color: var(--muted); transition: transform 0.15s; }
.debug.open .dbg-caret { transform: rotate(180deg); }
.dbg-body { display: none; padding: 0 10px 10px; overflow: auto; touch-action: pan-y; }
.debug.open .dbg-body { display: block; }
.dbg-section { margin: 9px 0 4px; color: var(--accent); font-size: 10px; text-transform: uppercase; letter-spacing: 0.08em; }
.dbg-row { display: flex; justify-content: space-between; gap: 8px; }
.dbg-row .k { color: var(--muted); flex: none; }
.dbg-row .v { text-align: right; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dbg-buttons { display: flex; flex-wrap: wrap; gap: 4px; }
.dbg-btn { padding: 4px 7px; border-radius: 7px; border: 1px solid var(--line); background: rgba(148, 163, 184, 0.12); font: inherit; }
.dbg-btn:hover, .dbg-btn.on { border-color: var(--accent); color: var(--accent); }
.dbg-mem { margin: 6px 0 0; padding: 6px 8px; border-radius: 8px; background: rgba(148, 163, 184, 0.1); color: #cbd5e1; white-space: pre-wrap; font: inherit; font-size: 10.5px; }
.debug .segmented { margin-bottom: 4px; }
.debug .seg { font: inherit; padding: 4px 2px; }

/* ───────── Điều khiển cảm ứng ───────── */
.touch-layer { position: absolute; inset: 0; z-index: 5; touch-action: none; }
.touch-zone { position: absolute; top: 0; bottom: 0; touch-action: none; }
.touch-zone-move { left: 0; width: 45%; }
.touch-zone-look { right: 0; width: 55%; }
.stick-base { position: absolute; width: 124px; height: 124px; margin: -62px 0 0 -62px; left: calc(92px + var(--safe-l)); top: calc(100% - 118px - var(--safe-b)); border-radius: 50%; background: rgba(255, 255, 255, 0.1); border: 2px solid rgba(255, 255, 255, 0.3); pointer-events: none; opacity: 0.55; transition: opacity 0.15s; }
.stick-base.active { opacity: 1; }
.stick-knob { position: absolute; left: 50%; top: 50%; width: 54px; height: 54px; margin: -27px 0 0 -27px; border-radius: 50%; background: rgba(255, 255, 255, 0.82); box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35); }
.touch-buttons { position: absolute; right: calc(14px + var(--safe-r)); bottom: calc(18px + var(--safe-b)); width: 196px; height: 190px; pointer-events: none; }
.tbtn { position: absolute; width: 60px; height: 60px; border-radius: 50%; border: 2px solid rgba(255, 255, 255, 0.4); background: rgba(15, 23, 42, 0.5); color: #fff; font-size: 1.35rem; font-weight: 800; pointer-events: auto; touch-action: none; backdrop-filter: blur(4px); }
.tbtn.down { background: rgba(56, 189, 248, 0.6); transform: scale(0.93); }
.tbtn.on { background: rgba(52, 211, 153, 0.55); border-color: var(--good); }
.tbtn.hint { border-color: var(--warn); box-shadow: 0 0 0 4px rgba(251, 191, 36, 0.3); }
.tbtn-jump { right: 0; bottom: 0; width: 74px; height: 74px; font-size: 1.7rem; }
.tbtn-punch { right: 84px; bottom: 6px; }
.tbtn-kick { right: 62px; bottom: 76px; }
.tbtn-f { right: 0; bottom: 88px; width: 54px; height: 54px; font-size: 1.1rem; }
.tbtn-run { right: 136px; bottom: 74px; width: 50px; height: 50px; font-size: 1.1rem; }

/* ───────── Màn hình nhỏ ───────── */
@media (max-width: 720px), (max-height: 520px) {
  .debug { width: auto; max-width: 62vw; left: 50%; transform: translateX(-50%); bottom: auto; top: calc(8px + var(--safe-t)); max-height: 70vh; }
  .debug:not(.open) .dbg-line { display: none; }
  .hud-top-left { gap: 4px; }
  .chip { font-size: 0.72rem; padding: 4px 9px; }
  .chip-dim { display: none; }
  .hud-btn { padding: 6px 9px; font-size: 0.76rem; }
  .minimap { transform: scale(0.74); transform-origin: top right; }
  .prompt { bottom: calc(46% + var(--safe-b)); font-size: 0.82rem; }
  .dialogue { bottom: calc(8px + var(--safe-b)); padding: 10px 14px; }
  .dlg-text { font-size: 1rem; }
  .card { padding: 20px; }
}
@media (max-width: 720px) and (orientation: portrait) {
  .onboarding-screen { place-items: end center; padding: 0; }
  .onboarding-card { width: 100%; max-height: 62vh; overflow: auto; border-radius: 20px 20px 0 0; padding-bottom: calc(20px + var(--safe-b)); touch-action: pan-y; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

/* ═════════ Cốt truyện Oddville: tiền, nhiệm vụ, túi đồ ═════════ */
.story-ui { position: absolute; inset: 0; pointer-events: none !important; z-index: 12; }
.story-ui > * { pointer-events: auto; }
.story-money { position: absolute; top: calc(12px + var(--safe-t)); right: calc(200px + var(--safe-r)); padding: 6px 13px; border-radius: 99px; background: var(--panel); border: 1px solid rgba(250, 204, 21, 0.6); font-weight: 800; font-size: 0.95rem; color: #fde68a; backdrop-filter: blur(6px); font-variant-numeric: tabular-nums; }
.story-money.up { animation: money-up 0.7s; } .story-money.down { animation: money-down 0.7s; }
@keyframes money-up { 30% { transform: scale(1.18); color: #86efac; } } @keyframes money-down { 30% { transform: scale(1.18); color: #fca5a5; } }
.story-held { position: absolute; left: 50%; bottom: calc(13% + var(--safe-b)); transform: translateX(-50%); padding: 7px 14px; border-radius: 12px; background: var(--panel); border: 1px solid var(--line); font-size: 0.84rem; white-space: nowrap; pointer-events: none; }
.story-quests { position: absolute; top: calc(200px + var(--safe-t)); right: calc(10px + var(--safe-r)); width: 268px; border-radius: 14px; background: rgba(15, 23, 42, 0.8); border: 1px solid var(--line); backdrop-filter: blur(6px); overflow: hidden; }
.story-quests-head { width: 100%; padding: 8px 12px; border: 0; background: rgba(56, 189, 248, 0.14); text-align: left; font-weight: 700; font-size: 0.84rem; }
.story-quests.collapsed .story-quests-body { display: none; }
.story-quests-body { display: grid; gap: 2px; padding: 6px; max-height: 38vh; overflow: auto; }
.story-quest { display: grid; gap: 2px; text-align: left; padding: 7px 9px; border: 1px solid transparent; border-radius: 9px; background: transparent; font-size: 0.8rem; line-height: 1.35; color: #cbd5e1; }
.story-quest:hover { background: rgba(148, 163, 184, 0.14); }
.story-quest.tracked { border-color: rgba(250, 204, 21, 0.55); color: #fff; background: rgba(250, 204, 21, 0.08); }
.story-quest i { color: var(--muted); font-size: 0.74rem; }
.story-quest-step { font-size: 0.73rem; color: #fde68a; }
.story-quest-empty { padding: 10px; font-size: 0.8rem; color: var(--muted); }
.story-vocab { position: fixed; padding: 6px 10px; border-radius: 10px; background: #fff8eb; color: #5b3a1a; border: 2px solid #f59e0b; font-size: 0.82rem; pointer-events: none !important; box-shadow: 0 6px 18px rgba(0, 0, 0, 0.35); z-index: 3; }
.story-vocab .ipa { color: #a16207; font-size: 0.74rem; }
.story-bubbles { position: absolute; left: 50%; top: 30%; transform: translateX(-50%); display: grid; gap: 6px; justify-items: center; pointer-events: none !important; width: min(92vw, 560px); }
.story-bubble { padding: 8px 14px; border-radius: 14px; background: #fff8eb; color: #4a2f14; border: 2px solid #f0c98a; font-size: 0.9rem; box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3); animation: toast-in 0.25s; text-align: center; }
.story-bubble.out { opacity: 0; transition: 0.3s; }
.story-modal { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(2, 6, 23, 0.55); z-index: 40; padding: 16px; }
.story-card { width: min(460px, 100%); max-height: 92vh; overflow: auto; background: var(--panel-solid); border: 1px solid var(--line); border-radius: 18px; padding: 20px; box-shadow: 0 24px 60px rgba(0, 0, 0, 0.5); }
.story-card.inv { width: min(560px, 100%); } .story-card.map { width: auto; } .story-card.map canvas { border-radius: 12px; display: block; max-width: 100%; }
.story-card h3 { margin: 0 0 8px; font-size: 1.1rem; text-transform: none; letter-spacing: 0; color: var(--text); }
.story-card-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; } .story-card-head h3 { margin: 0; }
.story-note { color: var(--muted); font-size: 0.82rem; margin: 6px 0 10px; }
.story-options { display: grid; gap: 8px; }
.story-option { display: flex; justify-content: space-between; gap: 10px; align-items: center; padding: 12px 14px; border-radius: 12px; border: 1.5px solid var(--line); background: #0b1324; text-align: left; font-weight: 600; }
.story-option:hover:not(:disabled) { border-color: var(--accent); } .story-option:disabled { opacity: 0.4; cursor: not-allowed; }
.story-option small { color: #fde68a; font-weight: 500; }
.story-tips { display: grid; gap: 6px; margin: 10px 0; } .story-tip { padding: 8px 10px; border-radius: 10px; background: rgba(56, 189, 248, 0.12); font-size: 0.9rem; }
.story-tipvi { color: #fde68a; font-size: 0.86rem; }
.story-inv-body { display: grid; gap: 6px; margin: 10px 0; min-height: 120px; align-content: start; }
.story-inv-item { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 10px; background: #0b1324; border: 1px solid var(--line); font-size: 0.88rem; }
.story-inv-name { flex: 1; } .story-inv-name i { color: var(--warn); font-size: 0.76rem; } .story-inv-icon { font-size: 1.3rem; }
.story-inv-tabs { grid-template-columns: repeat(4, 1fr); } .story-inv-tabs .tab { font-size: 0.74rem; padding: 7px 2px; }
.story-banner { position: absolute; left: 50%; top: 34%; transform: translate(-50%, -50%); padding: 22px 34px; border-radius: 22px; background: linear-gradient(135deg, #fde68a, #f59e0b); color: #3b1d00; text-align: center; box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5); z-index: 50; animation: toast-in 0.4s; }
.story-banner.out { opacity: 0; transition: 0.5s; } .story-banner-title { font-size: 1.5rem; font-weight: 900; } .story-banner-sub { margin-top: 6px; font-size: 0.9rem; }

/* ═════════ Hội thoại (bible §5.1) — box bo tròn mềm, nền kem, chữ nâu, tag tên viên thuốc cam ═════════ */
.conv { position: absolute; left: 0; right: 0; bottom: 0; display: flex; gap: 14px; align-items: flex-end; padding: 0 16px calc(14px + var(--safe-b)); z-index: 20; pointer-events: none !important; }
.conv > * { pointer-events: auto; }
.conv-side { width: 270px; flex: none; display: grid; gap: 8px; }
.conv-goals { padding: 12px 14px; border-radius: 16px; background: rgba(15, 23, 42, 0.9); border: 1px solid var(--line); font-size: 0.82rem; display: grid; gap: 5px; }
.conv-goal-title { font-weight: 800; color: #fde68a; line-height: 1.35; }
.conv-goal { color: #cbd5e1; line-height: 1.35; } .conv-goal.done { color: #86efac; text-decoration: line-through; text-decoration-color: rgba(134, 239, 172, 0.5); }
.conv-stats { display: flex; gap: 8px; }
.conv-pill { flex: 1; padding: 7px 10px; border-radius: 12px; background: rgba(15, 23, 42, 0.9); border: 1px solid var(--line); font-weight: 800; text-align: center; font-variant-numeric: tabular-nums; }
.conv-pill.low { color: #fca5a5; border-color: #f87171; animation: pulse 1s infinite; }
.conv-progress { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-radius: 12px; background: rgba(15, 23, 42, 0.9); border: 1px solid var(--line); }
.conv-progress.up { animation: bar-up 0.5s; } .conv-progress.down { animation: bar-down 0.5s; }
@keyframes bar-up { 40% { box-shadow: 0 0 0 4px rgba(52, 211, 153, 0.5); } } @keyframes bar-down { 40% { box-shadow: 0 0 0 4px rgba(248, 113, 113, 0.55); } }
.conv-bar { position: relative; flex: 1; height: 12px; border-radius: 99px; background: rgba(148, 163, 184, 0.25); overflow: hidden; }
.conv-bar-zero { position: absolute; left: 33.33%; top: 0; bottom: 0; width: 2px; background: rgba(255, 255, 255, 0.7); z-index: 1; }
.conv-bar-fill { position: absolute; top: 0; bottom: 0; background: linear-gradient(90deg, #34d399, #a3e635); transition: left 0.35s, width 0.35s; }
.conv-bar-fill.neg { background: #ef4444; }
.conv-bar-label { width: 44px; text-align: right; font-weight: 800; font-size: 0.82rem; font-variant-numeric: tabular-nums; }
.conv-main { position: relative; flex: 1; min-width: 0; max-width: 820px; display: grid; gap: 8px; }
.conv-box { position: relative; padding: 26px 22px 18px; border-radius: 26px; background: #fff6e4; color: #5a3a1c; border: 3px solid #f2d6a2; box-shadow: 0 14px 40px rgba(0, 0, 0, 0.45); min-height: 112px; }
.conv-name { position: absolute; left: 22px; top: -16px; padding: 5px 18px; border-radius: 99px; background: #f59e0b; color: #fff; font-weight: 800; transform: rotate(-3deg); box-shadow: 0 4px 10px rgba(0, 0, 0, 0.25); }
.conv-row { display: flex; gap: 14px; align-items: flex-start; }
.conv-portrait { flex: none; width: 58px; height: 58px; display: grid; place-items: center; border-radius: 50%; background: #ffe2ae; font-size: 2rem; border: 3px solid #f2c078; }
.conv-portrait[data-mood="angry"] { background: #fecaca; border-color: #ef4444; } .conv-portrait[data-mood="happy"] { background: #bbf7d0; border-color: #22c55e; } .conv-portrait[data-mood="annoyed"] { background: #fed7aa; border-color: #f97316; }
.conv-text { flex: 1; font-size: 1.18rem; font-weight: 700; line-height: 1.4; min-height: 3em; -webkit-user-select: text; user-select: text; }
.conv-input { display: flex; gap: 8px; }
.conv-input input { flex: 1; min-width: 0; padding: 13px 16px; border-radius: 16px; border: 2px solid #f2d6a2; background: #fffdf8; color: #3b2a16; font: inherit; font-size: 16px; outline: none; }
.conv-input input:focus { border-color: #f59e0b; box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.3); }
.conv-btn { padding: 0 14px; border-radius: 14px; border: 2px solid #f2d6a2; background: #fff6e4; color: #5a3a1c; font-weight: 800; white-space: nowrap; }
.conv-btn:disabled { opacity: 0.4; } .conv-send { background: #f59e0b; border-color: #f59e0b; color: #fff; }
/* giọng nói là mặc định: nút micro to ở giữa, chữ nghe được hiện bên cạnh; ⌨️ chỉ là nút nhỏ */
.conv-input { align-items: stretch; min-height: 60px; }
.conv-voice { flex: 1; min-width: 0; display: flex; gap: 8px; align-items: stretch; }
.conv-heard { position: relative; flex: 1; min-width: 0; display: flex; align-items: center; gap: 8px; padding: 8px 14px; border-radius: 16px; border: 2px dashed #f2d6a2; background: rgba(255, 253, 248, 0.92); color: #7c5a36; font-weight: 700; font-size: 0.95rem; overflow: hidden; }
.conv-heard-text { flex: 1; min-width: 0; line-height: 1.3; }
.conv-heard[data-state="rec"] { border-color: #ef4444; border-style: solid; color: #3b2a16; }
.conv-heard[data-state="pending"] { border-color: #f59e0b; border-style: solid; color: #3b2a16; font-size: 1.02rem; }
.conv-heard[data-state="sent"] { color: #a8845a; font-style: italic; } .conv-heard[data-state="warn"] { color: #b45309; }
.conv-heard-actions { display: none; gap: 6px; flex: none; } .conv-heard[data-state="pending"] .conv-heard-actions { display: flex; }
.conv-chip { width: 34px; height: 34px; border-radius: 50%; border: 2px solid #f2d6a2; background: #fff6e4; color: #5a3a1c; font-weight: 800; } .conv-chip.go { background: #f59e0b; border-color: #f59e0b; color: #fff; }
.conv-heard-bar { position: absolute; left: 0; bottom: 0; height: 4px; width: 0; background: #f59e0b; }
.conv-heard.auto .conv-heard-bar { animation: heard-count 1.4s linear forwards; } @keyframes heard-count { from { width: 100%; } to { width: 0; } }
.conv-mic { flex: none; display: flex; align-items: center; gap: 8px; padding: 0 20px 0 14px; border-radius: 99px; border: 3px solid #fff; background: linear-gradient(180deg, #fb923c, #f59e0b); color: #fff; font-weight: 800; font-size: 1rem; box-shadow: 0 6px 18px rgba(245, 158, 11, 0.5); touch-action: none; -webkit-user-select: none; user-select: none; }
.conv-mic-icon { font-size: 1.6rem; } .conv-mic:active { transform: scale(0.97); }
.conv-mic.rec { background: linear-gradient(180deg, #f87171, #dc2626); box-shadow: 0 0 0 6px rgba(239, 68, 68, 0.3), 0 6px 18px rgba(220, 38, 38, 0.55); animation: pulse 0.9s infinite; }
.conv-mode, .conv-tts { flex: none; padding: 0 10px; opacity: 0.75; font-size: 1rem; } .conv-mode:hover, .conv-tts:hover { opacity: 1; }
.conv-text[data-note]::after { content: attr(data-note); display: block; margin-top: 6px; font-size: 0.8rem; font-weight: 700; color: #b45309; }
@media (max-width: 640px) { .conv-mic-label { display: none; } .conv-mic { padding: 0 16px; } .conv-heard { font-size: 0.85rem; } }
.conv-exit { position: absolute; right: 10px; top: -14px; z-index: 2; width: 30px; height: 30px; border-radius: 50%; border: 2px solid #f2d6a2; background: #fff6e4; color: #5a3a1c; font-weight: 800; }
.conv-hints, .conv-menu { padding: 10px 12px; border-radius: 16px; background: rgba(15, 23, 42, 0.94); border: 1px solid var(--accent); display: grid; gap: 6px; font-size: 0.86rem; }
.conv-menu { border-color: #f59e0b; max-height: 30vh; overflow: auto; justify-self: start; min-width: 260px; } .conv-menu-title { font-weight: 800; color: #fde68a; }
.conv-hint-line { text-align: left; padding: 7px 10px; border-radius: 10px; border: 1px solid var(--line); background: rgba(56, 189, 248, 0.1); font-size: 0.92rem; }
.conv-hint-line:hover { border-color: var(--accent); } .conv-hint-note { color: #fde68a; }
.conv-vocab { display: flex; flex-wrap: wrap; gap: 6px 14px; color: #cbd5e1; font-size: 0.8rem; } .conv-vocab b { color: #7dd3fc; }

/* ═════════ Thiên thần & Ác quỷ ═════════ */
.guide-dim { position: absolute; inset: 0; background: rgba(2, 6, 23, 0.5); z-index: 44; }
.guide-hole { position: fixed; border-radius: 14px; box-shadow: 0 0 0 9999px rgba(2, 6, 23, 0.72), 0 0 0 3px #fde047; z-index: 45; pointer-events: none !important; transition: all 0.25s; }
.guide-box, .guide-toast { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; align-items: center; padding: 22px 18px 14px; border-radius: 22px; background: #fff6e4; color: #5a3a1c; border: 3px solid #f2d6a2; box-shadow: 0 14px 40px rgba(0, 0, 0, 0.45); position: relative; }
.guide-box { position: absolute; left: 50%; bottom: calc(26% + var(--safe-b)); transform: translateX(-50%); width: min(640px, 92vw); z-index: 46; cursor: pointer; }
.guide-box.top { bottom: auto; top: calc(16% + var(--safe-t)); }
.guide-box::after { content: "E / bấm để tiếp ▸"; position: absolute; right: 16px; bottom: 6px; font-size: 0.68rem; color: #b08a5a; }
.guide-tag { position: absolute; left: 18px; top: -14px; padding: 4px 16px; border-radius: 99px; font-weight: 800; font-size: 0.86rem; transform: rotate(-3deg); box-shadow: 0 3px 8px rgba(0, 0, 0, 0.25); }
.angel .guide-tag { background: #fff; color: #7a5a12; border: 2px solid #facc15; } .devil .guide-tag { background: #dc2626; color: #fff; } .npc .guide-tag { background: #1d4ed8; color: #fff; } .narrator .guide-tag { display: none; }
.guide-face { width: 50px; height: 50px; display: grid; place-items: center; border-radius: 50%; font-size: 1.8rem; background: #ffe9c4; grid-row: span 2; }
.angel .guide-face { box-shadow: 0 0 0 3px #fde047; } .devil .guide-face { box-shadow: 0 0 0 3px #ef4444; background: #fecaca; }
.guide-main { font-size: 1.06rem; font-weight: 700; line-height: 1.35; } .guide-sub { font-size: 0.82rem; color: #9a7748; line-height: 1.3; }
.guide-lines { display: grid; gap: 2px; }
.guide-toasts { position: absolute; left: 50%; top: calc(70px + var(--safe-t)); transform: translateX(-50%); display: grid; gap: 18px; width: min(520px, 90vw); z-index: 47; pointer-events: none !important; }
.guide-toast { animation: toast-in 0.3s; padding: 18px 14px 10px; } .guide-toast .guide-main { font-size: 0.94rem; } .guide-toast .guide-face { width: 40px; height: 40px; font-size: 1.4rem; } .guide-toast.out { opacity: 0; transition: 0.35s; }
.guide-card { position: absolute; inset: 0; z-index: 70; display: grid; place-content: center; justify-items: center; gap: 14px; padding: 24px; text-align: center; background: radial-gradient(ellipse at 50% 30%, #2b4a7a, #0b1120 75%); cursor: pointer; }
.guide-card-art { font-size: 5.5rem; filter: drop-shadow(0 10px 24px rgba(0, 0, 0, 0.5)); animation: bob 2.4s ease-in-out infinite; }
.guide-card-title { font-size: 1.6rem; font-weight: 900; color: #fde68a; } .guide-card-vi { max-width: 680px; font-size: 1.12rem; line-height: 1.6; } .guide-card-en { max-width: 640px; font-size: 0.9rem; color: #94a3b8; line-height: 1.5; font-style: italic; }
.guide-card-next { margin-top: 10px; font-size: 0.8rem; color: var(--accent); animation: pulse 1.4s infinite; }
.guide-fade { position: absolute; inset: 0; z-index: 75; display: grid; place-items: center; background: #05070f; opacity: 0; transition: opacity 0.42s; padding: 24px; text-align: center; }
.guide-fade.on { opacity: 1; } .guide-fade-text { max-width: 640px; font-size: 1.2rem; line-height: 1.6; color: #e2e8f0; }

@media (max-width: 900px) {
  .conv { flex-direction: column; align-items: stretch; gap: 8px; padding: 0 8px calc(8px + var(--safe-b)); }
  .conv-side { width: auto; grid-template-columns: 1fr 1fr; } .conv-goals { grid-column: span 2; max-height: 22vh; overflow: auto; }
  .conv-text { font-size: 1rem; } .story-quests { width: 210px; top: calc(150px + var(--safe-t)); } .story-money { right: calc(150px + var(--safe-r)); }
}
