* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

/* Light Theme (Dawn) */
:root {
  --bg: #fefcf8;
  --bg-secondary: #faf6ed;
  --fg: #2d2416;
  --fg-muted: #6b5d47;
  --border: #e8dcc4;
  --accent: #d4941f;
  --accent-hover: #b87d19;
  --accent-light: #f5e6cc;
  --secondary: #8b7355;
  --success: #6b8e23;
  --warning: #d4941f;
  --danger: #c44536;
  --shadow: rgba(212, 148, 31, 0.1);
  --link-gold: #e8b923;
  --link-gold-hover: #f5c842;
  --top-offset: 0px;
  --menu-offset: 0px;
}

/* Dark Theme (Night before Dawn) */
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1a1612;
    --bg-secondary: #2d2416;
    --fg: #f5e6cc;
    --fg-muted: #b89968;
    --border: #3d3020;
    --accent: #d4941f;
    --accent-hover: #f5a623;
    --accent-light: #2d2416;
    --secondary: #b89968;
    --success: #8fbc3f;
    --warning: #f5a623;
    --danger: #e65540;
    --shadow: rgba(0, 0, 0, 0.3);
    --link-gold: #f5c842;
    --link-gold-hover: #ffd966;
  }

  .nav-items a.active {
    background: var(--accent);
    color: #fff;
  }
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  line-height: 1.6;
  color: var(--fg);
  background: var(--bg);
  transition: background 0.3s ease, color 0.3s ease;
}

.page {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  padding-top: var(--top-offset);
  padding-bottom: var(--menu-offset);
}

/* Offline Banner */
.offline-banner {
  background: var(--warning);
  color: #fff;
  text-align: center;
  padding: 8px 16px;
  font-size: 14px;
  font-weight: 500;
}

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

#main-content {
  flex: 1;
}

/* Respect reduced motion preference */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

a {
  color: var(--accent);
  text-decoration: none;
  transition: color 0.2s ease;
}

a:hover {
  color: var(--accent-hover);
  text-decoration: underline;
}

a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 2px;
}

.container {
  width: 90%;
  max-width: 1000px;
  margin: 0 auto;
}

/* Navigation */
.nav {
  background: var(--bg);
  border-bottom: 2px solid var(--accent);
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 8px var(--shadow);
  backdrop-filter: blur(10px);
}

.nav-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 12px 20px;
}

@media (max-width: 839px) {
  .nav-container {
    width: 100%;
    max-width: none;
    margin: 0;
  }
}

@media (max-width: 479px) {
  .nav-container {
    width: 100%;
    max-width: none;
    margin: 0;
  }
}

.nav-items {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  justify-content: center;
  min-width: 0;
}

.nav-items a {
  color: var(--fg-muted);
  font-size: 13px;
  font-weight: 500;
  padding: 8px 12px;
  border-radius: 6px;
  display: inline-flex;
  flex-direction: row;
  align-items: center;
  gap: 8px;
  transition: background 0.2s ease, color 0.2s ease;
  white-space: nowrap;
}

.nav-items a:hover {
  color: var(--fg);
  background: var(--accent-light);
  text-decoration: none;
}

.nav-items a.active {
  color: var(--fg);
  background: var(--accent-light);
  font-weight: 600;
}

.nav-items svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

.nav-items span {
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Link-style nav items (brand, github) */
.nav-items a.nav-item-link {
  color: var(--link-gold);
}

.nav-items a.nav-item-link:hover {
  color: var(--link-gold-hover);
}

/* External links indicator */
a[target="_blank"]::after {
  content: "";
  display: inline-block;
  width: 1em;
  height: 1em;
  margin-inline-start: 0.3em;
  -webkit-mask-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="black"><path stroke-linecap="round" stroke-linejoin="round" d="M13.5 6H5.25A2.25 2.25 0 0 0 3 8.25v10.5A2.25 2.25 0 0 0 5.25 21h10.5A2.25 2.25 0 0 0 18 18.75V10.5m-10.5 6L21 3m0 0h-5.25M21 3v5.25"/></svg>');
  mask-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="black"><path stroke-linecap="round" stroke-linejoin="round" d="M13.5 6H5.25A2.25 2.25 0 0 0 3 8.25v10.5A2.25 2.25 0 0 0 5.25 21h10.5A2.25 2.25 0 0 0 18 18.75V10.5m-10.5 6L21 3m0 0h-5.25M21 3v5.25"/></svg>');
  -webkit-mask-size: contain;
  mask-size: contain;
  -webkit-mask-repeat: no-repeat;
  mask-repeat: no-repeat;
  -webkit-mask-position: center;
  mask-position: center;
  background-color: currentColor;
  opacity: 0.6;
  transition: opacity 0.2s ease;
  vertical-align: -0.125em;
}

a[target="_blank"]:hover::after {
  opacity: 1;
}

/* RTL: flip the arrow */
html[dir="rtl"] a[target="_blank"]::after {
  transform: scaleX(-1);
  margin-inline-start: 0;
  margin-inline-end: 0.3em;
}

.nav-loading {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--fg-muted);
}

.spinner {
  display: inline-block;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.language-select {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  color: var(--fg);
  padding: 6px 8px;
  border-radius: 6px;
  font-size: 12px;
}

.language-select:focus {
  outline: none;
  border-color: var(--accent);
}

.mobile-header {
  display: none;
  background: var(--bg);
  border-bottom: 2px solid var(--accent);
  box-shadow: 0 2px 8px var(--shadow);
  z-index: 110;
}

.mobile-header-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0.5rem 1.25rem;
}

.mobile-header-items {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  flex-wrap: wrap;
  justify-content: center;
  min-width: 0;
}

.mobile-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--link-gold);
  padding: 0.5rem 0.75rem;
  border-radius: 0.375rem;
  display: inline-flex;
  flex-direction: row;
  align-items: center;
  gap: 0.5rem;
  transition: background 0.2s ease, color 0.2s ease;
  white-space: nowrap;
}

.mobile-title:hover {
  color: var(--link-gold-hover);
  background: var(--accent-light);
  text-decoration: none;
}

.mobile-title svg {
  width: 1.125rem;
  height: 1.125rem;
}

/* Sections */
.section {
  display: none;
  padding: 40px 0;
  min-height: calc(100vh - 200px);
}


.section.active {
  display: block;
}

h1 {
  font-size: 36px;
  margin-bottom: 16px;
  color: var(--accent);
  font-weight: 700;
}

h2 {
  font-size: 24px;
  margin: 32px 0 16px;
  color: var(--fg);
  font-weight: 600;
}

.lead {
  font-size: 18px;
  color: var(--fg-muted);
  margin-bottom: 32px;
  max-width: 700px;
}

/* Buttons */
.btn {
  display: inline-block;
  padding: 12px 24px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  box-shadow: 0 2px 4px var(--shadow);
}

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

.btn-primary:hover {
  background: var(--accent-hover);
  text-decoration: none;
}

.btn-secondary {
  background: var(--secondary);
  color: #fff;
}

.btn-secondary:hover {
  background: #745d43;
  text-decoration: none;
}

.action-buttons {
  display: flex;
  gap: 16px;
  margin-top: 32px;
  flex-wrap: wrap;
}

/* Stats Grid */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 24px;
  margin: 32px 0;
}

.stat-card {
  padding: 24px;
  background: var(--bg-secondary);
  border: 2px solid var(--border);
  border-radius: 12px;
  text-align: center;
}

.stat-card:hover {
  border-color: var(--accent);
}

.stat-value {
  font-size: 36px;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 8px;
}

.stat-label {
  font-size: 14px;
  color: var(--fg-muted);
  text-transform: uppercase;
  letter-spacing: 1px;
  font-weight: 600;
}

/* Search & Filter */
.search-box {
  margin: 24px 0;
}

.search-box input {
  width: 100%;
  padding: 14px 18px;
  font-size: 16px;
  border: 2px solid var(--border);
  border-radius: 8px;
  background: var(--bg-secondary);
  color: var(--fg);
  transition: all 0.2s ease;
}

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

.filter-bar {
  display: flex;
  gap: 16px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}

.filter-bar select {
  padding: 10px 14px;
  border: 2px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  background: var(--bg-secondary);
  color: var(--fg);
  cursor: pointer;
  transition: all 0.2s ease;
}

.filter-bar select:focus {
  outline: none;
  border-color: var(--accent);
}

/* Content List */
.content-list {
  display: grid;
  gap: 16px;
}

.content-item {
  padding: 18px;
  background: var(--bg-secondary);
  border: 2px solid var(--border);
  border-left: 4px solid var(--accent);
  border-radius: 8px;
}

.content-item:hover {
  border-color: var(--accent);
}

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

.content-id {
  font-family: 'Monaco', 'Courier New', monospace;
  font-size: 12px;
  color: var(--fg-muted);
  background: var(--accent-light);
  padding: 4px 8px;
  border-radius: 4px;
}

.content-type {
  padding: 4px 12px;
  background: var(--accent);
  color: #fff;
  border-radius: 6px;
  font-size: 11px;
  text-transform: uppercase;
  font-weight: 700;
  letter-spacing: 0.5px;
}

.content-description {
  margin: 8px 0;
  color: var(--fg);
}

.content-meta {
  font-size: 12px;
  color: var(--fg-muted);
  margin-top: 8px;
}

/* Events List */
.events-list {
  display: grid;
  gap: 24px;
}

.event-item {
  padding: 24px;
  border-left: 4px solid var(--accent);
  background: var(--bg-secondary);
  border-radius: 8px;
}

.event-item:hover {
}

.event-title {
  font-size: 20px;
  font-weight: 700;
  margin-bottom: 8px;
  color: var(--accent);
}

.event-date {
  font-size: 14px;
  color: var(--fg-muted);
  margin-bottom: 8px;
  font-weight: 600;
}

.event-description {
  margin-top: 12px;
  color: var(--fg);
}

/* Stats Tables */
.stats-section {
  margin: 32px 0;
}

.stats-table {
  border: 2px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}

.stats-row {
  display: flex;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
}

.stats-row:last-child {
  border-bottom: none;
}

.stats-row:hover {
  background: var(--accent-light);
}

/* Activity Log */
.activity-log {
  display: grid;
  gap: 12px;
}

.activity-item {
  padding: 14px;
  border-left: 3px solid var(--accent);
  background: var(--bg-secondary);
  border-radius: 6px;
  font-size: 14px;
}

.activity-item:hover {
}

.activity-time {
  color: var(--fg-muted);
  font-size: 12px;
  margin-top: 4px;
}

/* Submit Guide */
.submit-guide {
  max-width: 700px;
}

.submit-steps {
  margin-left: 24px;
  margin-bottom: 32px;
}

.submit-steps li {
  margin: 12px 0;
  padding-left: 8px;
}

.submit-steps li::marker {
  color: var(--accent);
  font-weight: 700;
}

.guidelines {
  margin-left: 24px;
  margin-bottom: 32px;
}

.guidelines li {
  margin: 8px 0;
  padding-left: 8px;
}

.guidelines li::marker {
  color: var(--accent);
}

/* Loading */
.loading {
  color: var(--fg-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  text-align: center;
  padding: 40px;
  font-style: italic;
}

/* App Loading Progress */
.app-loading {
  padding: 60px 20px;
  text-align: center;
}

.app-loading-title {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  font-size: 24px;
  font-weight: 600;
  color: var(--accent);
  margin-bottom: 32px;
}

.app-loading-steps {
  list-style: none;
  max-width: 300px;
  margin: 0 auto;
  text-align: start;
}

.loading-step {
  padding: 8px 0;
  color: var(--fg-muted);
  display: flex;
  align-items: center;
  gap: 8px;
}

.loading-step::before {
  content: "";
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid var(--border);
  flex-shrink: 0;
}

.loading-step.active {
  color: var(--fg);
}

.loading-step.active::before {
  border-color: var(--accent);
  border-top-color: transparent;
  animation: spin 0.8s linear infinite;
}

.loading-step.done {
  color: var(--success);
}

.loading-step.done::before {
  border-color: var(--success);
  background: var(--success);
}

.loading-step.error {
  color: var(--danger);
}

.loading-step.error::before {
  border-color: var(--danger);
  background: var(--danger);
}

.app-loading-error {
  margin-top: 32px;
  padding: 20px;
  background: var(--bg-secondary);
  border: 2px solid var(--danger);
  border-radius: 8px;
  max-width: 400px;
  margin-inline: auto;
}

.app-loading-error p:first-child {
  font-weight: 600;
  color: var(--danger);
  margin-bottom: 8px;
}

.app-loading-error-message {
  color: var(--fg-muted);
  font-size: 14px;
  margin-bottom: 16px;
}

.app-loading-error button {
  background: var(--danger);
  color: #fff;
  border: none;
  padding: 10px 20px;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s ease;
}

.app-loading-error button:hover {
  background: var(--accent-hover);
}

/* Version Section in Settings */
.version-section {
  margin-top: 32px;
  padding: 24px;
  background: var(--bg-secondary);
  border: 2px solid var(--border);
  border-radius: 12px;
}

.version-section h2 {
  margin: 0 0 16px 0;
  font-size: 18px;
}

.version-info {
  margin-bottom: 16px;
}

.version-info p {
  margin: 8px 0;
  font-size: 14px;
  color: var(--fg);
}

.version-info #current-version {
  font-family: 'Monaco', 'Courier New', monospace;
  font-weight: 600;
  color: var(--accent);
}

.version-status {
  font-size: 13px;
  padding: 6px 12px;
  border-radius: 6px;
  display: inline-block;
  margin-top: 4px;
}

.version-status.status-ok {
  background: var(--success);
  color: #fff;
}

.version-status.status-warning {
  background: var(--warning);
  color: #fff;
}

.version-status.status-error {
  background: var(--danger);
  color: #fff;
}

.version-status.status-update {
  background: var(--accent);
  color: #fff;
}

.version-status.status-checking {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--fg-muted);
}

.version-actions {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.version-actions .btn {
  padding: 10px 18px;
  font-size: 13px;
}

.version-actions .btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

/* Desktop (>= 768px) - hide home nav link */
@media (min-width: 768px) {
  [data-nav="home"] {
    display: none;
  }
}

/* Mobile - adaptive layout */
@media (max-width: 839px) {
  :root {
    --top-offset: 50px;
    --menu-offset: 64px;
  }

  .mobile-header {
    display: block;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
  }

  .mobile-header-inner {
    padding: 10px 16px;
  }

  .nav {
    position: fixed;
    top: auto;
    bottom: 0;
    left: 0;
    right: 0;
    border-top: 2px solid var(--accent);
    border-bottom: none;
    box-shadow: 0 -2px 8px var(--shadow);
  }

  .nav-container {
    padding: 8px 16px;
  }

  .nav-items {
    flex-wrap: nowrap;
    justify-content: center;
    gap: 4px;
    overflow-x: auto;
    scrollbar-width: none;
  }

  .nav-items::-webkit-scrollbar {
    display: none;
  }

  .nav-items a {
    flex-direction: column;
    padding: 6px 10px;
    gap: 4px;
    font-size: 10px;
    text-align: center;
  }

  .nav-items svg {
    width: 20px;
    height: 20px;
  }

  .nav-items a.nav-item-link {
    display: none;
  }

  #nav-items-container {
    display: flex;
    gap: 4px;
  }

  #nav-items-container a {
    flex-direction: column;
    padding: 6px 10px;
    gap: 4px;
    font-size: 10px;
    text-align: center;
  }

  .language-select {
    padding: 4px 6px;
    font-size: 11px;
  }

  h1 {
    font-size: 28px;
  }

  h2 {
    font-size: 20px;
  }

  .lead {
    font-size: 16px;
  }

  .stats-grid {
    grid-template-columns: 1fr;
    gap: 16px;
  }

  .stat-value {
    font-size: 28px;
  }

  .action-buttons {
    flex-direction: column;
    width: 100%;
  }

  .action-buttons .btn {
    width: 100%;
    text-align: center;
  }

  .filter-bar {
    flex-direction: column;
  }

  .filter-bar select {
    width: 100%;
  }

  .content-header {
    flex-direction: column;
    gap: 8px;
  }

  .event-title {
    font-size: 18px;
  }

  .section {
    padding: 24px 0;
  }

  .container {
    padding: 0 16px;
  }

  /* Small screens - icons only (479px and below) */
  @media (max-width: 479px) {
    :root {
      --menu-offset: 52px;
    }

    .nav-container {
      padding: 6px 0;
    }

    .nav-items {
      gap: 0;
    }

    #nav-items-container {
      flex: 1;
      gap: 0;
      justify-content: space-around;
    }

    #nav-items-container a {
      flex: 1;
      flex-direction: row;
      padding: 8px;
      gap: 0;
      justify-content: center;
    }

    .nav-items a {
      flex-direction: row;
      padding: 8px;
      gap: 0;
    }

    .nav-items svg {
      width: 22px;
      height: 22px;
    }

    .nav-items span {
      display: none;
    }
  }
}

/* Print styles */
@media print {
  .nav,
  .mobile-header,
  .action-buttons {
    display: none;
  }
  
  body {
    color: #000;
    background: #fff;
  }
  
  a {
    color: #000;
    text-decoration: underline;
  }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
  :root {
    --border: #000;
  }
  
  .btn,
  .content-item,
  .event-item,
  .stat-card {
    border-width: 3px;
  }
}
