/* ============================================================
   Reading Atmosphere Themes
   ============================================================ */

/* ── Trigger button ─────────────────────────────────────────── */

.ao-atm-trigger {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.06);
  color: var(--text-muted, #aaa);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition:
    background 0.15s,
    color 0.15s,
    border-color 0.15s;
  white-space: nowrap;
}

.ao-atm-trigger:hover {
  background: rgba(255, 255, 255, 0.12);
  color: var(--text-primary, #fff);
  border-color: rgba(255, 255, 255, 0.22);
}

.ao-atm-trigger.is-active {
  border-color: var(--atm-accent, #6c5ce7);
  color: var(--atm-accent, #6c5ce7);
  background: rgba(108, 92, 231, 0.12);
}

/* ── Panel overlay ──────────────────────────────────────────── */

.ao-atm-overlay {
  position: fixed;
  inset: 0;
  z-index: 9990;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(3px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}

.ao-atm-overlay.is-open {
  opacity: 1;
  pointer-events: auto;
}

/* ── Panel ──────────────────────────────────────────────────── */

.ao-atm-panel {
  position: fixed;
  right: 0;
  top: 0;
  bottom: 0;
  z-index: 9991;
  width: min(420px, 100vw);
  background: var(--bg-card, #12121e);
  border-left: 1px solid rgba(255, 255, 255, 0.08);
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  overflow: hidden;
}

.ao-atm-panel.is-open {
  transform: translateX(0);
}

/* ── Panel header ───────────────────────────────────────────── */

.ao-atm-panel__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.07);
  flex-shrink: 0;
}

/* Drag handle — hidden on desktop, shown on mobile via responsive block */
.ao-atm-drag-handle {
  display: none;
  width: 36px;
  height: 4px;
  background: rgba(255, 255, 255, 0.18);
  border-radius: 2px;
  margin: 0 auto 10px;
  flex-shrink: 0;
}

/* Head row — always flex on desktop (inside head directly) */
.ao-atm-panel__head-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
}

.ao-atm-panel__title {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-primary, #e8e8f0);
  margin: 0;
  display: flex;
  align-items: center;
  gap: 8px;
}

.ao-atm-panel__title svg {
  opacity: 0.7;
}

.ao-atm-panel__close {
  width: 30px;
  height: 30px;
  border-radius: 6px;
  border: none;
  background: rgba(255, 255, 255, 0.06);
  color: var(--text-muted, #aaa);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  line-height: 1;
  transition:
    background 0.15s,
    color 0.15s;
}

.ao-atm-panel__close:hover {
  background: rgba(255, 255, 255, 0.12);
  color: var(--text-primary, #fff);
}

/* ── Tabs ───────────────────────────────────────────────────── */

.ao-atm-tabs {
  display: flex;
  border-bottom: 1px solid rgba(255, 255, 255, 0.07);
  flex-shrink: 0;
}

.ao-atm-tab {
  flex: 1;
  padding: 10px;
  font-size: 12px;
  font-weight: 600;
  text-align: center;
  cursor: pointer;
  border: none;
  background: none;
  color: var(--text-muted, #aaa);
  border-bottom: 2px solid transparent;
  transition:
    color 0.15s,
    border-color 0.15s;
}

.ao-atm-tab.is-active {
  color: var(--text-primary, #e8e8f0);
  border-bottom-color: #6c5ce7;
}

/* ── Panel body / scroll ────────────────────────────────────── */

.ao-atm-panel__body {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px;
}

/* ── Deactivate bar ─────────────────────────────────────────── */

.ao-atm-deactivate-bar {
  padding: 8px 20px 0;
  flex-shrink: 0;
}

.ao-atm-deactivate-btn {
  width: 100%;
  padding: 8px;
  border-radius: 8px;
  border: 1px dashed rgba(255, 255, 255, 0.15);
  background: none;
  color: var(--text-muted, #aaa);
  font-size: 12px;
  cursor: pointer;
  transition:
    border-color 0.15s,
    color 0.15s;
}

.ao-atm-deactivate-btn:hover {
  border-color: rgba(255, 255, 255, 0.3);
  color: var(--text-primary, #e8e8f0);
}

/* ── Preset list ────────────────────────────────────────────── */

.ao-atm-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.ao-atm-empty {
  text-align: center;
  padding: 32px 0;
  color: var(--text-muted, #aaa);
  font-size: 13px;
}

.ao-atm-empty svg {
  display: block;
  margin: 0 auto 10px;
  opacity: 0.4;
}

/* ── Preset card ────────────────────────────────────────────── */

.ao-atm-card {
  border-radius: 10px;
  overflow: hidden;
  border: 2px solid transparent;
  transition:
    border-color 0.15s,
    box-shadow 0.15s;
  cursor: pointer;
}

.ao-atm-card.is-active-preset {
  border-color: #6c5ce7;
  box-shadow: 0 0 0 2px rgba(108, 92, 231, 0.25);
}

.ao-atm-card__preview {
  height: 52px;
  position: relative;
  display: flex;
  align-items: center;
  padding: 0 12px;
  gap: 8px;
}

.ao-atm-card__preview-name {
  font-size: 13px;
  font-weight: 700;
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ao-atm-card__swatches {
  display: flex;
  gap: 3px;
}

.ao-atm-card__swatch {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.2);
}

/* ── Preset actions row ─────────────────────────────────────── */

.ao-atm-card__actions {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  background: rgba(0, 0, 0, 0.25);
  border-top: 1px solid rgba(255, 255, 255, 0.05);
}

.ao-atm-activate-btn {
  flex: 1;
  padding: 5px 10px;
  border-radius: 6px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  background: rgba(255, 255, 255, 0.07);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
  text-align: center;
}

.ao-atm-activate-btn:hover {
  background: rgba(255, 255, 255, 0.14);
}

.ao-atm-card.is-active-preset .ao-atm-activate-btn {
  background: #6c5ce7;
  border-color: #6c5ce7;
}

.ao-atm-vote-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 5px 8px;
  border-radius: 6px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-muted, #aaa);
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  transition:
    background 0.15s,
    color 0.15s,
    border-color 0.15s;
}

.ao-atm-vote-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
}

.ao-atm-vote-btn.is-voted {
  background: rgba(245, 158, 11, 0.15);
  border-color: #f59e0b;
  color: #f59e0b;
}

.ao-atm-mod-btn {
  padding: 5px 8px;
  border-radius: 6px;
  border: 1px solid rgba(239, 68, 68, 0.3);
  background: rgba(239, 68, 68, 0.08);
  color: #ef4444;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}

.ao-atm-mod-btn:hover {
  background: rgba(239, 68, 68, 0.18);
}

/* ── Create form ────────────────────────────────────────────── */

.ao-atm-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.ao-atm-field {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.ao-atm-field label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-muted, #aaa);
}

.ao-atm-field input[type="text"],
.ao-atm-field select {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 7px;
  padding: 8px 10px;
  color: var(--text-primary, #e8e8f0);
  font-size: 13px;
  width: 100%;
  outline: none;
  transition: border-color 0.15s;
}

.ao-atm-field input[type="text"]:focus,
.ao-atm-field select:focus {
  border-color: rgba(108, 92, 231, 0.5);
}

.ao-atm-field select option {
  background: #1a1a2e;
}

/* ── Colour row ─────────────────────────────────────────────── */

.ao-atm-colors {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.ao-atm-color-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.ao-atm-color-field label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-muted, #aaa);
}

.ao-atm-color-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 7px;
  padding: 4px 8px;
}

.ao-atm-color-wrap input[type="color"] {
  width: 24px;
  height: 24px;
  border: none;
  padding: 0;
  background: none;
  cursor: pointer;
  border-radius: 4px;
}

.ao-atm-color-wrap input[type="text"] {
  flex: 1;
  background: none;
  border: none;
  padding: 0;
  color: var(--text-primary, #e8e8f0);
  font-size: 12px;
  font-family: monospace;
  outline: none;
  min-width: 0;
}

/* ── Live preview ───────────────────────────────────────────── */

.ao-atm-preview-box {
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.08);
  height: 60px;
  display: flex;
  align-items: center;
  padding: 0 14px;
  gap: 10px;
  transition:
    background 0.2s,
    color 0.2s;
}

.ao-atm-preview-box__text {
  font-size: 13px;
  font-weight: 600;
}

.ao-atm-preview-box__accent {
  width: 12px;
  height: 12px;
  border-radius: 3px;
  flex-shrink: 0;
}

/* ── Submit button ──────────────────────────────────────────── */

.ao-atm-submit-btn {
  width: 100%;
  padding: 10px;
  border-radius: 8px;
  border: none;
  background: #6c5ce7;
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition:
    background 0.15s,
    opacity 0.15s;
}

.ao-atm-submit-btn:hover {
  background: #5a4bd1;
}
.ao-atm-submit-btn:disabled {
  opacity: 0.5;
  pointer-events: none;
}

.ao-atm-msg {
  font-size: 12px;
  padding: 8px 12px;
  border-radius: 7px;
  display: none;
}

.ao-atm-msg--ok {
  background: rgba(34, 197, 94, 0.15);
  color: #22c55e;
}
.ao-atm-msg--err {
  background: rgba(239, 68, 68, 0.15);
  color: #ef4444;
}

/* ── Loading skeleton ───────────────────────────────────────── */

.ao-atm-loading {
  text-align: center;
  padding: 24px 0;
  color: var(--text-muted, #aaa);
  font-size: 13px;
}

/* ── Pending notice (guest / non-approved) ──────────────────── */

.ao-atm-pending-notice {
  font-size: 11px;
  color: var(--text-muted, #888);
  text-align: center;
  padding: 8px 0 0;
}

/* ── Body atmosphere overrides ──────────────────────────────── */

body.has-atmosphere {
  --atm-accent: #6c5ce7;
  --atm-accent2: #4a3ab5;
  --atm-bg: #0d0d18;
  --atm-text: #e8e8f0;
  --atm-texture: none;
  --atm-texture-size: auto;
  --atm-font: inherit;
}

/* Site-wide surfaces that react to the atmosphere */
body.has-atmosphere .site-header,
body.has-atmosphere .ao-header {
  background-color: color-mix(
    in srgb,
    var(--atm-bg) 92%,
    transparent
  ) !important;
  border-bottom-color: color-mix(
    in srgb,
    var(--atm-accent) 30%,
    transparent
  ) !important;
}

body.has-atmosphere .site-footer,
body.has-atmosphere .ao-footer {
  background-color: var(--atm-bg) !important;
}

body.has-atmosphere .ao-reader,
body.has-atmosphere .ao-manga-single,
body.has-atmosphere .ao-single-body {
  background-color: var(--atm-bg) !important;
  color: var(--atm-text) !important;
  font-family: var(--atm-font) !important;
}

/* Novel reader content — needs explicit overrides because it has its own bg/color/font */
body.has-atmosphere .ao-reader-novel__content {
  background-color: var(--atm-bg) !important;
  color: var(--atm-text) !important;
  font-family: var(--atm-font) !important;
}

body.has-atmosphere .ao-reader-novel__content p,
body.has-atmosphere .ao-reader-novel__content h1,
body.has-atmosphere .ao-reader-novel__content h2,
body.has-atmosphere .ao-reader-novel__content h3,
body.has-atmosphere .ao-reader-novel__content blockquote,
body.has-atmosphere .ao-reader-novel__content li {
  color: var(--atm-text) !important;
  font-family: var(--atm-font) !important;
}

body.has-atmosphere .ao-reader-novel__content blockquote {
  border-left-color: var(--atm-accent) !important;
  background-color: color-mix(in srgb, var(--atm-accent) 8%, var(--atm-bg)) !important;
}

body.has-atmosphere .ao-reader-novel__content a {
  color: var(--atm-accent) !important;
}

/* Texture overlay — applied as pseudo-element on body */
body.has-atmosphere::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background-image: var(--atm-texture);
  background-size: var(--atm-texture-size);
  opacity: 1;
}

/* Accent colour applications */
body.has-atmosphere a:not(.ao-btn):not(.ao-nav-link) {
  color: var(--atm-accent);
}

body.has-atmosphere .ao-single-hero__title,
body.has-atmosphere .ao-reader-nav__manga-title {
  color: var(--atm-text);
}

body.has-atmosphere .ao-reader-nav {
  background-color: color-mix(in srgb, var(--atm-bg) 95%, transparent);
  border-color: color-mix(in srgb, var(--atm-accent) 25%, transparent);
}

body.has-atmosphere .ao-btn-primary {
  background: var(--atm-accent);
}

body.has-atmosphere .ao-btn-primary:hover {
  background: var(--atm-accent2);
}

/* Scrollbar theming */
body.has-atmosphere ::-webkit-scrollbar-thumb {
  background: color-mix(in srgb, var(--atm-accent) 60%, transparent);
}

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

/* ---- Tablet & narrow desktop: make panel a touch narrower ---- */
@media (max-width: 900px) {
  .ao-atm-panel {
    width: min(380px, 100vw);
  }
}

/* ---- Mobile: convert to bottom sheet ---- */
@media (max-width: 640px) {
  /* Bottom-sheet layout */
  .ao-atm-panel {
    right: 0;
    left: 0;
    top: auto;
    bottom: 0;
    width: 100%;
    border-left: none;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 16px 16px 0 0;
    /* Use dvh so the panel shrinks when the virtual keyboard opens */
    max-height: 90dvh;
    max-height: 90vh; /* fallback for browsers without dvh */
    /* Slide in from bottom instead of right */
    transform: translateY(100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    /* Home indicator padding */
    padding-bottom: env(safe-area-inset-bottom, 0);
  }

  .ao-atm-panel.is-open {
    transform: translateY(0);
  }

  /* Drag handle visible on mobile */
  .ao-atm-drag-handle {
    display: block;
  }

  .ao-atm-panel__head {
    flex-direction: column;
    align-items: stretch;
    padding-top: 10px;
    gap: 0;
  }

  /* Scrollable body — iOS momentum scrolling */
  .ao-atm-panel__body {
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-y: contain;
  }

  /* Pad bottom of last pane for safe area */
  .ao-atm-panel__body:last-of-type {
    padding-bottom: calc(20px + env(safe-area-inset-bottom, 0));
  }

  /* Colour grid: 2 col is fine on mobile, no need for 1 col */
  .ao-atm-colors {
    grid-template-columns: 1fr 1fr;
  }
}

/* ---- Very narrow screens (≤ 400px) ---- */
@media (max-width: 400px) {
  .ao-atm-panel {
    max-height: 95dvh;
    max-height: 95vh;
  }

  .ao-atm-colors {
    grid-template-columns: 1fr;
  }

  .ao-atm-panel__body {
    padding: 12px 14px;
  }
}
