:root {
  --tg-theme-bg-color: #ffffff;
  --tg-theme-text-color: #000000;
  --tg-theme-hint-color: #999999;
  --tg-theme-link-color: #2481cc;
  --tg-theme-button-color: #2481cc;
  --tg-theme-button-text-color: #ffffff;
  --tg-theme-secondary-bg-color: #f4f4f5;
}

@media (prefers-color-scheme: dark) {
  :root {
    --tg-theme-bg-color: #18222d;
    --tg-theme-text-color: #ffffff;
    --tg-theme-hint-color: #8e8e93;
    --tg-theme-secondary-bg-color: #131416;
  }
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--tg-theme-bg-color);
  color: var(--tg-theme-text-color);
  min-height: 100vh;
  padding-bottom: env(safe-area-inset-bottom, 0);
}

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

.header {
  padding: 20px 0 16px;
  text-align: center;
}

.header h1 {
  font-size: 1.5rem;
  font-weight: 700;
}

.subtitle {
  color: var(--tg-theme-hint-color);
  font-size: 0.9rem;
  margin-top: 4px;
}

.tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 20px;
  background: var(--tg-theme-secondary-bg-color);
  padding: 4px;
  border-radius: 12px;
}

.tab {
  flex: 1;
  padding: 10px 16px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--tg-theme-text-color);
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.2s;
}

.tab.active {
  background: var(--tg-theme-button-color);
  color: var(--tg-theme-button-text-color);
}

.tab-content {
  display: none;
}

.tab-content.active {
  display: block;
}

.news-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.news-card {
  background: var(--tg-theme-secondary-bg-color);
  border-radius: 12px;
  padding: 16px;
  cursor: pointer;
  transition: transform 0.15s, opacity 0.15s;
}

.news-card:active {
  opacity: 0.9;
}

.news-card h3 {
  font-size: 1rem;
  font-weight: 600;
  line-height: 1.4;
  margin-bottom: 6px;
}

.news-card p {
  font-size: 0.85rem;
  color: var(--tg-theme-hint-color);
  line-height: 1.4;
}

.news-card .meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 10px;
  font-size: 0.75rem;
  color: var(--tg-theme-hint-color);
}

.source-badge {
  background: var(--tg-theme-button-color);
  color: var(--tg-theme-button-text-color);
  padding: 2px 8px;
  border-radius: 6px;
  font-size: 0.7rem;
}

.loading, .empty {
  text-align: center;
  padding: 40px 20px;
  color: var(--tg-theme-hint-color);
}

.hidden {
  display: none !important;
}

.digest-box {
  background: var(--tg-theme-secondary-bg-color);
  border-radius: 12px;
  padding: 20px;
  line-height: 1.6;
  white-space: pre-wrap;
}

.digest-box h3 {
  margin-bottom: 12px;
  font-size: 1rem;
}

.sources-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 24px;
}

.source-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  background: var(--tg-theme-secondary-bg-color);
  border-radius: 12px;
  cursor: pointer;
}

.source-item input {
  width: 20px;
  height: 20px;
}

.btn {
  display: inline-block;
  padding: 12px 24px;
  border-radius: 12px;
  font-weight: 600;
  text-decoration: none;
  text-align: center;
  cursor: pointer;
  border: none;
  font-size: 1rem;
}

.btn.primary {
  width: 100%;
  background: var(--tg-theme-button-color);
  color: var(--tg-theme-button-text-color);
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 1000;
  padding: 0 0 env(safe-area-inset-bottom, 0);
}

.modal-content {
  background: var(--tg-theme-bg-color);
  border-radius: 20px 20px 0 0;
  padding: 24px;
  max-height: 85vh;
  overflow-y: auto;
  width: 100%;
  max-width: 480px;
  position: relative;
}

.modal-close {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 36px;
  height: 36px;
  border: none;
  background: var(--tg-theme-secondary-bg-color);
  border-radius: 50%;
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--tg-theme-text-color);
  line-height: 1;
}

.modal-content h2 {
  font-size: 1.2rem;
  margin-bottom: 12px;
  padding-right: 40px;
}

.modal-content #modal-desc {
  color: var(--tg-theme-hint-color);
  margin-bottom: 16px;
  font-size: 0.95rem;
}

.modal-content .btn {
  display: block;
  margin-bottom: 20px;
}

.ai-summary {
  padding-top: 16px;
  border-top: 1px solid var(--tg-theme-secondary-bg-color);
}

.ai-summary h3 {
  font-size: 0.9rem;
  margin-bottom: 8px;
  color: var(--tg-theme-hint-color);
}
