:root {
  color-scheme: dark;
  --bg: #050507;
  --panel: #111114;
  --panel-2: #17171b;
  --ink: #f5f2ea;
  --muted: #9b9a94;
  --soft: #6f706c;
  --line: #2a2a2e;
  --line-strong: #3a3a40;
  --green: #16d07f;
  --red: #ff4458;
  --blue: #3b82f6;
  --amber: #e4a93a;
  --scrim: rgba(5, 5, 7, 0.72);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  min-height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family:
    -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display",
    "Helvetica Neue", Arial, sans-serif;
  letter-spacing: 0;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button,
input {
  font: inherit;
}

button {
  border: 0;
}

a {
  color: inherit;
}

.app-shell {
  position: relative;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  width: 100%;
  min-height: 100dvh;
  overflow: hidden;
  background: var(--bg);
  padding:
    max(12px, env(safe-area-inset-top))
    max(12px, env(safe-area-inset-right))
    max(10px, env(safe-area-inset-bottom))
    max(12px, env(safe-area-inset-left));
}

.top-bar {
  position: relative;
  z-index: 5;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  width: min(720px, 100%);
  margin: 0 auto;
}

.brand {
  display: flex;
  align-items: center;
  min-width: 0;
  gap: 10px;
}

.brand-mark {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: 30px;
  height: 30px;
  background: var(--ink);
  color: var(--bg);
  border-radius: 6px;
  font-size: 0.9rem;
  font-weight: 800;
}

.brand h1 {
  margin: 0;
  font-size: 1rem;
  font-weight: 720;
  line-height: 1.1;
  white-space: nowrap;
}

.stats-grid {
  display: flex;
  align-items: center;
  gap: 6px;
  justify-self: end;
}

.stat {
  display: grid;
  gap: 1px;
  min-width: 48px;
  padding: 6px 8px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 7px;
}

.stat-value {
  color: var(--ink);
  font-size: 0.92rem;
  font-weight: 760;
  line-height: 1;
}

.stat-label {
  color: var(--muted);
  font-size: 0.62rem;
  font-weight: 680;
  line-height: 1;
  text-transform: uppercase;
}

.progress-track {
  grid-column: 1 / -1;
  height: 3px;
  overflow: hidden;
  background: #202024;
  border-radius: 3px;
}

.progress-track span {
  display: block;
  width: 0%;
  height: 100%;
  background: var(--green);
  transition: width 180ms ease;
}

.top-actions {
  position: fixed;
  right: max(12px, env(safe-area-inset-right));
  bottom: calc(86px + env(safe-area-inset-bottom));
  z-index: 7;
  display: grid;
  gap: 8px;
}

.icon-button,
.round-button,
.primary-button {
  color: var(--ink);
  background: var(--panel-2);
  border: 1px solid var(--line-strong);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition:
    transform 160ms ease,
    border-color 160ms ease,
    opacity 160ms ease,
    background 160ms ease;
}

.icon-button {
  display: inline-grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 8px;
}

.icon-button.compact {
  width: 36px;
  height: 36px;
}

.icon-button:active,
.round-button:active,
.primary-button:active {
  transform: scale(0.96);
}

.icon-button:disabled,
.round-button:disabled {
  cursor: not-allowed;
  opacity: 0.34;
  transform: none;
}

.icon-button svg,
.round-button svg,
.empty-state svg,
.notion-link svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.review-stage {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  align-items: center;
  justify-items: center;
  min-width: 0;
  min-height: 0;
  padding: 12px 0 0;
}

.deck {
  position: relative;
  display: grid;
  place-items: center;
  width: min(100%, 480px);
  height: min(660px, calc(100dvh - 178px - env(safe-area-inset-top) - env(safe-area-inset-bottom)));
  min-height: 460px;
}

.tier-card {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--panel);
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  box-shadow: 0 14px 40px rgba(0, 0, 0, 0.28);
  transform-origin: center 82%;
  transition:
    transform 230ms cubic-bezier(0.2, 0.8, 0.22, 1),
    opacity 180ms ease;
}

.tier-card.next {
  transform: translateY(18px) scale(0.97);
  opacity: 0.28;
  pointer-events: none;
}

.tier-card.current.enter-right {
  animation: enterRight 240ms cubic-bezier(0.2, 0.8, 0.22, 1) both;
}

.tier-card.current.enter-bottom {
  animation: enterBottom 240ms cubic-bezier(0.2, 0.8, 0.22, 1) both;
}

.tier-card.dragging {
  transition: none;
}

.tier-card.current {
  cursor: grab;
  touch-action: pan-y;
}

.tier-card.current.dragging {
  cursor: grabbing;
}

@keyframes enterRight {
  from {
    opacity: 0.4;
    transform: translateX(104vw) rotate(10deg);
  }
  to {
    opacity: 1;
    transform: translateX(0) rotate(0deg);
  }
}

@keyframes enterBottom {
  from {
    opacity: 0.35;
    transform: translateY(72vh) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.card-top {
  display: grid;
  gap: 14px;
  padding: 18px 18px 14px;
  border-bottom: 1px solid var(--line);
  cursor: grab;
  user-select: none;
  touch-action: none;
}

.card-top:active,
.card-bottom:active {
  cursor: grabbing;
}

.page-kicker {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 650;
  line-height: 1.2;
}

.page-kicker span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.notion-link {
  display: inline-grid;
  place-items: center;
  flex: 0 0 auto;
  width: 34px;
  height: 34px;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 8px;
  text-decoration: none;
}

.tier-heading {
  display: grid;
  gap: 6px;
}

.tier-heading p {
  margin: 0;
  color: var(--green);
  font-size: 0.76rem;
  font-weight: 780;
  line-height: 1;
  text-transform: uppercase;
}

.tier-heading h2 {
  margin: 0;
  color: var(--ink);
  font-size: 1.5rem;
  font-weight: 780;
  line-height: 1.12;
  overflow-wrap: anywhere;
}

.property-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.property-pill {
  display: inline-flex;
  align-items: center;
  max-width: 100%;
  min-height: 25px;
  padding: 5px 8px;
  color: #d9d7cf;
  background: #202024;
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 0.78rem;
  font-weight: 680;
  line-height: 1;
  overflow-wrap: anywhere;
}

.property-pill[data-color="green"] {
  color: var(--green);
}

.property-pill[data-color="red"],
.property-pill[data-color="pink"] {
  color: var(--red);
}

.property-pill[data-color="yellow"],
.property-pill[data-color="orange"] {
  color: var(--amber);
}

.property-pill[data-color="blue"],
.property-pill[data-color="purple"] {
  color: #9dbdff;
}

.card-content {
  min-height: 0;
  overflow: auto;
  padding: 18px;
  overscroll-behavior: contain;
  touch-action: pan-y;
  -webkit-overflow-scrolling: touch;
}

.content-loading,
.empty-content {
  display: grid;
  place-items: center;
  min-height: 180px;
  color: var(--muted);
  font-size: 0.96rem;
  font-weight: 650;
}

.block {
  margin: 0 0 15px;
  color: #ebe8df;
  font-size: 1.04rem;
  font-weight: 430;
  line-height: 1.62;
  overflow-wrap: anywhere;
}

.block h1,
.block h2,
.block h3,
.block p,
.block pre,
.markdown-list {
  margin: 0;
}

.block strong {
  color: var(--ink);
  font-weight: 780;
  text-decoration-line: underline;
  text-decoration-thickness: 0.08em;
  text-underline-offset: 0.14em;
}

.tier-heading strong,
.page-kicker strong {
  color: var(--ink);
  font-weight: 780;
}

.prose-block {
  display: block;
}

.prose-block p + .markdown-list {
  margin-top: 12px;
}

.markdown-list {
  padding-left: 1.15em;
}

.markdown-list li {
  margin: 0 0 10px;
  padding-left: 0.08em;
}

.markdown-list li:last-child {
  margin-bottom: 0;
}

.markdown-list li::marker {
  color: var(--green);
}

.bullet-list {
  margin-top: -2px;
  padding-left: 1.18em;
}

.bullet-list li {
  margin: 0 0 9px;
  padding-left: 0.08em;
}

.bullet-list li:last-child {
  margin-bottom: 0;
}

.bullet-list li::marker,
.prior-section li::marker {
  color: var(--green);
}

.support-section {
  margin: 24px 0 18px;
}

.support-section h3 {
  margin: 0 0 11px;
  color: var(--ink);
  font-size: 1rem;
  font-weight: 760;
  line-height: 1.25;
}

.prior-section ul {
  margin: 0;
  padding-left: 1.18em;
}

.prior-section li {
  margin: 0 0 9px;
  padding-left: 0.08em;
  color: #ebe8df;
  line-height: 1.5;
}

.prior-section li:last-child {
  margin-bottom: 0;
}

.concept-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.concept-chips span {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 5px 9px;
  color: #d9d7cf;
  background: #1b1b20;
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 0.84rem;
  font-weight: 650;
  line-height: 1.25;
}

.katex {
  color: var(--ink);
  font-size: 1.04em;
}

.equation-block {
  overflow-x: auto;
  padding: 12px 0;
}

.equation-block .katex-display {
  margin: 0;
}

.math-fallback {
  font-family: "SF Mono", ui-monospace, Menlo, monospace;
}

.block h1 {
  font-size: 1.36rem;
  font-weight: 780;
  line-height: 1.18;
}

.block h2 {
  font-size: 1.2rem;
  font-weight: 760;
  line-height: 1.24;
}

.block h3 {
  font-size: 1.08rem;
  font-weight: 730;
  line-height: 1.3;
}

.list-block,
.todo-block {
  display: grid;
  grid-template-columns: 22px minmax(0, 1fr);
  gap: 7px;
}

.list-marker {
  color: var(--muted);
  font-weight: 760;
}

.quote-block {
  padding-left: 14px;
  border-left: 2px solid var(--line-strong);
  color: #d7d4cc;
}

.code-block pre {
  overflow: auto;
  padding: 12px;
  background: #09090b;
  color: #f5f2ea;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 0.86rem;
  line-height: 1.48;
}

.media-block img {
  display: block;
  max-width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.media-block figcaption {
  margin-top: 8px;
  color: var(--muted);
  font-size: 0.88rem;
}

.bookmark-block a {
  color: #9dbdff;
  font-weight: 680;
}

.divider-block {
  height: 1px;
  margin: 22px 0;
  background: var(--line);
}

.child-block {
  padding: 11px 12px;
  background: #1b1b20;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-weight: 680;
}

.nested-blocks {
  margin: 12px 0 0 20px;
}

.card-bottom {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 48px;
  padding: 12px 18px;
  color: var(--muted);
  border-top: 1px solid var(--line);
  font-size: 0.8rem;
  font-weight: 680;
  cursor: grab;
  user-select: none;
  touch-action: none;
}

.swipe-badge {
  position: absolute;
  top: 18px;
  left: 18px;
  z-index: 3;
  padding: 7px 10px;
  color: var(--bg);
  background: var(--green);
  border-radius: 6px;
  font-size: 0.78rem;
  font-weight: 850;
  opacity: 0;
  transform: rotate(-8deg) scale(0.96);
  transition: opacity 120ms ease;
}

.swipe-badge.show {
  opacity: 1;
}

.swipe-actions {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  width: min(480px, 100%);
  min-height: 78px;
  padding-top: 8px;
}

.round-button {
  display: inline-grid;
  place-items: center;
  width: 58px;
  height: 58px;
  border-radius: 999px;
}

.round-button.approve {
  width: 66px;
  height: 66px;
  color: var(--bg);
  background: var(--green);
  border-color: var(--green);
}

.round-button.reject {
  color: var(--red);
}

.round-button.keep {
  color: #8ab0ff;
}

.property-strip {
  display: flex;
  justify-content: center;
  width: min(720px, 100%);
  margin: 0 auto;
  color: var(--soft);
  font-size: 0.74rem;
  font-weight: 650;
  line-height: 1;
}

.empty-state {
  display: none;
  place-items: center;
  gap: 8px;
  width: min(360px, 100%);
  padding: 24px;
  color: var(--ink);
  text-align: center;
  background: var(--panel);
  border: 1px solid var(--line-strong);
  border-radius: 8px;
}

.empty-state.show {
  display: grid;
}

.empty-state svg {
  width: 40px;
  height: 40px;
  color: var(--green);
}

.empty-state h1,
.empty-state h2 {
  margin: 0;
  font-size: 1.1rem;
  line-height: 1.2;
}

.empty-state p {
  margin: 0;
  color: var(--muted);
  font-size: 0.95rem;
  line-height: 1.35;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: end center;
  padding:
    max(12px, env(safe-area-inset-top))
    max(12px, env(safe-area-inset-right))
    max(12px, env(safe-area-inset-bottom))
    max(12px, env(safe-area-inset-left));
  background: var(--scrim);
  backdrop-filter: blur(14px);
}

.modal-backdrop[hidden] {
  display: none;
}

.settings-modal {
  width: min(560px, 100%);
  max-height: min(720px, calc(100dvh - 32px));
  overflow: auto;
  padding: 18px;
  color: var(--ink);
  background: var(--panel);
  border: 1px solid var(--line-strong);
  border-radius: 8px;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.settings-modal h2 {
  margin: 0;
  font-size: 1.1rem;
  line-height: 1.15;
}

.settings-form {
  display: grid;
  gap: 13px;
}

.settings-form label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 680;
}

.settings-form input,
.settings-form select {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  color: var(--ink);
  background: #0b0b0e;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  outline: none;
}

.settings-form input:focus,
.settings-form select:focus {
  border-color: var(--green);
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 110px;
  gap: 10px;
}

.primary-button {
  min-height: 46px;
  margin-top: 2px;
  color: var(--bg);
  background: var(--ink);
  border-color: var(--ink);
  border-radius: 8px;
  font-weight: 780;
}

.toast {
  position: fixed;
  right: max(12px, env(safe-area-inset-right));
  bottom: max(12px, env(safe-area-inset-bottom));
  z-index: 30;
  max-width: min(420px, calc(100vw - 24px));
  padding: 11px 13px;
  color: var(--bg);
  background: var(--ink);
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 720;
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
  transition:
    opacity 160ms ease,
    transform 160ms ease;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.toast.error {
  color: #fff;
  background: #b3283b;
}

.offline-shell {
  display: grid;
  place-items: center;
  min-height: 100dvh;
  padding: 20px;
  background: var(--bg);
}

@media (min-width: 760px) {
  .app-shell {
    padding-top: 18px;
  }

  .top-actions {
    position: static;
    display: flex;
    grid-column: 1 / -1;
    justify-content: center;
  }

  .deck {
    height: min(720px, calc(100dvh - 190px));
  }

  .tier-heading h2 {
    font-size: 1.72rem;
  }

  .block {
    font-size: 1.08rem;
  }

  .modal-backdrop {
    place-items: center;
  }
}

@media (max-width: 390px) {
  .brand h1 {
    font-size: 0.92rem;
  }

  .brand-mark {
    width: 28px;
    height: 28px;
  }

  .stat {
    min-width: 43px;
    padding: 5px 6px;
  }

  .deck {
    min-height: 430px;
  }

  .tier-heading h2 {
    font-size: 1.34rem;
  }

  .block {
    font-size: 0.99rem;
  }

  .round-button {
    width: 54px;
    height: 54px;
  }

  .round-button.approve {
    width: 62px;
    height: 62px;
  }

  .form-row {
    grid-template-columns: 1fr;
  }
}
