/* ============================================================
   สนามประลองลุงเอ — arena.css
   ภาษาภาพเดียวกับ style.css (ธีมมืด, Prompt, ชมพู accent) แต่แยกไฟล์ (prefix ar-)
   ============================================================ */
:root {
  --bg: #0b0b0f;
  --bg-2: #101016;
  --card: #15151c;
  --card-2: #1b1b24;
  --border: #2a2a35;
  --border-2: #3a3a48;
  --text: #f2f2f5;
  --muted: #9a9aa8;
  --accent: #e8456b;
  --accent-2: #ff6f8e;
  --accent-soft: rgba(232, 69, 107, .14);
  --gold: #f5c542;
  --gold-soft: rgba(245, 197, 66, .12);
  --green: #4cd28a;
  --blue: #4fb3ff;
  --radius: 12px;
  --radius-sm: 8px;
  --gutter: 16px;
  --font: 'Prompt', 'Noto Sans Thai', system-ui, -apple-system, 'Segoe UI', sans-serif;
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body.ar-body {
  margin: 0; background: var(--bg); color: var(--text); font-family: var(--font);
  font-size: 15px; line-height: 1.6; overflow-x: hidden; min-height: 100vh;
}
a { color: var(--accent-2); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, p { margin: 0; }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.ar-wrap { width: 100%; max-width: 1180px; margin: 0 auto; padding: 0 var(--gutter); }
.ar-muted { color: var(--muted); }
.ar-small { font-size: 13px; }
.ar-accent { color: var(--accent); }
.ar-err { color: #ff8a8a; }

/* ---------- top bar ---------- */
.ar-topbar {
  position: sticky; top: 0; z-index: 30; background: rgba(11, 11, 15, .86);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); border-bottom: 1px solid var(--border);
}
.ar-topbar-inner { display: flex; align-items: center; justify-content: space-between; gap: 10px; height: 54px; }
.ar-brand { color: var(--text); font-weight: 700; display: inline-flex; align-items: center; gap: 8px; white-space: nowrap; font-size: 15px; }
.ar-brand:hover { text-decoration: none; }
.ar-brand-mark { display: inline-grid; place-items: center; width: 28px; height: 28px; border-radius: 8px; background: var(--accent); color: #fff; }
.ar-topnav { display: flex; gap: 2px; align-items: center; min-width: 0; }
.ar-topnav a { color: var(--muted); padding: 6px 9px; border-radius: 8px; font-size: 14px; white-space: nowrap; }
.ar-topnav a:hover { color: var(--text); background: var(--card); text-decoration: none; }
.ar-topnav a.is-active { background: var(--accent); color: #fff; font-weight: 600; }
@media (max-width: 420px) {
  .ar-brand { font-size: 13px; gap: 6px; }
  .ar-brand-mark { width: 24px; height: 24px; }
  .ar-topnav a { padding: 6px 6px; font-size: 12.5px; }
}

/* ---------- buttons ---------- */
.ar-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 40px; padding: 8px 16px;
  border-radius: var(--radius-sm); border: 1px solid transparent; background: var(--card-2); color: var(--text);
  font-size: 14px; font-weight: 500; line-height: 1.3; text-align: center; max-width: 100%;
  transition: background .15s, border-color .15s, transform .08s, opacity .15s;
}
.ar-btn:hover { text-decoration: none; }
.ar-btn:active { transform: translateY(1px); }
.ar-btn[disabled] { opacity: .45; cursor: not-allowed; }
.ar-btn-primary { background: var(--accent); color: #fff; }
.ar-btn-primary:hover { background: var(--accent-2); }
.ar-btn-outline { background: transparent; border-color: var(--border-2); }
.ar-btn-outline:hover { border-color: var(--muted); background: var(--card); }
.ar-btn-ghost { background: transparent; color: var(--muted); }
.ar-btn-ghost:hover { color: var(--text); background: var(--card); }
.ar-btn-lg { min-height: 48px; padding: 10px 22px; font-size: 16px; font-weight: 600; box-shadow: 0 8px 28px rgba(232, 69, 107, .25); }
.ar-btn-sm { min-height: 32px; padding: 4px 12px; font-size: 13px; }

/* ---------- head ---------- */
.ar-main { padding-top: 18px; padding-bottom: 24px; }
.ar-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.ar-kicker { color: var(--muted); font-size: 13px; letter-spacing: .2px; }
.ar-title { font-size: clamp(26px, 6vw, 38px); font-weight: 700; line-height: 1.15; }
.ar-head-actions { display: flex; gap: 8px; flex-wrap: wrap; }
@media (max-width: 560px) {
  .ar-head-actions, .ar-head-actions .ar-btn { width: 100%; }
}

/* ---------- layout ---------- */
.ar-layout { display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px; }
@media (min-width: 980px) {
  .ar-layout { grid-template-columns: minmax(0, 1fr) 330px; align-items: start; }
}
.ar-stage-col, .ar-side { display: grid; gap: 14px; min-width: 0; }
.ar-card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); min-width: 0; }
.ar-panel { padding: 14px; }
.ar-h { font-size: 15px; font-weight: 600; margin-bottom: 10px; display: flex; align-items: center; gap: 8px; }
.ar-h-sub { font-size: 12.5px; font-weight: 400; }
.ar-live-tag { font-size: 10.5px; font-weight: 700; color: #fff; background: var(--accent); border-radius: 4px; padding: 0 6px; letter-spacing: .5px; }

/* ---------- stage ---------- */
.ar-stage-card { overflow: hidden; }
.ar-statusbar {
  display: flex; align-items: center; gap: 6px 14px; flex-wrap: wrap; padding: 10px 12px;
  border-bottom: 1px solid var(--border); font-size: 13px;
}
.ar-pill {
  display: inline-flex; align-items: center; gap: 6px; padding: 2px 10px; border-radius: 999px;
  background: var(--card-2); border: 1px solid var(--border-2); font-weight: 600; font-size: 12.5px; white-space: nowrap;
}
.ar-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.ar-pill.is-live { border-color: var(--accent); color: #fff; }
.ar-pill.is-live .ar-dot { background: var(--accent); animation: ar-blink 1s infinite; }
.ar-pill.is-lobby .ar-dot { background: var(--gold); }
.ar-pill.is-result .ar-dot { background: var(--green); }
@keyframes ar-blink { 50% { opacity: .25; } }
.ar-stat { display: inline-flex; align-items: center; gap: 4px; white-space: nowrap; }
.ar-stat-ico { color: var(--muted); font-size: 12px; }
.ar-stat-right { margin-left: auto; }
.ar-stat.is-danger { color: #ff8a8a; }

.ar-canvas-box { position: relative; width: 100%; aspect-ratio: 24 / 16; background: #14161c; touch-action: manipulation; }
.ar-canvas-box canvas { display: block; width: 100%; height: 100%; image-rendering: pixelated; }

.ar-hud { position: absolute; left: 8px; top: 8px; pointer-events: none; max-width: 55%; }
.ar-hud-me {
  background: rgba(11, 11, 15, .72); border: 1px solid var(--border-2); border-radius: 8px; padding: 6px 8px; min-width: 150px;
}
.ar-hud-name { font-size: 12px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ar-hpbar { position: relative; height: 12px; border-radius: 6px; background: #2b1a20; overflow: hidden; margin: 3px 0; }
.ar-hpbar-fill { height: 100%; width: 100%; background: linear-gradient(90deg, #4cd28a, #8ee6b0); transition: width .15s; }
.ar-hpbar-fill.is-low { background: linear-gradient(90deg, #e8456b, #ff8a8a); }
.ar-hpbar span { position: absolute; inset: 0; font-size: 9.5px; line-height: 12px; text-align: center; color: #0b0b0f; font-weight: 700; }
.ar-hud-sub { font-size: 11px; color: var(--muted); white-space: nowrap; }

.ar-killfeed {
  position: absolute; right: 8px; top: 8px; margin: 0; padding: 0; list-style: none; display: grid; gap: 4px;
  max-width: min(60%, 320px); pointer-events: none;
}
.ar-killfeed li {
  background: rgba(11, 11, 15, .75); border-left: 3px solid var(--accent); border-radius: 4px; padding: 2px 8px;
  font-size: 11.5px; line-height: 1.45; animation: ar-in .2s ease-out;
}
@keyframes ar-in { from { opacity: 0; transform: translateX(10px); } }
@media (max-width: 560px) {
  .ar-killfeed { top: auto; bottom: 6px; right: 6px; max-width: 70%; }
  .ar-killfeed li:nth-child(n+3) { display: none; }
  .ar-hud { left: 6px; top: 6px; }
  .ar-hud-me { min-width: 120px; padding: 4px 6px; }
}

.ar-overlay {
  position: absolute; inset: 0; display: grid; place-items: center; padding: 12px;
  background: rgba(11, 11, 15, .45); pointer-events: none;
}
.ar-overlay-solid { background: rgba(11, 11, 15, .82); pointer-events: auto; }
.ar-ov-card {
  text-align: center; background: rgba(21, 21, 28, .9); border: 1px solid var(--border-2); border-radius: var(--radius);
  padding: 14px 18px; max-width: 360px; width: 100%;
}
.ar-ov-kicker { color: var(--muted); font-size: 13px; }
.ar-countdown { font-size: clamp(30px, 9vw, 52px); font-weight: 700; color: var(--gold); line-height: 1.1; font-variant-numeric: tabular-nums; }
.ar-winner { font-size: clamp(20px, 5vw, 28px); font-weight: 700; color: var(--gold); line-height: 1.3; word-break: break-word; }
.ar-ov-big { font-size: clamp(22px, 6vw, 30px); font-weight: 700; margin-bottom: 6px; }
.ar-ov-note { font-size: 13px; color: var(--text); margin-top: 6px; }
.ar-ov-sub { font-size: 12.5px; color: var(--muted); margin-top: 6px; }
@media (max-width: 420px) {
  .ar-ov-card { padding: 8px 10px; }
  .ar-ov-note { font-size: 12px; }
}

/* ---------- controls ---------- */
.ar-controls {
  display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: 10px;
  padding: 10px 12px; border-top: 1px solid var(--border); user-select: none; -webkit-user-select: none;
}
.ar-joy {
  position: relative; width: 104px; height: 104px; border-radius: 50%; touch-action: none;
  background: radial-gradient(circle, #23232e 0 55%, #1a1a22 56%); border: 1px solid var(--border-2);
}
.ar-joy-knob {
  position: absolute; left: 50%; top: 50%; width: 44px; height: 44px; margin: -22px 0 0 -22px; border-radius: 50%;
  background: var(--card-2); border: 2px solid var(--accent); box-shadow: 0 4px 12px rgba(0, 0, 0, .4); pointer-events: none;
}
.ar-ctl-mid { display: grid; gap: 6px; justify-items: center; min-width: 0; }
.ar-keys { font-size: 11.5px; color: var(--muted); text-align: center; }
.ar-chip {
  border: 1px solid var(--border-2); background: transparent; border-radius: 999px; padding: 3px 12px; font-size: 12.5px; white-space: nowrap;
}
.ar-chip[aria-pressed="true"] { border-color: var(--gold); color: var(--gold); background: var(--gold-soft); }
.ar-actions { display: grid; grid-template-columns: repeat(2, 56px); grid-template-rows: 56px 56px; gap: 8px; }
.ar-act {
  border-radius: 50%; border: 0; font-weight: 700; font-size: 14px; color: #fff; touch-action: none;
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, .25);
}
.ar-act:active, .ar-act.is-down { transform: scale(.94); filter: brightness(1.15); }
.ar-act-atk { background: var(--accent); grid-column: 2; grid-row: 1 / span 2; border-radius: 28px; }
.ar-act-pick { background: #3b7fd1; grid-column: 1; grid-row: 1; }
.ar-act-dash { background: #8a5cd6; grid-column: 1; grid-row: 2; }
@media (hover: none) {
  .ar-keys { display: none; }
}
@media (hover: hover) and (pointer: fine) {
  .ar-joy { width: 84px; height: 84px; }
  .ar-joy-knob { width: 36px; height: 36px; margin: -18px 0 0 -18px; }
  .ar-actions { grid-template-columns: repeat(2, 48px); grid-template-rows: 48px 48px; }
}
@media (max-width: 360px) {
  .ar-controls { gap: 6px; padding: 8px; }
  .ar-joy { width: 92px; height: 92px; }
  .ar-actions { grid-template-columns: repeat(2, 50px); grid-template-rows: 50px 50px; gap: 6px; }
  .ar-keys { display: none; }
}

.ar-mebar {
  display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap;
  padding: 10px 12px; border-top: 1px solid var(--border); font-size: 13.5px;
}
.ar-mebar-actions { display: flex; gap: 6px; flex-wrap: wrap; }
#me-status b { color: var(--gold); }

/* ---------- lists ---------- */
.ar-rank, .ar-queue, .ar-rounds, .ar-feed { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.ar-rank li, .ar-queue li, .ar-rounds li {
  display: grid; grid-template-columns: 26px minmax(0, 1fr) auto; align-items: center; gap: 8px;
  padding: 5px 8px; border-radius: 8px; background: var(--bg-2); font-size: 13.5px;
}
.ar-rank li.ar-muted, .ar-queue li.ar-muted, .ar-rounds li.ar-muted, .ar-feed li.ar-muted { display: block; background: none; padding: 2px 0; }
.ar-rank .n, .ar-queue .n { color: var(--muted); font-variant-numeric: tabular-nums; text-align: right; font-size: 12px; }
.ar-rank li:nth-child(1) .n { color: var(--gold); font-weight: 700; }
.ar-rank .nm, .ar-queue .nm, .ar-rounds .nm { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ar-rank .v { font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.ar-rank .v small, .ar-queue small, .ar-rounds small { color: var(--muted); font-weight: 400; font-size: 11.5px; }
.ar-rank li.is-me, .ar-queue li.is-me { outline: 1px solid var(--accent); }
.ar-rank li.is-dead .nm { color: var(--muted); text-decoration: line-through; }
.ar-tag { font-size: 10.5px; border: 1px solid var(--border-2); border-radius: 4px; padding: 0 5px; color: var(--muted); white-space: nowrap; }
.ar-feed { max-height: 260px; overflow-y: auto; }
.ar-feed li { font-size: 13px; padding: 3px 0 3px 10px; border-left: 2px solid var(--border-2); }
.ar-feed li.k { border-left-color: var(--accent); }
.ar-feed li .t { color: var(--muted); font-size: 11px; margin-right: 6px; font-variant-numeric: tabular-nums; }

.ar-tabs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; background: var(--bg-2); border-radius: 8px; padding: 3px; margin-bottom: 8px; }
.ar-tab { border: 0; background: transparent; border-radius: 6px; padding: 5px 0; font-size: 13px; color: var(--muted); }
.ar-tab.is-on { background: var(--card-2); color: var(--text); font-weight: 600; }

/* ---------- dialog ---------- */
.ar-dialog {
  border: 1px solid var(--border-2); border-radius: var(--radius); background: var(--card); color: var(--text);
  padding: 0; width: min(440px, calc(100vw - 24px)); max-height: calc(100vh - 24px);
}
.ar-dialog::backdrop { background: rgba(0, 0, 0, .6); }
.ar-dialog-body { padding: 16px; display: grid; gap: 10px; }
.ar-strats { border: 0; margin: 0; padding: 0; display: grid; gap: 6px; }
.ar-strats legend { margin-bottom: 6px; color: var(--muted); }
.ar-strat {
  display: flex; gap: 10px; align-items: flex-start; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; cursor: pointer;
}
.ar-strat:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.ar-strat input { margin-top: 5px; accent-color: var(--accent); }
.ar-strat span { display: grid; }
.ar-strat small { color: var(--muted); font-size: 12px; }
.ar-dialog-actions { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; margin-top: 4px; }

/* ---------- footer / toast ---------- */
.ar-footer { display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; padding-top: 8px; padding-bottom: 28px; font-size: 13px; }
.ar-toast {
  position: fixed; left: 50%; bottom: calc(16px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--card-2); border: 1px solid var(--border-2); border-radius: 10px; padding: 8px 14px; font-size: 14px;
  z-index: 60; max-width: calc(100vw - 32px); box-shadow: 0 8px 24px rgba(0, 0, 0, .4);
}
.ar-toast.is-error { border-color: var(--accent); }

/* ---------- สนามต่อเนื่อง (ภาคผนวก C) ---------- */
.ar-sub { color: var(--muted); font-size: 13.5px; margin-top: 2px; }
.ar-live-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); margin-right: 2px; animation: ar-blink 1s infinite; vertical-align: 1px; }
.ar-main > .ar-statusbar { margin-bottom: 10px; border-bottom: 1px solid var(--border); }
.ar-statusbar b { font-variant-numeric: tabular-nums; }
#me-status { color: var(--muted); }
#me-status b { color: var(--gold); }
.ar-stage-wrap { margin-bottom: 14px; min-width: 0; }
.ar-layout { grid-template-columns: minmax(0, 1fr); }
@media (min-width: 900px) { .ar-layout { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); } }
.ar-col { display: grid; gap: 14px; min-width: 0; align-content: start; }
.ar-tabs-2 { grid-template-columns: repeat(2, 1fr); }
.ar-rank .nm .av-epi, .ar-queue .nm .av-epi { margin-left: 2px; }
.av-epi {
  display: inline-block; font-size: .86em; font-weight: 700; color: #ffd666; background: rgba(245, 197, 66, .14);
  border: 1px solid rgba(245, 197, 66, .55); border-radius: 5px; padding: 0 5px; line-height: 1.35; white-space: nowrap; vertical-align: 1px;
}
.ar-feed li.is-me { border-left-color: var(--gold); }
.ar-field { display: grid; gap: 4px; }
.ar-epi-row { display: flex; gap: 6px; }
.ar-epi-row input {
  flex: 1; min-width: 0; background: var(--bg); border: 1px solid var(--border-2); border-radius: 8px; padding: 8px 10px; font-size: 16px; color: var(--text);
}
.ar-epi-row input:focus { outline: none; border-color: var(--accent); }
.ar-epi-row input[readonly] { opacity: .7; }
.ar-rules ul { margin: 0 0 10px; padding-left: 18px; display: grid; gap: 6px; font-size: 13.5px; }
.ar-rules kbd, kbd.ar-k { font: inherit; font-size: 11.5px; font-weight: 700; padding: 0 5px; border-radius: 5px; background: var(--bg); border: 1px solid var(--border-2); color: var(--gold); }
.ar-stage-wrap { scroll-margin-top: 64px; }

/* ===== ทีม C (integration): ปุ่มบัญชีแถบบน · 👑 สายจ่าย · ข้ามคิว ===== */
.ar-auth-slot { flex: none; min-width: 0; }
@media (max-width: 560px) {
  .ar-topbar-inner { gap: 6px; }
  .ar-brand { font-size: 0 !important; gap: 0 !important; }
  .ar-brand .ar-brand-mark { font-size: 15px; }
  .ar-auth-slot .au-user-label { display: none; }
  .ar-auth-slot .au-user-handle { max-width: 84px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
}
.ar-crown { font-size: .95em; }
.ar-btn-fast { border-color: #f5c542; color: #f5c542; }
.ar-btn-fast:hover { background: rgba(245, 197, 66, .12); border-color: #f5c542; }
.ar-me-label { color: var(--text, #f2f2f5); }
#join-login a { color: var(--accent-2, #ff6f8e); font-weight: 600; }
#me-status { white-space: normal; flex-wrap: wrap; min-width: 0; max-width: 100%; }
.ar-me-label { white-space: normal; overflow-wrap: anywhere; }
