:root {
  --ink: #f5efdc;
  --ink-soft: rgba(245, 239, 220, .74);
  --ink-mute: rgba(245, 239, 220, .52);
  --glass: rgba(12, 30, 26, .58);
  --glass-strong: rgba(9, 24, 20, .88);
  --line: rgba(245, 239, 220, .16);
  --gold: #e8c77a;
  --gold-deep: #c9a24e;
  --leaf: #9fbf86;
  --warn: #f0a98a;
  --serif: 'Cormorant Garamond', Georgia, serif;
  --sans: 'Be Vietnam Pro', system-ui, -apple-system, 'Segoe UI', sans-serif;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; overflow: hidden; background: #0d2622; color: var(--ink);
  font-family: var(--sans); -webkit-font-smoothing: antialiased;
  -webkit-user-select: none; user-select: none; -webkit-tap-highlight-color: transparent;
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
kbd {
  display: inline-block; min-width: 1.6em; padding: 1px 6px; margin: 0 2px;
  border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 6px;
  font: 500 12px var(--sans); text-align: center; background: rgba(245,239,220,.06);
}
body.is-touch .desk { display: none !important; }
body:not(.is-touch) .touch { display: none !important; }

#world { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; outline: none; }

/* ---------- Màn tải & lời mời ---------- */
.screen { position: fixed; inset: 0; z-index: 30; display: grid; place-items: center; padding: 16px; }
#loading { background: radial-gradient(ellipse at 50% 40%, #1d3b33, #08130f 75%); }
#intro { background: rgba(5, 14, 12, .35); backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px); }
.loading-box { width: min(320px, 80vw); text-align: center; }
.brand-big { font-family: var(--serif); font-weight: 600; font-size: clamp(38px, 7vw, 54px); letter-spacing: .02em; }
.bar { height: 3px; margin: 18px 0 12px; background: rgba(245,239,220,.14); border-radius: 3px; overflow: hidden; }
.bar-fill { height: 100%; width: 0; background: linear-gradient(90deg, var(--leaf), var(--gold)); transition: width .25s ease; }
.loading-text { font-size: 14px; color: var(--ink-soft); }

.card {
  width: min(460px, 100%); padding: 30px 26px 24px; text-align: center;
  background: var(--glass-strong); border: 1px solid var(--line); border-radius: 24px;
  box-shadow: 0 24px 70px rgba(0, 0, 0, .45);
}
.intro-card p { color: var(--ink-soft); line-height: 1.6; margin: 10px 0 14px; font-size: 15px; }
.intro-card strong { color: var(--gold); font-weight: 600; }
.howto { list-style: none; padding: 0; margin: 0 0 20px; display: grid; gap: 8px; font-size: 14px; color: var(--ink-soft); }
.link-btn { margin-top: 12px; border: 0; background: none; color: var(--ink-mute); font-size: 13px; text-decoration: underline; text-underline-offset: 3px; }
.link-btn:hover { color: var(--ink); }

/* ---------- Thanh trên ---------- */
.topbar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  padding: max(14px, env(safe-area-inset-top)) 18px 10px; pointer-events: none;
}
.topbar > * { pointer-events: auto; }
body[data-mode="loading"] .topbar, body[data-mode="intro"] .topbar { opacity: 0; pointer-events: none; }
.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark { width: 24px; height: 24px; border-radius: 50%; background: radial-gradient(circle at 40% 35%, #fff4cf, var(--gold) 55%, var(--gold-deep)); box-shadow: 0 0 18px rgba(232,199,122,.55); }
.brand-name { font-family: var(--serif); font-size: 24px; font-weight: 600; text-shadow: 0 2px 12px rgba(0,0,0,.5); }
.top-actions { display: flex; gap: 8px; }
.icon-btn {
  display: inline-flex; align-items: center; gap: 8px; min-height: 40px; padding: 0 14px;
  border: 1px solid var(--line); border-radius: 999px; background: var(--glass);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); font-size: 14px;
}
.icon-btn:hover { background: rgba(20, 48, 40, .8); }
.icon-btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn.round { width: 40px; padding: 0; justify-content: center; }

/* ---------- Đồng hồ ---------- */
.timer { position: fixed; left: 50%; top: max(64px, 5vh); transform: translateX(-50%); z-index: 5; text-align: center; opacity: 0; pointer-events: none; transition: opacity .8s; }
body[data-session="running"] .timer, body[data-session="away"] .timer, body[data-session="moving"] .timer { opacity: 1; }
body[data-session="moving"] .timer-value { opacity: .55; }
.timer-label { font-size: 12px; letter-spacing: .18em; text-transform: uppercase; color: var(--ink-soft); text-shadow: 0 1px 8px rgba(0,0,0,.6); }
.timer-value { font-weight: 200; font-size: clamp(40px, 7vw, 68px); line-height: 1; margin-top: 6px; font-variant-numeric: tabular-nums; text-shadow: 0 4px 30px rgba(0,0,0,.55); }
.goal-track { width: min(240px, 60vw); height: 4px; margin: 14px auto 8px; background: rgba(245,239,220,.2); border-radius: 4px; overflow: hidden; }
.goal-fill { height: 100%; width: 0; background: linear-gradient(90deg, var(--leaf), var(--gold)); transition: width .3s linear; }
.goal-text { font-size: 14px; color: var(--ink-soft); text-shadow: 0 1px 8px rgba(0,0,0,.6); }
body.goal-hit .timer-value { color: #fff3cf; }

/* ---------- Gợi ý / nút ngồi ---------- */
.hint {
  position: fixed; left: 50%; bottom: calc(max(20px, env(safe-area-inset-bottom)) + 4px); transform: translateX(-50%);
  z-index: 5; padding: 8px 16px; border-radius: 999px; font-size: 13px; color: var(--ink-soft);
  background: var(--glass); border: 1px solid var(--line); white-space: nowrap; transition: opacity .5s;
}
body:not([data-mode="walk"]) .hint { opacity: 0; pointer-events: none; }
.sit-btn {
  position: fixed; left: 50%; bottom: calc(max(20px, env(safe-area-inset-bottom)) + 52px); transform: translateX(-50%);
  z-index: 6; min-height: 52px; padding: 0 26px; border: 0; border-radius: 999px;
  background: linear-gradient(180deg, #f3d892, var(--gold-deep)); color: #1c2a1f; font-weight: 600; font-size: 16px;
  box-shadow: 0 8px 30px rgba(232,199,122,.45); animation: pop .25s ease;
}
.sit-btn kbd { border-color: rgba(28,42,31,.3); background: rgba(255,255,255,.25); color: #1c2a1f; }
@keyframes pop { from { transform: translate(-50%, 10px); opacity: 0; } }
.session-bar { position: fixed; left: 50%; bottom: max(22px, env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 5; display: flex; gap: 10px; opacity: 0; pointer-events: none; transition: opacity .8s .3s; }
body[data-session="running"] .session-bar { opacity: .6; pointer-events: auto; }
body[data-session="running"] .session-bar:hover { opacity: 1; }
body[data-session="moving"] .session-bar { opacity: .9; pointer-events: auto; bottom: calc(max(20px, env(safe-area-inset-bottom)) + 112px); }
body[data-session="moving"] #btn-move { display: none; }
body[data-session="moving"] .hint { color: #fff0c4; border-color: rgba(232,199,122,.5); }
.text-input { width: 100%; min-height: 42px; padding: 0 14px; border-radius: 12px; border: 1px solid var(--line); background: rgba(245,239,220,.06); font-size: 15px; outline: none; -webkit-user-select: text; user-select: text; }
.text-input:focus { border-color: var(--gold); }
.ghost-btn { min-height: 42px; padding: 0 20px; white-space: nowrap; border-radius: 999px; border: 1px solid var(--line); background: var(--glass); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); font-size: 14px; }
.ghost-btn:hover { border-color: rgba(245,239,220,.35); }
.ghost-btn.danger:hover { border-color: var(--warn); color: #ffd9c9; }
.btn-primary { width: 100%; min-height: 52px; border: 0; border-radius: 999px; background: linear-gradient(180deg, #f3d892, var(--gold-deep)); color: #1c2a1f; font-weight: 600; font-size: 16px; box-shadow: 0 8px 26px rgba(232,199,122,.35); }
.btn-primary:hover { filter: brightness(1.05); }
:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }

/* ---------- Cần gạt ---------- */
.joystick { position: fixed; left: 28px; bottom: calc(max(28px, env(safe-area-inset-bottom)) + 10px); z-index: 6; width: 120px; height: 120px; border-radius: 50%; border: 1px solid var(--line); background: rgba(12,30,26,.35); display: none; pointer-events: none; }
body.is-touch[data-mode="walk"] .joystick { display: block; }
.knob { position: absolute; left: 50%; top: 50%; width: 52px; height: 52px; margin: -26px 0 0 -26px; border-radius: 50%; background: rgba(245,239,220,.35); border: 1px solid rgba(245,239,220,.5); }

/* ---------- Ngăn kéo ---------- */
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 20; width: min(400px, 100vw);
  padding: max(16px, env(safe-area-inset-top)) 22px 22px; overflow-y: auto;
  background: var(--glass-strong); border-left: 1px solid var(--line);
  backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px);
  transform: translateX(100%); transition: transform .26s ease; -webkit-user-select: text; user-select: text;
}
.drawer.open { transform: none; }
.drawer-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.drawer-head h2 { margin: 0; font-family: var(--serif); font-weight: 600; font-size: 28px; }
.drawer h3 { font-size: 13px; font-weight: 500; letter-spacing: .04em; color: var(--ink-soft); margin: 22px 0 10px; }
.muted { color: var(--ink-mute); font-weight: 400; }
.small { font-size: 12px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { min-height: 38px; padding: 0 14px; display: inline-flex; align-items: center; gap: 6px; border-radius: 999px; border: 1px solid var(--line); background: rgba(245,239,220,.06); font-size: 14px; white-space: nowrap; }
.chip:hover { background: rgba(245,239,220,.12); }
.chip.on { background: rgba(232,199,122,.2); border-color: var(--gold); color: #fff3cf; }
.chip-input { cursor: text; }
.chip-input input { width: 46px; border: 0; background: transparent; outline: none; padding: 0; font-size: 14px; text-align: right; -moz-appearance: textfield; }
.chip-input input::-webkit-outer-spin-button, .chip-input input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.chip-input input::placeholder, .chip-input span { color: var(--ink-mute); }
.volume { display: flex; align-items: center; gap: 12px; margin-top: 14px; font-size: 13px; color: var(--ink-soft); }
.volume input { flex: 1; accent-color: var(--gold); }
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 10px; }
.stat { padding: 14px; border: 1px solid var(--line); border-radius: 14px; background: rgba(245,239,220,.04); }
.stat-k { font-size: 12px; color: var(--ink-mute); }
.stat-v { font-size: 24px; font-weight: 500; margin-top: 2px; font-variant-numeric: tabular-nums; }
.week { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; height: 140px; }
.day { display: flex; flex-direction: column; align-items: center; gap: 4px; min-width: 0; }
.bar-wrap { flex: 1; width: 100%; display: flex; align-items: flex-end; justify-content: center; }
.week .bar { width: 70%; max-width: 26px; height: auto; margin: 0; border-radius: 6px 6px 3px 3px; background: linear-gradient(180deg, var(--gold), rgba(159,191,134,.7)); }
.day-v { font-size: 10px; color: var(--ink-soft); height: 13px; }
.day-n { font-size: 12px; color: var(--ink-mute); }
.day.today .day-n { color: var(--gold); font-weight: 600; }
.sessions { list-style: none; margin: 0 0 14px; padding: 0; }
.sessions li { padding: 12px 0; border-bottom: 1px solid var(--line); }
.sessions li.empty { color: var(--ink-soft); border: 0; }
.s-main { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.s-time { font-weight: 600; }
.s-when { font-size: 12px; color: var(--ink-mute); white-space: nowrap; }
.s-tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.tag { font-size: 11px; padding: 2px 8px; border-radius: 999px; border: 1px solid var(--line); color: var(--ink-soft); }
.tag.ok { border-color: rgba(159,191,134,.6); color: #cfe6bd; }
.tag.warn { border-color: rgba(240,169,138,.55); color: #ffd2bf; }
.tag.gold { border-color: var(--gold); color: #fff0c4; }

/* ---------- Lớp phủ ---------- */
.overlay { position: fixed; inset: 0; z-index: 25; display: grid; place-items: center; padding: 16px; background: rgba(5,14,12,.5); backdrop-filter: blur(5px); -webkit-backdrop-filter: blur(5px); animation: fade .3s ease; }
@keyframes fade { from { opacity: 0; } }
#away { --p: 1; }
.away-box { text-align: center; }
.away-box p { margin: 6px 0; font-size: 17px; }
.away-ring { width: 120px; height: 120px; margin: 0 auto 18px; position: relative; }
.away-ring::before { content: ''; position: absolute; inset: 0; border-radius: 50%; background: conic-gradient(var(--gold) calc(var(--p) * 360deg), rgba(245,239,220,.14) 0); -webkit-mask: radial-gradient(circle, transparent 54px, #000 55px); mask: radial-gradient(circle, transparent 54px, #000 55px); }
.away-ring span { position: absolute; inset: 0; display: grid; place-items: center; font-size: 46px; font-weight: 300; }
.result-badge { display: inline-block; margin-bottom: 12px; padding: 5px 12px; border-radius: 999px; background: rgba(232,199,122,.2); color: #fff0c4; font-size: 12px; font-weight: 600; letter-spacing: .12em; text-transform: uppercase; }
.result-kicker { margin: 0 0 10px; font-size: 14px; color: var(--ink-soft); }
.result-card h2 { margin: 0; font-family: var(--serif); font-weight: 500; font-size: 24px; color: var(--ink-soft); }
.result-time { font-weight: 300; font-size: clamp(40px, 9vw, 56px); margin: 4px 0 8px; color: #fff3cf; }
.result-goal { margin: 0 0 20px; color: var(--ink-soft); font-size: 15px; min-height: 1em; }
.result-actions { display: grid; gap: 10px; }
.result-actions .ghost-btn { min-height: 46px; }
.credits-card { text-align: left; -webkit-user-select: text; user-select: text; }
.credits-card h2 { font-family: var(--serif); font-weight: 600; font-size: 26px; margin: 0 0 10px; }
.credits-card ul { padding-left: 18px; margin: 0 0 18px; display: grid; gap: 10px; font-size: 14px; color: var(--ink-soft); line-height: 1.5; }
.credits-card a { color: var(--gold); }
.toast { position: fixed; left: 50%; top: 16px; transform: translate(-50%, -90px); padding: 10px 18px; border-radius: 999px; z-index: 40; background: var(--glass-strong); border: 1px solid var(--line); font-size: 14px; transition: transform .35s ease; pointer-events: none; max-width: calc(100vw - 32px); }
.toast.show { transform: translate(-50%, 0); }

@media (max-width: 560px) {
  .icon-btn span { display: none; }
  .icon-btn { width: 40px; padding: 0; justify-content: center; }
  .brand-name { font-size: 21px; }
  .timer { top: 62px; }
  .hint { font-size: 12px; }
  .joystick { width: 110px; height: 110px; left: 20px; }
}

/* ---------- Tên nhân vật ---------- */
.name-field { display: grid; gap: 8px; text-align: left; margin: 0 0 16px; font-size: 13px; color: var(--ink-soft); }
.name-field .text-input { font-size: 16px; min-height: 48px; text-align: center; }
.field-error { color: var(--warn); font-size: 13px; text-align: center; }
.nametag {
  position: fixed; left: 0; top: 0; z-index: 4; pointer-events: none; white-space: nowrap;
  padding: 3px 12px; border-radius: 999px; font-size: 13px; font-weight: 500;
  background: rgba(12,30,26,.55); border: 1px solid rgba(245,239,220,.22); color: #fff3cf;
  text-shadow: 0 1px 4px rgba(0,0,0,.5); will-change: transform;
}
body[data-mode="loading"] .nametag, body[data-mode="intro"] .nametag { display: none; }
