/* ============================================================
   kirkart.css — KirKart-specific styles
   Complements /kirkacss/framework/kirka-ui.css
   ============================================================ */

/* ── Page layout ─────────────────────────────────────────── */

/* Lobby: body stays overflow:hidden, inner .kk-main scrolls */
/* Scrollable pages (profile, hub, news): allow body scroll */
body.kk-scroll { overflow-y: auto !important; }
body.kk-scroll .game-bg { position: fixed; }

/* Main content area — starts below the 96px left-interface panel, right of the 96px left-icons */
/* No z-index here: letting kk-main be z-index:auto means it doesn't create its own stacking
   context, so child modals (map-picker z-index:200) compete in the .interface context and
   correctly appear above left-icons (9) and right-interface (15). */
.kk-main {
  position: absolute;
  top: 96px; left: 96px; right: 0; bottom: 0;
  overflow: hidden;
  padding: 0;
  display: flex;
  flex-direction: column;
}

/* Page content wrapper for scrollable pages */
.kk-page-wrap {
  max-width: 960px;
  margin: 0 auto;
  padding: 0 1.5rem 3rem;
}

/* View toggle — JS adds/removes .active */
.view { display: none; flex-direction: column; gap: 0.75rem; padding: 0.5rem 1.5rem 1rem; }
.view.active { display: flex; }

/* Lobby view fills kk-main and manages its own internal scroll */
#view-lobby {
  flex: 1;
  min-height: 0;
  overflow: hidden;
  gap: 0.5rem;
}

/* Game section (divider + header + list) fills remaining space in lobby */
.kk-game-section {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 0;
  overflow: hidden;
}

/* Game list scrolls within its reserved zone */
.kk-game-section .game-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding-bottom: 8rem; /* space so last item isn't hidden behind fixed lobby-actions */
}

/* Room view — fills kk-main, inner panels own their scroll */
#view-room {
  flex: 1;
  min-height: 0;
  overflow: hidden;
  padding: 0;
  gap: 0;
}

/* iOS: ensure overflow-scroll containers work inside fixed/absolute parents */
.kk-main, .kk-hub-main, .game-list, #view-room, .chat-messages, .players-list {
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

/* Player KirKart-ID label (inside left-interface) */
.kk-kid-label {
  font-size: 0.7rem;
  color: var(--gold-1);
  letter-spacing: 1px;
  padding: 0 12px 6px;
}

/* ── Standardized left user panel ─────────────────────────────────────── */
/* Square avatar-info panel — 96px keeps the face viewer centred with room for the KID label.
   Fixed height prevents auto-grow from pushing left-icons and kk-main out of alignment. */
.avatar-info { height: 96px !important; width: 96px !important; overflow: hidden; }
.user-info   { height: 96px !important; justify-content: flex-start !important; gap: 3px; overflow: hidden; }

/* Keep left-icons top + icon-btn width in sync with the 96px avatar-info */
.left-icons  { top: 96px; }
.icon-btn    { width: 96px; }
.icon-btn .icon { width: 40px !important; }

/* Page name + username on one line */
.kk-panel-title-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.4rem;
  min-width: 0;
}
.kk-panel-title-row .username {
  font-size: 0.85rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Page name label */
.kk-panel-page {
  font-size: 0.62rem;
  color: var(--gray-2);
  text-transform: uppercase;
  letter-spacing: .09em;
  line-height: 1;
  white-space: nowrap;
  flex-shrink: 0;
}

/* KirkartID shown below the avatar face */
.kk-panel-kid {
  font-size: 0.6rem;
  color: var(--white);
  letter-spacing: 1px;
  font-family: monospace;
  opacity: .65;
  margin-top: 5px;
  text-align: center;
  line-height: 1;
}

/* Level + XP text row inside user-info */
.kk-panel-xp-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.67rem;
  margin: 1px 0;
}
.kk-panel-level { font-weight: 700; color: var(--gold-1); }
.kk-panel-xp-val { color: var(--gray-2); }
/* ─────────────────────────────────────────────────────────────────────── */

/* Connection status row */
.kk-conn-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 4px 12px;
  font-size: var(--text-xs);
  pointer-events: auto;
}

.status     { color: var(--gray-2); font-size: var(--text-xs); }
.status.ok  { color: var(--green-1); }

.kk-online-count { color: var(--gray-2); font-size: var(--text-xs); }

/* Page header (profile, hub, news) */
.kk-page-header {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1rem 1.5rem;
  background: var(--panel-3);
  border-bottom: 3px solid var(--panel-6);
  position: sticky; top: 0;
  z-index: var(--z-overlay);
}

.kk-page-title {
  font-family: var(--font-display);
  font-size: var(--text-xl);
  color: var(--gold-1);
  letter-spacing: 2px;
}

.kk-page-subtitle { font-size: var(--text-sm); color: var(--gray-2); }

.kk-back-btn {
  margin-left: auto;
  padding: 6px 14px;
  background: var(--panel-4);
  border: 2px solid var(--panel-6);
  border-radius: var(--radius-md);
  color: var(--white);
  font-size: var(--text-xs);
  font-weight: 700;
  cursor: pointer;
  text-decoration: none;
  font-family: var(--font-body);
  transition: var(--transition-fast);
  display: inline-block;
}

.kk-back-btn:hover { border-color: var(--gold-1); color: var(--gold-1); }

.kk-section-title {
  font-family: var(--font-display);
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 2px;
  color: var(--gray-2);
  opacity: 0.7;
  margin-bottom: 0.75rem;
}

/* Card panels */
.kk-card {
  background: var(--panel-3);
  border: 2px solid var(--panel-6);
  border-radius: var(--radius-lg);
  padding: 20px 24px;
}

/* ── Options modal visibility ─────────────────────────────── */

/* Hidden by default; JS adds .open to show.
   Background here so clicks outside modal hit #options-overlay (e.target === overlay).
   High z-index so it clears touch controls (9200) on the game page. */
#options-overlay { display: none; background: rgba(0,0,0,.55); z-index: 10001; }
#options-overlay.open { display: flex; }

/* Options pane show/hide */
.opts-pane { display: none; }
.opts-pane.active { display: block; }

/* Pane scroll area inside modal — min-height prevents resize when tabs have few items */
.vm--modal .opts-pane {
  min-height: 380px;
  max-height: 400px;
  overflow-y: auto;
  padding: 0.5rem 1rem 1rem;
}

/* Options pane inner list container (gap between generated rows) */
.kk-opts-list { display: flex; flex-direction: column; gap: 10px; margin-top: 4px; }

/* Super Cup resume modal */
#sc-resume-overlay .vm--modal { max-width: 28rem; padding: 0; }
#sc-resume-overlay .name-page { color: var(--gold-1); }
.sc-resume-body    { padding: 1.5rem 2rem 2rem; text-align: center; }
#sc-resume-text    { margin: 0 0 1.5rem; font-size: 1rem; line-height: 1.5; white-space: pre-line; }
.sc-resume-actions { display: flex; gap: 1rem; justify-content: center; }

/* Options pane section label */
.kk-pane-header {
  font-family: var(--font-display);
  font-size: var(--text-xs);
  color: var(--gold-1);
  letter-spacing: 2px;
  padding: 0.6rem 0 0.3rem;
  border-bottom: 1px solid var(--panel-6);
  margin-bottom: 0.5rem;
}

/* Options footer row (reset button) */
.kk-opts-footer {
  padding: 0.6rem 1rem;
  display: flex;
  justify-content: flex-end;
  border-top: 1px solid var(--panel-6);
}

/* ── JS-generated options elements ───────────────────────── */

.opts-section-header {
  font-size: var(--text-sm);
  font-weight: 700;
  color: var(--white);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 12px 0 4px;
  border-bottom: 1px solid rgba(255,255,255,.15);
  margin-bottom: 2px;
}

.keybind-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 0;
  border-bottom: 1px solid rgba(255,255,255,.06);
}

.keybind-label {
  font-size: var(--text-sm);
  color: var(--gray-2);
}

.keybind-btn {
  min-width: 90px;
  padding: 5px 12px;
  background: var(--panel-4);
  border: 2px solid var(--panel-6);
  border-radius: var(--radius-sm);
  color: var(--white);
  font-size: var(--text-sm);
  font-family: monospace;
  cursor: pointer;
  text-align: center;
  transition: var(--transition-fast);
}

.keybind-btn:hover { border-color: var(--gold-1); }

.keybind-btn.listening {
  border-color: var(--gold-1);
  color: var(--gold-1);
  animation: kbpulse 1s infinite;
}

@keyframes kbpulse { 0%,100% { opacity: 1; } 50% { opacity: 0.45; } }

.audio-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.audio-label {
  font-size: var(--text-sm);
  color: var(--gray-2);
  width: 120px;
  flex-shrink: 0;
}

.audio-slider { flex: 1; accent-color: var(--gold-1); cursor: pointer; }

.audio-value {
  font-size: var(--text-xs);
  color: var(--white);
  width: 38px;
  text-align: right;
  font-family: monospace;
}

.gfx-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 7px 0;
  border-bottom: 1px solid rgba(255,255,255,.06);
}

.gfx-label { font-size: var(--text-sm); color: var(--gray-2); }
.gfx-note  { font-size: var(--text-xs); color: var(--gray-2); opacity: .6; font-style: italic; }

/* Toggle switch */
.gfx-toggle {
  position: relative;
  display: inline-block;
  width: 44px; height: 24px;
  flex-shrink: 0;
}
.gfx-toggle input { opacity: 0; width: 0; height: 0; }

.gfx-slider {
  position: absolute; inset: 0;
  cursor: pointer;
  background: var(--panel-4);
  border-radius: 24px;
  transition: background .2s;
}
.gfx-slider::before {
  content: '';
  position: absolute;
  height: 18px; width: 18px; left: 3px; bottom: 3px;
  background: var(--gray-2);
  border-radius: 50%;
  transition: transform .2s, background .2s;
}
.gfx-toggle input:checked + .gfx-slider { background: var(--panel-2); }
.gfx-toggle input:checked + .gfx-slider::before {
  transform: translateX(20px);
  background: var(--gold-1);
}

.gfx-select {
  background: var(--panel-4);
  border: 2px solid var(--panel-6);
  border-radius: var(--radius-sm);
  color: var(--white);
  font-size: var(--text-sm);
  padding: 5px 8px;
  cursor: pointer;
  font-family: var(--font-body);
}
.gfx-select:hover { border-color: var(--gold-1); }
.gfx-select option { background: var(--panel-3); }

.gfx-slider-wrap { display: flex; align-items: center; gap: 8px; }

.gfx-range { width: 130px; accent-color: var(--gold-1); cursor: pointer; }

.gfx-val {
  font-size: var(--text-xs); color: var(--white);
  width: 44px; text-align: right; font-family: monospace;
}

.gfx-texture-section { border-bottom: 1px solid rgba(255,255,255,.06); padding-bottom: 6px; }
.gfx-texture-section .gfx-row { border-bottom: none; padding-bottom: 4px; }
.gfx-texture-input-row { display: flex; align-items: center; gap: 8px; padding: 4px 0 2px; }
.gfx-texture-input {
  flex: 1; background: var(--panel-1); border: 2px solid var(--panel-6);
  border-radius: var(--radius-sm); color: var(--white); font-size: var(--text-xs);
  padding: 5px 8px; font-family: monospace; outline: none;
}
.gfx-texture-input:focus { border-color: var(--gold-1); }
.gfx-texture-input::placeholder { color: rgba(255,255,255,.3); }
.gfx-texture-status { font-size: var(--text-xs); white-space: nowrap; font-family: monospace; min-width: 14px; }
.gfx-texture-status.ok      { color: var(--green-1); }
.gfx-texture-status.err     { color: var(--red-1); }
.gfx-texture-status.checking{ color: var(--gray-2); }

/* HUD position picker */
.hud-pos-grid {
  display: grid;
  grid-template-columns: repeat(3, 28px);
  grid-template-rows: repeat(3, 20px);
  gap: 3px; flex-shrink: 0;
}
.hud-pos-btn {
  background: var(--panel-4); border: 1px solid var(--panel-6);
  border-radius: var(--radius-xs); cursor: pointer; padding: 0;
  transition: var(--transition-fast);
}
.hud-pos-btn:not(:disabled):hover { border-color: var(--gray-2); }
.hud-pos-btn.active { background: var(--panel-2); border-color: var(--gold-1); }
.hud-pos-blank { opacity: 0; pointer-events: none; }

/* ── Compatibility button layer ──────────────────────────── */
/* Maps old .btn classes to kirka-ui aesthetic */
.btn {
  font-family: var(--font-body);
  font-weight: 700;
  padding: 0.5em 1.2em;
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: var(--transition-fast);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: var(--text-sm);
  color: var(--white);
  white-space: nowrap;
}
.btn:disabled { opacity: 0.35; cursor: not-allowed; }
.btn:not(:disabled):hover { opacity: .85; }

.btn-primary   { background: var(--blue-4); }
.btn-primary:not(:disabled):hover { background: var(--blue-5) !important; opacity: 1 !important; }
.btn-secondary { background: var(--panel-4); border: 2px solid var(--panel-6); }
.btn-secondary:not(:disabled):hover { background: var(--panel-2) !important; opacity: 1 !important; }
.btn-success   { background: var(--green-3); }
.btn-success:not(:disabled):hover { background: var(--green-1) !important; opacity: 1 !important; }
.btn-warning   { background: var(--orange-1); }
.btn-danger    { background: var(--red-2, #b03030); }
.btn-danger:not(:disabled):hover { background: var(--red-1, #c03030) !important; opacity: 1 !important; }
.btn-sm        { padding: 0.35em 0.8em; font-size: var(--text-xs); }
.panel-title   { font-size: var(--text-xs); font-weight: 700; letter-spacing: 2px; text-transform: uppercase; color: var(--gray-2); margin-bottom: 4px; opacity: .7; }

/* Speed class buttons (CC) */
.cc-btn {
  padding: 4px 12px;
  font-size: var(--text-xs);
  font-weight: 700;
  cursor: pointer;
  border-radius: var(--radius-md);
  border: 2px solid var(--panel-6);
  background: var(--panel-4);
  color: var(--gray-2);
  font-family: var(--font-body);
  transition: var(--transition-fast);
}
.cc-btn:hover { border-color: var(--gold-1); color: var(--white); }
.cc-btn.active { background: var(--panel-2); border-color: var(--gold-1); color: var(--gold-1); }

/* ── Lobby elements ──────────────────────────────────────── */
/* Fixed bottom-right card: [map] | [settings row / buttons row] */
.lobby-actions {
  position: fixed;
  /* bottom: 1rem;
  right: 1rem; */
  bottom: 0;
  right: 0;
  z-index: 50;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.75rem;
  padding: 0.75rem;
  align-items: start;
  max-width: min(540px, calc(100vw - 2rem));
}
.la-right {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  min-width: 0;
}
.la-map, .la-settings-row, .la-laps, .la-cc, .la-items, .la-btns {
  display: flex; align-items: center; gap: 6px;
}
.la-settings-row { gap: 8px; }
.la-btns { gap: 4px; grid-column: 1 / -1; flex-direction: column; align-items: stretch; }
.la-btns-row { display: flex; gap: 6px; }
.la-btns-row .button { flex: 1; }

/* Lobby action button colors */
#btn-solo        { background-color: var(--gold-1);  --hover-color: var(--gold-2);  --top: var(--gold-2);  --bottom: var(--gold-3); }
#btn-create      { background-color: var(--blue-4);  --hover-color: var(--blue-5);  --top: var(--blue-5);  --bottom: var(--blue-6); }
#btn-load-replay { background-color: var(--panel-2); --hover-color: var(--panel-4); }

/* Map picker button */
.map-picker-btn {
  position: relative; cursor: pointer; border-radius: var(--radius-md);
  overflow: hidden; border: 2px solid var(--panel-6); flex-shrink: 0;
  width: 120px; transition: var(--transition-fast); background: var(--panel-3);
}
.map-picker-btn:hover { border-color: var(--gold-1); }
.map-picker-btn img { display: block; width: 100%; height: 70px; object-fit: cover; }
.map-picker-btn .map-picker-label {
  position: absolute; bottom: 0; left: 0; right: 0;
  background: rgba(0,0,0,.65); color: var(--white); font-size: var(--text-xs);
  text-align: center; padding: 3px 4px; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis;
}
.map-picker-btn .map-picker-placeholder {
  width: 100%; height: 70px; background: var(--panel-3);
  display: flex; align-items: center; justify-content: center;
  color: var(--gray-2); font-size: var(--text-xs);
}

/* Super Cup diagonal composite thumbnail */
.super-cup-thumb {
  position: relative; width: 100%; height: 70px; overflow: hidden;
}
.map-picker-card .super-cup-thumb { height: 80px; }
.room-map-card .super-cup-thumb   { height: auto; aspect-ratio: 16/10; border-radius: var(--radius-sm); border: 2px solid var(--panel-6); margin-top: 4px; }
.tab-sc-thumb { width: 96px; height: 60px; border-radius: var(--radius-sm); border: 2px solid transparent; display: block; }
.tab-header .tab.active .tab-sc-thumb { border-color: var(--gold-1); }
.tab-header .tab:hover  .tab-sc-thumb { border-color: var(--panel-2); }
.super-cup-thumb .sct-slice {
  position: absolute; inset: 0;
  background-size: cover; background-position: center;
}
.super-cup-thumb .sct-slice:nth-child(1) { clip-path: polygon(0% 0%, 28% 0%, 38% 100%, 0% 100%); }
.super-cup-thumb .sct-slice:nth-child(2) { clip-path: polygon(28% 0%, 53% 0%, 63% 100%, 38% 100%); }
.super-cup-thumb .sct-slice:nth-child(3) { clip-path: polygon(53% 0%, 78% 0%, 88% 100%, 63% 100%); }
.super-cup-thumb .sct-slice:nth-child(4) { clip-path: polygon(78% 0%, 100% 0%, 100% 100%, 88% 100%); }

/* Map picker modal */
.map-picker-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.7); z-index: 200; }
.map-picker-dialog {
  position: fixed; top: 50%; left: 50%; transform: translate(-50%,-50%);
  background: var(--panel-3); border: 2px solid var(--panel-6);
  border-radius: var(--radius-lg); z-index: 201;
  width: min(700px, 95vw); max-height: 80vh;
  display: flex; flex-direction: column;
}
.map-picker-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px; border-bottom: 1px solid var(--panel-6); flex-shrink: 0;
  font-size: var(--text-base); font-weight: 600;
}
.map-picker-header button {
  background: none; border: none; color: var(--gray-2); font-size: var(--text-base);
  cursor: pointer; padding: 2px 6px;
}
.map-picker-header button:hover { color: var(--white); }
.map-picker-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 12px; padding: 16px; overflow-y: auto;
}
.map-picker-card {
  cursor: pointer; border-radius: var(--radius-md); overflow: hidden;
  border: 2px solid var(--panel-6); background: var(--panel-4);
  transition: var(--transition-fast);
}
.map-picker-card:hover { border-color: var(--gold-1); }
.map-picker-card.active { border-color: var(--gold-1); box-shadow: 0 0 0 1px var(--gold-1); }
.map-picker-card img { display: block; width: 100%; height: 80px; object-fit: cover; }
.map-no-thumb {
  width: 100%; height: 80px; background: var(--panel-3);
  display: flex; align-items: center; justify-content: center;
  color: var(--gray-2); font-size: var(--text-xs);
}
.map-card-name {
  padding: 5px 6px; font-size: var(--text-xs); color: var(--gray-1); text-align: center;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* Game list */
.game-list-header { display: flex; align-items: center; gap: 10px; padding: 0.5rem 0; }
.game-list-header h2 { font-size: var(--text-base); font-family: var(--font-display); letter-spacing: 1px; }
.game-list { display: flex; flex-direction: column; gap: 8px; }
.game-card {
  background: var(--panel-4); border: 2px solid var(--panel-6);
  border-radius: var(--radius-lg); padding: 12px 16px;
  display: flex; align-items: center; gap: 14px;
  transition: var(--transition-fast);
}
.game-card:hover { border-color: var(--gold-1); }
.game-thumb { width: 80px; height: 50px; object-fit: cover; border-radius: var(--radius-sm); flex-shrink: 0; border: 1px solid var(--panel-6); }
.game-info { flex: 1; }
.game-id { font-size: var(--text-xs); color: var(--gray-2); opacity: .7; }
.game-meta { font-size: var(--text-sm); margin-top: 2px; }
.game-players { font-size: var(--text-xs); color: var(--gray-2); }
.no-games { color: var(--gray-2); opacity: .5; font-size: var(--text-sm); padding: 1.5rem 0; }

/* Divider */
.divider { border: none; border-top: 1px solid var(--panel-6); margin: 0.5rem 0; }

/* Refresh button */
.refresh-btn {
  background: none; border: none; color: var(--gray-2); cursor: pointer;
  font-size: var(--text-sm); padding: 4px 8px; border-radius: var(--radius-sm);
  font-family: var(--font-body); transition: var(--transition-fast);
}
.refresh-btn:hover { color: var(--white); background: var(--panel-4); }

/* ── Room view layout ─────────────────────────────────────── */

/* Three columns fill the view, all sharing the same panel-2 background */
.room-body { flex: 1; min-height: 0; display: flex; overflow: hidden; }

/* Shared column header — identical across all three columns */
.room-section-head {
  flex-shrink: 0;
  padding: 6px 12px;
  background: var(--panel-6);
  border-bottom: 1px solid var(--panel-6);
}

/* Left: sidebar (room info card + actions) */
.room-sidebar {
  width: 210px; flex-shrink: 0;
  display: flex; flex-direction: column;
  background: var(--panel-2);
  border-right: 2px solid var(--panel-6);
  overflow-y: auto;
}
.room-map-card {
  margin: 10px; flex-shrink: 0;
  display: flex; flex-direction: column; gap: 8px;
}
.room-title    { font-size: var(--text-md); font-weight: 700; font-family: var(--font-display); letter-spacing: 0.3px; }
.room-meta     { font-size: var(--text-xs); color: var(--gray-2); }
.room-divider  { border: none; border-top: 1px solid var(--panel-6); margin: 4px 0; }
.room-map-thumb {
  display: block; width: 100%; aspect-ratio: 16/10; object-fit: cover;
  border-radius: var(--radius-sm); border: 2px solid var(--panel-6);
  margin-top: 4px;
}
.room-map-name   { font-size: var(--text-sm); font-weight: 700; color: var(--white); line-height: 1.3; }
.room-map-badges { display: flex; flex-direction: column; gap: 4px; margin-top: 2px; }
.room-badge-cc   { font-size: var(--text-xs); font-weight: 700; font-family: var(--font-display); color: var(--gold-1); }
.room-laps       { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.room-laps label { font-size: var(--text-xs); color: var(--gray-2); }
.room-laps input { width: 52px; }
.room-laps-display { font-size: var(--text-xs); color: var(--gray-1); }
.room-actions {
  margin-top: auto; flex-shrink: 0;
  padding: 10px; gap: 8px;
  border-top: 1px solid var(--panel-6);
  display: flex; flex-direction: column;
}
.room-status-text { font-size: var(--text-xs); color: var(--gray-2); min-height: 1em; }

/* Items on/off badge */
.items-tag { font-size: var(--text-xs); font-weight: 700; font-family: var(--font-display); padding: 1px 6px; border-radius: var(--radius-xs); }
.items-on  { color: var(--green-1); border: 1px solid var(--green-1); }
.items-off { color: var(--gray-2);  border: 1px solid var(--gray-2); }

/* Center: players panel */
.room-players-panel {
  flex: 1; min-width: 0;
  display: flex; flex-direction: column;
  background: var(--panel-2);
  border-right: 2px solid var(--panel-6);
  overflow: hidden;
}
.players-list {
  flex: 1; overflow-y: auto;
  padding: 8px;
  display: flex; flex-direction: column;
}
.prow { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 6px 10px; margin-bottom: 4px; }
.pface  { flex-shrink: 0; width: 32px !important; height: 32px !important; background-size: 256px !important; }
.pname  { flex: 1; min-width: 0; font-size: var(--text-sm); font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pkid   { font-size: var(--text-xs); color: var(--gray-2); font-weight: 400; font-family: var(--font-body); margin-left: 2px; }
.phost  { font-size: var(--text-xs); color: var(--gold-1); border: 1px solid var(--gold-1); border-radius: var(--radius-xs); padding: 1px 5px; font-family: var(--font-display); flex-shrink: 0; }
/* Fixed width on ready badge prevents column from resizing when state changes */
.pready { font-size: var(--text-xs); font-weight: 700; min-width: 6rem; text-align: right; flex-shrink: 0; }
.pready.yes { color: var(--green-1); }
.pready.no  { color: var(--red-1); }

/* Right: chat */
.room-chat {
  width: 230px; flex-shrink: 0;
  display: flex; flex-direction: column;
  background: var(--panel-2);
  overflow: hidden;
}
.chat-messages {
  flex: 1; overflow-y: auto; padding: 8px 12px;
  display: flex; flex-direction: column; gap: 5px;
}
.chat-msg        { font-size: var(--text-sm); line-height: 1.4; word-break: break-word; }
.chat-msg .chat-author { font-weight: 700; margin-right: 4px; }
.chat-msg .chat-author.is-self  { color: var(--green-1); }
.chat-msg .chat-author.is-other { color: var(--red-2); }
.chat-msg .chat-kid { font-size: 0.72rem; color: var(--gold-1); font-weight: 700; letter-spacing: 1px; }
.chat-msg.system { color: var(--gray-2); font-style: italic; opacity: .7; }
.chat-input-area {
  display: flex; gap: 6px; padding: 8px; flex-shrink: 0;
  border-top: 1px solid var(--panel-6);
}
.chat-input-area .input { flex: 1; min-width: 0; }

/* Room action button colors */
#btn-ready { background-color: var(--green-3); --hover-color: var(--green-4); --top: var(--green-4); --bottom: #033a06; }
#btn-start { background-color: var(--gold-1);  --hover-color: var(--gold-2);  --top: var(--gold-2);  --bottom: var(--gold-3); }
#btn-leave { background-color: var(--panel-4); --hover-color: var(--panel-5); --top: var(--panel-5); --bottom: var(--panel-6); }
.button:disabled         { opacity: 0.35; cursor: not-allowed; pointer-events: none; }
.button:disabled::before { display: none; }

/* Form elements */
input[type="text"], input[type="number"], select, textarea {
  background: var(--panel-1);
  border: 2px solid var(--panel-6);
  color: var(--white);
  border-radius: var(--radius-sm);
  padding: 7px 10px;
  font-size: var(--text-sm);
  outline: none;
  font-family: var(--font-body);
}
input[type="text"]:focus, input[type="number"]:focus, select:focus, textarea:focus {
  border-color: var(--gold-1);
}
select option { background: var(--panel-3); }
/* number inputs — width controlled per context (e.g. .la-laps .input) */
/* Themed spin buttons for number inputs */
input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button {
  opacity: 1;
  background: var(--panel-4);
  border-left: 2px solid var(--panel-6);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  cursor: pointer;
}
input[type="number"]::-webkit-inner-spin-button:hover,
input[type="number"]::-webkit-outer-spin-button:hover {
  background: var(--panel-2);
}
label { font-size: var(--text-sm); color: var(--gray-2); display: block; margin-bottom: 4px; }

/* ── Profile page ─────────────────────────────────────────── */
.profile-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 24px; align-items: start;
}
.field-label {
  font-size: var(--text-xs); text-transform: uppercase;
  letter-spacing: 1.5px; color: var(--gray-2); margin-bottom: 6px;
}
.field-kid {
  font-size: var(--text-sm); color: var(--gold-1);
  font-weight: 700; letter-spacing: 1px; font-family: monospace;
}
.input-row { display: flex; gap: 8px; align-items: center; margin-top: 8px; }
.input-row input { flex: 1; min-width: 0; }

.skin-preview {
  width: 100%; aspect-ratio: 1; max-width: 140px;
  background: var(--panel-4); border: 2px solid var(--panel-6);
  border-radius: var(--radius-lg); overflow: hidden;
  display: flex; align-items: center; justify-content: center; margin-bottom: 10px;
}
.skin-preview img { width: 100%; height: 100%; object-fit: contain; }

.color-dot {
  width: 32px; height: 32px; border-radius: 50%;
  border: 2px solid var(--panel-6); cursor: pointer; flex-shrink: 0;
  transition: var(--transition-fast);
}
.color-dot:hover { border-color: var(--gold-1); }

.save-notice { font-size: var(--text-xs); color: var(--green-1); margin-left: 6px; opacity: 0; transition: opacity .3s; }
.save-notice.visible { opacity: 1; }

.stats-grid { display: grid; grid-template-columns: 1fr auto; gap: 24px; align-items: start; }

/* ── General stat boxes ────────────────────────────────────────────────��─── */
.kk-stat-grid {
  display: flex; flex-wrap: wrap; gap: 12px;
}
.kk-stat-box {
  background: var(--panel-3); border: 1px solid var(--panel-6);
  border-radius: var(--radius-md); padding: 12px 18px; min-width: 100px;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
}
.kk-stat-box.kk-stat-accent { border-color: var(--gold-1); }
.kk-stat-value {
  font-size: 1.5rem; font-weight: 900; color: var(--white);
  font-family: var(--font-display); line-height: 1;
}
.kk-stat-accent .kk-stat-value { color: var(--gold-1); }
.kk-stat-label {
  font-size: var(--text-xs); text-transform: uppercase; letter-spacing: 1.2px;
  color: var(--gray-2); margin-top: 4px; text-align: center;
}

/* ── Item history two-column layout ─────────────────────────────────────── */
.kk-items-split {
  display: grid; grid-template-columns: 1fr 1fr; gap: 24px; align-items: start;
}
/*.kk-items-col {}*/
.kk-items-heading {
  font-size: var(--text-xs); text-transform: uppercase; letter-spacing: 2px;
  color: var(--gray-2); margin-bottom: 10px; border-bottom: 1px solid var(--panel-6);
  padding-bottom: 6px;
}
.kk-item-name { font-size: var(--text-sm); color: var(--white); padding: 5px 10px; }
.kk-item-count { text-align: right; font-family: monospace; font-weight: 700; color: var(--green-1); padding: 5px 10px; }

.elo-card {
  background: var(--panel-3); border: 2px solid var(--panel-6);
  border-radius: var(--radius-lg); padding: 20px 28px;
  min-width: 180px; display: flex; flex-direction: column; align-items: center; gap: 4px;
}
.elo-value { font-size: 2.4rem; font-weight: 900; color: var(--gold-1); letter-spacing: 1px; font-family: var(--font-display); }
.elo-label { font-size: var(--text-xs); text-transform: uppercase; letter-spacing: 2px; color: var(--gray-2); }
.elo-games { font-size: var(--text-xs); color: var(--gray-2); margin-top: 4px; }
.elo-rank  { font-size: var(--text-xs); color: var(--gray-2); margin-top: 2px; }

/* Tables */
table { width: 100%; border-collapse: collapse; font-size: var(--text-sm); }
thead tr { background: var(--panel-3); }
thead th {
  padding: 8px 12px; text-align: left; font-size: var(--text-xs);
  text-transform: uppercase; letter-spacing: 2px; color: var(--gray-2);
  border-bottom: 1px solid var(--panel-6); white-space: nowrap;
}
thead th.center { text-align: center; }
tbody tr { border-bottom: 1px solid rgba(255,255,255,.05); }
tbody tr:hover { background: rgba(255,255,255,.03); }
tbody td { padding: 8px 12px; vertical-align: middle; }
.map-thumb { width: 72px; height: 45px; object-fit: cover; border-radius: var(--radius-sm); border: 1px solid var(--panel-6); margin-right: 8px; vertical-align: middle; }
.map-name { font-weight: 600; color: var(--white); }
.prof-rank-badge { font-size: var(--text-xs); font-weight: 700; font-family: monospace; margin-right: 5px; }
tr.prof-total-row { border-top: 2px solid var(--panel-6); background: rgba(255,255,255,.04); }
tr.prof-total-row .lap-time { font-weight: 800; }
.lap-time { text-align: center; font-family: monospace; font-size: var(--text-sm); color: var(--green-1); font-weight: 600; }
.lap-time.best { color: var(--red-1); }
.no-time { text-align: center; color: var(--gray-2); opacity: .4; }
.no-data { color: var(--gray-2); opacity: .4; padding: 24px 0; text-align: center; font-size: var(--text-sm); }

/* ── Hub / Leaderboard ─────────────────────────────────────── */
.kk-hub-main { padding: 1.5rem; flex: 1; min-height: 0; overflow-y: auto; }

/* Tab header scrollable strip */
.kk-tab-scroll { overflow-x: auto; height: auto !important; position: sticky; top: 0; z-index: 10; flex-shrink: 0; }
.kk-tab-scroll::-webkit-scrollbar { height: 4px; }

/* Special tab labels (Ranked, News, Super Cup) */
.kk-special-tab {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  letter-spacing: 2px;
  text-transform: uppercase;
}

/* News feed container */
.kk-news-feed { display: flex; flex-direction: column; gap: 12px; }

/* Tabs with thumbnails */
.tab-header .tab { flex-direction: column; gap: 4px; min-width: fit-content; }
.tab-thumb { width: 96px; height: 60px; object-fit: cover; border-radius: var(--radius-sm); border: 2px solid transparent; display: block; }
.tab-header .tab.active .tab-thumb { border-color: var(--gold-1); }
.tab-header .tab:hover .tab-thumb  { border-color: var(--panel-2); }

.board-note { font-size: var(--text-xs); color: var(--gray-2); opacity: .6; margin-bottom: 1rem; letter-spacing: 1px; text-transform: uppercase; }
#board { overflow-x: auto; }

/* Leaderboard table */
.rank { color: var(--gray-2); font-size: var(--text-sm); font-weight: 700; width: 40px; }
.rank-1 { color: #ffd700 !important; }
.rank-2 { color: #c0c0c0 !important; }
.rank-3 { color: #cd7f32 !important; }
.player-name { font-weight: 700; color: var(--white); }
.player-kid  { font-size: var(--text-xs); color: var(--gold-1); font-weight: 700; letter-spacing: 1px; margin-left: 3px; }
.cc-header   { text-align: center; color: var(--gray-2); }
.cc-header.sortable { cursor: pointer; user-select: none; }
.cc-header.sortable:hover { color: var(--white); }
.cc-header.sorted { color: var(--gold-1); }
.sort-arrow { font-size: var(--text-xs); margin-left: 3px; opacity: .6; }
.map-group { text-align: center; color: var(--gold-1); font-size: var(--text-xs); letter-spacing: 1px; border-bottom: 1px solid var(--panel-6); padding: 6px 14px; }
.divider-col { width: 1px; background: var(--panel-6); padding: 0; }
.elo-score { text-align: right; font-family: monospace; font-size: var(--text-base); color: var(--gold-1); font-weight: 700; }
.elo-games { text-align: right; font-size: var(--text-xs); color: var(--gray-2); }
.elo-wl    { text-align: right; font-size: var(--text-xs); color: var(--gray-2); white-space: nowrap; }
tr.row-you { background: rgba(255,185,20,.06); outline: 1px solid rgba(255,185,20,.15); }
tr.row-you .rank { color: var(--gold-1) !important; }
.row-ellipsis td { text-align: center; color: var(--gray-2); padding: 3px 0; font-size: var(--text-xs); letter-spacing: 2px; border: none !important; }

/* Pagination */
.pagination { display: flex; align-items: center; gap: 10px; padding: 10px 0; margin-top: 0.5rem; }
.page-btn {
  padding: 5px 14px; background: var(--panel-4); border: 2px solid var(--panel-6);
  border-radius: var(--radius-sm); color: var(--white); font-size: var(--text-xs); font-weight: 700; cursor: pointer;
  font-family: var(--font-body);
}
.page-btn:disabled { opacity: .3; cursor: not-allowed; }
.page-btn:not(:disabled):hover { border-color: var(--gold-1); color: var(--gold-1); }
.page-info { flex: 1; text-align: center; font-size: var(--text-xs); color: var(--gray-2); }

/* Replay / ghost buttons */
.replay-btn {
  display: inline-block; margin-left: 6px; padding: 1px 6px;
  background: rgba(0,40,80,.6); border: 1px solid var(--blue-4);
  border-radius: var(--radius-xs); color: var(--blue-5);
  font-size: var(--text-xs); cursor: pointer; vertical-align: middle; line-height: 1.5;
}
.replay-btn:hover:not(:disabled) { border-color: var(--blue-5); }
.replay-btn:disabled { opacity: .5; cursor: not-allowed; }

.ghost-btn {
  display: inline-block; margin-left: 3px; padding: 1px 6px;
  background: rgba(0,40,20,.6); border: 1px solid var(--green-3);
  border-radius: var(--radius-xs); color: var(--green-1);
  font-size: var(--text-xs); cursor: pointer; vertical-align: middle; line-height: 1.5;
}
.ghost-btn:hover:not(:disabled) { border-color: var(--green-1); }
.ghost-btn:disabled { opacity: .5; cursor: not-allowed; }

/* News cards */
.news-card {
  background: var(--panel-4); border: 2px solid var(--panel-6);
  border-radius: var(--radius-lg); padding: 20px 22px;
  display: flex; gap: 18px; transition: var(--transition-fast);
}
.news-card:hover { border-color: var(--panel-2); }
.news-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 8px; }
.news-meta { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.news-tag  { font-size: var(--text-xs); font-weight: 900; letter-spacing: 1.5px; text-transform: uppercase; padding: 3px 9px; border-radius: var(--radius-sm); }
.tag-update       { background: rgba(0,50,140,.5);  color: var(--blue-5);    border: 1px solid var(--blue-4); }
.tag-press        { background: rgba(60,0,100,.5);  color: var(--purple-2);  border: 1px solid var(--purple-1); }
.tag-announcement { background: rgba(80,40,0,.5);   color: var(--orange-1);  border: 1px solid rgba(200,100,0,.5); }
.tag-bugfix       { background: rgba(0,60,30,.5);   color: var(--green-1);   border: 1px solid var(--green-3); }
.tag-maintenance  { background: rgba(80,70,0,.5);   color: var(--gold-1);    border: 1px solid var(--gold-3); }
.news-date  { font-size: var(--text-xs); color: var(--gray-2); font-family: monospace; letter-spacing: .5px; }
.news-title { font-size: var(--text-md); font-weight: 800; color: var(--white); letter-spacing: .3px; line-height: 1.3; }
.news-desc  { font-size: var(--text-sm); color: var(--gray-2); line-height: 1.6; }
.news-image { width: 110px; height: 110px; flex-shrink: 0; border-radius: var(--radius-md); object-fit: cover; border: 2px solid var(--panel-6); align-self: flex-start; }

/* ── Game HUD (index.html) ─────────────────────────────────── */
html, body { width: 100%; height: 100%; overflow: hidden; }

#hud {
  position: absolute; top: 0; left: 0; width: 100%; height: 100%;
  pointer-events: none; color: var(--white);
}

#timer {
  position: absolute; top: 16px; left: 50%; transform: translateX(-50%);
  font-size: 2rem; font-weight: 700; letter-spacing: 3px;
  background: rgba(32,38,57,.85); border: 2px solid var(--panel-6);
  border-radius: var(--radius-lg); padding: 6px 22px;
  font-family: var(--font-body);
  font-variant-numeric: tabular-nums;
  min-width: 9ch; text-align: center; white-space: nowrap;
}

#lap-times {
  position: absolute; top: 16px; right: 16px;
  font-size: var(--text-base); text-align: right; line-height: 1.7;
  background: rgba(32,38,57,.85); border: 2px solid var(--panel-6);
  border-radius: var(--radius-lg); padding: 8px 14px;
  font-variant-numeric: tabular-nums; white-space: nowrap; min-width: 10ch;
}
#lap-times .lap-current { color: var(--gold-1); font-weight: 700; font-size: var(--text-md); }
#lap-times .lap-prev    { color: var(--gray-2); font-size: var(--text-xs); }

#speed-panel {
  position: absolute; bottom: 20px; right: 20px;
  background: rgba(32,38,57,.85); border: 2px solid var(--panel-6);
  border-radius: var(--radius-lg); padding: 12px 18px; min-width: 150px; text-align: center;
}
#speed-num  { font-size: 2.4rem; font-weight: 900; line-height: 1; color: var(--white); font-family: var(--font-display); }
#speed-unit { font-size: var(--text-xs); color: var(--gray-2); letter-spacing: 2px; text-transform: uppercase; margin-bottom: 10px; }
#speed-bar-bg   { width: 100%; height: 8px; background: var(--panel-4); border-radius: var(--radius-pill); overflow: hidden; }
#speed-bar-fill { height: 100%; width: 0%; border-radius: var(--radius-pill); transition: width .08s ease-out, background-color .08s ease-out; background: var(--green-1); }

#item-hud {
  position: absolute; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: rgba(32,38,57,.85); border: 2px solid var(--panel-6);
  border-radius: var(--radius-lg); padding: 8px 16px 10px; text-align: center; min-width: 90px;
}
#item-hud .item-label { font-size: var(--text-xs); color: var(--gray-2); letter-spacing: 2px; text-transform: uppercase; margin-bottom: 6px; }
#item-icon { width: 48px; height: 48px; image-rendering: pixelated; display: block; margin: 0 auto 4px; }
#item-name { font-size: var(--text-sm); font-weight: 700; color: var(--gray-2); letter-spacing: 1px; }

#minimap {
  position: absolute; bottom: 20px; right: 20px;
  width: 150px; height: 166px; pointer-events: none;
}
#minimap-circle {
  position: absolute; top: 0; left: 0;
  width: 150px; height: 150px; border-radius: 50%; overflow: hidden;
  border: 2px solid rgba(255,255,255,.18); background: rgba(0,0,0,.55);
}
#minimap-canvas { position: absolute; inset: 0; width: 100%; height: 100%; image-rendering: pixelated; }
#minimap-arrow {
  position: absolute;
  width: 0; height: 0;
  border-left: 5px solid transparent; border-right: 5px solid transparent;
  border-bottom: 12px solid var(--red-1);
  filter: drop-shadow(0 0 2px #000);
  transform-origin: 50% 66%; transform: translate(-50%, -66%);
}
#minimap-zoom {
  position: absolute; bottom: 0; left: 50%; transform: translateX(-50%);
  display: flex; gap: 4px; pointer-events: auto;
}

.mm-zoom-btn {
  width: 22px; height: 22px; padding: 0;
  background: rgba(0,0,0,.65); border: 1px solid rgba(255,255,255,.2);
  border-radius: var(--radius-sm); color: var(--white); font-size: 15px; line-height: 1;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  font-family: monospace;
}
.mm-zoom-btn:hover { background: rgba(255,255,255,.18); }

#fps-counter {
  display: none; position: absolute; top: 16px; left: 16px;
  background: rgba(0,0,0,.55); border-radius: var(--radius-xs);
  padding: 2px 7px; font-size: var(--text-xs); font-weight: 700;
  color: var(--red-1); pointer-events: none; font-family: monospace;
}

#debug-info {
  position: absolute; top: 40px; left: 16px;
  background: rgba(32,38,57,.85); border: 2px solid var(--panel-6);
  border-radius: var(--radius-lg); padding: 8px 14px;
  font-size: var(--text-xs); color: var(--gray-2); line-height: 1.8;
  pointer-events: none; white-space: pre;
}

#replay-controls {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: rgba(32,38,57,.92); border: 2px solid var(--panel-6);
  border-radius: var(--radius-lg); padding: 10px 18px;
  display: none; flex-direction: column; align-items: center; gap: 8px;
  z-index: 1500; font-family: var(--font-body); color: var(--white);
  user-select: none; pointer-events: all;
}
#replay-controls .rc-btns { display: flex; gap: 6px; align-items: center; }

.rc-btn {
  background: var(--panel-4); border: 2px solid var(--panel-6); border-radius: var(--radius-sm);
  padding: 5px 10px; font-size: var(--text-xs); color: var(--gray-1); cursor: pointer;
  font-family: var(--font-body);
}
.rc-btn:hover { border-color: var(--gold-1); color: var(--white); }

.rc-speed {
  background: var(--gold-1); color: var(--black); border-radius: var(--radius-xs);
  padding: 2px 7px; font-size: var(--text-xs); font-weight: 700;
  min-width: 36px; text-align: center;
}

.rc-time { font-size: var(--text-xs); color: var(--gray-2); font-family: monospace; letter-spacing: 1px; }

#instructions {
  position: absolute; bottom: 20px; left: 20px;
  background: rgba(32,38,57,.85); border: 2px solid var(--panel-6);
  border-radius: var(--radius-lg); padding: 10px 14px;
  font-size: var(--text-xs); color: var(--gray-2); line-height: 2;
}

.key {
  display: inline-block; background: var(--panel-4); border: 1px solid var(--panel-6);
  border-radius: var(--radius-xs); padding: 1px 6px; color: var(--gray-1);
  font-size: var(--text-xs); margin: 0 1px;
}

/* Touch controls */
#touch-controls { display: none; position: fixed; inset: 0; pointer-events: none; z-index: 9200; user-select: none; -webkit-user-select: none; }
#touch-controls.visible { display: block; }
@media (hover: none) and (pointer: coarse) { #touch-controls { display: block; } #instructions { display: none; } }
#touch-left  { position: absolute; left: 16px; bottom: 36px; pointer-events: all; touch-action: none; }
#touch-stick-bg {
  width: 120px; height: 120px;
  background: rgba(255,255,255,.05); border: 2px solid rgba(255,255,255,.12);
  border-radius: 50%; position: relative;
}
#touch-stick-knob {
  width: 48px; height: 48px;
  background: rgba(255,255,255,.2); border: 2px solid rgba(255,255,255,.35);
  border-radius: 50%; position: absolute; top: 50%; left: 50%;
  transform: translate(-50%,-50%); pointer-events: none;
}
#touch-right {
  position: absolute; right: 16px; bottom: 36px;
  display: grid; grid-template-columns: repeat(3, 68px); grid-template-rows: repeat(2, 68px);
  gap: 10px; pointer-events: auto; touch-action: none;
}
.touch-btn {
  width: 68px; height: 68px; border-radius: 50%;
  border: 2px solid rgba(255,255,255,.18); background: rgba(226,79,79,.22);
  color: rgba(255,255,255,.85); font-size: var(--text-xs); font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  user-select: none; cursor: pointer; letter-spacing: 1px;
  -webkit-tap-highlight-color: transparent;
}
.touch-btn.pressed { background: rgba(226,79,79,.55); }
#touch-accel-btn   { background: rgba(28,206,108,.25); border-color: rgba(28,206,108,.35); }
#touch-accel-btn.pressed { background: rgba(28,206,108,.55); }
#touch-brake-btn   { background: rgba(255,185,20,.25);  border-color: rgba(255,185,20,.35); }
#touch-brake-btn.pressed { background: rgba(255,185,20,.55); }
#touch-reverse-btn.pressed { background: rgba(226,79,79,.55); }
#touch-item-btn    { background: rgba(68,136,255,.22); }
#touch-item-btn.pressed  { background: rgba(68,136,255,.55); }
#touch-start-btn   { background: rgba(34,170,85,.22); }
#touch-start-btn.pressed { background: rgba(34,170,85,.55); }
#touch-menu-btn {
  position: absolute; top: 16px; right: 16px;
  width: 44px; height: 44px; border-radius: 50%;
  border: 2px solid rgba(255,255,255,.18); background: rgba(32,38,57,.75);
  color: rgba(255,255,255,.85); font-size: var(--text-xs); font-weight: 700; letter-spacing: 2px;
  display: flex; align-items: center; justify-content: center;
  pointer-events: all; user-select: none; cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

/* Responsive HUD */
@media (max-width: 600px) {
  #timer { font-size: 1.2rem; padding: 4px 12px; top: 10px; }
  #lap-times { font-size: var(--text-xs); padding: 6px 10px; top: 10px; right: 10px; }
  #speed-panel { padding: 8px 12px; min-width: 100px; bottom: 220px; right: 12px; }
  #speed-num { font-size: 1.7rem; }
  #item-hud { bottom: 220px; }
  .vm--modal#options-panel { width: calc(100vw - 24px) !important; }
  .vm--modal .opts-pane { max-height: 220px !important; }
}
@media (max-width: 380px) {
  #touch-stick-bg { width: 90px; height: 90px; }
  #touch-stick-knob { width: 36px; height: 36px; }
  #touch-right { grid-template-columns: repeat(3, 52px); grid-template-rows: repeat(2, 52px); gap: 8px; right: 10px; bottom: 20px; }
  .touch-btn { width: 52px; height: 52px; font-size: var(--text-xs); }
  #touch-left { bottom: 20px; }
  #speed-panel { bottom: 175px; }
}

/* ── In-game pause menu (Tab) ────────────────────────────── */
.game-menu-overlay {
  display: none; position: fixed; inset: 0; z-index: 9000;
  background: rgba(0,0,0,0.65);
  align-items: center; justify-content: center;
}
.game-menu-panel {
  background: var(--panel-5);
  border-top: 4px solid #4d5c8b; border-bottom: 6px solid var(--panel-6);
  border-left: 4px solid #3e4d7c; border-right: 4px solid #3e4d7c;
  padding: 2rem 2.5rem; min-width: 280px;
  display: flex; flex-direction: column; gap: 12px;
}
.game-menu-title {
  margin: 0 0 4px; color: var(--white);
  font-size: 1.5rem; font-family: var(--font-display);
  text-align: center; letter-spacing: 2px; text-transform: uppercase;
}

/* ── Finish banner ────────────────────────────────────────── */
/* #finish-overlay (full-screen flex) centers .finish-banner on all devices */
#finish-overlay {
  position: fixed;
  inset: 0;
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  box-sizing: border-box;
}
.finish-banner {
  max-height: 85dvh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 1.5rem;
  text-align: center;
  background: var(--panel-5);
  border-bottom: 6px solid var(--panel-6);
  border-top: 4px solid #4d5c8b;
  border-right: 4px solid #3e4d7c;
  border-left: 4px solid #3e4d7c;
  color: var(--white);
  font-family: var(--font-body);
  box-sizing: border-box;
}
.finish-title {
  font-size: 1.8rem;
  font-weight: 900;
  color: var(--red-1);
  letter-spacing: 2px;
  font-family: var(--font-display);
  text-transform: uppercase;
}
.finish-meta {
  margin-top: 4px;
  font-size: var(--text-xs);
  color: var(--gray-2);
  letter-spacing: 2px;
  text-transform: uppercase;
}
.finish-items-on { color: var(--green-1); }
.finish-time-total {
  margin-top: 1rem;
  font-size: 2rem;
  font-weight: 700;
  color: var(--gold-1);
  font-family: var(--font-display);
}
.finish-time-label { font-size: var(--text-xs); color: var(--gray-2); margin-top: 2px; }
.finish-laps {
  margin-top: 1rem;
  display: flex;
  flex-direction: column;
  gap: 4px;
  text-align: left;
}
.finish-lap-row {
  display: flex;
  justify-content: space-between;
  gap: 2rem;
  font-size: var(--text-sm);
  padding: 2px 0;
}
.finish-lap-label { color: var(--gray-2); }
.finish-lap-time  { color: var(--white); font-weight: 600; }
.finish-replay-section {
  margin-top: 1rem;
  border-top: 1px solid var(--panel-6);
  padding-top: 0.75rem;
  text-align: left;
}
.finish-replay-title {
  font-size: var(--text-xs);
  color: var(--gray-2);
  letter-spacing: 2px;
  text-transform: uppercase;
  margin-bottom: 8px;
}
.finish-replay-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 8px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--panel-6);
  background: var(--panel-4);
  margin-bottom: 4px;
  cursor: pointer;
}
.finish-replay-row input[type="radio"] { accent-color: var(--gold-1); flex-shrink: 0; }
.finish-replay-num  { font-size: var(--text-sm); color: var(--gray-1); }
.finish-replay-time { font-size: var(--text-sm); color: var(--white); font-weight: 600; margin-left: auto; }
.finish-replay-unavail { opacity: 0.5; cursor: default; }
.finish-replay-na   { font-size: var(--text-xs); color: var(--gray-2); font-style: italic; margin-left: auto; }
.finish-dl-btn  { width: 100%; margin-top: 6px; }
.finish-back-btn { margin-top: 1rem; width: 100%; }
.finish-action-row { display: flex; gap: 8px; margin-top: 1rem; justify-content: center; flex-wrap: wrap; }
.finish-action-row .btn { flex: 1; min-width: 100px; }
.finish-action-row .btn.btn-sm { flex: 0; min-width: unset; }

/* ── Profile page extras ──────────────────────────────────── */

/* kk-card with no padding (for tables) */
.kk-card.kk-card-raw { padding: 0; overflow-x: auto; }

/* Monospace hex color input */
.kk-mono-input { font-family: monospace; font-size: var(--text-sm); }

/* Hidden native color picker (positioned over color-dot via JS click) */
.kk-hidden-color-input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
  width: 0; height: 0;
}

/* ── z-index fixes ────────────────────────────────────────── */

/* Top-right social+options row — above page content */
.right-interface { z-index: 15; pointer-events: none; }
.kk-soc-right {
  display: flex;
  flex-direction: row;
  align-items: stretch;
  gap: 0;
  padding: 10px 10px 0;
  pointer-events: auto;
}
/* Normalize margins/radius when soc-group buttons sit in a row */
.kk-soc-right .soc-group { margin-left: 0; border-radius: 0; }
.kk-soc-right .soc-group:first-child { border-top-left-radius: 4px; border-bottom-left-radius: 4px; }
.kk-soc-right .soc-group:last-child  { border-top-right-radius: 4px; border-bottom-right-radius: 4px; }

/* Options soc-group button */
.soc-group.kk-soc-opts {
  background: var(--panel-3) !important;
  border-top-color: var(--panel-5) !important;
  border-bottom-color: var(--panel-6) !important;
}
.soc-group.kk-soc-opts:hover { background: var(--panel-4) !important; }

/* ── Lobby left-interface extras ──────────────────────────── */

/* Compact input for laps counter — inherits kirka-ui .input but smaller */
.la-laps .input {
  width: 64px;
  height: 2rem;
  padding: 0 0.4rem;
  text-align: center;
  font-size: var(--text-sm);
}

/* Header logo — centered across the full header strip, pointer-events:none so panels stay clickable */
.kk-lobby-hero {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 96px;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  z-index: 2;
}
.kk-lobby-hero-logo {
  height: 50px;
  width: auto;
  max-width: 100%;
  pointer-events: none;
}

/* Social-links row in left-interface (legacy, kept for map-editor or other uses) */
.kk-soc-row {
  display: flex;
  pointer-events: auto;
}

/* Lobby logo in avatar-info slot */
.kk-lobby-logo {
  width: 72px;
  height: 72px;
  object-fit: contain;
  filter: drop-shadow(0 1px 3px rgba(0,0,0,.5));
}

/* Player KID inside user-info card (no extra padding) */
.kk-player-kid {
  font-size: var(--text-xs);
  color: var(--gold-1);
  letter-spacing: 1px;
  font-weight: 700;
  font-family: monospace;
}

/* (room-map-info and room-laps-display moved to room layout section) */

/* Items checkbox label */
.kk-items-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: var(--text-sm);
  color: var(--gray-2);
  cursor: pointer;
  user-select: none;
}
.kk-items-label input[type="checkbox"] { accent-color: var(--gold-1); width: 14px; height: 14px; }

/* Custom map file-picker row */
.kk-file-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 4px;
}
.kk-file-label {
  cursor: pointer;
  padding: 4px 10px;
  background: var(--panel-4);
  border: 2px solid var(--panel-6);
  border-radius: var(--radius-sm);
  font-size: var(--text-xs);
  color: var(--gray-1);
  font-family: var(--font-body);
}
.kk-file-label:hover { border-color: var(--gold-1); }
.kk-file-status { font-size: var(--text-xs); color: var(--gray-2); }

/* Custom-map area section header */
.kk-custom-map-label {
  font-size: var(--text-xs);
  color: var(--gray-2);
  display: block;
  margin-bottom: 4px;
}

/* ── Responsive ───────────────────────────────────────────── */

/* ── Portrait ≤540px  +  landscape touch (≤500px tall, pointer:coarse) ───
   Covers: iPhone SE/12/13/14 Pro, Galaxy S-series, etc. in both orientations.
   Desktop and tablet (>540px landscape) are completely untouched.          */
@media (max-width: 540px),
       (orientation: landscape) and (max-height: 500px) and (pointer: coarse) {

  /* Square avatar-info: 80×80px on small devices (face viewer is 64px, still fits) */
  .avatar-info              { height: 80px !important; width: 80px !important; }
  .user-info                { height: 80px !important; width: 200px; }

  /* right-interface: fixed so it's always viewport-relative, never buried by lobby-actions z-index */
  .right-interface          { position: fixed; }

  /* soc-right: icon-only so it doesn't overlap user-info on narrow viewports */
  .kk-soc-right .soc-group span { display: none; }

  /* Left sidebar: flush with avatar panel */
  .left-icons               { top: 80px; }
  .icon-btn                 { width: 80px; }
  .icon-btn .icon           { height: 22px !important; width: 36px !important; }
  .icon-btn .text-icon      { font-size: 0.68rem; }

  /* Main content: adjust offsets to match reduced header/sidebar */
  .kk-main                  { top: 80px; left: 80px; }

  /* Social buttons: smaller icons */
  .soc-icon                 { height: 32px !important; width: 32px !important; margin: 2px; }
  .kk-soc-right             { padding: 7px 7px 0; }
  .kk-soc-right .soc-group  { padding: 6px 10px; }

  /* Logo: reduce height to fit 80px header */
  .kk-lobby-hero            { height: 80px; }
  .kk-lobby-hero-logo       { height: 38px; }

  /* lobby-actions: cap width so the card can't bleed over the left-icons strip.
     Keep right: 0 anchor from desktop — no left: needed. */
  .lobby-actions            { max-width: calc(100vw - 88px); }
}

/* ── Landscape touch only: further logo + map-thumb compaction ──────────── */
@media (orientation: landscape) and (max-height: 500px) and (pointer: coarse) {
  .kk-lobby-hero-logo       { height: 30px; }

  .map-picker-btn img,
  .map-picker-btn .map-picker-placeholder { height: 50px; }

  .lobby-actions            { padding: 0.4rem; gap: 0.3rem; }
  .la-btns .button          { font-size: var(--text-xs); }

  /* Options modal: constrain to viewport height so the tab-header is always visible.
     Flex-column lets the pane scroll while top-bar + tabs + footer stay fixed. */
  #options-overlay.vm--container {
    align-items: flex-start;
    padding: 4px;
    overflow-y: auto;
  }
  .vm--modal#options-panel {
    width: calc(100vw - 8px) !important;
    max-height: calc(100dvh - 8px);
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }
  .vm--modal#options-panel .opts-pane {
    min-height: unset !important;
    max-height: calc(100dvh - 150px) !important;
    overflow-y: auto;
  }
}

/* ── Phablets + phones: single-column content layout (profile / hub / news) */
@media (max-width: 900px) {
  .profile-grid   { grid-template-columns: 1fr; }
  .stats-grid     { grid-template-columns: 1fr; }
  .elo-card       { flex-direction: row; justify-content: space-between; align-items: center; min-width: 0; }
  .kk-items-split { grid-template-columns: 1fr; }
  .news-image   { display: none; }
  .kk-page-header { padding: 10px 14px; }
  .kk-hub-main  { padding: 1rem; }
}

/* ── Phone-width: room view single-column ─────────────────────────────── */
@media (max-width: 768px) {
  .room-body        { flex-direction: column; }
  .room-sidebar     { width: 100%; min-width: 0; flex-direction: row; flex-wrap: wrap; align-items: center; border-right: none; border-bottom: 2px solid var(--panel-6); }
  .room-sidebar .room-map-thumb { width: 80px; height: 50px; aspect-ratio: unset; }
  .chat-panel       { width: 100%; min-width: 0; }
  .room-players-panel { border-right: none; }
}

/* ── Game loading screen ──────────────────────────────────────────────── */
#loading-screen {
  position: fixed;
  inset: 0;
  background: var(--panel-3);
  z-index: 9500;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.5s ease;
}
#loading-screen.fade-out {
  opacity: 0;
  pointer-events: none;
}
#loading-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  width: min(440px, 88vw);
  text-align: center;
}
#loading-title {
  font-family: var(--font-display);
  font-size: var(--text-4xl);
  color: var(--gold-1);
  text-shadow: 0 0 28px rgba(255, 185, 20, 0.45);
  letter-spacing: 0.12em;
  margin-bottom: 0.5rem;
}
#loading-label {
  font-family: var(--font-body);
  font-size: var(--text-base);
  font-weight: 600;
  color: var(--gray-1);
  min-height: 1.5em;
  transition: opacity 0.2s;
}
#loading-bar-bg {
  width: 100%;
  height: 10px;
  background: var(--panel-6);
  border-radius: 5px;
  overflow: hidden;
}
#loading-bar-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--gold-3), var(--gold-1));
  border-radius: 5px;
  transition: width 0.35s ease;
}
#loading-quote {
  font-family: var(--font-body);
  font-size: var(--text-sm);
  color: var(--gray-2);
  font-style: italic;
  padding: 0 0.5rem;
  min-height: 1.4em;
}
