/**
 * 1Timeline – styles
 * Minimal, modern, professional. Single design system.
 */

/* ---------- Design tokens ---------- */
/* Warm base + one accent (teal): minimal, game-like, professional */
:root {
  --font-sans: 'DM Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-inscribed: 'Cormorant Garamond', Georgia, 'Times New Roman', serif;
  /* Warm base */
  --color-bg: #f6f4f0;
  --color-surface: #fffefb;
  --color-border: #e6e4df;
  --color-border-subtle: #eeebe6;
  /* Warm text */
  --color-text: #1c1b19;
  --color-text-secondary: #6b6560;
  --color-text-tertiary: #9c9893;
  /* Single accent: rich teal (chosen, primary actions, focus) */
  --color-accent: #0d9488;
  --color-accent-hover: #0f766e;
  --color-accent-muted: rgba(13, 148, 136, 0.12);
  --color-accent-bg: #f0fdfa;
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-card: 14px;
  --shadow-sm: 0 1px 2px rgba(28, 27, 25, 0.04);
  --shadow-md: 0 4px 12px rgba(28, 27, 25, 0.06);
  --shadow-card: 0 2px 8px rgba(28, 27, 25, 0.04), 0 1px 2px rgba(28, 27, 25, 0.03);
  /* Monument: anchored, unerasable, lasts centuries */
  --shadow-monument: 0 8px 32px rgba(28, 27, 25, 0.08), 0 2px 8px rgba(28, 27, 25, 0.04);
  --shadow-monument-inset: inset 0 1px 0 rgba(255, 255, 255, 0.9), inset 0 0 0 1px rgba(28, 27, 25, 0.04);
  --space-xs: 4px;
  --space-sm: 8px;
  --space-md: 16px;
  --space-lg: 24px;
  --space-xl: 32px;
  --space-2xl: 48px;
  --space-3xl: 64px;
}

/* ---------- Reset & base ---------- */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: var(--font-sans);
  font-size: 15px;
  font-weight: 400;
  line-height: 1.55;
  background: var(--color-bg);
  color: var(--color-text);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

/* ---------- Header (recedes; timeline is the hero) ---------- */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-md) var(--space-xl);
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border-subtle);
}

.app-header-brand {
  flex: 1;
}

.app-title {
  font-size: 1.125rem;
  font-weight: 500;
  letter-spacing: -0.02em;
  color: var(--color-text-secondary);
  margin-bottom: 1px;
}

.app-tagline {
  font-size: 0.75rem;
  font-weight: 400;
  color: var(--color-text-tertiary);
}

.app-header-actions {
  display: flex;
  align-items: center;
  gap: var(--space-lg);
}

.countdown-wrap {
  text-align: right;
}

.countdown-label {
  display: block;
  font-size: 0.6875rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-text-tertiary);
  margin-bottom: 2px;
}

.countdown-value {
  font-size: 1rem;
  font-weight: 500;
  letter-spacing: 0.02em;
  color: var(--color-text);
}

/* ---------- Layout ---------- */
.layout-container {
  display: flex;
  min-height: calc(100vh - 65px);
  position: relative;
}

/* ---------- Timeline: the main event ---------- */
.timeline {
  flex: 1;
  min-width: 0;
  padding: var(--space-3xl) var(--space-xl);
  background: var(--color-bg);
  overflow-y: auto;
}

.timeline-content {
  max-width: 640px;
  margin: 0 auto;
}

/* ---------- Message cards: monument, sacred, unerasable, centuries-lasting ---------- */
.message-card {
  position: relative;
  background: linear-gradient(180deg, var(--color-surface) 0%, #fefdfb 100%);
  border-radius: var(--radius-card);
  padding: var(--space-3xl) var(--space-xl);
  margin-bottom: var(--space-xl);
  box-shadow: var(--shadow-monument), var(--shadow-monument-inset);
  border: 2px solid var(--color-border);
  /* Sealed at top and bottom – cannot be removed, never erased */
  border-top: 4px solid var(--color-accent);
  border-bottom: 3px solid var(--color-accent);
  transition: none;
}

.message-card:hover {
  box-shadow: var(--shadow-monument), var(--shadow-monument-inset);
  border-color: var(--color-border);
}

.message-card:last-child {
  margin-bottom: 0;
}

/* Official seal strip: INSCRIBED – like a ribbon on a decree */
.message-card::before {
  content: "Inscribed";
  display: block;
  font-size: 0.625rem;
  font-weight: 700;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--color-accent);
  margin: 0 calc(-1 * var(--space-xl)) var(--space-lg);
  padding: var(--space-sm) var(--space-xl);
  background: var(--color-accent-bg);
  text-align: center;
  font-family: var(--font-sans);
}

/* The message: carved in stone – dominant, lasting */
.message-text {
  font-family: var(--font-inscribed);
  font-size: 1.625rem;
  font-weight: 600;
  line-height: 1.5;
  color: var(--color-text);
  margin-bottom: var(--space-lg);
  word-wrap: break-word;
  letter-spacing: 0.02em;
}

/* Meta: when and how – secondary to the inscription */
.message-meta-line {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: var(--space-sm);
  font-family: var(--font-sans);
  font-size: 0.8125rem;
  color: var(--color-text-secondary);
}

.message-timestamp {
  font-weight: 500;
  color: var(--color-text-secondary);
}

.message-chance {
  font-weight: 400;
  color: var(--color-text-tertiary);
}

.message-chance::before {
  content: " · ";
}

/* Permanent – sealed forever, one of the strongest messages on earth */
.message-permanent {
  margin-left: auto;
  font-size: 0.6875rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--color-accent);
  padding: var(--space-xs) var(--space-sm);
  background: var(--color-accent-bg);
  border-radius: var(--radius-sm);
}

.message-permanent::before {
  content: "◆ ";
  font-size: 0.5rem;
  vertical-align: 0.15em;
  margin-right: 2px;
}

/* Explicit: this message will never be erased */
.message-immutable {
  font-family: var(--font-sans);
  font-size: 0.6875rem;
  font-weight: 500;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--color-text-tertiary);
  margin-top: var(--space-md);
  margin-bottom: 0;
}

/* ---------- Sidebar ---------- */
.sidebar {
  width: 340px;
  flex-shrink: 0;
  border-left: 1px solid var(--color-border-subtle);
  background: var(--color-surface);
  padding: var(--space-xl);
  position: sticky;
  top: 0;
  height: calc(100vh - 65px);
  overflow-y: auto;
  overflow-x: hidden;
  transition: transform 0.25s ease, opacity 0.25s ease;
}

.sidebar.hidden {
  transform: translateX(100%);
  opacity: 0;
  pointer-events: none;
}

.sidebar-toggle {
  width: 40px;
  height: 40px;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 0;
  cursor: pointer;
  color: var(--color-text-secondary);
  transition: border-color 0.15s ease, color 0.15s ease, background 0.15s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}

.sidebar-toggle:hover {
  background: var(--color-surface);
  border-color: var(--color-text-tertiary);
  color: var(--color-text);
}

.sidebar-toggle svg {
  width: 20px;
  height: 20px;
}

.sidebar-header {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  margin-bottom: var(--space-md);
  padding-bottom: var(--space-md);
  border-bottom: 1px solid var(--color-border-subtle);
}

.sidebar-tabs {
  display: flex;
  flex: 1;
  gap: 0;
  min-width: 0;
}

.sidebar-tab {
  flex: 1;
  padding: var(--space-sm) var(--space-md);
  font-size: 0.875rem;
  font-weight: 500;
  font-family: var(--font-sans);
  color: var(--color-text-secondary);
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  cursor: pointer;
  transition: color 0.15s ease, border-color 0.15s ease;
}

.sidebar-tab:hover {
  color: var(--color-text);
}

.sidebar-tab[aria-selected="true"] {
  color: var(--color-accent);
  border-bottom-color: var(--color-accent);
}

.sidebar-close-mobile {
  display: none;
  flex-shrink: 0;
  width: 44px;
  height: 44px;
  align-items: center;
  justify-content: center;
  padding: 0;
  font-size: 1.5rem;
  line-height: 1;
  color: var(--color-text-secondary);
  background: none;
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: color 0.15s ease, background 0.15s ease;
}

.sidebar-close-mobile:hover {
  color: var(--color-text);
  background: var(--color-bg);
}

.sidebar-panel {
  display: block;
}

.sidebar-panel[hidden] {
  display: none;
}

.sidebar-section {
  margin-bottom: var(--space-xl);
}

.sidebar-section:last-child {
  margin-bottom: 0;
}

.sidebar-section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-md);
}

.sidebar-refresh {
  font-size: 0.8125rem;
  color: var(--color-text-secondary);
  background: none;
  border: none;
  cursor: pointer;
  padding: var(--space-xs) var(--space-sm);
  border-radius: var(--radius-sm);
  transition: color 0.15s ease, background 0.15s ease;
}

.sidebar-refresh:hover {
  color: var(--color-text);
  background: var(--color-bg);
}

.sidebar-title {
  font-size: 0.6875rem;
  font-weight: 500;
  color: var(--color-text-tertiary);
  margin-bottom: var(--space-md);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.promote-controls {
  margin-bottom: var(--space-md);
}

.promote-toolbar {
  margin-bottom: var(--space-sm);
  display: flex;
  justify-content: flex-end;
}

.selected-label {
  font-size: 0.8125rem;
  color: var(--color-text-secondary);
  margin-top: var(--space-sm);
  margin-bottom: var(--space-sm);
}

/* ---------- Forms ---------- */
.message-form {
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
}

.message-form .sidebar-title {
  margin-bottom: var(--space-sm);
}

.message-input {
  width: 100%;
  min-height: 96px;
  padding: var(--space-md);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  font-size: 0.9375rem;
  font-family: var(--font-sans);
  line-height: 1.5;
  resize: none;
  background: var(--color-surface);
  color: var(--color-text);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.message-input::placeholder {
  color: var(--color-text-tertiary);
}

.message-input:focus {
  outline: none;
  border-color: var(--color-accent);
  box-shadow: 0 0 0 3px var(--color-accent-muted);
}

.btn-primary {
  width: 100%;
  padding: 12px var(--space-md);
  background: var(--color-accent);
  color: var(--color-surface);
  border: none;
  border-radius: var(--radius-md);
  font-size: 0.875rem;
  font-weight: 500;
  font-family: var(--font-sans);
  cursor: pointer;
  transition: background 0.15s ease, opacity 0.15s ease;
}

.btn-primary:hover {
  background: var(--color-accent-hover);
}

.btn-primary:active {
  opacity: 0.9;
}

.btn-secondary {
  padding: 10px var(--space-md);
  background: var(--color-surface);
  color: var(--color-text);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  font-size: 0.875rem;
  font-weight: 500;
  font-family: var(--font-sans);
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease, color 0.15s ease;
}

.btn-secondary:hover {
  background: var(--color-bg);
  border-color: var(--color-text-tertiary);
}

.btn-secondary.active {
  background: var(--color-accent);
  color: var(--color-surface);
  border-color: var(--color-accent);
}

.btn-secondary.active:hover {
  background: var(--color-accent-hover);
  border-color: var(--color-accent-hover);
}

.w-full { width: 100%; }
.mb-2 { margin-bottom: var(--space-sm); }

.captcha-block {
  width: 100%;
}

.captcha-hint {
  font-size: 0.75rem;
  color: var(--color-text-tertiary);
  margin-bottom: var(--space-xs);
  line-height: 1.4;
}

/* Captcha: contained block so widget + any warning have room and don’t overlap */
/* Extra top padding so hCaptcha’s localhost warning doesn’t overlap the checkbox */
.hcaptcha-wrap {
  width: 100%;
  min-height: 1px;
  display: block;
}

.hcaptcha-wrap > div {
  display: block;
  max-width: 100%;
}

/* ---------- Queue list ---------- */
.queue-container {
  background: var(--color-bg);
  border: 1px solid var(--color-border-subtle);
  border-radius: var(--radius-md);
  overflow: hidden;
}

.queue-list {
  list-style: none;
  max-height: 280px;
  overflow-y: auto;
}

.queue-item {
  padding: var(--space-md) var(--space-lg);
  border-bottom: 1px solid var(--color-border-subtle);
  cursor: pointer;
  transition: background 0.15s ease;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-sm);
}

.queue-item:last-child {
  border-bottom: none;
}

.queue-item:hover {
  background: var(--color-surface);
}

.queue-item.selected {
  background: var(--color-accent-bg);
  border-left: 3px solid var(--color-accent);
  padding-left: calc(var(--space-lg) - 3px);
}

.queue-message {
  flex: 1;
  font-size: 0.875rem;
  color: var(--color-text);
  margin-right: var(--space-sm);
  word-break: break-word;
}

.queue-count {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--color-text-secondary);
  background: var(--color-surface);
  padding: var(--space-xs) var(--space-sm);
  border-radius: var(--radius-sm);
  flex-shrink: 0;
}

.queue-pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-md);
  padding: var(--space-md);
  border-top: 1px solid var(--color-border-subtle);
  background: var(--color-surface);
}

.pagination-btn {
  width: 32px;
  height: 32px;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 0;
  cursor: pointer;
  color: var(--color-text-secondary);
  font-size: 0.875rem;
  transition: border-color 0.15s ease, color 0.15s ease, background 0.15s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}

.pagination-btn:hover:not(:disabled) {
  background: var(--color-surface);
  border-color: var(--color-text-tertiary);
  color: var(--color-text);
}

.pagination-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.pagination-num {
  font-size: 0.75rem;
  color: var(--color-text-tertiary);
}

/* ---------- Empty states ---------- */
.timeline-content .empty-state {
  text-align: center;
  padding: var(--space-3xl) var(--space-xl);
  color: var(--color-text-tertiary);
  font-size: 1rem;
  font-weight: 400;
  max-width: 360px;
  margin: 0 auto;
}

/* ---------- Mobile ---------- */
@media (max-width: 768px) {
  .app-header {
    padding: var(--space-sm) var(--space-md);
    flex-wrap: wrap;
    gap: var(--space-sm);
  }

  .app-header-brand {
    min-width: 0;
  }

  .app-title {
    font-size: 1rem;
  }

  .app-tagline {
    font-size: 0.6875rem;
  }

  .app-header-actions {
    gap: var(--space-md);
    flex-shrink: 0;
  }

  .countdown-wrap {
    text-align: right;
  }

  .countdown-value {
    font-size: 0.875rem;
  }

  .sidebar-toggle {
    width: 44px;
    height: 44px;
    min-width: 44px;
    min-height: 44px;
  }

  .layout-container {
    flex-direction: column;
    min-height: calc(100vh - 65px);
  }

  .timeline {
    padding: var(--space-md) var(--space-md);
    padding-bottom: 120px; /* space so last message isn’t behind bottom drawer */
    box-shadow: 0 0 0 1px var(--color-border-subtle);
    min-height: 0;
  }

  .timeline-content {
    padding: 0;
    max-width: none;
  }

  .message-card {
    padding: var(--space-lg) var(--space-md);
    margin-bottom: var(--space-lg);
  }

  .message-card::before {
    margin: 0 calc(-1 * var(--space-md)) var(--space-md);
    padding: var(--space-sm) var(--space-md);
  }

  .message-text {
    font-size: 1.375rem;
    line-height: 1.45;
    margin-bottom: var(--space-md);
  }

  .message-meta-line {
    font-size: 0.75rem;
    gap: var(--space-xs);
  }

  .timeline-content .empty-state {
    padding: var(--space-xl) var(--space-md);
    font-size: 0.9375rem;
  }

  .sidebar {
    width: 100%;
    border-left: none;
    border-top: 1px solid var(--color-border-subtle);
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: auto;
    max-height: 85vh;
    padding: var(--space-md) var(--space-md);
    padding-bottom: max(var(--space-md), env(safe-area-inset-bottom));
    z-index: 100;
    box-shadow: 0 -4px 24px rgba(28, 27, 25, 0.12);
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
  }

  .sidebar.hidden {
    transform: translateY(100%);
  }

  .sidebar-header {
    flex-shrink: 0;
    margin-bottom: var(--space-md);
    padding-bottom: var(--space-md);
    background: var(--color-surface);
  }

  .sidebar-close-mobile {
    display: flex;
  }

  .sidebar-tab {
    min-height: 44px;
    padding: var(--space-md);
  }

  .sidebar-section {
    margin-bottom: var(--space-lg);
  }

  .sidebar-section:last-child {
    margin-bottom: 0;
  }

  .message-form {
    gap: var(--space-sm);
  }


  .queue-list {
    max-height: 200px;
  }

  .queue-item {
    padding: var(--space-sm) var(--space-md);
  }

  .queue-message {
    font-size: 0.8125rem;
  }

  #toast-container {
    top: var(--space-md);
    left: var(--space-md);
    right: var(--space-md);
    align-items: center;
  }

  .toast {
    max-width: none;
    width: 100%;
  }
}

/* Very small phones */
@media (max-width: 380px) {
  .app-header {
    padding: var(--space-xs) var(--space-sm);
  }

  .app-title {
    font-size: 0.9375rem;
  }

  .app-tagline {
    display: none;
  }

  .countdown-label {
    font-size: 0.625rem;
  }

  .countdown-value {
    font-size: 0.8125rem;
  }

  .timeline {
    padding: var(--space-sm);
  }

  .message-card {
    padding: var(--space-md) var(--space-sm);
  }

  .message-card::before {
    margin: 0 calc(-1 * var(--space-sm)) var(--space-sm);
    padding: var(--space-xs) var(--space-sm);
    font-size: 0.5625rem;
    letter-spacing: 0.12em;
  }

  .message-text {
    font-size: 1.25rem;
  }

  .sidebar {
    padding: var(--space-sm);
    padding-bottom: max(var(--space-sm), env(safe-area-inset-bottom));
  }

  .message-input {
    min-height: 80px;
    padding: var(--space-sm);
  }

  .btn-primary,
  .btn-secondary {
    padding: 10px var(--space-sm);
    font-size: 0.8125rem;
  }
}

/* ---------- Toasts ---------- */
#toast-container {
  position: fixed;
  top: var(--space-lg);
  right: var(--space-lg);
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
  pointer-events: none;
}

.toast {
  padding: var(--space-md) var(--space-lg);
  border-radius: var(--radius-md);
  font-size: 0.875rem;
  font-family: var(--font-sans);
  line-height: 1.45;
  box-shadow: var(--shadow-md);
  pointer-events: auto;
  max-width: 320px;
  border: 1px solid var(--color-border-subtle);
}

.toast-info {
  background: var(--color-surface);
  color: var(--color-text);
}

.toast-error {
  background: var(--color-surface);
  color: #b91c1c;
  border-color: #fecaca;
}
