:root {
  --bg: #0f172a;
  --surface: #1e293b;
  --surface-2: #273449;
  --text: #f1f5f9;
  --text-dim: #94a3b8;
  --accent: #0f4c81;
  --accent-light: #3b82f6;
  --danger: #ef4444;
  --success: #22c55e;
  --radius: 20px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* {
  box-sizing: border-box;
}

/* Several elements below (.modal, .empty-state, .loading-state,
   .action-status) set an unconditional `display` value for layout, but are
   also toggled via the `hidden` attribute in app.js. Author CSS normally
   overrides the browser's built-in `[hidden] { display: none }` rule
   regardless of selector specificity, so without this, those elements stay
   visible AND clickable even while "hidden". This rule forces `hidden` to
   always win. */
[hidden] {
  display: none !important;
}

html, body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  overscroll-behavior-y: contain;
  -webkit-tap-highlight-color: transparent;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 480px;
  margin: 0 auto;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(var(--safe-top) + 14px) 18px 14px;
  background: var(--bg);
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.topbar h1 {
  font-size: 1.15rem;
  font-weight: 700;
  margin: 0;
}

.sync-btn {
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 999px;
  padding: 8px 18px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.1s ease, opacity 0.15s ease;
}

.sync-btn:active {
  transform: scale(0.95);
}

.sync-btn:disabled {
  opacity: 0.6;
  cursor: default;
}

.card-area {
  position: relative;
  flex: 1;
  overflow: hidden;
  padding: 20px 18px calc(24px + var(--safe-bottom));
  display: flex;
  flex-direction: column;
}

.deck {
  position: relative;
  flex: 1;
  min-height: 0;
}

.card {
  position: absolute;
  inset: 0;
  background: var(--surface);
  border-radius: var(--radius);
  padding: 22px;
  display: flex;
  flex-direction: column;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  touch-action: pan-y;
  will-change: transform;
  transition: transform 0.25s ease, opacity 0.25s ease;
}

.card.dragging {
  transition: none;
}

.card-sender {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-dim);
  margin-bottom: 10px;
}

.card-hook {
  font-size: 1.4rem;
  line-height: 1.3;
  font-weight: 700;
  margin: 0 0 16px;
}

.card-bullets {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
  flex: 1;
  overflow-y: auto;
}

.card-bullets li {
  position: relative;
  padding-left: 18px;
  font-size: 1rem;
  line-height: 1.45;
  color: #dbe4f0;
}

.card-bullets li::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0.55em;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent-light);
}

.card-actions {
  display: flex;
  gap: 12px;
  margin-top: 18px;
}

.card-actions button {
  flex: 1;
  padding: 14px;
  border-radius: 14px;
  border: none;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.1s ease;
}

.card-actions button:active {
  transform: scale(0.96);
}

.skip-btn {
  background: var(--surface-2);
  color: var(--text-dim);
}

.read-btn {
  background: var(--accent);
  color: white;
}

.card-swipe-hint {
  position: absolute;
  top: 22px;
  padding: 6px 14px;
  border-radius: 999px;
  font-weight: 700;
  font-size: 0.85rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.1s ease;
}

.card-swipe-hint.read {
  right: 22px;
  border: 2px solid var(--success);
  color: var(--success);
  transform: rotate(8deg);
}

.card-swipe-hint.skip {
  left: 22px;
  border: 2px solid var(--danger);
  color: var(--danger);
  transform: rotate(-8deg);
}

.empty-state,
.loading-state {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 8px;
  padding: 40px;
  color: var(--text-dim);
}

.empty-emoji {
  font-size: 2.6rem;
  margin: 0 0 4px;
}

.empty-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text);
  margin: 0;
}

.empty-sub {
  margin: 0;
  font-size: 0.95rem;
  max-width: 30ch;
}

.spinner {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, 0.15);
  border-top-color: var(--accent-light);
  animation: spin 0.8s linear infinite;
}

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

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(20px + var(--safe-bottom));
  transform: translateX(-50%);
  background: var(--surface-2);
  color: var(--text);
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 0.9rem;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.4);
  z-index: 20;
}

/* --- Read modal --- */

.modal {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: flex;
  align-items: flex-end;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
}

.modal-sheet {
  position: relative;
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
  max-height: 82dvh;
  background: var(--surface);
  border-radius: 22px 22px 0 0;
  padding: 10px 20px calc(24px + var(--safe-bottom));
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal-handle {
  width: 40px;
  height: 4px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.2);
  margin: 6px auto 14px;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-meta {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-dim);
}

.modal-close {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 1.6rem;
  line-height: 1;
  cursor: pointer;
  padding: 4px 8px;
}

.modal-title {
  font-size: 1.2rem;
  margin: 10px 0 14px;
}

/* The only element that scrolls or shrinks in the modal-sheet's flex
   column — everything else (header, title, action bar) keeps its natural
   size, so this is genuinely the full available space, not a guess. */
.modal-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
}

.modal-text {
  white-space: pre-wrap;
  line-height: 1.55;
  color: #dbe4f0;
  font-size: 0.98rem;
}

/* Shown only when a topic has a source_url — the email was a short
   excerpt/teaser linking out to a full article elsewhere. Sits inside
   modal-body (the scrollable area), not the action bar, so reaching it is
   part of "reading to the end" like the rest of the text. */
.modal-source-link {
  display: inline-block;
  margin-top: 16px;
  padding: 10px 16px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--accent-light);
  font-size: 0.92rem;
  font-weight: 600;
  text-decoration: none;
}

/* Deliberately a sibling of modal-body, not nested inside its scroll area —
   always visible below the text, but its controls stay disabled (see
   app.js) until the reader has actually scrolled the text to the end.
   That's an explicit, content-length-independent gate, not something that
   depends on the action bar happening to sit below the fold. */
.modal-action-bar {
  flex-shrink: 0;
  padding-top: 18px;
  margin-top: 18px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.action-label {
  display: block;
  font-size: 0.85rem;
  color: var(--text-dim);
  margin-bottom: 8px;
  transition: color 0.15s ease;
}

.action-label.ready {
  color: var(--text);
  font-weight: 600;
}

.action-picker {
  width: 100%;
  padding: 14px 16px;
  border-radius: 14px;
  border: none;
  background: var(--surface-2);
  color: var(--text);
  font-size: 1rem;
  font-weight: 600;
  appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='%2394a3b8'><path d='M5.5 7.5l4.5 4.5 4.5-4.5z'/></svg>");
  background-repeat: no-repeat;
  background-position: right 16px center;
  background-size: 18px;
}

.action-picker:disabled {
  opacity: 0.6;
}

.action-confirm {
  width: 100%;
  margin-top: 10px;
  padding: 14px;
  border-radius: 14px;
  border: none;
  background: var(--accent);
  color: white;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.1s ease, opacity 0.15s ease;
}

.action-confirm:disabled {
  opacity: 0.35;
  cursor: default;
}

.action-confirm:active:not(:disabled) {
  transform: scale(0.97);
}

.action-status {
  margin: 10px 0 0;
  font-size: 0.9rem;
  color: var(--text-dim);
  display: flex;
  align-items: center;
  gap: 8px;
}

.action-status .spinner {
  width: 16px;
  height: 16px;
  border-width: 2px;
}

@media (min-width: 481px) {
  #app {
    border-left: 1px solid rgba(255, 255, 255, 0.06);
    border-right: 1px solid rgba(255, 255, 255, 0.06);
  }
}
