:root {
  --bg: #0f1117;
  --panel: rgba(18, 21, 30, 0.82);
  --panel-solid: #161a24;
  --line: rgba(255, 255, 255, 0.09);
  --text: #eef1f7;
  --muted: #9aa3b5;
  --accent: #ff5a36;
  --accent-2: #ffb02e;
  --good: #4ade80;
  --bad: #f87171;
  --radius: 12px;
  --font: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font-family: var(--font); overflow: hidden; }
button, select { font: inherit; color: inherit; }

#app { position: fixed; inset: 0; }
#scene { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; cursor: grab; }
#scene.dragging { cursor: grabbing; }

.panel, .topbar .brand, .controls, .feed-line, .help, .overlay-card, .toast {
  background: var(--panel);
  border: 1px solid var(--line);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.topbar { position: absolute; top: 14px; left: 14px; right: 14px; display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; pointer-events: none; }
.topbar > * { pointer-events: auto; }
.brand { display: flex; align-items: center; gap: 12px; padding: 10px 16px 10px 12px; border-radius: var(--radius); min-width: 0; }
.brand img { flex: none; border-radius: 8px; }
.brand-title { font-weight: 700; font-size: 16px; letter-spacing: 0.2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand-sub { color: var(--muted); font-size: 13px; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }

.btn { background: rgba(255, 255, 255, 0.07); border: 1px solid var(--line); border-radius: 9px; padding: 8px 13px; cursor: pointer; font-size: 14px; font-weight: 600; white-space: nowrap; transition: background 0.15s, border-color 0.15s; }
.btn:hover { background: rgba(255, 255, 255, 0.13); }
.btn:focus-visible, select:focus-visible { outline: 2px solid var(--accent-2); outline-offset: 2px; }
.btn.icon { min-width: 40px; padding: 8px 10px; }
.btn.play { background: var(--accent); border-color: transparent; min-width: 48px; }
.btn.play:hover { background: #ff7354; }
.topbar .btn { background: var(--panel); backdrop-filter: blur(10px); }

.side { position: absolute; top: 84px; right: 14px; width: 260px; display: flex; flex-direction: column; gap: 10px; max-height: calc(100% - 200px); }
.panel { border-radius: var(--radius); padding: 12px; }
.panel h2 { margin: 0 0 8px; font-size: 12px; text-transform: uppercase; letter-spacing: 1.2px; color: var(--muted); }
#players-panel { overflow: auto; min-height: 0; }
#players { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
#players li { display: flex; align-items: center; gap: 9px; padding: 6px 7px; border-radius: 8px; cursor: pointer; border: 1px solid transparent; user-select: none; -webkit-user-select: none; }
#players li:hover { background: rgba(255, 255, 255, 0.06); }
#players li.followed { background: rgba(255, 90, 54, 0.16); border-color: rgba(255, 90, 54, 0.45); }
#players li.absent { opacity: 0.45; }
#players img { width: 26px; height: 26px; image-rendering: pixelated; border-radius: 4px; flex: none; background: #2a2f3c; }
.p-main { min-width: 0; flex: 1; }
.p-name { font-weight: 650; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.p-meta { font-size: 12px; color: var(--muted); display: flex; gap: 6px; align-items: center; }
.badge { font-size: 11px; font-weight: 700; padding: 1px 6px; border-radius: 6px; background: rgba(255, 255, 255, 0.1); }
.badge.it { background: #c62828; color: #fff; }
.badge.win { background: rgba(74, 222, 128, 0.2); color: var(--good); }
.badge.loss { background: rgba(248, 113, 113, 0.18); color: var(--bad); }
.hearts { color: #ff4d5e; letter-spacing: -1px; }
.hint { margin: 8px 2px 0; font-size: 12px; color: var(--muted); }

.scoreboard { font-family: "Minecraft", var(--font); }
.sb-title { text-align: center; font-weight: 700; margin-bottom: 6px; font-size: 15px; }
#sb-lines { list-style: none; margin: 0; padding: 0; font-size: 13.5px; line-height: 1.45; }
#sb-lines li { white-space: pre; overflow: hidden; text-overflow: ellipsis; min-height: 1.45em; }

.feed { position: absolute; left: 14px; bottom: 112px; width: min(540px, calc(100% - 300px)); display: flex; flex-direction: column; gap: 3px; pointer-events: none; }
.feed-line { padding: 4px 10px; border-radius: 7px; font-size: 14px; line-height: 1.35; transition: opacity 0.6s; text-shadow: 1px 1px 0 rgba(0, 0, 0, 0.55); }
.feed-line.old { opacity: 0; }
.feed.hidden { display: none; }

.controls { position: absolute; left: 14px; right: 14px; bottom: 14px; border-radius: var(--radius); padding: 10px 14px; display: flex; align-items: center; gap: 14px; }
.controls .buttons { display: flex; align-items: center; gap: 8px; }
.time { font-variant-numeric: tabular-nums; color: var(--muted); font-size: 14px; min-width: 96px; text-align: center; }
.timeline { position: relative; flex: 1; height: 34px; cursor: pointer; touch-action: none; }
.track { position: absolute; left: 0; right: 0; top: 14px; height: 6px; border-radius: 3px; background: rgba(255, 255, 255, 0.14); overflow: hidden; }
.fill { position: absolute; left: 0; top: 0; bottom: 0; width: 0; background: linear-gradient(90deg, var(--accent), var(--accent-2)); }
.knob { position: absolute; top: 9px; width: 16px; height: 16px; margin-left: -8px; border-radius: 50%; background: #fff; box-shadow: 0 1px 6px rgba(0, 0, 0, 0.5); pointer-events: none; }
.markers { position: absolute; left: 0; right: 0; top: 4px; height: 26px; pointer-events: none; }
.marker { position: absolute; top: 0; width: 3px; height: 8px; margin-left: -1.5px; border-radius: 2px; background: #cfd5e2; pointer-events: auto; }
.marker.k2, .marker.k8 { background: #f87171; }
.marker.k3 { background: #ffb02e; }
.marker.k4 { background: #ff5a36; height: 10px; }
.marker.k5 { background: #c084fc; height: 10px; }
.marker.k6 { background: #60a5fa; }
.marker.k7 { background: #4ade80; height: 12px; width: 4px; }
.tooltip { position: absolute; bottom: 36px; transform: translateX(-50%); background: var(--panel-solid); border: 1px solid var(--line); padding: 5px 9px; border-radius: 7px; font-size: 13px; white-space: nowrap; pointer-events: none; max-width: 340px; overflow: hidden; text-overflow: ellipsis; }
.select { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 13px; }
.select select { background: rgba(255, 255, 255, 0.07); border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; color: var(--text); }
.select option { background: var(--panel-solid); }

.overlay { position: absolute; inset: 0; display: grid; place-items: center; background: radial-gradient(ellipse at center, rgba(25, 29, 40, 0.92), rgba(10, 12, 17, 0.98)); z-index: 20; }
.overlay[hidden] { display: none; }
.overlay-card { width: min(420px, calc(100% - 32px)); border-radius: 16px; padding: 28px; text-align: center; }
.overlay-card h1 { margin: 14px 0 6px; font-size: 21px; }
.overlay-card p { margin: 0; color: var(--muted); line-height: 1.5; }
.spinner { width: 30px; height: 30px; margin: 18px auto 0; border: 3px solid rgba(255, 255, 255, 0.15); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.9s linear infinite; }
.spinner[hidden] { display: none; }
@keyframes spin { to { transform: rotate(360deg); } }

.help { position: absolute; top: 74px; right: 14px; width: 300px; border-radius: var(--radius); padding: 16px; z-index: 15; background: var(--panel-solid); }
.help h2 { margin: 0 0 10px; font-size: 15px; }
.help dl { display: grid; grid-template-columns: auto 1fr; gap: 6px 12px; margin: 0 0 14px; font-size: 13.5px; }
.help dt { font-weight: 700; color: var(--accent-2); }
.help dd { margin: 0; color: var(--muted); }

.toast { position: absolute; top: 76px; left: 50%; transform: translateX(-50%); padding: 9px 16px; border-radius: 10px; font-size: 14px; z-index: 30; }

@media (max-width: 760px) {
  .topbar { top: 10px; left: 10px; right: 10px; flex-direction: column; }
  .brand { width: 100%; }
  .top-actions { justify-content: flex-start; }
  #copy-time, #help-button { display: none; }
  .side { top: auto; bottom: 150px; right: 10px; left: 10px; width: auto; max-height: 34%; }
  .scoreboard { display: none; }
  #players { flex-direction: row; flex-wrap: wrap; }
  #players li { padding: 4px 6px; }
  .p-meta, .hint { display: none; }
  .feed { display: none; }
  .controls { left: 10px; right: 10px; bottom: 10px; flex-wrap: wrap; gap: 8px; padding: 8px 10px; }
  .timeline { order: -1; flex-basis: 100%; }
  .time { min-width: 0; }
}
