:root {
  --bg: var(--tg-theme-bg-color, #10131a);
  --surface: var(--tg-theme-secondary-bg-color, #1a1f2b);
  --text: var(--tg-theme-text-color, #f2f4f8);
  --muted: var(--tg-theme-hint-color, #98a2b3);
  --accent: var(--tg-theme-button-color, #4c8dff);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --keep: #2fbf71;
  --archive: #e0a03a;
  --defer: #7a8cff;
  --danger: #ef5350;
  --radius: 14px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  min-height: 100vh;
}

.app {
  max-width: 640px;
  margin: 0 auto;
  padding: 16px 16px 32px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

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

.eyebrow {
  margin: 0;
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

h1 {
  margin: 2px 0 0;
  font-size: 22px;
}

.progress {
  min-width: 140px;
  text-align: right;
  font-size: 13px;
  color: var(--muted);
}

.progress-track {
  margin-top: 6px;
  height: 6px;
  border-radius: 999px;
  background: var(--surface);
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 0;
  background: var(--accent);
  transition: width 160ms ease;
}

.card-region {
  min-height: 200px;
}

.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: 0 8px 24px rgb(0 0 0 / 0.25);
  transform: translateX(var(--swipe-x, 0));
  touch-action: pan-y;
  transition: transform 120ms ease;
  cursor: grab;
}

.card.dragging {
  transition: none;
  cursor: grabbing;
}

.card:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.badge {
  margin: 0 0 8px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.excerpt {
  margin: 0;
  font-size: 18px;
  line-height: 1.45;
}

.link {
  margin-top: 12px;
  background: none;
  border: none;
  color: var(--accent);
  font-size: 14px;
  padding: 4px 0;
  cursor: pointer;
}

.link:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.details {
  margin: 8px 0 0;
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 4px 12px;
  font-size: 13px;
  color: var(--muted);
  word-break: break-word;
}

.details dt {
  font-weight: 600;
}

.details dd {
  margin: 0;
}

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

.action {
  border: 1px solid transparent;
  border-radius: 12px;
  padding: 14px 10px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  background: var(--surface);
  cursor: pointer;
}

.action:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.action:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.action-keep {
  background: color-mix(in srgb, var(--keep) 22%, var(--surface));
  border-color: var(--keep);
}

.action-archive {
  background: color-mix(in srgb, var(--archive) 22%, var(--surface));
  border-color: var(--archive);
}

.action-defer {
  background: color-mix(in srgb, var(--defer) 22%, var(--surface));
  border-color: var(--defer);
}

.hint {
  margin: 0;
  font-size: 12px;
  color: var(--muted);
  text-align: center;
}

.banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border-radius: 12px;
  background: color-mix(in srgb, var(--danger) 20%, var(--surface));
  border: 1px solid var(--danger);
  font-size: 14px;
}

.retry {
  border: none;
  border-radius: 10px;
  padding: 8px 14px;
  font-weight: 600;
  background: var(--accent);
  color: var(--accent-text);
  cursor: pointer;
}

.panel {
  text-align: center;
  padding: 32px 16px;
  background: var(--surface);
  border-radius: var(--radius);
}

.panel h2 {
  margin: 0 0 8px;
}

.panel p {
  margin: 0;
  color: var(--muted);
}

.section-title {
  margin: 0 0 8px;
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.view-controls {
  text-align: center;
}

.review-list,
.history-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.review-item {
  background: var(--surface);
  border: 1px solid transparent;
  border-radius: 12px;
  padding: 12px 14px;
}

.review-item[data-selected="true"] {
  border-color: var(--accent);
}

.review-item-summary {
  margin: 0;
  font-size: 15px;
}

.review-item-meta {
  margin: 4px 0 10px;
  font-size: 12px;
  color: var(--muted);
}

.review-item-actions {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}

.review-item-actions .action {
  padding: 10px 6px;
  font-size: 13px;
}

.history-list {
  margin-top: 8px;
}

.history-item {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  padding: 8px 12px;
  border-radius: 10px;
  background: var(--surface);
  border-left: 4px solid var(--muted);
  font-size: 13px;
}

.history-item.history-applied {
  border-left-color: var(--keep);
}

.history-item.history-pending {
  border-left-color: var(--defer);
}

.history-item.history-stale {
  border-left-color: var(--archive);
}

.history-meta {
  color: var(--muted);
  font-size: 12px;
  word-break: break-all;
}

.undo {
  margin-top: 12px;
}

.undo .action {
  width: 100%;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.dialog {
  border: none;
  border-radius: var(--radius);
  padding: 20px;
  background: var(--surface);
  color: var(--text);
  max-width: 420px;
  width: calc(100% - 32px);
}

.dialog::backdrop {
  background: rgb(0 0 0 / 0.5);
}

.dialog h2 {
  margin-top: 0;
}

.dialog p {
  color: var(--muted);
  font-size: 14px;
}

.dialog label {
  display: block;
  margin-bottom: 6px;
  font-size: 13px;
  color: var(--muted);
}

.dialog textarea {
  width: 100%;
  border-radius: 10px;
  border: 1px solid var(--muted);
  background: var(--bg);
  color: var(--text);
  padding: 10px;
  font: inherit;
  resize: vertical;
}

.dialog-actions {
  margin-top: 16px;
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

@media (prefers-reduced-motion: reduce) {
  .card,
  .progress-fill {
    transition: none;
  }
}

.reduced-motion .card,
.reduced-motion .progress-fill {
  transition: none;
}
