:root {
  color-scheme: light;
  --bg: #f4f1ec;
  --surface: #ffffff;
  --text: #1a1d23;
  --text-muted: #6b7280;
  --border: #e5e0d8;
  --primary: #2d2a4a;
  --primary-contrast: #ffffff;
  --accent: #6d5bd0;
  --success: #15803d;
  --success-bg: #dcfce7;
  --pending: #b45309;
  --pending-bg: #fef3c7;
  --danger: #b91c1c;
  --danger-bg: #fee2e2;
  --radius: 14px;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #14121f;
    --surface: #1e1b2e;
    --text: #f1f2f4;
    --text-muted: #a7a2bd;
    --border: #33304a;
    --primary: #f1f2f4;
    --primary-contrast: #14121f;
    --accent: #a996ff;
    --success: #4ade80;
    --success-bg: #14301f;
    --pending: #fbbf24;
    --pending-bg: #3a2c0c;
    --danger: #f87171;
    --danger-bg: #3a1414;
  }
}

* { box-sizing: border-box; }

/* Alguns elementos (ex: .badge) fixam `display` explicitamente, o que na
   cascata (regra de autor) vence o `[hidden]{display:none}` do stylesheet
   do navegador mesmo com especificidade igual — então reforça aqui. */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
  padding-bottom: env(safe-area-inset-bottom);
}

.offline-banner {
  background: var(--pending-bg);
  color: var(--pending);
  text-align: center;
  font-size: 13px;
  padding: 8px 16px;
}

.update-banner {
  background: var(--accent);
  color: #fff;
  text-align: center;
  font-size: 13px;
  padding: 8px 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding-top: env(safe-area-inset-top);
}

.app-header-inner {
  max-width: 640px;
  margin: 0 auto;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.app-header h1 {
  font-size: 18px;
  margin: 0;
}

.app-header-actions {
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
}

.icon-btn {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 16px;
  line-height: 1;
  padding: 6px 9px;
  cursor: pointer;
  touch-action: manipulation;
}

.menu-panel {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  min-width: 220px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
  padding: 6px;
  z-index: 20;
}

.menu-item {
  display: block;
  width: 100%;
  background: none;
  border: none;
  text-align: left;
  font: inherit;
  font-size: 14px;
  color: var(--text);
  padding: 10px 10px;
  border-radius: 8px;
  cursor: pointer;
  touch-action: manipulation;
}

.menu-item:active {
  background: var(--bg);
}

.menu-item-status {
  font-size: 12px;
  color: var(--text-muted);
  margin: 2px 10px 4px;
  min-height: 15px;
}

.badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding: 3px 9px;
  border-radius: 999px;
}

.badge-online { background: var(--success-bg); color: var(--success); }
.badge-offline { background: var(--danger-bg); color: var(--danger); }
.badge-new { background: var(--accent); color: #fff; flex-shrink: 0; }

#app {
  max-width: 640px;
  margin: 0 auto;
  padding: 16px;
}

.view-toolbar {
  display: flex;
  gap: 10px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.btn {
  border: none;
  border-radius: var(--radius);
  padding: 12px 18px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  touch-action: manipulation;
}

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

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

.btn-ghost {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-small {
  padding: 6px 12px;
  font-size: 13px;
}

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

.filters-row {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.search-input {
  flex: 1 1 200px;
  min-width: 0;
  font-size: 15px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
}

.search-input::-webkit-search-cancel-button {
  cursor: pointer;
}

.sort-select {
  flex: 0 1 auto;
  font-size: 14px;
  padding: 10px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
}

.sync-status {
  font-size: 13px;
  color: var(--text-muted);
  min-height: 18px;
  margin: 0 0 12px;
}

.empty-state {
  color: var(--text-muted);
  font-size: 14px;
  text-align: center;
  padding: 40px 16px;
}

/* ---------- Índice de histórias ---------- */
.story-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.story-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.story-item-btn {
  width: 100%;
  background: none;
  border: none;
  padding: 14px 16px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  text-align: left;
  cursor: pointer;
  font: inherit;
  color: inherit;
  touch-action: manipulation;
}

.story-item-main {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}

.story-item-title {
  font-size: 15px;
}

.story-item-stats {
  font-size: 12.5px;
  color: var(--text-muted);
}

.story-item-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 2px;
}

.tag-chip {
  display: inline-block;
  font-size: 11px;
  line-height: 1.4;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--bg);
  color: var(--text-muted);
  border: 1px solid var(--border);
}

/* ---------- Leitura ---------- */
.story-title {
  font-size: 22px;
  margin: 0 0 6px;
  line-height: 1.25;
}

.story-meta {
  font-size: 13px;
  color: var(--text-muted);
  margin: 0 0 20px;
}

.story-body {
  font-size: 17px;
  line-height: 1.7;
}

.story-body p {
  margin: 0 0 14px;
}

.story-end {
  text-align: center;
  color: var(--text-muted);
  font-size: 15px;
  margin: 24px 0 20px;
}

.btn-block {
  display: block;
  width: 100%;
  margin: 0 0 40px;
}

.view[hidden] { display: none; }
