/* 3D Xiangqi — Traditional Chinese Scroll & Ornate Plaque HUD (ui.jpeg inspired)
   Full-bleed 3D canvas with floating scroll player cards, vertical plaque action rails,
   and slide-out lacquer drawers. Responsive across desktop, tablet, and notched mobile. */

:root {
  --bg: #140f0d;
  --bg-alt: #1f1714;
  --panel: rgba(28, 20, 17, 0.94);
  --panel-2: rgba(48, 34, 28, 0.92);
  --line: rgba(212, 175, 90, 0.36);
  --gold: #e8c776;
  --gold-deep: #9c742e;
  --jade: #1e6b6b;
  --jade-bright: #34a09a;
  --crimson: #8f1d1d;
  --crimson-bright: #c9332b;
  --purple: #5b2e7a;
  --text: #f7eedb;
  --muted: #bcae92;
  --accent: #d94a3a;
  --accent-2: #f0c050;
  --good: #48c78e;
  --bad: #f05a5a;
  --shadow: 0 10px 28px rgba(0, 0, 0, 0.5);
  --radius: 12px;
  --font-serif: "Kaiti TC", "KaiTi", "Songti TC", "Noto Serif TC", "PMingLiU", Georgia, serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; overflow: hidden; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang TC", "Microsoft JhengHei", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  user-select: none;
  touch-action: manipulation;
}

.app {
  position: relative;
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

/* Top decorative gold-jade trim */
.hud-top-trim {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 4px;
  z-index: 30;
  background: linear-gradient(90deg, #8b6220 0%, #f3d689 22%, #2b8a82 50%, #f3d689 78%, #8b6220 100%);
  box-shadow: 0 2px 10px rgba(240, 192, 80, 0.45);
  pointer-events: none;
}

/* Translucent top utility bar */
.topbar {
  position: fixed;
  top: 4px; left: 0; right: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(6px + env(safe-area-inset-top, 0px)) calc(14px + env(safe-area-inset-right, 0px)) 6px calc(14px + env(safe-area-inset-left, 0px));
  background: linear-gradient(180deg, rgba(20, 13, 10, 0.82) 0%, rgba(20, 13, 10, 0.35) 75%, transparent 100%);
  pointer-events: none;
}
.topbar > * { pointer-events: auto; }

.brand { display: flex; align-items: baseline; gap: 8px; }
.brand-mark {
  display: inline-flex; align-items: center; justify-content: center;
  width: 30px; height: 30px; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #e05242, #7d1714);
  border: 1.5px solid var(--gold);
  color: #fff3d1; font-family: var(--font-serif); font-weight: 800; font-size: 16px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
}
.brand-text { font-weight: 700; letter-spacing: 0.5px; font-size: 15px; text-shadow: 0 1px 4px rgba(0,0,0,0.7); }
.brand-sub { color: var(--gold); font-family: var(--font-serif); font-size: 13px; text-shadow: 0 1px 4px rgba(0,0,0,0.7); }
.topbar-right { display: flex; align-items: center; gap: 8px; }

.pill {
  padding: 4px 10px; border-radius: 999px;
  background: rgba(24, 17, 14, 0.78);
  color: var(--gold); font-size: 12px; font-weight: 600;
  border: 1px solid var(--line);
  backdrop-filter: blur(6px);
}
.pill.online { color: #98f5c2; border-color: rgba(72, 199, 142, 0.55); }

.icon-btn {
  background: rgba(28, 20, 17, 0.82);
  border: 1px solid var(--line);
  color: var(--gold);
  border-radius: 8px; padding: 5px 10px; font-size: 15px; cursor: pointer;
  backdrop-filter: blur(6px);
}
.icon-btn:hover { background: var(--panel-2); border-color: var(--gold); }

/* Full-bleed Stage */
.layout {
  position: relative;
  flex: 1;
  min-height: 0;
  width: 100%;
  height: 100%;
}
.stage {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
}
#canvas-host {
  position: relative;
  flex: 1;
  width: 100%;
  height: 100%;
  background: radial-gradient(600px 400px at 50% 40%, #2a3454 0%, #131a2b 70%);
  overflow: hidden;
}
#board-canvas { display: block; width: 100%; height: 100%; touch-action: none; }

/* ============ ORNATE PLAYER SCROLL CARDS (ui.jpeg inspired) ============ */
.hud-scroll {
  position: absolute;
  top: calc(50px + env(safe-area-inset-top, 0px));
  z-index: 12;
  display: flex;
  align-items: stretch;
  pointer-events: auto;
  filter: drop-shadow(0 8px 18px rgba(0, 0, 0, 0.45));
  transition: transform 0.25s ease, filter 0.25s ease;
}
.hud-scroll-red { left: calc(74px + env(safe-area-inset-left, 0px)); }
.hud-scroll-black { right: calc(74px + env(safe-area-inset-right, 0px)); }

.scroll-roller {
  width: 10px;
  border-radius: 5px;
  background: linear-gradient(90deg, #5d2412 0%, #d49c54 45%, #7c3818 100%);
  border: 1px solid #f0d084;
  box-shadow: inset 0 2px 4px rgba(255, 240, 190, 0.35);
}
.hud-scroll-black .scroll-roller {
  background: linear-gradient(90deg, #133c48 0%, #5fb8be 45%, #0e2d38 100%);
  border-color: #d9c37a;
}

.scroll-inner {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  min-width: 205px;
  border-top: 2px solid var(--gold);
  border-bottom: 2px solid var(--gold);
  position: relative;
}
.scroll-inner::after {
  content: '';
  position: absolute;
  inset: 3px 4px;
  border: 1px solid rgba(240, 212, 130, 0.32);
  pointer-events: none;
}

.hud-scroll-red .scroll-inner {
  background: linear-gradient(180deg, rgba(132, 26, 24, 0.94) 0%, rgba(74, 13, 13, 0.94) 100%);
}
.hud-scroll-black .scroll-inner {
  background: linear-gradient(180deg, rgba(20, 74, 92, 0.94) 0%, rgba(10, 38, 48, 0.94) 100%);
}

.hud-scroll.active {
  transform: translateY(-2px) scale(1.02);
  filter: drop-shadow(0 0 14px rgba(245, 198, 78, 0.65));
}
.hud-scroll.active .scroll-inner {
  border-color: #ffe89e;
}

.avatar-badge {
  width: 40px; height: 40px;
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-serif); font-size: 22px; font-weight: 900;
  border: 1.5px solid var(--gold);
  flex: none;
  box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.45);
}
.avatar-badge.red {
  background: radial-gradient(circle at 35% 30%, #d93e2e, #59100d);
  color: #ffe8b0;
}
.avatar-badge.black {
  background: radial-gradient(circle at 35% 30%, #2a6375, #0e242e);
  color: #f3e2b2;
}

.scroll-meta {
  display: flex; flex-direction: column; flex: 1; min-width: 0;
}
.scroll-meta.right-align { text-align: right; }
.p-name {
  font-family: var(--font-serif);
  font-size: 14px; font-weight: 700;
  color: #fff2d6;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.hud-scroll.active .p-name { color: #ffe384; }

.clock-box {
  display: flex; flex-direction: column; align-items: center; gap: 1px;
  padding: 2px 6px;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.28);
  border: 1px solid rgba(232, 199, 118, 0.28);
}
.hourglass { font-size: 12px; line-height: 1; }
.p-clock {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 15px; font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: #fff6e0;
}
.player.low-time .p-clock { color: #ff7b7b; animation: pulse 1s infinite; }

/* Center turn banner */
.turn-banner {
  position: absolute;
  top: calc(54px + env(safe-area-inset-top, 0px));
  left: 50%; transform: translateX(-50%);
  z-index: 11;
  padding: 5px 16px; border-radius: 999px;
  background: linear-gradient(180deg, rgba(32, 22, 16, 0.88), rgba(18, 12, 9, 0.88));
  border: 1.5px solid var(--gold);
  font-family: var(--font-serif);
  font-size: 13px; font-weight: 700; letter-spacing: 0.08em;
  color: #fff0cc;
  backdrop-filter: blur(6px);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.45);
  pointer-events: none;
  white-space: nowrap;
}
.turn-banner.red { border-color: #f08060; color: #ffd4c4; }
.turn-banner.black { border-color: #5eb8c4; color: #c8f0f6; }

/* AI Thinking breathing indicator */
.thinking-tag {
  display: none;
  align-items: center;
  gap: 5px;
  margin-top: 2px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: #ffe384;
}
.scroll-meta.right-align .thinking-tag { justify-content: flex-end; }
.hud-scroll.thinking .thinking-tag { display: inline-flex; }

.thinking-dots {
  display: inline-flex;
  align-items: center;
  gap: 3px;
}
.thinking-dots i {
  display: inline-block;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: #ffe384;
  opacity: 0.35;
  animation: aiDotBounce 1.2s ease-in-out infinite;
}
.thinking-dots i:nth-child(2) { animation-delay: 0.2s; }
.thinking-dots i:nth-child(3) { animation-delay: 0.4s; }

.hud-scroll.thinking {
  animation: aiScrollBreathe 2.2s ease-in-out infinite alternate;
}
.hud-scroll.thinking .scroll-inner {
  border-color: #ffe89e;
  box-shadow: 0 0 18px rgba(245, 198, 78, 0.35), inset 0 0 12px rgba(245, 198, 78, 0.16);
}
.hud-scroll.thinking .avatar-badge {
  border-color: #fff0b8;
  box-shadow: 0 0 10px rgba(245, 198, 78, 0.55), inset 0 0 10px rgba(0, 0, 0, 0.45);
}

.turn-banner.thinking {
  border-color: #ffe384;
  color: #fff2c2;
  animation: aiBannerBreathe 1.8s ease-in-out infinite alternate;
}

@keyframes aiScrollBreathe {
  0% { filter: drop-shadow(0 6px 14px rgba(245, 198, 78, 0.3)); }
  100% { filter: drop-shadow(0 0 22px rgba(255, 214, 102, 0.85)); }
}
@keyframes aiBannerBreathe {
  0% { box-shadow: 0 4px 12px rgba(0, 0, 0, 0.45), 0 0 6px rgba(245, 198, 78, 0.25); }
  100% { box-shadow: 0 4px 16px rgba(0, 0, 0, 0.45), 0 0 18px rgba(255, 214, 102, 0.72); }
}
@keyframes aiDotBounce {
  0%, 80%, 100% { opacity: 0.3; transform: translateY(0); }
  40% { opacity: 1; transform: translateY(-2px); }
}

@media (prefers-reduced-motion: reduce) {
  .hud-scroll.thinking,
  .turn-banner.thinking,
  .thinking-dots i {
    animation: none;
  }
  .thinking-dots i { opacity: 0.85; }
  .hud-scroll.thinking { filter: drop-shadow(0 0 12px rgba(245, 198, 78, 0.6)); }
}

/* ============ FLOATING VERTICAL PLAQUE BUTTONS (ui.jpeg inspired) ============ */
.hud-rail {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  z-index: 12;
  display: flex;
  flex-direction: column;
  gap: 14px;
  pointer-events: none;
}
.hud-rail-left { left: calc(14px + env(safe-area-inset-left, 0px)); }
.hud-rail-right { right: calc(14px + env(safe-area-inset-right, 0px)); }

.plaque-btn {
  pointer-events: auto;
  position: relative;
  width: 48px;
  min-height: 82px;
  padding: 10px 6px;
  border-radius: 24px;
  border: 2px solid var(--gold);
  display: flex;
  align-items: center;
  justify-content: center;
  writing-mode: vertical-rl;
  text-orientation: upright;
  font-family: var(--font-serif);
  font-size: 17px;
  font-weight: 800;
  letter-spacing: 0.16em;
  color: #fff6dc;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.7);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.48), inset 0 0 0 2px rgba(255, 232, 170, 0.25);
  cursor: pointer;
  transition: transform 0.16s ease, filter 0.16s ease, box-shadow 0.16s ease;
}
.plaque-btn:hover {
  transform: translateY(-2px) scale(1.04);
  filter: brightness(1.12);
  box-shadow: 0 8px 20px rgba(240, 192, 80, 0.35), inset 0 0 0 2px rgba(255, 240, 190, 0.5);
}
.plaque-btn:active { transform: scale(0.96); }

.plaque-crimson { background: linear-gradient(180deg, #b83228 0%, #6e1513 100%); }
.plaque-purple  { background: linear-gradient(180deg, #7f44a8 0%, #431d63 100%); }
.plaque-jade    { background: linear-gradient(180deg, #2d8a7e 0%, #164f4c 100%); }
.plaque-teal    { background: linear-gradient(180deg, #23748a 0%, #103e4d 100%); }
.plaque-amber   { background: linear-gradient(180deg, #c4842b 0%, #7a4a12 100%); }

body.lang-en .plaque-btn {
  writing-mode: horizontal-tb;
  font-family: inherit;
  font-size: 11px;
  letter-spacing: 0.04em;
  width: 52px;
  min-height: 52px;
  border-radius: 16px;
}
body.lang-en .plaque-btn .zh { display: none; }
body.lang-zh .plaque-btn .en { display: none; }

/* ============ SLIDE-OUT LACQUER DRAWERS ============ */
.drawer-backdrop {
  position: fixed;
  inset: 0;
  z-index: 25;
  background: rgba(8, 6, 5, 0.45);
  backdrop-filter: blur(2px);
}

.panel {
  position: fixed;
  top: 4px;
  bottom: 0;
  width: 320px;
  max-width: 88vw;
  z-index: 35;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: calc(14px + env(safe-area-inset-top, 0px)) 14px calc(18px + env(safe-area-inset-bottom, 0px));
  background: var(--panel);
  backdrop-filter: blur(14px);
  overflow-y: auto;
  scrollbar-width: thin;
  transition: transform 0.28s cubic-bezier(0.2, 0.85, 0.25, 1);
  box-shadow: 0 0 36px rgba(0, 0, 0, 0.65);
}
.panel-left {
  left: 0;
  border-right: 1.5px solid var(--gold-deep);
  transform: translateX(-105%);
}
.panel-left.open { transform: translateX(0); }

.panel-right {
  right: 0;
  border-left: 1.5px solid var(--gold-deep);
  transform: translateX(105%);
}
.panel-right.open { transform: translateX(0); }

.panel::-webkit-scrollbar { width: 6px; }
.panel::-webkit-scrollbar-thumb { background: var(--gold-deep); border-radius: 4px; }

.drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--line);
}
.drawer-title {
  font-family: var(--font-serif);
  font-size: 16px;
  font-weight: 700;
  color: var(--gold);
  letter-spacing: 0.06em;
}

.card {
  background: rgba(38, 27, 22, 0.85);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow);
}
.card.grow { flex: 1; min-height: 160px; display: flex; flex-direction: column; }
.card-title {
  margin: 0 0 10px; font-size: 12px; letter-spacing: 1.4px;
  text-transform: uppercase; color: var(--gold); font-weight: 700;
}

/* Check Flash & Call (GPU-composited CSS animation, zero rAF DOM writes) */
.check-flash {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 72px; font-weight: 900; letter-spacing: 8px;
  color: rgba(255, 82, 82, 0.95);
  text-shadow: 0 0 24px rgba(255, 0, 0, 0.7);
  pointer-events: none;
  will-change: transform, opacity;
  animation: checkPulse 1.1s ease-in-out infinite;
}
.check-flash.hidden { display: none; }
@keyframes pulse { 0%,100% { opacity: 0.35; } 50% { opacity: 1; } }
@keyframes checkPulse {
  0%, 100% { opacity: 0.38; transform: scale(0.97); }
  50% { opacity: 0.96; transform: scale(1.03); }
}

.check-call {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-serif);
  font-size: min(18vw, 140px); font-weight: 900; letter-spacing: 0.18em;
  color: #f6e7c2;
  text-shadow: 0 0 26px rgba(180, 28, 18, 0.95), 0 8px 0 #6a1410;
  pointer-events: none;
  z-index: 15;
  animation: callIn 0.35s cubic-bezier(0.2, 1.4, 0.3, 1) both;
}
.check-call.hidden { display: none; }
@keyframes callIn {
  from { transform: scale(1.55); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.toast {
  position: absolute; bottom: calc(18px + env(safe-area-inset-bottom, 0px));
  left: 50%; transform: translateX(-50%);
  z-index: 16;
  padding: 8px 18px; border-radius: 999px;
  background: rgba(24, 16, 13, 0.92);
  border: 1px solid var(--gold);
  color: var(--text); font-size: 13px;
  transition: opacity 0.25s;
  pointer-events: none;
  white-space: nowrap;
}
.toast.hidden { opacity: 0; }

/* Bottom sheet hidden by default (floating plaques handle quick actions cleanly) */
.bottom-sheet { display: none; }

/* Buttons & inputs */
button {
  font-family: inherit; cursor: pointer;
  border: 1px solid var(--line);
  color: var(--text);
  background: var(--panel-2);
  padding: 8px 14px; border-radius: 8px;
  font-size: 14px; font-weight: 500;
  transition: background 0.15s, transform 0.05s, border-color 0.15s;
}
button:hover { background: rgba(74, 52, 40, 0.95); border-color: var(--gold); }
button:active { transform: scale(0.98); }
button.primary {
  background: linear-gradient(180deg, #c93d30, #8a1d19);
  border-color: var(--gold);
  color: #fff6e0;
  font-weight: 600;
}
button.primary:hover { filter: brightness(1.1); }
button.ghost { background: rgba(255, 255, 255, 0.04); }
button.ghost:hover { background: var(--panel-2); }
button.danger { color: #ffb3b3; border-color: rgba(240, 90, 90, 0.45); }
button:disabled { opacity: 0.45; cursor: not-allowed; }

.btn-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 10px; }

.segmented {
  display: flex; background: var(--bg-alt); border-radius: 8px;
  padding: 3px; border: 1px solid var(--line);
}
.segmented.small .seg-btn { padding: 4px 8px; font-size: 12px; }
.seg-btn {
  flex: 1; background: transparent; border: none; color: var(--muted);
  padding: 6px 10px; border-radius: 6px; font-size: 13px;
}
.seg-btn.active {
  background: linear-gradient(180deg, #a62b22, #6f1814);
  color: #fff4d6;
  box-shadow: inset 0 0 0 1px rgba(240, 200, 110, 0.45);
}

.field { display: flex; flex-direction: column; gap: 6px; margin: 10px 0; }
.field > span { font-size: 12px; color: var(--muted); letter-spacing: 0.5px; }
.field input[type=text], .select {
  background: var(--bg-alt); border: 1px solid var(--line);
  color: var(--text); padding: 8px 10px; border-radius: 8px;
  font-family: inherit; font-size: 14px; width: 100%;
}
.field input[type=range] { width: 100%; accent-color: var(--accent-2); }
.level-row { display: flex; align-items: center; gap: 10px; }
.level-row input { flex: 1; }
.level-row output {
  min-width: 112px; text-align: right; font-size: 13px;
  color: var(--accent-2); font-variant-numeric: tabular-nums;
}
.row { display: flex; gap: 8px; }
.row input { flex: 1; }
.or {
  text-align: center; color: var(--muted); font-size: 12px; margin: 8px 0;
  position: relative;
}
.or::before, .or::after {
  content: ''; position: absolute; top: 50%; width: 40%;
  height: 1px; background: var(--line);
}
.or::before { left: 0; }
.or::after { right: 0; }

.status {
  font-size: 12px; color: var(--muted); padding: 6px 10px;
  background: var(--bg-alt); border-radius: 6px; border: 1px solid var(--line);
}
.status.ok { color: var(--good); border-color: rgba(72, 199, 142, 0.35); }
.status.err { color: var(--bad); border-color: rgba(240, 90, 90, 0.35); }

.hidden { display: none !important; }

/* History list */
.history {
  list-style: none; padding: 0; margin: 0;
  overflow-y: auto; flex: 1; min-height: 100px;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 13px;
}
.history li {
  display: grid; grid-template-columns: 32px 1fr 1fr; gap: 6px;
  padding: 4px 6px; border-radius: 4px;
}
.history li:nth-child(odd) { background: rgba(255, 255, 255, 0.03); }
.history li .mv-no { color: var(--muted); }
.history li .mv { cursor: pointer; padding: 2px 4px; border-radius: 4px; }
.history li .mv:hover { background: var(--panel-2); }
.history li .mv.current { background: var(--crimson-bright); color: #fff; }
.history li .mv.red { color: #ffb8a8; }
.history li .mv.black { color: #a8e0e8; }

/* Replay */
.replay-card .replay-row { display: flex; gap: 6px; margin-bottom: 8px; align-items: center; }
.replay-controls { display: flex; flex-direction: column; gap: 6px; }
.speed-row { justify-content: space-between; }
.sheet-label { color: var(--muted); font-size: 12px; }
#rp-scrub { width: 100%; accent-color: var(--accent-2); }

/* Overlay */
.overlay {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(12, 8, 6, 0.78); backdrop-filter: blur(6px);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
.overlay.hidden { display: none; }
.overlay-card {
  background: var(--panel); border: 2px solid var(--gold);
  border-radius: 16px; padding: 28px 32px;
  max-width: 420px; width: 100%; text-align: center;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.65);
}
.overlay-card.small { max-width: 340px; padding: 20px 24px; }
.overlay-card h1 { margin: 0 0 8px; font-size: 26px; font-family: var(--font-serif); color: var(--gold); }
.overlay-card p { margin: 0 0 20px; color: var(--muted); font-size: 14px; line-height: 1.5; }
.overlay-btns { display: flex; gap: 10px; justify-content: center; }
.countdown {
  font-family: ui-monospace, monospace;
  font-size: 32px; color: var(--accent-2);
  margin: 8px 0 16px;
}

/* -------- Ladder / ratings -------- */
.p-rating {
  font-size: 11px;
  font-weight: 600;
  color: var(--accent-2);
  letter-spacing: 0.02em;
  margin-top: 2px;
}
.p-rating .delta-up { color: var(--good); margin-left: 5px; }
.p-rating .delta-down { color: var(--bad); margin-left: 5px; }

.ladder-note {
  font-size: 11px; color: var(--muted); line-height: 1.4; margin: 6px 0 8px;
}
.ladder-note strong { color: var(--accent-2); }

.ladder-card .card-title {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
}
.ladder-card .icon-btn {
  width: 26px; height: 26px; padding: 0; font-size: 15px; line-height: 1;
}

.ladder {
  list-style: none; margin: 8px 0 0; padding: 0;
  max-height: 240px; overflow-y: auto;
}
.ladder li {
  display: flex; align-items: center; gap: 8px;
  padding: 5px 6px; border-radius: 6px; font-size: 13px;
}
.ladder li:nth-child(odd) { background: rgba(255, 255, 255, 0.03); }
.ladder li.self { background: rgba(240, 192, 80, 0.14); outline: 1px solid rgba(240, 192, 80, 0.4); }
.ladder .rank { width: 22px; text-align: right; font-weight: 700; color: var(--muted); flex: none; }
.ladder li:nth-child(1) .rank { color: #ffd700; }
.ladder li:nth-child(2) .rank { color: #c0c0c0; }
.ladder li:nth-child(3) .rank { color: #cd7f32; }
.ladder .l-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ladder .l-rating { font-weight: 700; color: var(--accent-2); flex: none; }
.ladder .l-record { font-size: 11px; color: var(--muted); flex: none; }

.ladder-self {
  font-size: 12px; color: var(--muted); padding: 6px; border-radius: 6px;
  background: rgba(240, 192, 80, 0.08); border: 1px solid rgba(240, 192, 80, 0.25);
}
.ladder-self strong { color: var(--accent-2); }
.ladder-empty { font-size: 12px; color: var(--muted); padding: 8px 6px; }
.delta-up { color: var(--good); }
.delta-down { color: var(--bad); }
.rating-line { margin-top: 4px; font-size: 14px; }

/* Rules link & language toggle */
.rules-link {
  display: inline-flex; align-items: center;
  padding: 4px 12px;
  background: rgba(28, 20, 17, 0.8);
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--text); text-decoration: none;
  font-size: 13px; font-weight: 500;
  transition: all 0.2s;
  backdrop-filter: blur(6px);
}
.rules-link:hover { background: var(--gold); color: #1a100c; border-color: var(--gold); }
body.lang-en .rules-link .zh { display: none; }
body.lang-zh .rules-link .en { display: none; }

.lang-toggle-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 32px; height: 32px; padding: 0;
  background: rgba(28, 20, 17, 0.8);
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--gold); font-size: 13px; font-weight: 700;
  cursor: pointer; transition: all 0.2s;
  backdrop-filter: blur(6px);
}
.lang-toggle-btn:hover { background: var(--gold); color: #1a100c; }
body.lang-en .lang-toggle-btn .zh { display: none; }
body.lang-zh .lang-toggle-btn .en { display: none; }

.bgm-btn.muted { opacity: 0.48; text-decoration: line-through; }
.bgm-btn.playing {
  border-color: var(--gold);
  box-shadow: 0 0 10px rgba(240, 192, 80, 0.45);
}

/* ============ RESPONSIVE ============ */
@media (max-width: 900px) {
  .hud-scroll-red { left: calc(10px + env(safe-area-inset-left, 0px)); }
  .hud-scroll-black { right: calc(10px + env(safe-area-inset-right, 0px)); }
  .scroll-inner { min-width: 155px; padding: 6px 8px; gap: 6px; }
  .avatar-badge { width: 32px; height: 32px; font-size: 17px; }
  .p-name { font-size: 12px; }
  .p-clock { font-size: 13px; }
  .turn-banner { top: calc(114px + env(safe-area-inset-top, 0px)); font-size: 11px; padding: 4px 12px; }
}

@media (max-width: 640px) {
  .brand-text, .brand-sub { display: none; }
  .hud-rail { gap: 10px; }
  .hud-rail-left { left: calc(8px + env(safe-area-inset-left, 0px)); }
  .hud-rail-right { right: calc(8px + env(safe-area-inset-right, 0px)); }
  .plaque-btn {
    width: 38px; min-height: 66px; font-size: 14px; padding: 8px 4px;
  }
  body.lang-en .plaque-btn { width: 44px; min-height: 44px; font-size: 10px; }
  .scroll-roller { width: 7px; }
  .scroll-inner { min-width: 132px; padding: 5px 6px; }
  .hourglass { display: none; }
  .check-flash { font-size: 42px; letter-spacing: 4px; }
}

@media (max-height: 500px) and (orientation: landscape) {
  .hud-scroll { top: calc(40px + env(safe-area-inset-top, 0px)); }
  .turn-banner { top: calc(44px + env(safe-area-inset-top, 0px)); font-size: 10px; padding: 3px 10px; }
  .plaque-btn { min-height: 56px; font-size: 13px; }
}
