:root {
  --ink: #10212f;
  --muted: #667487;
  --paper: #fffaf0;
  --panel: rgba(255, 255, 255, 0.78);
  --accent: #f77f00;
  --accent-2: #2a9d8f;
  --danger: #d62828;
  --line: rgba(16, 33, 47, 0.12);
  --shadow: 0 24px 80px rgba(19, 37, 56, 0.18);
  font-family: "Aptos Display", "Trebuchet MS", Verdana, system-ui, sans-serif;
}

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

body {
  color: var(--ink);
  min-height: 100vh;
  min-height: 100dvh;
  background:
    radial-gradient(circle at 12% 10%, rgba(247, 127, 0, 0.24), transparent 28rem),
    radial-gradient(circle at 88% 18%, rgba(42, 157, 143, 0.22), transparent 26rem),
    linear-gradient(135deg, #fff3d6 0%, #eef7f4 55%, #e8eef7 100%);
  -webkit-font-smoothing: antialiased;
}

.shell {
  width: min(1080px, calc(100% - 28px));
  margin: 0 auto;
  padding: 28px 0 48px;
}

/* ── Hero ── */
.hero {
  display: flex;
  gap: 22px;
  justify-content: space-between;
  align-items: flex-end;
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: 32px;
  background: var(--panel);
  backdrop-filter: blur(18px);
  box-shadow: var(--shadow);
}

.eyebrow {
  margin: 0 0 8px;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  color: var(--accent-2);
  font-weight: 800;
  font-size: 0.78rem;
}

h1 {
  margin: 0;
  font-size: clamp(2.5rem, 11vw, 7.5rem);
  letter-spacing: -0.09em;
  line-height: 0.86;
}

.sub {
  max-width: 620px;
  margin: 14px 0 0;
  color: var(--muted);
  font-size: 1.06rem;
  line-height: 1.5;
}

.hero-actions, .toolbar {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

/* ── Buttons (44px min for touch) ── */
button {
  border: 0;
  border-radius: 999px;
  padding: 12px 18px;
  min-height: 44px;
  color: white;
  background: var(--ink);
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 10px 24px rgba(16, 33, 47, 0.15);
  font-size: 0.92rem;
  white-space: nowrap;
  transition: transform 0.15s ease;
  -webkit-tap-highlight-color: transparent;
}

button:hover { transform: translateY(-1px); }
button:active { transform: translateY(0); }

/* ── Stats ── */
.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
  margin: 18px 0;
}

.stats article, .toolbar, .card {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.72);
  backdrop-filter: blur(14px);
  border-radius: 24px;
}

.stats article { padding: 18px; text-align: center; }
.stats span { display: block; font-size: 2rem; font-weight: 900; }
.stats small, .meta, time { color: var(--muted); }

/* ── Toolbar ── */
.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  margin-bottom: 18px;
  flex-wrap: wrap;
  gap: 8px;
}
.toolbar label {
  font-size: 0.92rem;
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  min-height: 44px;
}

/* ── Feed ── */
.feed {
  display: grid;
  gap: 14px;
}

/* ── Card ── */
.card {
  padding: 18px;
  box-shadow: 0 12px 34px rgba(16, 33, 47, 0.08);
  animation: rise 360ms ease both;
  word-break: break-word;
  overflow-wrap: break-word;
}

.card.unread {
  border-color: rgba(247, 127, 0, 0.5);
  border-width: 1.5px;
}
.card.error { border-color: rgba(214, 40, 40, 0.45); }

.card-top {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
}

.badge {
  border-radius: 999px;
  padding: 5px 9px;
  color: white;
  background: var(--accent-2);
  font-size: 0.74rem;
  font-weight: 900;
  text-transform: uppercase;
}

.badge.error { background: var(--danger); }
.badge.warning { background: var(--accent); }
.badge.info { background: #4895ef; }

.card h2 {
  margin: 12px 0 6px;
  font-size: 1.25rem;
  line-height: 1.25;
}

pre {
  margin: 10px 0 0;
  white-space: pre-wrap;
  word-break: break-word;
  font: 0.92rem/1.55 "Cascadia Mono", "SFMono-Regular", Consolas, monospace;
  color: #21384c;
  max-height: 50vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.action-hint {
  margin: 8px 0 0;
  padding: 8px 12px;
  background: #e8f5e9;
  color: #2e7d32;
  border-radius: 8px;
  font-size: 0.85rem;
  line-height: 1.4;
}

/* ── Card Actions ── */
.card-actions {
  display: flex;
  gap: 8px;
  margin-top: 14px;
  flex-wrap: wrap;
  align-items: center;
}

.readBtn {
  background: var(--accent-2);
  margin-left: auto;
}
.readBtn[hidden] { display: none; }

/* ── Link buttons ── */
.link-group {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.btn-link {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 8px 14px;
  min-height: 44px;
  border-radius: 999px;
  font-size: 0.82rem;
  font-weight: 700;
  text-decoration: none;
  color: var(--ink);
  background: rgba(16, 33, 47, 0.07);
  border: 1px solid var(--line);
  transition: background 0.15s, transform 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.btn-link:hover {
  background: rgba(16, 33, 47, 0.14);
  transform: translateY(-1px);
}
.btn-link:active { transform: translateY(0); }

.btn-link .link-icon {
  font-size: 1em;
  flex-shrink: 0;
}

.toolbar-right {
  display: flex;
  gap: 8px;
  align-items: center;
}

select {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 10px 14px;
  min-height: 44px;
  background: white;
  color: var(--ink);
  font-weight: 700;
  font-size: 0.88rem;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M2 4l4 4 4-4' fill='none' stroke='%23667487' stroke-width='2'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 32px;
}

/* ── Bot buttons ── */
.btn-bot {
  border-color: rgba(42, 157, 143, 0.35);
  background: rgba(42, 157, 143, 0.08);
  color: var(--ink);
}
.btn-bot:hover {
  background: rgba(42, 157, 143, 0.18);
}

@keyframes rise {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ═══════════════════════════════════════
   MOBILE RESPONSIVE — ≤720px
   ═══════════════════════════════════════ */
@media (max-width: 720px) {
  .shell {
    width: calc(100% - 16px);
    padding: 12px 0 24px;
  }

  .hero {
    align-items: stretch;
    flex-direction: column;
    padding: 18px;
    border-radius: 20px;
    gap: 12px;
  }

  h1 {
    font-size: clamp(2rem, 10vw, 3.5rem);
  }

  .sub {
    font-size: 0.88rem;
    line-height: 1.4;
  }

  .hero-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    width: 100%;
  }

  .hero-actions button {
    width: 100%;
    padding: 12px 10px;
    font-size: 0.84rem;
    min-height: 48px;
  }

  .stats {
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    margin: 12px 0;
  }
  .stats article { padding: 12px 8px; border-radius: 18px; }
  .stats span { font-size: 1.5rem; }
  .stats small { font-size: 0.72rem; }

  .toolbar {
    padding: 12px 14px;
    border-radius: 18px;
    gap: 8px;
  }
  .toolbar-right {
    width: 100%;
    justify-content: space-between;
  }

  .toolbar-right select {
    flex: 1;
    font-size: 0.82rem;
  }

  .toolbar button {
    min-height: 44px;
    padding: 10px 14px;
    font-size: 0.84rem;
  }

  .card {
    padding: 14px;
    border-radius: 18px;
  }

  .card h2 { font-size: 1.05rem; line-height: 1.3; }

  pre {
    font-size: 0.8rem;
    max-height: 35vh;
    padding: 8px;
    border-radius: 12px;
    background: rgba(0,0,0,0.02);
  }

  .card-actions {
    flex-direction: column;
    gap: 8px;
    align-items: stretch;
  }

  .link-group {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
    width: 100%;
  }

  .btn-link {
    justify-content: center;
    padding: 10px 12px;
    font-size: 0.78rem;
    min-height: 44px;
    border-radius: 14px;
  }

  .readBtn {
    width: 100%;
    min-height: 44px;
    margin-left: 0;
    border-radius: 14px;
    font-size: 0.84rem;
  }
}

/* ═══════════════════════════════════════
   VERY SMALL — ≤380px (SE, Mini, etc)
   ═══════════════════════════════════════ */
@media (max-width: 380px) {
  .stats {
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
  }
  .stats article { padding: 10px 4px; }
  .stats span { font-size: 1.3rem; }
  .stats small { font-size: 0.68rem; }

  .hero { padding: 14px; border-radius: 16px; }
  .card { padding: 12px; border-radius: 16px; }
  .shell { width: calc(100% - 10px); padding: 8px 0 16px; }

  .link-group {
    grid-template-columns: 1fr;
  }

  .card h2 { font-size: 0.95rem; }
  time, .meta { font-size: 0.76rem; }
  .badge { font-size: 0.68rem; padding: 4px 7px; }
}

/* ═══════════════════════════════════════
   PWA STANDALONE SAFE-AREA
   ═══════════════════════════════════════ */
@supports(padding: max(0px)) {
  body {
    padding-left: env(safe-area-inset-left, 0);
    padding-right: env(safe-area-inset-right, 0);
  }
  .shell {
    padding-top: max(28px, env(safe-area-inset-top, 0));
    padding-bottom: max(48px, env(safe-area-inset-bottom, 0));
  }
  @media (max-width: 720px) {
    .shell {
      padding-top: max(12px, calc(env(safe-area-inset-top, 0) + 4px));
      padding-bottom: max(24px, calc(env(safe-area-inset-bottom, 0) + 8px));
    }
  }
}
