/* ============================================================================
 * styles.css — Layout, the frosted panel (login + settings), gear, controls.
 * Theme colours arrive as CSS variables set by app.js.
 * ========================================================================== */

:root {
  --bg: #1a1b26;
  --bg2: #16161e;
  --fg: #c0caf5;
  --dim: #292e42;
  --accent: #7aa2f7;
  --accent2: #7dcfff;
  --panel-bg: rgba(20, 22, 30, 0.42);
  --panel-border: rgba(192, 202, 245, 0.16);
  --field-bg: rgba(192, 202, 245, 0.08);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Inter,
    'Helvetica Neue', Arial, sans-serif;
  background: var(--bg);
  color: var(--fg);
  transition: background 0.6s ease, color 0.6s ease;
}

/* Background gradient washes behind the canvas. */
#stage {
  position: fixed;
  inset: 0;
  background:
    radial-gradient(120% 120% at 15% 10%, var(--bg) 0%, var(--bg2) 70%, var(--bg2) 100%);
  transition: background 0.6s ease;
}

/* Cyberpunk neon world map, sitting faded behind the network. */
#worldmap {
  position: fixed;
  inset: 0;
  z-index: 1;
  /* The continents are a CSS gradient (admin-customisable) masked by the map
     shape. Full viewport width, height scales to keep the aspect ratio. */
  background: var(--map-gradient, linear-gradient(120deg, #00eaff, #22c1ff, #a742ff, #ff2bd6));
  -webkit-mask: center / 100% auto no-repeat url("worldmap.svg");
  mask: center / 100% auto no-repeat url("worldmap.svg");
  opacity: var(--map-opacity, 0.2);
  /* Glow follows the active theme's accent. */
  filter: drop-shadow(0 0 7px var(--accent)) saturate(1.25);
  mix-blend-mode: screen;
  pointer-events: none;
  transition: opacity 0.6s ease, filter 0.6s ease;
}
body.is-light #worldmap {
  mix-blend-mode: multiply;
  opacity: var(--map-opacity, 0.28);
  filter: drop-shadow(0 0 4px var(--accent)) saturate(1.1);
}
/* Portrait screens (height > width): fill the map to the screen height instead
   of the width, keeping the map's aspect ratio (it overflows horizontally and
   stays centred). */
@media (orientation: portrait) {
  #worldmap {
    -webkit-mask-size: auto 100%;
    mask-size: auto 100%;
  }
}

#web {
  position: fixed;
  inset: 0;
  z-index: 2;
  display: block;
}

/* ---- Centre brand / hint ------------------------------------------------- */
.brand {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
  pointer-events: none;
  user-select: none;
  opacity: 0.92;
  z-index: 3;
}
.brand h1 {
  margin: 0;
  font-size: clamp(28px, 6vw, 64px);
  font-weight: 700;
  letter-spacing: -0.02em;
  background: var(--title-grad, linear-gradient(90deg, var(--accent), var(--accent2)));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  text-shadow: 0 2px 40px rgba(0, 0, 0, 0.25);
  transition: opacity 0.4s ease;
}
.brand p {
  margin: 10px 0 0;
  font-size: clamp(12px, 1.6vw, 15px);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  opacity: 0.55;
  color: var(--fg);
}

/* ---- Gear button --------------------------------------------------------- */
.gear {
  position: fixed;
  right: 18px;
  bottom: 18px;
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  border: 1px solid var(--panel-border);
  background: var(--panel-bg);
  -webkit-backdrop-filter: blur(10px) saturate(140%);
  backdrop-filter: blur(10px) saturate(140%);
  color: var(--fg);
  cursor: pointer;
  z-index: 20;
  opacity: 0.6;
  transition: opacity 0.25s ease, transform 0.5s ease, box-shadow 0.25s ease;
}
.gear:hover {
  opacity: 1;
  box-shadow: 0 0 0 4px rgba(0, 0, 0, 0.06), 0 6px 24px rgba(0, 0, 0, 0.25);
}
.gear svg { width: 20px; height: 20px; display: block; }
.gear.spin svg { transform: rotate(60deg); }
.gear svg { transition: transform 0.5s ease; }

/* ---- Scrim + panel ------------------------------------------------------- */
.scrim {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.15);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
  z-index: 15;
}
.scrim.show { opacity: 1; pointer-events: auto; }

.panel {
  position: fixed;
  right: 18px;
  bottom: 72px;
  width: min(380px, calc(100vw - 36px));
  max-height: min(78vh, 720px);
  display: flex;
  flex-direction: column;
  border-radius: 18px;
  border: 1px solid var(--panel-border);
  background: var(--panel-bg);
  -webkit-backdrop-filter: blur(26px) saturate(150%);
  backdrop-filter: blur(26px) saturate(150%);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4), inset 0 1px 0 rgba(255, 255, 255, 0.06);
  color: var(--fg);
  z-index: 25;
  transform: translateY(14px) scale(0.98);
  opacity: 0;
  pointer-events: none;
  transform-origin: bottom right;
  transition: opacity 0.28s ease, transform 0.28s cubic-bezier(0.2, 0.9, 0.3, 1);
}
.panel.open { opacity: 1; transform: translateY(0) scale(1); pointer-events: auto; }

.panel-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: 16px 18px 10px;
  border-bottom: 1px solid var(--panel-border);
}
.panel-head h2 {
  margin: 0;
  font-size: 15px;
  font-weight: 650;
  letter-spacing: 0.01em;
}
.panel-head .close {
  border: none;
  background: transparent;
  color: var(--fg);
  opacity: 0.5;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 8px;
}
.panel-head .close:hover { opacity: 1; background: var(--field-bg); }

.panel-body {
  padding: 14px 18px 18px;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.section-label {
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  opacity: 0.5;
  margin: 4px 0 10px;
}
.section-label.mt { margin-top: 20px; }

/* ---- Theme grid ---------------------------------------------------------- */
.theme-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}
.swatch {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 7px;
  padding: 8px;
  border-radius: 12px;
  border: 1px solid var(--sw-border, rgba(255, 255, 255, 0.12));
  background: var(--field-bg);
  cursor: pointer;
  text-align: left;
  color: inherit;
  transition: transform 0.15s ease, box-shadow 0.2s ease, border-color 0.2s ease;
}
.swatch:hover { transform: translateY(-2px); }
.swatch.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent);
}
.sw-preview {
  height: 42px;
  border-radius: 8px;
  display: flex;
  align-items: flex-end;
  padding: 7px;
  overflow: hidden;
}
.sw-dots { display: flex; gap: 5px; }
.sw-dots .dot {
  width: 9px; height: 9px; border-radius: 50%;
  box-shadow: 0 0 6px rgba(0, 0, 0, 0.35);
}
.sw-meta { display: flex; align-items: center; gap: 6px; }
.sw-name {
  font-size: 12.5px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sw-badge {
  font-size: 9px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 2px 5px;
  border-radius: 6px;
  background: var(--field-bg);
  border: 1px solid var(--panel-border);
  opacity: 0.75;
}
.sw-remove {
  position: absolute;
  top: 5px; right: 7px;
  width: 18px; height: 18px;
  display: grid; place-items: center;
  border-radius: 50%;
  font-size: 15px; line-height: 1;
  background: rgba(0, 0, 0, 0.35);
  color: #fff;
  opacity: 0;
  transition: opacity 0.15s ease;
}
.swatch:hover .sw-remove { opacity: 0.85; }
.sw-remove:hover { opacity: 1 !important; background: #e0405a; }

/* ---- Add-from-link ------------------------------------------------------- */
.link-row { display: flex; gap: 8px; margin-top: 2px; }
.link-row input {
  flex: 1;
  min-width: 0;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--panel-border);
  background: var(--field-bg);
  color: var(--fg);
  font-size: 13px;
  outline: none;
}
.link-row input:focus { border-color: var(--accent); }
.link-row input::placeholder { color: var(--fg); opacity: 0.4; }
.btn {
  padding: 10px 14px;
  border-radius: 10px;
  border: none;
  background: var(--accent);
  color: #05070d;
  font-weight: 650;
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
  transition: filter 0.15s ease, transform 0.1s ease;
}
.btn:hover { filter: brightness(1.08); }
.btn:active { transform: scale(0.97); }
.link-hint { font-size: 11px; opacity: 0.45; margin: 8px 0 0; line-height: 1.5; }
.link-hint code {
  font-size: 10.5px;
  background: var(--field-bg);
  padding: 1px 5px;
  border-radius: 5px;
}
.link-msg { font-size: 12px; margin: 8px 0 0; min-height: 16px; opacity: 0; transition: opacity 0.2s ease; }
.link-msg.ok, .link-msg.warn { opacity: 1; }
.link-msg.ok { color: #3ec77e; }
.link-msg.warn { color: #f0a34b; }

/* ---- Colour editor ------------------------------------------------------- */
.color-editor { margin-top: 4px; }
.color-rows { display: flex; flex-direction: column; gap: 2px; }
.color-row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: center;
  gap: 10px;
  padding: 7px 0;
  cursor: pointer;
}
.cr-label { font-size: 13px; opacity: 0.85; }
.cr-hex {
  font-size: 11px; opacity: 0.5;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  text-transform: uppercase;
}
/* Native colour input, restyled to a neat round swatch */
input[type='color'] {
  -webkit-appearance: none;
  appearance: none;
  width: 26px; height: 26px;
  padding: 0;
  border: 1px solid var(--panel-border);
  border-radius: 7px;
  background: none;
  cursor: pointer;
}
input[type='color']::-webkit-color-swatch-wrapper { padding: 2px; }
input[type='color']::-webkit-color-swatch { border: none; border-radius: 5px; }
input[type='color']::-moz-color-swatch { border: none; border-radius: 5px; }

.color-block { margin-top: 12px; }
.cb-head {
  display: flex; align-items: center; justify-content: space-between;
  font-size: 12px; opacity: 0.7; margin-bottom: 8px;
}
.mini-btn {
  width: 22px; height: 22px;
  display: grid; place-items: center;
  border-radius: 7px;
  border: 1px solid var(--panel-border);
  background: var(--field-bg);
  color: var(--fg);
  font-size: 15px; line-height: 1; cursor: pointer;
}
.mini-btn:hover { background: var(--panel-border); }
.color-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.color-chip { position: relative; display: inline-flex; }
.color-chip .chip-x {
  position: absolute; top: -6px; right: -6px;
  width: 15px; height: 15px;
  display: grid; place-items: center;
  border: none; border-radius: 50%;
  background: rgba(0, 0, 0, 0.55); color: #fff;
  font-size: 12px; line-height: 1; cursor: pointer;
  opacity: 0; transition: opacity 0.15s ease;
}
.color-chip:hover .chip-x { opacity: 1; }
.color-chip .chip-x:hover { background: #e0405a; }

/* ---- Cookie consent banner ---------------------------------------------- */
.cookie-banner {
  position: fixed;
  left: 18px;
  bottom: 18px;
  right: 76px; /* leave the gear clear */
  max-width: 620px;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 16px;
  border-radius: 14px;
  border: 1px solid var(--panel-border);
  background: var(--panel-bg);
  -webkit-backdrop-filter: blur(20px) saturate(150%);
  backdrop-filter: blur(20px) saturate(150%);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
  color: var(--fg);
  z-index: 30;
}
.cookie-banner[hidden] { display: none; }
.cookie-text { font-size: 12.5px; line-height: 1.5; opacity: 0.9; }
.cookie-text strong { display: block; font-size: 13px; margin-bottom: 2px; }
.cookie-text a { color: var(--accent); text-decoration: none; }
.cookie-text a:hover { text-decoration: underline; }
.cookie-more { display: block; margin-top: 8px; opacity: 0.75; }
.cookie-more[hidden] { display: none; }
.cookie-more code {
  font-size: 11px; background: var(--field-bg);
  padding: 1px 4px; border-radius: 4px;
}
.cookie-actions { display: flex; gap: 8px; flex-shrink: 0; }
@media (max-width: 640px) {
  .cookie-banner { flex-direction: column; align-items: stretch; right: 18px; bottom: 76px; }
  .cookie-actions { justify-content: flex-end; }
}

/* ---- Controls (sliders/toggles) ----------------------------------------- */
.control {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 9px 0;
  border-bottom: 1px solid var(--panel-border);
}
.control:last-child { border-bottom: none; }
.control label { font-size: 13px; opacity: 0.85; }
.control input[type='range'] {
  grid-column: 1 / -1;
  width: 100%;
  accent-color: var(--accent);
  cursor: pointer;
}
.control .val { font-size: 12px; opacity: 0.5; text-align: right; }

/* toggle switch */
.switch { position: relative; width: 40px; height: 22px; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .track {
  position: absolute; inset: 0;
  border-radius: 999px;
  background: var(--field-bg);
  border: 1px solid var(--panel-border);
  transition: background 0.2s ease;
}
.switch .track::before {
  content: '';
  position: absolute;
  left: 3px; top: 50%;
  transform: translateY(-50%);
  width: 16px; height: 16px;
  border-radius: 50%;
  background: var(--fg);
  opacity: 0.8;
  transition: left 0.2s ease, background 0.2s ease;
}
.switch input:checked + .track { background: var(--accent); }
.switch input:checked + .track::before { left: 21px; background: #05070d; opacity: 1; }

/* ---- Auth form + admin bar ---------------------------------------------- */
.field { margin-bottom: 8px; }
.field input {
  width: 100%;
  padding: 11px 12px;
  border-radius: 10px;
  border: 1px solid var(--panel-border);
  background: var(--field-bg);
  color: var(--fg);
  font-size: 14px;
  outline: none;
}
.field input:focus { border-color: var(--accent); }
.field input::placeholder { color: var(--fg); opacity: 0.4; }

.auth-actions { display: flex; gap: 8px; margin-top: 4px; }
.auth-actions .btn { flex: 1; }

.btn.ghost {
  background: var(--field-bg);
  color: var(--fg);
  border: 1px solid var(--panel-border);
  font-weight: 600;
}
.btn.ghost:hover { filter: none; background: var(--panel-border); }
.btn.sm { padding: 6px 10px; font-size: 12px; }
.btn[hidden] { display: none; }

.admin-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding-bottom: 4px;
}
.signed-in { font-size: 12.5px; opacity: 0.8; margin: 0; }
.signed-in strong { font-weight: 650; opacity: 1; }
.tag {
  font-size: 9px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 2px 6px;
  margin-left: 4px;
  border-radius: 6px;
  background: var(--accent);
  color: #05070d;
  font-weight: 700;
  vertical-align: middle;
}
.save-status { font-size: 12px; margin: 12px 0 0; min-height: 16px; opacity: 0; transition: opacity 0.2s ease; }
.save-status.ok, .save-status.warn, .save-status.pending { opacity: 1; }
.save-status.ok { color: #3ec77e; }
.save-status.warn { color: #f0a34b; }
.save-status.pending { color: var(--fg); opacity: 0.5; }

/* light-theme fine tuning */
body.is-light .btn { color: #fff; }
body.is-light .btn.ghost { color: var(--fg); }
body.is-light .tag { color: #fff; }
body.is-light .sw-remove { color: #fff; }
body.is-light .switch input:checked + .track::before { background: #fff; }

/* scrollbar */
.panel-body::-webkit-scrollbar { width: 8px; }
.panel-body::-webkit-scrollbar-thumb {
  background: var(--panel-border);
  border-radius: 8px;
}
