:root {
  --bg: #0f0f1a;
  --panel-bg: #1a1a2e;
  --text: #e0e0e0;
  --text-muted: #888;
  --border: #2e2e4e;
  --accent: #6c63ff;
  --btn-bg: #252540;
  --btn-hover: #35356a;
  --input-bg: #252540;
  --item-hover: #252540;
}
[data-theme="light"] {
  --bg: #f0f0f8;
  --panel-bg: #ffffff;
  --text: #1a1a2e;
  --text-muted: #666;
  --border: #d8d8ee;
  --accent: #6c63ff;
  --btn-bg: #ebebf8;
  --btn-hover: #d8d8f0;
  --input-bg: #f5f5ff;
  --item-hover: #efefff;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  /* use dvh so mobile browser chrome doesn't overflow */
  height: 100dvh;
}

body {
  font-family: 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: row;
  overflow: hidden;
  transition: background 0.25s, color 0.25s;
}

/* ─────────────────────────────────────────────
   LEFT PANEL  (desktop / tablet)
───────────────────────────────────────────── */
#panel {
  width: 260px;
  min-width: 260px;
  background: var(--panel-bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 14px 12px;
  gap: 10px;
  transition: background 0.25s, width 0.2s;
  overflow: hidden;
}

#search {
  width: 100%;
  padding: 7px 10px;
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: 7px;
  color: var(--text);
  font-size: 0.83rem;
  outline: none;
  transition: border-color 0.15s;
  flex-shrink: 0;
}
#search:focus { border-color: var(--accent); }

#flag-count {
  font-size: 0.72rem;
  color: var(--text-muted);
  flex-shrink: 0;
}

#flag-list {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-height: 0;
}
#flag-list::-webkit-scrollbar { width: 4px; }
#flag-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.flag-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 8px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.81rem;
  transition: background 0.12s;
  user-select: none;
  flex-shrink: 0;
}
.flag-item:hover { background: var(--item-hover); }
.flag-item.in-arena { opacity: 0.4; pointer-events: none; }

.flag-item img {
  width: 28px;
  height: 19px;
  object-fit: cover;
  border-radius: 2px;
  flex-shrink: 0;
}
.flag-item .fname {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.badge {
  background: var(--accent);
  color: #fff;
  font-size: 0.65rem;
  padding: 1px 5px;
  border-radius: 8px;
  flex-shrink: 0;
}

/* ─────────────────────────────────────────────
   MAIN AREA
───────────────────────────────────────────── */
#main {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 12px 14px 10px;
  gap: 10px;
  overflow: hidden;
  min-width: 0;
}

/* ─────────────────────────────────────────────
   TOP BAR
───────────────────────────────────────────── */
#topbar {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex-shrink: 0;
}

/* Settings row — arena/flag/quick-add */
#topbar-settings {
  display: flex;
  align-items: flex-end;
  gap: 4px;
  flex-wrap: wrap;
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 10px;
}

/* Game controls row — start/pause/reset/theme */
#topbar-controls {
  display: flex;
  align-items: center;
  gap: 6px;
}

/* Labelled control group */
.ctrl-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.ctrl-label {
  font-size: 0.6rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.07em;
  padding-left: 1px;
  white-space: nowrap;
}

/* Vertical divider between groups */
.ctrl-divider {
  width: 1px;
  align-self: stretch;
  background: var(--border);
  margin: 0 4px;
  flex-shrink: 0;
}
#topbar-controls .ctrl-divider {
  height: 20px;
  align-self: center;
}

.btn-group { display: flex; gap: 4px; }

.btn {
  padding: 6px 11px;
  border: 1px solid var(--border);
  background: var(--btn-bg);
  color: var(--text);
  border-radius: 7px;
  cursor: pointer;
  font-size: 0.78rem;
  font-weight: 600;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
  white-space: nowrap;
  touch-action: manipulation;
}
.btn:hover    { background: var(--btn-hover); }
.btn.active   { border-color: var(--accent); color: var(--accent); }
.btn:disabled { opacity: 0.32; cursor: not-allowed; pointer-events: none; }

.btn-start  { background: #1e7a3e; color: #fff; border-color: #1e7a3e; font-size: 0.85rem; padding: 7px 16px; }
.btn-start:hover { background: #28a852; border-color: #28a852; }
.btn-stop   { background: #7a1e1e; color: #fff; border-color: #7a1e1e; }
.btn-stop:hover  { background: #a82828; border-color: #a82828; }
.btn-theme  { font-size: 1rem; padding: 6px 10px; margin-left: auto; }
.btn-random { border-color: #b86a00; color: #ff9500; }
.btn-random:hover { background: rgba(255,149,0,0.12); }

#random-count {
  width: 44px;
  padding: 6px 4px;
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: 7px;
  color: var(--text);
  font-size: 0.78rem;
  font-weight: 600;
  text-align: center;
  outline: none;
  transition: border-color 0.15s;
}
#random-count:focus { border-color: var(--accent); }
#random-count::-webkit-inner-spin-button,
#random-count::-webkit-outer-spin-button { display: none; }
#random-count[type=number] { -moz-appearance: textfield; }

/* ─────────────────────────────────────────────
   ARENA CANVAS
───────────────────────────────────────────── */
#arena-wrap {
  position: relative;
  flex-shrink: 0;
  overflow: visible;
}

#arena { display: block; }

/* ─────────────────────────────────────────────
   WINNER OVERLAY
───────────────────────────────────────────── */
#winner-overlay {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.78);
  gap: 10px;
  z-index: 20;
}
#winner-overlay.show { display: flex; }

#winner-overlay img {
  width: 90px;
  height: 60px;
  object-fit: cover;
  border-radius: 6px;
  box-shadow: 0 0 40px rgba(108, 99, 255, 0.9);
  animation: pop 0.4s ease;
}
@keyframes pop {
  from { transform: scale(0.4); opacity: 0; }
  to   { transform: scale(1);   opacity: 1; }
}
#winner-overlay h2  { color: #fff; font-size: 1.3rem; text-align: center; padding: 0 12px; }
#winner-overlay .sub { color: #aaa; font-size: 0.85rem; }

/* ═══════════════════════════════════════════════════════
   RESPONSIVE — TABLET  (≤ 860px)
═══════════════════════════════════════════════════════ */
@media (max-width: 860px) {
  #panel {
    width: 210px;
    min-width: 210px;
  }
  .flag-item { font-size: 0.76rem; }
}

/* ═══════════════════════════════════════════════════════
   RESPONSIVE — MOBILE  (≤ 600px)
   Panel moves to the top as a compact horizontal strip
═══════════════════════════════════════════════════════ */
@media (max-width: 600px) {
  body {
    flex-direction: column;
  }

  /* Panel becomes a top strip */
  #panel {
    width: 100%;
    min-width: unset;
    height: auto;
    max-height: 42vh;
    flex-direction: column;
    border-right: none;
    border-bottom: 1px solid var(--border);
    padding: 8px 10px;
    gap: 7px;
  }

  /* Horizontal scrolling flag list on mobile */
  #flag-list {
    flex-direction: row;
    flex-wrap: nowrap;
    overflow-x: auto;
    overflow-y: hidden;
    gap: 5px;
    padding-bottom: 4px;
  }
  #flag-list::-webkit-scrollbar { height: 3px; }

  .flag-item {
    flex-direction: column;
    align-items: center;
    min-width: 52px;
    padding: 5px 4px;
    gap: 3px;
    font-size: 0.68rem;
    text-align: center;
    border-radius: 7px;
  }
  .flag-item img {
    width: 36px;
    height: 24px;
  }
  .flag-item .fname {
    white-space: normal;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    line-height: 1.2;
    max-height: 2.4em;
  }

  #main {
    flex: 1;
    padding: 6px 8px 4px;
    gap: 5px;
    min-height: 0;
  }

  #topbar { gap: 5px; }

  #topbar-settings {
    padding: 5px 8px;
    gap: 5px;
    flex-wrap: nowrap;
    overflow-x: auto;
    scrollbar-width: none;
  }
  #topbar-settings::-webkit-scrollbar { display: none; }

  .ctrl-label { display: none; }
  .ctrl-divider { margin: 0 2px; }

  .btn { padding: 5px 8px; font-size: 0.72rem; }
  .btn-start { padding: 6px 12px; font-size: 0.78rem; }
  .btn-theme { padding: 5px 7px; }
  #shape-group .btn { padding: 5px 6px; }

  #topbar-controls { gap: 5px; }
}

/* ═══════════════════════════════════════════════════════
   RESPONSIVE — SMALL MOBILE  (≤ 380px)
═══════════════════════════════════════════════════════ */
@media (max-width: 380px) {
  #topbar { gap: 4px; }
  .btn { padding: 4px 6px; font-size: 0.68rem; }
  .btn-group { gap: 3px; }
}

/* ─────────────────────────────────────────────
   KILL FEED
───────────────────────────────────────────── */
#kill-feed {
  position: fixed;
  bottom: 16px;
  right: 16px;
  display: flex;
  flex-direction: column-reverse;
  gap: 4px;
  z-index: 100;
  pointer-events: none;
}

.kf-entry {
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(0, 0, 0, 0.72);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 6px;
  padding: 4px 8px 4px 5px;
  font-size: 0.72rem;
  color: #e0e0e0;
  animation: kf-slide-in 0.2s ease;
  white-space: nowrap;
}
[data-theme="light"] .kf-entry {
  background: rgba(255,255,255,0.88);
  border-color: rgba(0,0,0,0.12);
  color: #1a1a2e;
}

.kf-entry img {
  width: 22px;
  height: 15px;
  object-fit: cover;
  border-radius: 2px;
  flex-shrink: 0;
}

.kf-out {
  font-size: 0.62rem;
  font-weight: 700;
  color: #ff3b30;
  margin-left: 2px;
}

@keyframes kf-slide-in {
  from { opacity: 0; transform: translate(16px, 8px); }
  to   { opacity: 1; transform: translate(0, 0); }
}



