:root {
  --bg: #0f172a;
  --panel: #111827;
  --panel-soft: #1f2937;
  --line: #334155;
  --text: #e5e7eb;
  --muted: #94a3b8;
  --accent: #22c55e;
  --danger: #ef4444;
  --cell: 24px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
  background: radial-gradient(circle at top, #1e293b 0%, #020617 60%);
  color: var(--text);
}

body.fan-showing {
  transition: background-color 0.3s ease;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
  border: 1px solid var(--line);
  background: var(--panel-soft);
  color: var(--text);
  padding: 0.6rem 0.85rem;
  border-radius: 10px;
}

button.primary {
  background: var(--accent);
  border-color: transparent;
  color: #052e16;
  font-weight: 700;
}

button.danger {
  background: var(--danger);
  border-color: transparent;
  color: white;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.6;
}

input,
select {
  width: 100%;
  border: 1px solid var(--line);
  background: #020617;
  color: var(--text);
  border-radius: 10px;
  padding: 0.7rem 0.8rem;
}

input[type="number"] {
  padding: 0.8rem 0.85rem;
  font-size: 1rem;
}

.page {
  max-width: 1280px;
  margin: 0 auto;
  padding: 1.5rem;
}

.landing-page {
  display: grid;
  gap: 1rem;
}

.hero {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: center;
  margin-bottom: 1.5rem;
}

.hero h1 {
  margin: 0;
  font-size: clamp(1.8rem, 4vw, 3rem);
}

.hero p,
.muted {
  color: var(--muted);
}

.hero-tools {
  display: flex;
  align-items: stretch;
  gap: 1rem;
  flex-wrap: wrap;
}

.show-pill {
  display: grid;
  gap: 0.3rem;
  min-height: 76px;
  min-width: 150px;
  padding: 0.65rem 0.9rem;
  border: 1px solid rgba(148, 163, 184, 0.15);
  border-radius: 12px;
  background: rgba(2, 6, 23, 0.35);
  align-content: center;
}

.language-switch {
  display: grid;
  gap: 0.35rem;
  min-width: 150px;
  min-height: 76px;
  padding: 0.65rem 0.9rem;
  border: 1px solid rgba(148, 163, 184, 0.15);
  border-radius: 12px;
  background: rgba(2, 6, 23, 0.35);
  align-content: center;
}

#exit-admin {
  min-height: 76px;
  min-width: 150px;
  padding: 0.65rem 0.9rem;
  border-radius: 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.landing-hero {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
}

.landing-brand {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.landing-logo {
  width: clamp(84px, 14vw, 132px);
  height: auto;
  border-radius: 22px;
  border: 1px solid rgba(148, 163, 184, 0.2);
  box-shadow: 0 18px 60px rgba(0, 0, 0, 0.28);
}

.eyebrow {
  margin: 0 0 0.35rem;
  font-size: 0.82rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: #86efac;
}

.landing-subtitle {
  max-width: 720px;
}

.landing-grid {
  display: grid;
  grid-template-columns: 1.2fr 0.8fr;
  gap: 1rem;
}

.landing-panel h2 {
  margin-top: 0;
}

.landing-steps {
  margin: 0;
  padding-left: 1.2rem;
  display: grid;
  gap: 0.65rem;
}

.hidden {
  display: none !important;
}

.modal-shell {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 1rem;
  background: rgba(2, 6, 23, 0.74);
  z-index: 120;
}

.modal-card {
  width: min(100%, 640px);
  padding: 1rem;
  border-radius: 18px;
  background: rgba(15, 23, 42, 0.98);
  border: 1px solid rgba(148, 163, 184, 0.18);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.3);
}

.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: 1rem;
}

.share-link-grid {
  margin-top: 0.5rem;
}

.button-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  border: 1px solid var(--line);
  background: var(--panel-soft);
  color: var(--text);
  padding: 0.6rem 0.85rem;
  border-radius: 10px;
}

.fan-hero-tools {
  justify-content: space-between;
  margin-bottom: 1rem;
}

.share-qr-section {
  margin-top: 1rem;
}

.share-qr-wrap {
  display: grid;
  gap: 0.9rem;
  justify-items: start;
}

.share-qr-wrap img {
  display: block;
  max-width: 100%;
  height: auto;
  border-radius: 12px;
  border: 1px solid rgba(148, 163, 184, 0.25);
  background: #ffffff;
  padding: 0.55rem;
}

.share-qr-link {
  color: #86efac;
  word-break: break-all;
}

.fan-show-label {
  margin: 0.35rem 0 0;
}

.panel-grid {
  display: grid;
  grid-template-columns: minmax(380px, 440px) 1fr;
  gap: 1rem;
}

.panel,
.login-card,
.fan-card {
  background: rgba(15, 23, 42, 0.92);
  border: 1px solid rgba(148, 163, 184, 0.15);
  border-radius: 18px;
  padding: 1rem;
  backdrop-filter: blur(8px);
}

.controls {
  display: grid;
  gap: 1rem;
}

.control-section {
  display: grid;
  gap: 0.75rem;
  padding: 1rem;
  background: rgba(15, 23, 42, 0.6);
  border: 1px solid rgba(148, 163, 184, 0.1);
  border-radius: 12px;
}

.control-section:first-child {
  padding-top: 1rem;
}

.section-title {
  margin: 0 0 0.5rem 0;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.button-group {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.full-width {
  width: 100%;
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  cursor: pointer;
  user-select: none;
}

.checkbox-label input {
  width: auto;
  margin: 0;
}

.checkbox-label span {
  font-size: 0.9rem;
}

.select-with-button {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.5rem;
}

.info-text {
  margin: 1rem 0 0 0;
  font-size: 0.8rem;
  line-height: 1.4;
}

.field-group {
  display: grid;
  gap: 0.5rem;
}

.field-row {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.75rem;
}

.field-row.full {
  grid-template-columns: 1fr;
}

.button-row,
.slot-row,
.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.toolbar .tool {
  flex: 1 1 0;
  min-width: 0;
}

.toolbar .tool#clear-image {
  flex: 1 1 0;
}

.countdown-panel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border: 1px solid rgba(148, 163, 184, 0.2);
  border-radius: 12px;
  padding: 0.65rem 0.8rem;
  background: rgba(2, 6, 23, 0.45);
}

.admin-countdown {
  font-size: 1.35rem;
  letter-spacing: 0.06em;
}

.color-palette {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.color-chip {
  width: 26px;
  height: 26px;
  border-radius: 999px;
  border: 2px solid rgba(255, 255, 255, 0.35);
  padding: 0;
  min-width: 26px;
  transition: transform 0.12s ease, box-shadow 0.12s ease, border-color 0.12s ease;
}

.color-chip.selected {
  border-color: #ffffff;
  box-shadow: 0 0 0 2px rgba(34, 197, 94, 0.95), 0 0 0 4px rgba(2, 6, 23, 0.9);
  transform: scale(1.04);
}

.color-chip:focus-visible {
  outline: 2px solid #86efac;
  outline-offset: 2px;
}

.color-chip.empty {
  border-style: dashed;
  border-color: rgba(148, 163, 184, 0.35);
  background: transparent;
  color: var(--muted);
  font-size: 0.7rem;
}

.slot-preview-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 0.5rem;
}

.copy-row {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 0.5rem;
  align-items: center;
}

.slot-pagination-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.slot-pagination-controls {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.slot-pagination-controls .muted {
  min-width: 92px;
  text-align: center;
}

.slot-page-jump {
  display: flex;
  align-items: center;
  gap: 0.45rem;
}

.slot-page-jump input {
  width: 72px;
}

.slot-preview-hint {
  margin: 0.5rem 0 0;
  font-size: 0.78rem;
  line-height: 1.4;
}

.animation-frames {
  display: grid;
  gap: 0.45rem;
}

.animation-frame-row {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.5rem;
  align-items: center;
}

.animation-frame-row label {
  color: var(--muted);
  font-size: 0.85rem;
}

.monitor-panel {
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid rgba(148, 163, 184, 0.2);
}

.monitor-panel h3 {
  margin: 0 0 0.35rem;
  font-size: 1rem;
}

.fan-monitor-grid {
  border-collapse: collapse;
}

.fan-monitor-grid th,
.fan-monitor-grid td {
  border: 1px solid rgba(148, 163, 184, 0.15);
  text-align: center;
}

.fan-monitor-grid th {
  color: var(--muted);
  min-width: 22px;
  height: 22px;
  font-size: 0.74rem;
}

.fan-monitor-cell {
  position: relative;
  width: 22px;
  height: 22px;
  border: 0;
  background: #0b1220;
  padding: 0;
}

.fan-monitor-cell.ready {
  outline: 2px solid #22c55e;
  outline-offset: -2px;
}

.fan-monitor-badge {
  position: absolute;
  right: -3px;
  top: -3px;
  min-width: 12px;
  height: 12px;
  border-radius: 999px;
  background: #22c55e;
  color: #052e16;
  font-size: 0.6rem;
  line-height: 12px;
  font-weight: 700;
}

.animation-sequence {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  gap: 0.55rem;
}

.sequence-card {
  border: 1px solid rgba(148, 163, 184, 0.2);
  border-radius: 10px;
  padding: 0.5rem;
  background: rgba(2, 6, 23, 0.45);
}

.sequence-title {
  font-size: 0.76rem;
  color: var(--muted);
  margin-bottom: 0.35rem;
}

.sequence-canvas {
  width: 100%;
  aspect-ratio: 1;
  border-radius: 8px;
  border: 1px solid rgba(148, 163, 184, 0.25);
  background: #0b1220;
  image-rendering: pixelated;
}

.slot-preview {
  border: 1px solid rgba(148, 163, 184, 0.2);
  border-radius: 10px;
  padding: 0.45rem;
  background: rgba(2, 6, 23, 0.45);
  display: grid;
  gap: 0.35rem;
  cursor: pointer;
  transition: border-color 0.18s ease, transform 0.18s ease;
}

.slot-preview:hover {
  border-color: rgba(148, 163, 184, 0.45);
  transform: translateY(-1px);
}

.slot-preview:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.slot-preview.active {
  border-color: var(--accent);
}

.slot-preview-head {
  display: flex;
  justify-content: space-between;
  font-size: 0.75rem;
  color: var(--muted);
}

.slot-preview-canvas {
  width: 100%;
  aspect-ratio: 1;
  border-radius: 8px;
  border: 1px solid rgba(148, 163, 184, 0.25);
  image-rendering: pixelated;
  background: #0b1220;
}

.slot-preview-empty {
  font-size: 0.72rem;
  color: var(--muted);
}

.status {
  min-height: 1.4rem;
  color: #fde68a;
}

.status.error {
  color: #fca5a5;
}

.status.success {
  color: #86efac;
}

.fan-connection-badge {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.45rem 0.65rem;
  margin-bottom: 0.75rem;
  border: 1px solid rgba(148, 163, 184, 0.25);
  border-radius: 10px;
  background: rgba(2, 6, 23, 0.45);
}

.fan-connection-badge .state {
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  padding: 0.2rem 0.5rem;
  border-radius: 999px;
  border: 1px solid transparent;
}

.fan-connection-badge .state.connected {
  color: #052e16;
  background: #86efac;
  border-color: #4ade80;
}

.fan-connection-badge .state.reconnecting {
  color: #78350f;
  background: #fde68a;
  border-color: #facc15;
}

.fan-connection-badge .state.disconnected {
  color: #7f1d1d;
  background: #fecaca;
  border-color: #f87171;
}

.fan-connection-badge .sync {
  font-size: 0.78rem;
  color: var(--muted);
}

.grid-wrap {
  overflow: auto;
  border: 1px solid rgba(148, 163, 184, 0.15);
  border-radius: 16px;
  padding: 0.75rem;
  background: rgba(2, 6, 23, 0.7);
}

.pixel-grid {
  border-collapse: collapse;
  user-select: none;
}

.pixel-grid th,
.pixel-grid td {
  border: 1px solid rgba(148, 163, 184, 0.15);
  text-align: center;
}

.pixel-grid th {
  background: rgba(30, 41, 59, 0.9);
  color: var(--muted);
  min-width: var(--cell);
  height: var(--cell);
  padding: 0.15rem 0.35rem;
  position: sticky;
}

.pixel-grid td {
  width: var(--cell);
  height: var(--cell);
  min-width: var(--cell);
  padding: 0;
}

.pixel-cell {
  width: 100%;
  height: 100%;
  border: 0;
  background: transparent;
  border-radius: 0;
  padding: 0;
}

.pixel-cell.empty {
  background-image:
    linear-gradient(45deg, #1e293b 25%, transparent 25%),
    linear-gradient(-45deg, #1e293b 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #1e293b 75%),
    linear-gradient(-45deg, transparent 75%, #1e293b 75%);
  background-size: 10px 10px;
  background-position: 0 0, 0 5px, 5px -5px, -5px 0;
}

.toolbar .tool.active {
  outline: 2px solid var(--accent);
}

.login-shell,
.fan-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1rem;
}

.login-card,
.fan-card {
  width: min(520px, 100%);
}

.fan-card {
  text-align: center;
}

.fan-stage {
  margin-top: 1rem;
  padding: 1.25rem;
  border-radius: 16px;
  background: rgba(2, 6, 23, 0.7);
  border: 1px solid rgba(148, 163, 184, 0.15);
}

.countdown {
  font-size: clamp(3rem, 16vw, 8rem);
  line-height: 1;
  margin: 0.5rem 0;
}

.assigned-color {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  justify-content: center;
  margin-top: 0.75rem;
}

.swatch {
  width: 22px;
  height: 22px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.5);
}

body.fan-fullscreen .fan-card > *:not(.fan-stage) {
  display: none !important;
}

body.fan-fullscreen .fan-card {
  width: 100%;
  max-width: none;
  background: transparent;
  border: none;
  border-radius: 0;
  padding: 0;
}

body.fan-fullscreen .fan-shell {
  padding: 0;
}

body.fan-fullscreen .fan-stage {
  position: fixed;
  inset: 0;
  z-index: 100;
  margin: 0;
  border-radius: 0;
  border: none;
  background: transparent;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

body.fan-fullscreen .countdown {
  font-size: clamp(1.5rem, 8vw, 4rem);
}

.fullscreen-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  pointer-events: none;
}

.fullscreen-overlay.hidden {
  display: none;
}

.fullscreen-back-btn {
  pointer-events: all;
  padding: 1.1rem 2.4rem;
  font-size: 1.15rem;
  font-weight: 700;
  border-radius: 999px;
  border: none;
  background: rgba(255, 255, 255, 0.18);
  color: #9ca3af;
  backdrop-filter: blur(12px);
  box-shadow: 0 4px 32px rgba(0, 0, 0, 0.45), 0 0 0 1.5px rgba(255,255,255,0.18);
  cursor: pointer;
  letter-spacing: 0.06em;
  transition: background 0.2s, transform 0.15s;
}

.fullscreen-back-btn:hover {
  background: rgba(255, 255, 255, 0.28);
  transform: scale(1.06);
}

@media (max-width: 900px) {
  .panel-grid {
    grid-template-columns: 1fr;
  }

  .landing-grid,
  .landing-hero,
  .landing-brand {
    grid-template-columns: 1fr;
    flex-direction: column;
  }

  .field-row {
    grid-template-columns: 1fr;
  }

  .slot-preview-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .slot-pagination-row {
    align-items: stretch;
  }

  .slot-pagination-controls {
    width: 100%;
    justify-content: space-between;
  }

  .slot-page-jump {
    width: 100%;
    justify-content: flex-end;
  }

  .slot-page-jump input {
    width: 100%;
    max-width: 92px;
  }

  .copy-row {
    grid-template-columns: 1fr;
  }

  .modal-head {
    flex-direction: column;
  }
}
