/* ╔══════════════════════════════════════════════════╗
   ║  PIXEL BATTLE — Unified Design System v2         ║
   ║  pixel.alexdorado.com.ua                         ║
   ╚══════════════════════════════════════════════════╝ */

/* ─── TOKENS ─── */
:root {
  /* Surfaces */
  --c-bg:       #0a0d13;
  --c-surface:  #11151f;
  --c-raised:   #171c28;
  --c-input:    #0d1017;
  --c-hover:    rgba(255,255,255,0.04);

  /* Borders */
  --c-border:   rgba(255,255,255,0.07);
  --c-border-h: rgba(255,255,255,0.14);

  /* Text */
  --c-text:     #e2e8f0;
  --c-dim:      #64748b;
  --c-white:    #fff;

  /* Accent palette */
  --c-accent:   #5b8def;
  --c-accent-h: #4a7de0;
  --c-glow:     rgba(91,141,239,0.15);
  --c-green:    #34d399;
  --c-gold:     #fbbf24;
  --c-red:      #f87171;
  --c-purple:   #a78bfa;

  /* Layout */
  --hdr:   46px;
  --foot:  36px;
  --side:  58px;
  --r:     8px;
  --r-sm:  5px;
  --speed: .15s;

  /* Type */
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

/* ─── RESET ─── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body, html {
  width: 100%; height: 100%;
  overflow: hidden;
  background: var(--c-bg);
  color: var(--c-text);
  font: 400 13px/1.4 var(--font);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  user-select: none;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
}

.hidden { display: none !important; }

/* ─── SCROLLBARS ─── */
::-webkit-scrollbar { width: 4px; height: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.12); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.2); }

/* ╔══════════════════════════════════════════════════╗
   ║  HEADER                                          ║
   ╚══════════════════════════════════════════════════╝ */
.hdr {
  position: fixed; top: 0; left: 0; right: 0;
  height: var(--hdr);
  background: rgba(11,13,19,0.85);
  backdrop-filter: blur(24px) saturate(1.6);
  -webkit-backdrop-filter: blur(24px) saturate(1.6);
  border-bottom: 1px solid var(--c-border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 12px;
  z-index: 100;
  gap: 6px;
}

/* Brand */
.hdr__brand {
  display: flex; align-items: center; gap: 7px;
  text-decoration: none; flex-shrink: 0;
}
.hdr__logo { color: var(--c-accent); }
.hdr__name {
  font-size: 12px; font-weight: 800; color: var(--c-white);
  letter-spacing: .6px;
}
.hdr__name--accent { color: var(--c-accent); }

/* Chips (badges) */
.hdr__center { display: flex; align-items: center; gap: 5px; }

.chip {
  display: inline-flex; align-items: center; gap: 4px;
  height: 24px; padding: 0 7px;
  background: var(--c-hover);
  border: 1px solid var(--c-border);
  border-radius: 12px;
  font-size: 11px; font-weight: 600;
  white-space: nowrap;
  transition: border-color var(--speed);
}
.chip:hover { border-color: var(--c-border-h); }

.chip--green { color: var(--c-green); }
.chip--purple { color: var(--c-purple); }

.chip__dot {
  width: 5px; height: 5px;
  background: var(--c-green);
  border-radius: 50%;
  box-shadow: 0 0 4px var(--c-green);
  animation: dot-pulse 2s ease-in-out infinite;
}
@keyframes dot-pulse {
  0%,100% { opacity:.4; }
  50% { opacity:1; }
}

.chip__tag {
  background: var(--c-purple);
  color: var(--c-white);
  padding: 1px 4px; border-radius: 4px;
  font-size: 9px; font-weight: 700;
}

/* Buttons */
.hdr__actions { display: flex; align-items: center; gap: 3px; }

.icon-btn {
  width: 30px; height: 30px;
  display: flex; align-items: center; justify-content: center;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--r-sm);
  color: var(--c-dim);
  cursor: pointer;
  transition: all var(--speed);
}
.icon-btn:hover {
  color: var(--c-text);
  background: var(--c-hover);
  border-color: var(--c-border);
}
.icon-btn.active {
  color: var(--c-accent);
  background: var(--c-glow);
  border-color: rgba(91,141,239,0.3);
}

.pill-btn {
  display: inline-flex; align-items: center; gap: 5px;
  height: 28px; padding: 0 10px;
  background: var(--c-accent);
  color: var(--c-white);
  border: none; border-radius: 14px;
  font: 600 11px var(--font);
  cursor: pointer;
  transition: background var(--speed);
}
.pill-btn:hover { background: var(--c-accent-h); }

/* Dropdown */
.dropdown { position: relative; }
.dropdown__menu {
  display: none;
  position: absolute; top: calc(100% + 6px); right: 0;
  min-width: 190px;
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--r);
  box-shadow: 0 12px 40px rgba(0,0,0,.55);
  padding: 4px; z-index: 200;
}
.dropdown.open .dropdown__menu { display: block; }
.dropdown__item {
  display: flex; flex-direction: column;
  padding: 7px 10px; border-radius: var(--r-sm);
  color: var(--c-text); text-decoration: none;
  transition: background var(--speed);
}
.dropdown__item:hover { background: var(--c-hover); }
.dropdown__item strong { font-size: 11px; color: var(--c-accent); }
.dropdown__item small { font-size: 9.5px; color: var(--c-dim); margin-top: 1px; }

/* ╔══════════════════════════════════════════════════╗
   ║  PALETTE SIDEBAR (Desktop)                       ║
   ╚══════════════════════════════════════════════════╝ */
.palette {
  position: fixed;
  top: calc(var(--hdr) + 8px);
  left: 8px;
  bottom: calc(var(--foot) + 8px);
  width: var(--side);
  background: rgba(11,13,19,0.85);
  backdrop-filter: blur(20px);
  border: 1px solid var(--c-border);
  border-radius: var(--r);
  display: flex; flex-direction: column;
  padding: 5px;
  z-index: 90;
  overflow: hidden;
}

.palette__label {
  text-align: center;
  font-size: 7.5px; font-weight: 700;
  color: var(--c-dim);
  letter-spacing: 1.4px;
  text-transform: uppercase;
  padding-bottom: 4px;
  margin-bottom: 3px;
  border-bottom: 1px solid var(--c-border);
  flex-shrink: 0;
}

.palette__grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 3px;
  overflow-y: auto;
  flex: 1;
  scrollbar-width: none;
}
.palette__grid::-webkit-scrollbar { width: 0; }

.color-swatch {
  width: 20px; height: 20px;
  border-radius: 4px;
  border: 1.5px solid rgba(0,0,0,.55);
  cursor: pointer;
  position: relative;
  transition: transform var(--speed), box-shadow var(--speed);
  display: flex; align-items: center; justify-content: center;
  margin: 0 auto; flex-shrink: 0;
}
.color-swatch:hover {
  transform: scale(1.15);
  z-index: 5;
}
.color-swatch.active {
  border: 2px solid var(--c-white);
  box-shadow: 0 0 0 1px var(--c-accent), 0 0 8px var(--c-glow);
  z-index: 10;
  transform: scale(1.1);
}
.color-swatch.active::after {
  content: ''; width: 4px; height: 4px;
  background: var(--c-white); border-radius: 50%;
  box-shadow: 0 0 3px rgba(0,0,0,.8);
}

.color-key {
  font-size: 6px; font-weight: 700;
  color: rgba(255,255,255,.8);
  text-shadow: 0 1px 2px rgba(0,0,0,.9);
  pointer-events: none;
  position: absolute; bottom: 0; right: 1px;
}

/* ╔══════════════════════════════════════════════════╗
   ║  CANVAS VIEWPORT                                 ║
   ╚══════════════════════════════════════════════════╝ */
.canvas-area {
  position: absolute;
  top: var(--hdr); bottom: var(--foot);
  left: 0; right: 0;
  background: #050710;
  cursor: crosshair;
  overflow: hidden;
  touch-action: none;
}

#pixel-canvas {
  position: absolute;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  touch-action: none;
}

/* Coords chip */
.coords {
  position: absolute;
  bottom: 8px; left: calc(var(--side) + 18px);
  display: flex; align-items: center; gap: 6px;
  height: 24px; padding: 0 8px;
  background: rgba(10,13,19,.85);
  backdrop-filter: blur(12px);
  border: 1px solid var(--c-border);
  border-radius: 12px;
  font-size: 10px; font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--c-dim);
  pointer-events: none; z-index: 50;
}
.coords__color {
  width: 8px; height: 8px;
  border-radius: 2px;
  border: 1px solid rgba(255,255,255,.25);
  background: var(--c-white);
}

/* Tool buttons panel */
.tools {
  position: absolute;
  bottom: 8px; right: 10px;
  display: flex; flex-direction: column; gap: 2px;
  z-index: 50;
}
.tools__sep {
  height: 1px; margin: 3px 4px;
  background: var(--c-border);
}

.tool-btn {
  width: 30px; height: 30px;
  display: flex; align-items: center; justify-content: center;
  background: rgba(10,13,19,.85);
  backdrop-filter: blur(12px);
  border: 1px solid var(--c-border);
  color: var(--c-dim);
  border-radius: var(--r-sm);
  cursor: pointer;
  transition: all var(--speed);
}
.tool-btn:hover {
  color: var(--c-text);
  border-color: var(--c-border-h);
}
.tool-btn.active {
  color: var(--c-accent);
  border-color: var(--c-accent);
  background: var(--c-glow);
}
.tool-btn--sm {
  width: 24px; height: 24px;
  font-size: 12px; font-weight: 700;
  backdrop-filter: none;
  background: var(--c-surface);
}

/* ╔══════════════════════════════════════════════════╗
   ║  STATUS BAR (Footer)                             ║
   ╚══════════════════════════════════════════════════╝ */
.status {
  position: fixed; bottom: 0; left: 0; right: 0;
  height: var(--foot);
  background: rgba(11,13,19,0.85);
  backdrop-filter: blur(20px);
  border-top: 1px solid var(--c-border);
  display: flex; flex-direction: column; justify-content: center;
  padding: 0 14px; gap: 3px;
  z-index: 100;
}

.status__row {
  display: flex; align-items: center; justify-content: space-between;
  font-size: 10px;
}
.status__label { font-weight: 700; color: var(--c-green); }
.status.waiting .status__label { color: var(--c-gold); }
.status__xp { color: var(--c-dim); font-size: 10px; }

.status__bar {
  width: 100%; height: 3px;
  background: rgba(255,255,255,.06);
  border-radius: 2px; overflow: hidden;
}
.status__fill {
  height: 100%; width: 100%;
  background: var(--c-green);
  border-radius: 2px;
  transition: width .1s linear;
}
.status.waiting .status__fill { background: var(--c-gold); }

/* ╔══════════════════════════════════════════════════╗
   ║  UNIFIED DIALOG SYSTEM                           ║
   ╚══════════════════════════════════════════════════╝ */
.overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,.65);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 1000;
  align-items: center; justify-content: center;
  padding: 16px;
}
.overlay.open { display: flex; }

.dialog {
  position: relative;
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: 12px;
  width: 100%; max-width: 400px;
  max-height: 82vh;
  padding: 20px;
  box-shadow: 0 0 0 1px rgba(255,255,255,.02), 0 24px 64px rgba(0,0,0,.5);
  display: flex; flex-direction: column;
  overflow-y: auto;
  overflow-x: hidden;
}
.dialog--wide { max-width: 680px; }

.dialog::-webkit-scrollbar { width: 5px; }
.dialog::-webkit-scrollbar-track { background: rgba(255,255,255,0.03); border-radius: 0 12px 12px 0; }
.dialog::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 4px; }
.dialog::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.18); }
.dialog { scrollbar-width: thin; scrollbar-color: rgba(255,255,255,0.1) transparent; }

/* Template compact grid */
.tpl-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}
.tpl-grid .field { margin-bottom: 6px; }
.tpl-grid .field > input {
  width: 100%;
  padding: 0 6px;
  font-size: 12px;
  text-align: center;
}
.tpl-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 8px;
  align-items: end;
}
.tpl-row .field { margin-bottom: 0; }

.dialog__close {
  position: absolute; top: 12px; right: 12px;
  width: 26px; height: 26px;
  display: flex; align-items: center; justify-content: center;
  background: var(--c-hover);
  border: 1px solid var(--c-border);
  border-radius: var(--r-sm);
  color: var(--c-dim);
  font-size: 16px; line-height: 1;
  cursor: pointer; z-index: 10;
  transition: all var(--speed);
}
.dialog__close:hover { color: var(--c-white); background: rgba(255,255,255,.08); }

.dialog__title {
  font-size: 15px; font-weight: 700;
  margin-bottom: 2px; padding-right: 30px;
}
.dialog__hint {
  font-size: 11px; color: var(--c-dim);
  margin-bottom: 14px; line-height: 1.5;
}

/* Dialog Tabs */
.dialog__tabs {
  display: flex; gap: 0;
  border-bottom: 1px solid var(--c-border);
  margin-bottom: 14px;
}
.dialog__tab {
  flex: 1; padding: 7px 0;
  background: none; border: none;
  border-bottom: 2px solid transparent;
  color: var(--c-dim);
  font: 600 11.5px var(--font);
  cursor: pointer;
  transition: color var(--speed);
  text-align: center;
}
.dialog__tab:hover { color: var(--c-text); }
.dialog__tab.active {
  color: var(--c-accent);
  border-bottom-color: var(--c-accent);
}

/* ─── UNIFIED BUTTONS ─── */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: 5px; height: 32px; padding: 0 12px;
  border: 1px solid var(--c-border);
  border-radius: var(--r-sm);
  font: 600 12px var(--font);
  cursor: pointer;
  transition: all var(--speed);
  white-space: nowrap;
  background: var(--c-hover);
  color: var(--c-text);
}
.btn:hover { background: rgba(255,255,255,.08); border-color: var(--c-border-h); }

.btn--accent {
  background: var(--c-accent); color: var(--c-white);
  border-color: transparent;
}
.btn--accent:hover { background: var(--c-accent-h); }

.btn--ghost {
  background: transparent; color: var(--c-dim);
  border-color: var(--c-border);
}
.btn--ghost:hover { color: var(--c-text); background: var(--c-hover); }

.btn--danger { background: rgba(248,113,113,.12); color: var(--c-red); border-color: rgba(248,113,113,.2); }
.btn--danger:hover { background: rgba(248,113,113,.2); }

.btn--block { width: 100%; justify-content: center; }

/* ─── UNIFIED FORM FIELDS ─── */
.field {
  display: flex; flex-direction: column; gap: 4px;
  margin-bottom: 12px;
}
.field > span {
  font-size: 10.5px; font-weight: 600;
  color: var(--c-dim); letter-spacing: .3px;
  text-transform: uppercase;
}
.field > input, .field > textarea {
  height: 34px; padding: 0 10px;
  background: var(--c-input);
  border: 1px solid var(--c-border);
  border-radius: var(--r-sm);
  color: var(--c-white);
  font: 400 12.5px var(--font);
  outline: none;
  transition: border-color var(--speed);
}
.field > input:focus, .field > textarea:focus { border-color: var(--c-accent); }
.field > input::placeholder { color: var(--c-dim); opacity: .6; }

.field__error {
  color: var(--c-red); font-size: 11px;
  margin-bottom: 6px; display: none;
  min-height: 0;
}

/* Auth form toggling */
.auth-form { display: none; }
.auth-form.active { display: block; }

/* ─── UNIFIED TABLES ─── */
.table-wrap {
  overflow-y: auto; overflow-x: hidden;
  max-height: 320px;
  border: 1px solid var(--c-border);
  border-radius: var(--r);
  flex: 1;
}

.tbl {
  width: 100%; border-collapse: collapse; text-align: left;
}
.tbl th {
  position: sticky; top: 0; z-index: 1;
  background: var(--c-raised);
  padding: 7px 10px;
  font-size: 9.5px; font-weight: 700;
  color: var(--c-dim);
  letter-spacing: .4px; text-transform: uppercase;
}
.tbl td {
  padding: 7px 10px;
  border-top: 1px solid var(--c-border);
  font-size: 12px;
}
.tbl tr:hover td { background: var(--c-hover); }

/* Clan tag inline */
.clan-tag-badge {
  display: inline-block;
  padding: 1px 4px; border-radius: 3px;
  font-size: 9px; font-weight: 700;
  color: var(--c-white);
  background: var(--c-accent);
  margin-right: 2px;
}

/* ╔══════════════════════════════════════════════════╗
   ║  TIME MACHINE                                    ║
   ╚══════════════════════════════════════════════════╝ */
.tm-view {
  width: 100%; aspect-ratio: 1;
  max-height: 320px;
  background: #050710;
  border: 1px solid var(--c-border);
  border-radius: var(--r);
  overflow: hidden;
  margin-bottom: 10px;
  position: relative;
  cursor: grab;
}
.tm-view:active { cursor: grabbing; }
.tm-view__zoom {
  position: absolute; top: 6px; right: 6px;
  display: flex; flex-direction: column; gap: 2px;
  z-index: 10;
}

#tm-canvas {
  width: 100%; height: 100%;
  object-fit: contain;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

.tm-controls { display: flex; flex-direction: column; gap: 6px; }
.tm-controls__scrub {
  display: flex; align-items: center; gap: 8px;
  font-size: 10.5px; font-weight: 600;
  color: var(--c-accent);
}
.tm-controls__row {
  display: flex; align-items: center; gap: 6px;
}
.tm-controls__count { font-size: 10px; color: var(--c-dim); margin-left: auto; }

/* Range input */
.range-input {
  flex: 1; height: 4px;
  -webkit-appearance: none; appearance: none;
  background: rgba(255,255,255,.08);
  border-radius: 2px; outline: none;
  cursor: pointer;
}
.range-input::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--c-accent);
  border: 2px solid var(--c-white);
  cursor: pointer;
  box-shadow: 0 0 4px rgba(0,0,0,.4);
}
.range-input::-moz-range-thumb {
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--c-accent);
  border: 2px solid var(--c-white);
  cursor: pointer;
}

/* ╔══════════════════════════════════════════════════╗
   ║  RESPONSIVE — MOBILE (≤ 768px)                   ║
   ╚══════════════════════════════════════════════════╝ */
@media (max-width: 768px) {
  :root {
    --hdr:  42px;
    --foot: 32px;
    --side: 0px;
  }

  .hdr { padding: 0 6px; gap: 3px; }
  .hdr__name { font-size: 10.5px; }
  .hdr__brand { gap: 5px; }
  .hdr__logo { width: 16px; height: 16px; }
  .hdr__actions { gap: 1px; }

  .chip { height: 22px; padding: 0 5px; font-size: 10px; }
  .chip__dot { width: 4px; height: 4px; }

  .icon-btn { width: 28px; height: 28px; }
  .pill-btn { height: 26px; padding: 0 8px; font-size: 10px; }

  /* Palette → bottom horizontal strip */
  .palette {
    position: fixed; top: auto; left: 0; right: 0;
    bottom: var(--foot);
    width: 100%; height: 42px;
    border-radius: 0;
    border-left: 0; border-right: 0;
    padding: 3px 5px;
    flex-direction: row; align-items: center;
  }
  .palette__label { display: none; }
  .palette__grid {
    display: flex; flex-direction: row;
    gap: 4px; overflow-x: auto; overflow-y: hidden;
    width: 100%; height: 100%;
    padding: 0 2px; align-items: center;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .color-swatch {
    min-width: 28px; width: 28px; height: 28px;
    border-radius: 5px; flex-shrink: 0;
  }
  .color-key { font-size: 5.5px; }

  .canvas-area {
    top: var(--hdr);
    bottom: calc(42px + var(--foot));
  }

  .coords { left: 6px; bottom: 6px; font-size: 9px; height: 22px; padding: 0 6px; }
  .tools { bottom: 6px; right: 6px; }
  .tool-btn { width: 30px; height: 30px; }

  .status { padding: 0 8px; }
  .status__row { font-size: 9px; }

  .dialog { padding: 16px; max-width: 96%; border-radius: 10px; }
  .dialog--wide { max-width: 96%; }
  .dialog__title { font-size: 14px; }
  .dialog__tab { font-size: 11px; }
  
  .tpl-grid { grid-template-columns: 1fr 1fr; }
  .tpl-row { grid-template-columns: 1fr; gap: 8px; }
}

/* ─── Small Phones ─── */
@media (max-width: 400px) {
  .hdr { padding: 0 4px; }
  .hdr__center { gap: 3px; }
  .hdr__name { font-size: 9.5px; letter-spacing: .3px; }
  .chip { padding: 0 4px; font-size: 9px; }
  .icon-btn { width: 26px; height: 26px; }
  .pill-btn { height: 24px; padding: 0 6px; font-size: 9px; }
  .color-swatch { min-width: 26px; width: 26px; height: 26px; }
}
