:root {
  color-scheme: light;
  --ink: #34305C;
  --ink-soft: #6B678F;
  --panel: rgba(255, 255, 255, .88);
  --line: rgba(52, 48, 92, .13);
  --chip: #F6F4FF;
  --accent: #FF6F91;
  --accent-ink: #fff;
  --mint: #4CC38A;
  --focus: #2F4BFF;
  --shadow: 0 10px 30px rgba(70, 60, 140, .18);
  --font-display: "Baloo 2", "Segoe UI", system-ui, sans-serif;
  --font-body: "Be Vietnam Pro", "Segoe UI", system-ui, -apple-system, sans-serif;
  --gl: max(14px, env(safe-area-inset-left, 0px));
  --gr: max(14px, env(safe-area-inset-right, 0px));
  --gb: max(14px, env(safe-area-inset-bottom, 0px));
  --gt: max(10px, env(safe-area-inset-top, 0px));
}
html { height: 100%; box-sizing: border-box; }
*, *::before, *::after { box-sizing: inherit; }
body {
  height: 100%; margin: 0; overflow: hidden; color: var(--ink);
  background: linear-gradient(180deg, #F6F3FF, #E3DEFA);
  font-family: var(--font-body); font-size: 14px; line-height: 1.4;
  -webkit-tap-highlight-color: transparent; overscroll-behavior: none;
  user-select: none; -webkit-user-select: none;
}
[hidden] { display: none !important; }
button { font: inherit; color: inherit; }
#stage { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; cursor: grab; outline: none; }
#stage:active { cursor: grabbing; }

.hud-top {
  position: fixed; z-index: 3; top: var(--gt); left: var(--gl); right: var(--gr);
  display: flex; flex-wrap: wrap; gap: 8px; align-items: center; pointer-events: none;
}
.chip {
  pointer-events: auto; background: var(--panel); border: 1px solid var(--line); border-radius: 999px;
  padding: 6px 14px; box-shadow: var(--shadow); font-weight: 600; display: flex; align-items: center; gap: 8px;
  -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
}
.chip.title { font-family: var(--font-display); font-size: 18px; font-weight: 700; color: var(--accent); padding: 3px 14px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--mint); box-shadow: 0 0 0 3px rgba(76, 195, 138, .25); }
.chip-btn { margin-left: auto; pointer-events: auto; }

.btn {
  appearance: none; border: 1px solid var(--line); background: var(--panel); border-radius: 999px;
  padding: 8px 16px; min-height: 40px; font-weight: 600; cursor: pointer; box-shadow: var(--shadow);
  transition: transform .1s, background .15s;
}
.btn:active { transform: scale(.96); }
.btn[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
button:focus-visible, .swatch:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

.stats-card {
  position: fixed; z-index: 2; top: calc(var(--gt) + 52px); left: var(--gl);
  width: 178px; background: var(--panel); border: 1px solid var(--line); border-radius: 18px;
  box-shadow: var(--shadow); padding: 8px 12px;
  -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
}
.stats-card ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 5px; }
.stats-card li { display: grid; grid-template-columns: 54px 1fr 24px; align-items: center; gap: 6px; font-size: 12px; font-weight: 500; }
.stats-card .bar { height: 8px; border-radius: 8px; background: #E4E0F7; overflow: hidden; }
.stats-card .bar i { display: block; height: 100%; width: 0; border-radius: 8px; background: var(--accent); transition: width .5s ease; }
.stats-card li.hot .bar i { background: var(--mint); }
.stats-card li.hot { color: #1f8a5b; font-weight: 600; }
.stats-card output { text-align: right; font-variant-numeric: tabular-nums; color: var(--ink-soft); }

.hint {
  position: fixed; z-index: 2; left: 50%; transform: translateX(-50%); bottom: calc(var(--gb) + 74px);
  margin: 0; max-width: calc(100% - 32px); text-align: center; font-size: 12px; color: var(--ink-soft);
  background: rgba(255, 255, 255, .6); border-radius: 999px; padding: 4px 12px; pointer-events: none;
}
.hint:empty { display: none; }
#toast {
  position: fixed; z-index: 6; left: 50%; top: calc(var(--gt) + 200px); transform: translate(-50%, -12px);
  background: var(--ink); color: #fff; padding: 8px 16px; border-radius: 999px; font-weight: 500; opacity: 0;
  pointer-events: none; transition: opacity .25s, transform .25s; max-width: calc(100% - 32px); text-align: center;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

.act {
  position: fixed; z-index: 4; left: 50%; transform: translateX(-50%); bottom: var(--gb);
  min-height: 52px; min-width: 190px; max-width: calc(100% - 200px); padding: 10px 26px; border-radius: 999px; border: 0;
  background: var(--accent); color: var(--accent-ink); font-family: var(--font-display); font-weight: 700; font-size: 20px;
  box-shadow: 0 8px 22px rgba(255, 111, 145, .45); cursor: pointer; animation: pop .35s ease;
}
.act.stop { background: var(--ink); box-shadow: 0 8px 22px rgba(52, 48, 92, .35); }
.act:disabled { background: #B9B5D6; box-shadow: none; cursor: default; }
.act kbd { font: inherit; font-size: 13px; opacity: .8; margin-left: 6px; background: rgba(255,255,255,.25); border-radius: 6px; padding: 1px 6px; }
@keyframes pop { from { transform: translateX(-50%) scale(.85); opacity: 0; } to { transform: translateX(-50%) scale(1); opacity: 1; } }

.joy {
  position: fixed; z-index: 4; left: calc(var(--gl) + 6px); bottom: calc(var(--gb) + 6px);
  width: 120px; height: 120px; border-radius: 50%; touch-action: none;
  background: rgba(255, 255, 255, .55); border: 2px solid rgba(52, 48, 92, .18); box-shadow: var(--shadow);
}
.joy .knob {
  position: absolute; left: 50%; top: 50%; width: 52px; height: 52px; margin: -26px 0 0 -26px; border-radius: 50%;
  background: var(--accent); box-shadow: 0 4px 10px rgba(255, 111, 145, .5); pointer-events: none;
}

#fx { position: fixed; inset: 0; z-index: 5; pointer-events: none; overflow: hidden; }
.fx {
  position: absolute; transform: translate(-50%, -50%); font-family: var(--font-display); font-weight: 700; font-size: 22px;
  color: #FF5C85; text-shadow: 0 2px 0 #fff, 0 0 8px #fff; white-space: nowrap; animation: floatup 1.3s ease-out forwards;
}
.fx.minus { color: #2FA372; }
@keyframes floatup { 0% { opacity: 0; margin-top: 8px; scale: .6; } 15% { opacity: 1; scale: 1.15; } 100% { opacity: 0; margin-top: -70px; scale: 1; } }

.sheet {
  position: fixed; z-index: 7; right: var(--gr); top: calc(var(--gt) + 52px); width: min(340px, calc(100% - 28px));
  max-height: calc(100% - var(--gt) - 70px); display: flex; flex-direction: column;
  background: var(--panel); border: 1px solid var(--line); border-radius: 22px; box-shadow: var(--shadow); overflow: hidden;
  -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
}
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px 6px; }
.sheet-head h2 { margin: 0; font-family: var(--font-display); font-size: 21px; }
.sheet-body { overflow-y: auto; padding: 4px 16px 16px; overscroll-behavior: contain; }
.group { margin-top: 12px; }
.group h3 { margin: 0 0 6px; font-family: var(--font-display); font-size: 13px; color: var(--ink-soft); font-weight: 600; }
.row { display: flex; flex-wrap: wrap; gap: 8px; }
.opt { box-shadow: none; padding: 6px 12px; min-height: 36px; font-size: 13px; background: var(--chip); }
.swatch {
  appearance: none; width: 34px; height: 34px; border-radius: 50%; padding: 0; cursor: pointer;
  border: 3px solid #fff; box-shadow: 0 0 0 1px var(--line), 0 2px 5px rgba(40, 50, 110, .15);
}
.swatch[aria-pressed="true"] { box-shadow: 0 0 0 3px var(--accent), 0 2px 5px rgba(40, 50, 110, .15); }
.reset { margin-top: 16px; width: 100%; box-shadow: none; background: var(--chip); }

.fallback { position: fixed; inset: 0; z-index: 9; display: flex; align-items: center; justify-content: center; padding: 24px; }
.fallback div { max-width: 420px; background: #fff; border-radius: 20px; padding: 22px; text-align: center; box-shadow: var(--shadow); }

/* ----- sức sống ----- */
.right-col { position: fixed; z-index: 2; top: calc(var(--gt) + 52px); right: var(--gr); display: flex; flex-direction: column; align-items: flex-end; gap: 8px; pointer-events: none; }
.right-col > * { pointer-events: auto; }
.vitals-card {
  position: relative; width: 204px; cursor: pointer;
  background: var(--panel); border: 1px solid var(--line); border-radius: 18px; box-shadow: var(--shadow); padding: 8px 12px;
  display: grid; gap: 5px; -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
}
.v-row { display: grid; grid-template-columns: 74px 1fr 24px; align-items: center; gap: 6px; font-size: 12px; font-weight: 500; }
.v-row .bar { height: 8px; border-radius: 8px; background: #E4E0F7; overflow: hidden; }
.v-row .bar i { display: block; height: 100%; width: 100%; border-radius: 8px; transition: width .4s ease, background .3s; }
.v-row.water .bar i { background: #5BB8FF; }
.v-row.energy .bar i { background: #FFC83D; }
.v-row.low { color: #D2542B; font-weight: 600; }
.v-row.low .bar i { background: #FF8A4C; animation: lowpulse 1.1s ease-in-out infinite; }
.v-row output { text-align: right; font-variant-numeric: tabular-nums; color: var(--ink-soft); }
.v-line { font-size: 12px; font-weight: 600; white-space: nowrap; }
.v-more { display: none; font-size: 11px; color: var(--ink-soft); line-height: 1.35; }
.vitals-card.open .v-more { display: block; }
.vitals-card:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
@keyframes lowpulse { 50% { opacity: .55; } }
.bubble {
  position: fixed; z-index: 4; transform: translate(-50%, -100%); font-size: 26px; pointer-events: none;
  filter: drop-shadow(0 2px 3px rgba(40, 50, 110, .25)); animation: bob 1s ease-in-out infinite;
}
@keyframes bob { 50% { margin-top: -6px; } }

/* ----- tạo nhân vật ----- */
.creator {
  position: fixed; inset: 0; z-index: 10; display: grid; grid-template-columns: minmax(0, 1fr) minmax(360px, 460px);
  background: linear-gradient(160deg, #FFF1F5 0%, #EFEAFF 55%, #DDF3EA 100%);
}
.cr-preview { position: relative; min-height: 0; }
.cr-preview canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: pan-y; cursor: grab; }
.cr-title { position: absolute; top: calc(var(--gt) + 6px); left: var(--gl); margin: 0; font-family: var(--font-display); font-size: 26px; color: var(--accent); pointer-events: none; }
.cr-tag {
  position: absolute; left: 50%; bottom: 14px; transform: translateX(-50%); margin: 0; max-width: calc(100% - 28px);
  background: var(--panel); border: 1px solid var(--line); border-radius: 999px; padding: 5px 14px; font-weight: 600; font-size: 13px;
  text-align: center; box-shadow: var(--shadow); pointer-events: none; border-radius: 18px; display: grid; gap: 1px;
}
.cr-tag strong { font-family: var(--font-display); font-size: 17px; line-height: 1.2; }
.cr-tag span { font-weight: 500; font-size: 12px; color: var(--ink-soft); }
.cr-panel {
  display: flex; flex-direction: column; min-height: 0; background: var(--panel); border-left: 1px solid var(--line);
  padding: var(--gt) var(--gr) var(--gb) 20px; -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
}
.cr-steps { display: flex; gap: 8px; justify-content: center; padding: 10px 0 4px; }
.cr-dot { width: 26px; height: 8px; border-radius: 8px; background: #DAD5F3; transition: background .2s; }
.cr-dot.done { background: #FFB5C8; }
.cr-dot.on { background: var(--accent); }
.cr-body { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 4px 4px 10px 0; }
.cr-head h2 { margin: 6px 0 0; font-family: var(--font-display); font-size: 24px; outline: none; }
.cr-head p { margin: 2px 0 6px; color: var(--ink-soft); }
.cr-hint { margin: -2px 0 6px; font-size: 12px; color: var(--ink-soft); }
.cr-note { margin: 12px 0 0; font-size: 12px; color: var(--ink-soft); background: var(--chip); border-radius: 12px; padding: 8px 12px; }
.cr-name {
  width: 100%; font: inherit; font-size: 18px; font-weight: 600; padding: 10px 14px; min-height: 46px; color: var(--ink);
  border: 2px solid var(--line); border-radius: 14px; background: #fff; outline: none;
}
.cr-name:focus { border-color: var(--accent); }
.cr-slider { display: grid; grid-template-columns: 82px 1fr 64px; align-items: center; gap: 10px; margin: 10px 0; font-weight: 600; }
.cr-slider output { text-align: right; font-variant-numeric: tabular-nums; color: var(--ink-soft); }
.cr-slider input[type="range"] { width: 100%; height: 32px; margin: 0; background: transparent; -webkit-appearance: none; appearance: none; --p: 50%; }
.cr-slider input[type="range"]::-webkit-slider-runnable-track { height: 10px; border-radius: 10px; background: linear-gradient(90deg, var(--accent) var(--p), #E4E0F7 var(--p)); }
.cr-slider input[type="range"]::-moz-range-track { height: 10px; border-radius: 10px; background: #E4E0F7; }
.cr-slider input[type="range"]::-moz-range-progress { height: 10px; border-radius: 10px; background: var(--accent); }
.cr-slider input[type="range"]::-webkit-slider-thumb { -webkit-appearance: none; width: 26px; height: 26px; margin-top: -8px; border-radius: 50%; background: #fff; border: 3px solid var(--accent); box-shadow: 0 2px 6px rgba(70, 60, 140, .3); }
.cr-slider input[type="range"]::-moz-range-thumb { width: 20px; height: 20px; border-radius: 50%; background: #fff; border: 3px solid var(--accent); }
.cr-slider input[type="range"]:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 8px; }
.cr-types { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.cr-type { display: flex; flex-direction: column; align-items: flex-start; gap: 1px; padding: 10px 12px; min-height: 58px; text-align: left; border-radius: 16px; }
.cr-type strong { font-family: var(--font-display); font-size: 16px; }
.cr-type small { font-size: 12px; opacity: .8; font-weight: 500; }
.cr-actions { display: flex; gap: 10px; padding-top: 10px; }
.cr-actions .btn { flex: 1; min-height: 48px; padding: 8px 10px; white-space: nowrap; }
.cr-actions .primary { flex: 1.6; background: var(--accent); color: #fff; border-color: var(--accent); font-family: var(--font-display); font-size: 17px; box-shadow: 0 8px 20px rgba(255, 111, 145, .4); }
.cr-skip { appearance: none; border: 0; background: none; color: var(--ink-soft); font-weight: 500; text-decoration: underline; padding: 10px; min-height: 40px; cursor: pointer; }
.redo { width: 100%; margin-top: 8px; background: var(--accent); color: #fff; border-color: var(--accent); box-shadow: none; }

@media (max-width: 760px) {
  .creator { grid-template-columns: 1fr; grid-template-rows: minmax(210px, 40%) minmax(0, 1fr); }
  .cr-title { font-size: 21px; }
  .cr-panel { border-left: 0; border-top: 1px solid var(--line); border-radius: 22px 22px 0 0; padding: 4px var(--gr) var(--gb) var(--gl); margin-top: -14px; z-index: 1; }
  .cr-tag { left: auto; right: var(--gr); bottom: auto; top: calc(var(--gt) + 4px); transform: none; max-width: 52%; text-align: right; padding: 5px 12px; }
  .cr-tag strong { font-size: 15px; }
  .cr-tag span { font-size: 11px; }
  .cr-slider { grid-template-columns: 74px 1fr 56px; }
  .cr-head h2 { font-size: 21px; }
}
@media (max-height: 560px) and (min-width: 761px) { .cr-panel { padding-top: 6px; } }

@media (max-width: 600px) {
  .hud-top { flex-wrap: nowrap; gap: 6px; }
  .chip { padding: 5px 10px; font-size: 12px; white-space: nowrap; }
  .chip.title { font-size: 16px; padding: 3px 10px; }
  .chip-btn { padding: 6px 12px; min-height: 34px; font-size: 13px; }
  .stats-card { width: 142px; padding: 6px 10px; }
  .stats-card li { grid-template-columns: 52px 1fr 22px; font-size: 11.5px; }
  .vitals-card { width: 164px; padding: 6px 10px; }
  .v-row { grid-template-columns: 62px 1fr 20px; font-size: 11px; gap: 4px; }
  .v-line { font-size: 11px; }
  .act { font-size: 18px; min-width: 0; max-width: calc(100% - 180px); left: auto; right: var(--gr); transform: none; bottom: calc(var(--gb) + 28px); animation: none; }
  .hint { bottom: calc(var(--gb) + 140px); }
  .sheet { right: 14px; left: 14px; width: auto; top: auto; bottom: 10px; max-height: 62%; }
}
@media (prefers-reduced-motion: reduce) { .act, .fx { animation-duration: .01s; } }

/* ----- bản đồ nhỏ, bản đồ lớn, dịch chuyển nhanh ----- */
.map-compact {
  appearance: none; position: relative; width: 204px; height: 112px; padding: 0; cursor: pointer; overflow: hidden;
  background: var(--panel); border: 1px solid var(--line); border-radius: 18px; box-shadow: var(--shadow);
  -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
}
.map-compact canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.mc-label { position: absolute; left: 8px; bottom: 5px; font-size: 11px; font-weight: 600; color: var(--ink-soft); background: rgba(255,255,255,.75); border-radius: 999px; padding: 1px 8px; pointer-events: none; }
.map-panel { position: fixed; inset: 0; z-index: 8; display: flex; align-items: center; justify-content: center; padding: 12px; background: rgba(52, 48, 92, .35); }
.map-card {
  width: min(660px, 100%); max-height: 100%; overflow-y: auto; border: 1px solid var(--line); border-radius: 22px; box-shadow: var(--shadow); padding: 4px 14px 14px;
  background: rgba(255,255,255,.96);
}
.map-hint { margin: 0 0 8px; font-size: 12px; color: var(--ink-soft); }
.map-stage { position: relative; width: 100%; aspect-ratio: 40 / 30; background: #EEEAFB; border-radius: 16px; overflow: hidden; }
.map-stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.map-btns { position: absolute; inset: 0; }
.map-zone {
  appearance: none; position: absolute; transform: translate(-50%, -50%); min-width: 44px; min-height: 44px; padding: 4px 10px; border-radius: 999px;
  background: rgba(255,255,255,.92); border: 2px solid rgba(52,48,92,.18); box-shadow: 0 3px 10px rgba(70,60,140,.22); cursor: pointer;
  display: flex; align-items: center; justify-content: center; gap: 4px; font-weight: 600; font-size: 12px; line-height: 1.1; white-space: nowrap;
}
.map-zone:hover { background: #fff; border-color: var(--accent); }
.map-zone.here { border-color: var(--accent); background: #FFE9EF; }
.map-zone .mz-ico { font-size: 18px; }
.map-zone.icon-only { padding: 4px; } .map-zone.icon-only .mz-name { display: none; }
.map-list { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.map-chip { min-height: 44px; }
.map-chip.here { background: #FFE9EF; border-color: var(--accent); }
.zone-sign {
  position: fixed; z-index: 4; left: 50%; top: calc(var(--gt) + 52px); transform: translate(-50%, -14px) scale(.92); opacity: 0; pointer-events: none;
  background: var(--accent); color: #fff; font-family: var(--font-display); font-weight: 700; font-size: 22px; padding: 6px 22px; border-radius: 999px;
  border: 3px dashed rgba(255,255,255,.85); box-shadow: 0 8px 22px rgba(255, 111, 145, .35); transition: opacity .3s, transform .3s; white-space: nowrap; max-width: calc(100% - 24px);
}
.zone-sign.show { opacity: 1; transform: translate(-50%, 0) scale(1); }

/* ----- bảng chọn bài và bảng thông tin ----- */
.picker, .info {
  position: fixed; z-index: 7; left: 50%; bottom: var(--gb); transform: translateX(-50%); width: min(420px, calc(100% - 24px)); max-height: calc(100% - var(--gt) - 90px);
  display: flex; flex-direction: column; background: rgba(255,255,255,.96); border: 1px solid var(--line); border-radius: 22px; box-shadow: var(--shadow); overflow: hidden;
}
.info { bottom: auto; top: 50%; transform: translate(-50%, -50%); }
.pk-head { display: flex; align-items: center; justify-content: space-between; padding: 10px 14px 6px; }
.pk-head h2 { margin: 0; font-family: var(--font-display); font-size: 20px; }
.pk-head .btn { min-height: 40px; box-shadow: none; }
.pk-list { list-style: none; margin: 0; padding: 0 10px 12px; overflow-y: auto; display: grid; gap: 6px; overscroll-behavior: contain; }
.pk-item {
  appearance: none; width: 100%; display: flex; align-items: center; gap: 12px; padding: 8px 12px; min-height: 56px; text-align: left; cursor: pointer;
  background: var(--chip); border: 2px solid transparent; border-radius: 16px;
}
.pk-item:hover, .pk-item:focus-visible { border-color: var(--accent); background: #fff; }
.pk-ico { font-size: 28px; width: 38px; text-align: center; flex: none; }
.pk-main { display: grid; gap: 3px; flex: 1; min-width: 0; }
.pk-main strong { font-family: var(--font-display); font-size: 17px; line-height: 1.15; }
.pk-stats { display: flex; flex-wrap: wrap; gap: 4px; }
.pk-chip { font-size: 11.5px; font-weight: 600; padding: 1px 9px; border-radius: 999px; background: #FFD6E1; color: #B2294F; }
.pk-chip.down { background: #CFF1E1; color: #1F7A53; }
.pk-note { font-size: 12px; color: var(--ink-soft); }
.pk-key { font: inherit; font-size: 12px; opacity: .6; background: #fff; border: 1px solid var(--line); border-radius: 6px; padding: 1px 7px; flex: none; }
.info-body { padding: 4px 16px 16px; overflow-y: auto; display: grid; gap: 8px; }
.info-row { display: grid; grid-template-columns: 78px 1fr 36px; align-items: center; gap: 8px; font-weight: 500; font-size: 13px; }
.info-row .bar { height: 9px; border-radius: 9px; background: #E4E0F7; overflow: hidden; }
.info-row .bar i { display: block; height: 100%; border-radius: 9px; background: var(--accent); }
.info-row output { text-align: right; font-variant-numeric: tabular-nums; color: var(--ink-soft); }
.info-big { font-family: var(--font-display); font-size: 26px; font-weight: 700; color: var(--accent); }
.info-line { font-size: 13px; color: var(--ink-soft); }
.rank-row { display: grid; grid-template-columns: 30px 1fr auto; gap: 8px; align-items: center; padding: 6px 10px; border-radius: 12px; background: var(--chip); font-weight: 500; }
.rank-row.you { background: #FFE0E8; font-weight: 700; outline: 2px solid var(--accent); }
.rank-row b { font-family: var(--font-display); font-size: 17px; text-align: center; }
.rank-row output { font-variant-numeric: tabular-nums; color: var(--ink-soft); }

@media (max-width: 600px) {
  .map-compact { width: 164px; height: 92px; border-radius: 14px; }
  .mc-label { font-size: 10px; padding: 0 6px; }
  .zone-sign { font-size: 18px; padding: 5px 16px; top: calc(var(--gt) + 250px); }
  .picker { bottom: 0; width: 100%; border-radius: 22px 22px 0 0; padding-bottom: var(--gb); }
  .map-zone { font-size: 11px; padding: 3px 7px; }
}
@media (max-height: 520px) {
  .map-compact { height: 74px; width: 140px; }
  .mc-label { display: none; }
}

/* ----- lớp aerobic: thẻ trạng thái, nút tắt nhạc, mini-game bấm theo nhịp ----- */
.class-hud {
  position: fixed; z-index: 4; left: 50%; transform: translateX(-50%); bottom: calc(var(--gb) + 74px); width: min(440px, calc(100% - 28px));
  padding: 8px 12px 10px; background: var(--panel); border: 1px solid var(--line); border-radius: 20px; box-shadow: var(--shadow);
  -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
}
.in-class .hint { display: none; }
.ch-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.ch-title { display: flex; align-items: center; gap: 6px; font-family: var(--font-display); font-size: 17px; min-width: 0; }
.ch-btns { display: flex; gap: 6px; flex: none; }
.ch-btn { min-height: 38px; padding: 4px 12px; font-size: 13px; box-shadow: none; background: var(--chip); }
.ch-mute { min-width: 44px; padding: 4px 8px; font-size: 17px; }
.ch-mute[aria-pressed="true"] { background: #FFD6E1; color: var(--ink); border-color: var(--line); }
.ch-sub { margin-top: 2px; font-size: 12px; color: var(--ink-soft); line-height: 1.3; }
.rhythm { margin-top: 6px; display: grid; gap: 6px; }
#rhCanvas { width: 100%; height: 50px; display: block; touch-action: manipulation; cursor: pointer; }
.rh-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 28px; }
.rh-judge { font-family: var(--font-display); font-weight: 700; font-size: 22px; min-width: 96px; line-height: 1; }
.rh-judge.perfect { color: #E08A00; } .rh-judge.good { color: #1F9D68; } .rh-judge.miss { color: #8F8BB5; }
.rh-judge.pop { animation: judgePop .45s ease-out both; }
@keyframes judgePop { 0% { transform: scale(.6); opacity: 0; } 35% { transform: scale(1.18); opacity: 1; } 100% { transform: scale(1); opacity: .9; } }
.rh-stat { display: flex; align-items: baseline; gap: 10px; font-size: 12px; font-weight: 600; color: var(--ink-soft); flex-wrap: wrap; justify-content: flex-end; }
.rh-stat b { color: #1F9D68; }
.rh-tap {
  appearance: none; border: 0; min-height: 52px; border-radius: 16px; background: var(--accent); color: #fff; font-family: var(--font-display); font-size: 20px; font-weight: 700;
  box-shadow: 0 6px 16px rgba(255, 111, 145, .4); touch-action: manipulation; cursor: pointer;
}
.rh-tap:active { transform: scale(.97); }
.rh-tap kbd { font: inherit; font-size: 12px; opacity: .85; margin-left: 6px; background: rgba(255,255,255,.25); border-radius: 6px; padding: 1px 6px; }
.lbl-short { display: none; }
@media (max-width: 600px) {
  /* điện thoại: thẻ lớp học nằm trên cần điều khiển, chừa bên phải cho nút "Chạm theo nhịp" tròn (ngón cái phải) nằm trên nút "Dừng tập" */
  .class-hud { left: var(--gl); right: calc(var(--gr) + 112px); width: auto; transform: none; bottom: calc(var(--gb) + 140px); padding: 6px 10px 8px; background: rgba(255, 255, 255, .95); -webkit-backdrop-filter: none; backdrop-filter: none; }   /* không dùng backdrop-filter: nó biến thẻ thành khung chứa của nút tròn (position: fixed) bên trong */
  .ch-head { flex-wrap: wrap; gap: 4px; }
  .ch-title { font-size: 15px; }
  .ch-btn { min-height: 38px; padding: 3px 10px; }
  .lbl-full { display: none; } .lbl-short { display: inline; }
  .ch-sub { font-size: 11px; }
  #rhCanvas { height: 44px; }
  .rh-judge { font-size: 19px; min-width: 70px; }
  .rh-stat { font-size: 11px; gap: 6px; }
  .rh-tap { position: fixed; right: var(--gr); bottom: calc(var(--gb) + 104px); width: 96px; height: 96px; min-height: 0; border-radius: 50%; font-size: 16px; line-height: 1.1; padding: 8px; z-index: 5; }
  .rh-tap kbd { display: none; }
}
@media (prefers-reduced-motion: reduce) { .rh-judge.pop { animation-duration: .01s; } }

/* ----- công cụ: góc nhìn, chụp ảnh, biểu cảm / tạo dáng, ẩn giao diện ----- */
.tools { position: fixed; z-index: 3; right: var(--gr); top: 50%; transform: translateY(-50%); display: flex; flex-direction: column; gap: 8px; }
.tool { width: 46px; height: 46px; min-height: 0; padding: 0; display: grid; place-items: center; font-size: 21px; line-height: 1; border-radius: 50%; }
.tool[aria-pressed="true"], .tool[aria-expanded="true"] { background: var(--accent); border-color: var(--accent); }
.ui-show { position: fixed; z-index: 4; right: var(--gr); bottom: var(--gb); min-height: 36px; padding: 4px 14px; font-size: 12px; opacity: .55; }
.ui-show:hover, .ui-show:focus-visible { opacity: 1; }
.ui-hidden .hud-top, .ui-hidden .stats-card, .ui-hidden .right-col, .ui-hidden .tools, .ui-hidden .hint, .ui-hidden .joy, .ui-hidden .act, .ui-hidden .class-hud,
.ui-hidden .zone-sign, .ui-hidden .bubble, .ui-hidden #toast, .ui-hidden #fx, .ui-hidden .picker, .ui-hidden .info { display: none !important; }
.show-panel { max-height: min(70%, 560px); }
.sh-body { padding: 0 14px 14px; overflow-y: auto; overscroll-behavior: contain; }
.sh-h { margin: 8px 0 6px; font-family: var(--font-display); font-size: 13px; color: var(--ink-soft); font-weight: 600; }
.sh-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.sh-item { appearance: none; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; min-height: 64px; padding: 6px 4px; border: 2px solid transparent; border-radius: 16px; background: var(--chip); cursor: pointer; font-size: 12.5px; font-weight: 600; text-align: center; line-height: 1.15; }
.sh-item .sh-ico { font-size: 24px; line-height: 1; }
.sh-item:hover, .sh-item:focus-visible { border-color: var(--accent); background: #fff; }
.sh-item[aria-pressed="true"] { background: #FFE0E8; border-color: var(--accent); }
.sh-item:disabled { opacity: .45; cursor: default; }
.sh-note { margin: 6px 0 0; font-size: 12px; color: var(--ink-soft); }
.sh-note:empty { display: none; }

/* chế độ chụp ảnh */
.photo-ui { position: fixed; inset: 0; z-index: 6; pointer-events: none; }
.photo-ui > * { pointer-events: auto; }
.ph-top { position: absolute; top: var(--gt); left: var(--gl); right: var(--gr); display: flex; gap: 8px; align-items: center; justify-content: space-between; pointer-events: none; }
.ph-top > * { pointer-events: auto; }
.ph-mode { white-space: nowrap; background: var(--panel); border: 1px solid var(--line); border-radius: 999px; padding: 6px 14px; font-weight: 600; box-shadow: var(--shadow); margin-right: auto; }
.ph-top .btn { min-height: 40px; padding: 6px 14px; }
.ph-top kbd { font: inherit; font-size: 11px; opacity: .7; margin-left: 4px; }
.ph-hint { position: absolute; left: 50%; transform: translateX(-50%); bottom: calc(var(--gb) + 92px); margin: 0; max-width: calc(100% - 32px); text-align: center; font-size: 12px; color: var(--ink-soft); background: rgba(255,255,255,.7); border-radius: 999px; padding: 4px 12px; pointer-events: none !important; }
.ph-shutter { position: absolute; left: 50%; transform: translateX(-50%); bottom: var(--gb); width: 76px; height: 76px; padding: 0; border-radius: 50%; border: 5px solid #fff; background: rgba(255,111,145,.35); box-shadow: 0 6px 20px rgba(52,48,92,.35); cursor: pointer; display: grid; place-items: center; }
.ph-shutter i { width: 54px; height: 54px; border-radius: 50%; background: var(--accent); display: block; }
.ph-shutter:active i { transform: scale(.9); }
.photo-mode .hud-top, .photo-mode .stats-card, .photo-mode .right-col, .photo-mode .tools, .photo-mode .hint, .photo-mode .act, .photo-mode .class-hud,
.photo-mode .zone-sign, .photo-mode .bubble, .photo-mode .picker, .photo-mode .info, .photo-mode .ui-show { display: none !important; }
.flash { position: fixed; inset: 0; z-index: 8; background: #fff; opacity: 0; pointer-events: none; }
.flash.go { animation: flash .35s ease-out; }
@keyframes flash { 0% { opacity: .9; } 100% { opacity: 0; } }
.preview { position: fixed; inset: 0; z-index: 9; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; padding: calc(var(--gt) + 6px) var(--gr) var(--gb) var(--gl); background: rgba(52, 48, 92, .82); }
.preview img { max-width: 100%; max-height: calc(100% - 120px); border-radius: 14px; box-shadow: var(--shadow); object-fit: contain; background: #fff; }
.pv-actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.pv-actions .btn { min-height: 46px; padding: 8px 20px; }
.pv-actions .primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.pv-note { margin: 0; font-size: 12px; color: #fff; opacity: .85; text-align: center; }
@media (max-width: 600px) {
  .show-panel { max-height: 56%; }
  .sh-body { padding: 0 10px 10px; }
  .sh-grid.emo { grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 4px; }
  .sh-grid.poses { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }
  .sh-item { min-height: 54px; padding: 4px 2px; font-size: 11px; border-radius: 14px; }
  .sh-item .sh-ico { font-size: 21px; }
  .sh-h { margin: 6px 0 4px; }
  .sh-note:not(.warn) { display: none; }
}
@media (pointer: coarse) { .ph-top kbd { display: none; } }
@media (max-height: 520px) {
  .tools { top: auto; bottom: var(--gb); right: var(--gr); transform: none; flex-direction: row; }
  .tool { width: 40px; height: 40px; font-size: 18px; }
}
@media (prefers-reduced-motion: reduce) { .flash.go { animation-duration: .01s; } }

/* ----- online: trạng thái, tên trên đầu, bong bóng chat, danh sách bạn, tương tác đôi ----- */
.net-chip { cursor: pointer; font-family: inherit; color: inherit; }
.net-chip[data-state="reconnecting"], .net-chip[data-state="connecting"] { color: #b26a00; }
.dot.off { background: #B9B5D6; box-shadow: 0 0 0 3px rgba(185, 181, 214, .3); }
.dot.wait { background: #F4B03A; box-shadow: 0 0 0 3px rgba(244, 176, 58, .3); animation: lowpulse 1s infinite; }
.name-layer { position: fixed; inset: 0; z-index: 3; pointer-events: none; overflow: hidden; }
.ntag { position: absolute; left: 0; top: 0; display: flex; flex-direction: column; align-items: center; gap: 1px; will-change: transform; max-width: 190px; text-align: center; }
.nt-name { font-size: 12px; font-weight: 600; color: #fff; background: rgba(52, 48, 92, .72); border-radius: 999px; padding: 1px 9px; white-space: nowrap; max-width: 150px; overflow: hidden; text-overflow: ellipsis; }
.nt-do { font-size: 10.5px; font-weight: 500; color: var(--ink); background: rgba(255, 255, 255, .8); border-radius: 999px; padding: 0 7px; white-space: nowrap; }
.nt-bub { font-size: 13px; font-weight: 500; color: var(--ink); background: #fff; border: 1px solid var(--line); border-radius: 14px; padding: 4px 10px; margin-bottom: 3px; box-shadow: 0 3px 10px rgba(70, 60, 140, .18); word-break: break-word; max-width: 190px; }
.nt-bub::after { content: ""; display: block; width: 8px; height: 8px; background: #fff; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); transform: rotate(45deg); margin: 2px auto -7px; }
.nt-bub[hidden], .nt-do[hidden] { display: none; }
.ntag.self { max-width: 210px; }
.tool.dim { opacity: .5; }
.tool.glow { box-shadow: 0 0 0 3px rgba(255, 111, 145, .55), var(--shadow); animation: lowpulse 1.4s infinite; }
.people { max-height: min(78%, 620px); }
.ppl-body { padding: 0 14px 14px; overflow-y: auto; overscroll-behavior: contain; display: grid; gap: 8px; }
.ppl-room { margin: 0; font-weight: 600; color: var(--ink-soft); }
.ppl-room:empty { display: none; }
.ppl-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.ppl-actions .btn { flex: 1 1 150px; min-height: 40px; box-shadow: none; font-size: 13px; padding: 6px 12px; }
.ppl-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.ppl-row { display: flex; align-items: center; gap: 8px; background: var(--chip); border-radius: 14px; padding: 6px 10px; min-height: 48px; flex-wrap: wrap; }
.ppl-row.you { background: #FFE9EF; }
.ppl-main { display: grid; flex: 1 1 110px; min-width: 0; }
.ppl-main strong { font-family: var(--font-display); font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ppl-do { font-size: 12px; color: var(--ink-soft); }
.ppl-btn { min-height: 36px; padding: 4px 12px; font-size: 12.5px; box-shadow: none; }
.btn.ghost { background: transparent; box-shadow: none; }
.ppl-note { margin: 0; font-size: 12.5px; color: var(--ink-soft); }
.pk-item[aria-disabled="true"] { opacity: .55; }
.req-card {
  position: fixed; z-index: 8; left: 50%; top: calc(var(--gt) + 56px); transform: translateX(-50%); width: min(420px, calc(100% - 24px));
  background: rgba(255, 255, 255, .97); border: 2px solid var(--accent); border-radius: 20px; box-shadow: var(--shadow); padding: 10px 14px 12px; display: grid; gap: 8px;
}
.req-card p { margin: 0; font-weight: 600; text-align: center; overflow-wrap: anywhere; }
.req-bar { height: 5px; border-radius: 5px; background: #F2E4E9; overflow: hidden; }
.req-bar i { display: block; height: 100%; width: 100%; background: var(--accent); }
.req-btns { display: flex; gap: 8px; }
.req-btns .btn { flex: 1; min-height: 44px; padding: 6px 8px; box-shadow: none; }
.req-btns .primary, .chat-bar .primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.req-card.wait { grid-template-columns: 1fr auto; align-items: center; border-style: dashed; }
.req-card.wait .btn { min-height: 38px; box-shadow: none; }
.chat-bar {
  position: fixed; z-index: 9; left: 50%; transform: translateX(-50%); bottom: calc(var(--gb) + var(--kb, 0px)); width: min(520px, calc(100% - 24px));
  display: flex; gap: 8px; background: rgba(255, 255, 255, .97); border: 1px solid var(--line); border-radius: 999px; box-shadow: var(--shadow); padding: 6px 6px 6px 16px;
}
.chat-bar input { flex: 1; min-width: 0; border: 0; outline: 0; background: transparent; font: inherit; font-size: 16px; color: var(--ink); user-select: text; -webkit-user-select: text; }
.chat-bar .btn { min-height: 40px; box-shadow: none; }
.chat-log {
  position: fixed; z-index: 3; left: var(--gl); bottom: calc(var(--gb) + 140px); width: min(300px, calc(100% - 200px)); display: grid; gap: 3px; pointer-events: none;
}
.cl-line { font-size: 12.5px; background: rgba(255, 255, 255, .82); border-radius: 12px; padding: 3px 10px; overflow-wrap: anywhere; transition: opacity .6s; user-select: text; }
.cl-line.mine { background: rgba(255, 233, 239, .9); }
.cl-line.old { opacity: .35; }
.photo-mode .chat-log { display: none; }
.photo-mode .nt-bub, .photo-mode .nt-do, .photo-mode .ntag.self { display: none !important; }   /* chế độ chụp ảnh: chỉ giữ thẻ tên (có trong ảnh), bỏ bong bóng chat / hoạt động */
.ui-hidden .name-layer, .ui-hidden .chat-log, .ui-hidden .chat-bar, .ui-hidden .req-card, .ui-hidden .people { display: none !important; }
@media (max-width: 600px) {
  .net-chip { padding: 5px 9px; }
  .chat-log { bottom: calc(var(--gb) + 140px); width: calc(100% - 28px - 130px); }
  .req-card { top: calc(var(--gt) + 44px); }
}
@media (max-width: 420px) {
  .hud-top .chip.title { display: none; }
  .hud-top { gap: 5px; }
}
