@font-face {
  font-family: "AlmaraiLocal";
  src: url("./fonts/Almarai-ExtraBold.ttf") format("truetype");
  font-weight: 800;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "LalezarLocal";
  src: url("./fonts/Lalezar-Regular.ttf") format("truetype");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

:root {
  --bg: #0b101a;
  --glass: rgba(11, 16, 26, 0.78);
  --glass-strong: rgba(13, 19, 31, 0.94);
  --border: rgba(255, 255, 255, 0.14);
  --border-gold: rgba(245, 185, 66, 0.42);
  --text: #f8fafc;
  --muted: #cbd5e1;
  --gold: #f5b942;
  --gold-deep: #d98218;
  --cyan: #22d3ee;
  --red: #ef4444;
  --green: #22c55e;
  --radius: 16px;
  --shadow: 0 12px 32px rgba(0, 0, 0, 0.45);
  --font-ui: "AlmaraiLocal", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-display: "LalezarLocal", "AlmaraiLocal", system-ui, sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Stage & Poster */
.stage {
  position: relative;
  width: 100vw;
  height: 100dvh;
  overflow: hidden;
  background: radial-gradient(circle at 50% 25%, #2d3c52 0%, #0b101a 78%);
}

.poster-img,
.scene-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

.poster-img {
  object-fit: cover;
  z-index: 1;
  transition: opacity 420ms ease-out;
}

.poster-img.is-hidden {
  opacity: 0;
  pointer-events: none;
}

.scene-canvas {
  z-index: 2;
  touch-action: none;
  cursor: grab;
}

.scene-canvas:active {
  cursor: grabbing;
}

/* Loader Pill */
.loader-pill {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 12;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 10px 18px;
  border-radius: 999px;
  background: var(--glass-strong);
  border: 1px solid var(--border-gold);
  box-shadow: var(--shadow);
  font-size: 0.9rem;
  backdrop-filter: blur(12px);
  transition: opacity 280ms ease-out, transform 280ms ease-out;
}

.loader-pill.is-done {
  opacity: 0;
  transform: translate(-50%, -44%);
  pointer-events: none;
}

.loader-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--cyan);
  box-shadow: 0 0 12px var(--cyan);
  animation: pulse 1.1s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { transform: scale(0.85); opacity: 0.65; }
  50% { transform: scale(1.2); opacity: 1; }
}

/* Top HUD */
.hud-top {
  position: absolute;
  top: 0;
  inset-inline: 0;
  z-index: 10;
  padding: calc(10px + env(safe-area-inset-top)) 12px 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: 560px;
  margin-inline: auto;
  pointer-events: none;
}

.hud-top > * {
  pointer-events: auto;
}

.hud-top-row {
  display: flex;
  align-items: stretch;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}

.brand-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 13px;
  border-radius: 14px;
  background: var(--glass);
  border: 1px solid var(--border);
  backdrop-filter: blur(12px);
  font-family: var(--font-display);
  font-size: 1.05rem;
  letter-spacing: 0.2px;
  box-shadow: var(--shadow);
}

.live-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--red);
  box-shadow: 0 0 10px var(--red);
  animation: pulse 1.4s ease-in-out infinite;
}

.countdown-card {
  flex: 1;
  min-width: 205px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 7px 12px;
  border-radius: 14px;
  background: linear-gradient(135deg, rgba(20, 26, 40, 0.88), rgba(38, 22, 16, 0.86));
  border: 1px solid var(--border-gold);
  backdrop-filter: blur(12px);
  box-shadow: var(--shadow);
}

.countdown-label {
  font-size: 0.72rem;
  line-height: 1.25;
  color: #fde68a;
}

.countdown-value {
  font-variant-numeric: tabular-nums;
  font-size: 1.02rem;
  font-weight: 800;
  color: #ffffff;
  background: rgba(239, 68, 68, 0.22);
  border: 1px solid rgba(239, 68, 68, 0.55);
  padding: 4px 9px;
  border-radius: 10px;
  white-space: nowrap;
}

/* Search Bar */
.search-form {
  display: flex;
  gap: 6px;
  padding: 5px;
  border-radius: 14px;
  background: var(--glass);
  border: 1px solid var(--border);
  backdrop-filter: blur(12px);
  box-shadow: var(--shadow);
}

.search-input {
  flex: 1;
  min-width: 0;
  border: 0;
  outline: none;
  background: transparent;
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 0.9rem;
  padding: 7px 10px;
}

.search-input::placeholder {
  color: #94a3b8;
}

.search-btn {
  border: 0;
  border-radius: 10px;
  padding: 0 16px;
  min-height: 36px;
  background: linear-gradient(135deg, var(--cyan), #0ea5e9);
  color: #06131c;
  font-family: var(--font-ui);
  font-size: 0.86rem;
  font-weight: 800;
  cursor: pointer;
  transition: transform 120ms ease-out;
}

.search-btn:active {
  transform: scale(0.96);
}

.search-feedback {
  margin: 0;
  min-height: 0;
  font-size: 0.78rem;
  color: #fde68a;
  text-align: center;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.9);
}

.search-feedback:empty {
  display: none;
}

/* Filter Bar */
.filter-bar {
  display: flex;
  gap: 5px;
  justify-content: space-between;
  overflow-x: auto;
  scrollbar-width: none;
  padding-bottom: 2px;
}

.filter-bar::-webkit-scrollbar {
  display: none;
}

.chip {
  flex: 1 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 6px 8px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--glass);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 0.72rem;
  cursor: pointer;
  backdrop-filter: blur(10px);
  transition: background-color 160ms ease-out, border-color 160ms ease-out, transform 120ms ease-out;
}

.chip:active {
  transform: scale(0.96);
}

.chip.is-active {
  background: rgba(34, 211, 238, 0.2);
  border-color: var(--cyan);
  color: #ffffff;
}

.chip-count {
  padding: 1px 6px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.14);
  font-size: 0.68rem;
}

.chip-count--ok { background: rgba(34, 197, 94, 0.25); color: #86efac; }
.chip-count--bad { background: rgba(239, 68, 68, 0.28); color: #fca5a5; }
.chip-count--open { background: rgba(34, 211, 238, 0.25); color: #a5f3fc; }

/* Preview Active Banner */
.preview-banner {
  position: absolute;
  bottom: calc(76px + env(safe-area-inset-bottom));
  inset-inline: 12px;
  z-index: 11;
  max-width: 540px;
  margin-inline: auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  padding: 10px 14px;
  border-radius: 16px;
  background: linear-gradient(135deg, rgba(13, 25, 38, 0.94), rgba(20, 38, 52, 0.94));
  border: 1px solid rgba(34, 211, 238, 0.55);
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
}

.preview-banner[hidden] {
  display: none;
}

.preview-banner-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.preview-badge {
  font-size: 0.68rem;
  color: var(--cyan);
}

.preview-hint {
  font-size: 0.72rem;
  color: var(--muted);
}

.preview-banner-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

/* Bottom Dock */
.hud-bottom {
  position: absolute;
  bottom: 0;
  inset-inline: 0;
  z-index: 10;
  padding: 0 12px calc(12px + env(safe-area-inset-bottom));
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  max-width: 560px;
  margin-inline: auto;
  pointer-events: none;
}

.hud-bottom > * {
  pointer-events: auto;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 44px;
  padding: 0 15px;
  border-radius: 14px;
  border: 1px solid transparent;
  font-family: var(--font-ui);
  font-size: 0.85rem;
  font-weight: 800;
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
  box-shadow: var(--shadow);
  transition: transform 120ms ease-out, filter 160ms ease-out;
}

.btn:active {
  transform: scale(0.96);
}

.btn--primary {
  flex: 1.25;
  background: linear-gradient(135deg, #22d3ee, #0284c7);
  color: #04131c;
}

.btn--gold {
  flex: 1;
  background: linear-gradient(135deg, var(--gold), var(--gold-deep));
  color: #160c02;
}

.btn--glass {
  background: var(--glass);
  border-color: var(--border);
  color: var(--text);
  backdrop-filter: blur(12px);
}

.btn--ghost {
  background: rgba(255, 255, 255, 0.08);
  border-color: var(--border);
  color: var(--text);
}

.btn--sm {
  min-height: 36px;
  padding: 0 12px;
  font-size: 0.78rem;
  border-radius: 11px;
}

.btn--full {
  width: 100%;
}

/* Native <dialog> */
.tactical-dialog {
  width: min(92vw, 420px);
  max-height: 88dvh;
  overflow-y: auto;
  padding: 18px;
  border-radius: 20px;
  border: 1px solid var(--border-gold);
  background: var(--glass-strong);
  color: var(--text);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.72);
  backdrop-filter: blur(18px);
}

.tactical-dialog::backdrop {
  background: rgba(4, 8, 16, 0.64);
  backdrop-filter: blur(4px);
}

.dialog-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.dialog-title {
  margin: 6px 0 0;
  font-family: var(--font-display);
  font-size: 1.5rem;
  line-height: 1.15;
}

.dialog-close {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
  font-size: 1.35rem;
  line-height: 1;
  cursor: pointer;
}

.status-pill {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.74rem;
  background: rgba(34, 197, 94, 0.22);
  border: 1px solid rgba(34, 197, 94, 0.5);
  color: #86efac;
}

.status-pill--destroyed {
  background: rgba(239, 68, 68, 0.22);
  border-color: rgba(239, 68, 68, 0.55);
  color: #fca5a5;
}

.status-pill--open {
  background: rgba(34, 211, 238, 0.2);
  border-color: rgba(34, 211, 238, 0.5);
  color: #a5f3fc;
}

.dialog-body {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 16px;
}

.info-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border);
}

.info-label {
  font-size: 0.78rem;
  color: var(--muted);
}

.info-val {
  font-size: 0.9rem;
}

.info-sub {
  margin: 0;
  font-size: 0.8rem;
  color: var(--muted);
  line-height: 1.5;
}

.info-note {
  margin: 0;
  padding: 10px 12px;
  border-radius: 12px;
  background: rgba(245, 185, 66, 0.1);
  border: 1px solid rgba(245, 185, 66, 0.3);
  font-size: 0.84rem;
  line-height: 1.5;
  color: #fef3c7;
}

.dialog-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* Preview Form */
.preview-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.field-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field-label {
  font-size: 0.8rem;
  color: #e2e8f0;
}

.field-input {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.07);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 0.94rem;
}

.field-input option {
  background: #0f172a;
  color: #f8fafc;
}

.field-input:focus {
  outline: 2px solid var(--cyan);
  outline-offset: 1px;
}

.field-error {
  margin: 0;
  font-size: 0.76rem;
  color: #fca5a5;
}

.field-error:empty {
  display: none;
}

.defense-fieldset {
  margin: 0;
  padding: 0;
  border: 0;
}

.defense-fieldset legend {
  margin-bottom: 8px;
}

.defense-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 7px;
}

.defense-option {
  position: relative;
  cursor: pointer;
}

.defense-option input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.defense-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 3px;
  padding: 10px 6px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.05);
  font-size: 0.76rem;
  transition: border-color 150ms ease-out, background-color 150ms ease-out;
}

.defense-card small {
  font-size: 0.66rem;
  color: var(--muted);
}

.defense-option input:checked + .defense-card--1 {
  border-color: #ef4444;
  background: rgba(239, 68, 68, 0.2);
}

.defense-option input:checked + .defense-card--2 {
  border-color: #f59e0b;
  background: rgba(245, 158, 11, 0.2);
}

.defense-option input:checked + .defense-card--3 {
  border-color: #22d3ee;
  background: rgba(34, 211, 238, 0.2);
}

.local-disclaimer {
  margin: 0;
  padding: 8px 10px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.05);
  font-size: 0.72rem;
  line-height: 1.45;
  color: var(--muted);
}

@media (max-width: 420px) {
  .brand-chip {
    font-size: 0.94rem;
    padding: 7px 11px;
  }
  .btn {
    padding: 0 11px;
    font-size: 0.79rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  .loader-dot,
  .live-dot {
    animation: none;
  }
  .poster-img {
    transition: none;
  }
}
