:root {
  --bg: #f7f6f4;
  --surface: #ffffff;
  --surface-subtle: #f0eeea;
  --text: #1c1b1a;
  --text-muted: #6e6a65;
  --border: #e4e1db;
  --accent: #272523;
  --accent-text: #ffffff;
  --add: #2b6b52;
  --add-soft: rgba(43, 107, 82, 0.1);
  --skip: #8e5454;
  --skip-soft: rgba(142, 84, 84, 0.1);
  --danger: #a13a3a;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 6px 20px rgba(0, 0, 0, 0.04);
  --radius: 14px;
  --radius-sm: 10px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121211;
    --surface: #1b1b19;
    --surface-subtle: #242320;
    --text: #eceae6;
    --text-muted: #9a958e;
    --border: #2e2d29;
    --accent: #eceae6;
    --accent-text: #141413;
    --add: #5fb892;
    --add-soft: rgba(95, 184, 146, 0.14);
    --skip: #d18686;
    --skip-soft: rgba(209, 134, 134, 0.14);
    --danger: #e07878;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.25);
  }
}

:root[data-theme="dark"] {
  --bg: #121211;
  --surface: #1b1b19;
  --surface-subtle: #242320;
  --text: #eceae6;
  --text-muted: #9a958e;
  --border: #2e2d29;
  --accent: #eceae6;
  --accent-text: #141413;
  --add: #5fb892;
  --add-soft: rgba(95, 184, 146, 0.14);
  --skip: #d18686;
  --skip-soft: rgba(209, 134, 134, 0.14);
  --danger: #e07878;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.25);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: contain;
}

.hidden {
  display: none !important;
}

.app-root {
  min-height: 100dvh;
}

.centered-view {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px 16px calc(20px + env(safe-area-inset-bottom));
}

.loading-mark {
  width: 28px;
  height: 28px;
  border: 2px solid var(--border);
  border-top-color: var(--text);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

.surface-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
}

.auth-card,
.onboarding-card {
  width: 100%;
  max-width: 420px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.brand-lockup {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-icon {
  border-radius: 9px;
}

.brand-icon-sm {
  border-radius: 6px;
}

.brand-title {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.section-heading,
.panel-title {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 600;
  letter-spacing: -0.015em;
}

.muted-text {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.875rem;
}

.helper-text {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.8rem;
}

.stack-sm {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.stack-md {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field-label {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-muted);
}

input[type="text"],
input[type="email"],
input[type="search"],
select,
textarea {
  width: 100%;
  font: inherit;
  font-size: 0.95rem;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  outline: none;
  transition: border-color 0.15s ease;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--text-muted);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 44px;
  padding: 0 16px;
  font: inherit;
  font-size: 0.92rem;
  font-weight: 500;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  text-decoration: none;
  transition: opacity 0.15s ease, background-color 0.15s ease, transform 0.1s ease;
  -webkit-tap-highlight-color: transparent;
}

.btn:active {
  transform: scale(0.98);
}

.btn-sm {
  min-height: 36px;
  padding: 0 12px;
  font-size: 0.83rem;
}

.btn-full {
  width: 100%;
}

.btn-primary {
  background: var(--accent);
  color: var(--accent-text);
}

.btn-secondary {
  background: var(--surface-subtle);
  color: var(--text);
  border-color: var(--border);
}

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
}

.btn-ghost:hover {
  color: var(--text);
  background: var(--surface-subtle);
}

.btn-danger-ghost {
  background: transparent;
  color: var(--danger);
}

.btn-disabled {
  opacity: 0.45;
  pointer-events: none;
}

.alert-banner {
  margin: 0;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--skip-soft);
  color: var(--skip);
  font-size: 0.875rem;
}

.dev-auth-box {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-top: 4px;
}

.divider-label {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text-muted);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.divider-label::before,
.divider-label::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--border);
}

.dev-quick-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.inline-form {
  display: flex;
  gap: 8px;
}

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

.segmented-tabs {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(0, 1fr));
  gap: 4px;
  background: var(--surface-subtle);
  padding: 4px;
  border-radius: var(--radius-sm);
}

.seg-btn {
  min-height: 36px;
  border: 0;
  background: transparent;
  color: var(--text-muted);
  font: inherit;
  font-size: 0.85rem;
  font-weight: 500;
  border-radius: 7px;
  cursor: pointer;
}

.seg-btn.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
}

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

.role-option {
  cursor: pointer;
}

.role-option input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.role-box {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg);
  height: 100%;
}

.role-box strong {
  font-size: 0.9rem;
}

.role-box small {
  font-size: 0.78rem;
  color: var(--text-muted);
  line-height: 1.3;
}

.role-option input:checked + .role-box {
  border-color: var(--accent);
  background: var(--surface-subtle);
}

/* Main App Shell */
.app-shell {
  height: 100dvh;
  display: flex;
  flex-direction: column;
  max-width: 560px;
  margin: 0 auto;
  background: var(--bg);
}

.topbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.topbar-title {
  font-weight: 600;
  font-size: 1rem;
  letter-spacing: -0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.role-badge {
  font-size: 0.72rem;
  font-weight: 500;
  color: var(--text-muted);
  background: var(--surface-subtle);
  border: 1px solid var(--border);
  padding: 2px 8px;
  border-radius: 999px;
}

.tonight-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 34px;
  padding: 0 11px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 0.82rem;
  font-weight: 500;
  cursor: pointer;
}

.count-dot {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-text);
  font-size: 0.74rem;
  font-weight: 600;
}

.main-content {
  flex: 1 1 auto;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 14px 16px 28px;
  -webkit-overflow-scrolling: touch;
}

.panel {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.panel-intro {
  padding: 2px 2px 0;
}

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

.row-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

/* Feed & Swipe Cards */
.feed-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.feed-card-slot {
  position: relative;
  overflow: hidden;
  border-radius: var(--radius);
}

.swipe-backdrop {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 22px;
  font-size: 0.85rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  border-radius: var(--radius);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.12s ease;
}

.swipe-backdrop.is-add {
  background: var(--add-soft);
  color: var(--add);
  opacity: 1;
}

.swipe-backdrop.is-skip {
  background: var(--skip-soft);
  color: var(--skip);
  opacity: 1;
}

.feed-card {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 16px 14px;
  box-shadow: var(--shadow);
  touch-action: pan-y;
  user-select: none;
  will-change: transform, opacity;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.feed-card.animating {
  transition: transform 0.22s ease, opacity 0.22s ease;
}

.card-meta-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.category-tag {
  font-size: 0.72rem;
  font-weight: 500;
  color: var(--text-muted);
  background: var(--surface-subtle);
  padding: 3px 9px;
  border-radius: 999px;
}

.card-title {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.card-desc {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.9rem;
}

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

.card-btn {
  min-height: 40px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text-muted);
  font: inherit;
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
}

.card-btn-add {
  color: var(--text);
  background: var(--surface-subtle);
}

.feed-sentinel {
  height: 24px;
}

/* Tonight & Archive */
.intensity-card {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 14px 16px;
}

.intensity-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.intensity-value {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text);
}

.intensity-value.is-unset {
  color: var(--text-muted);
  font-weight: 500;
}

.intensity-slider {
  width: 100%;
  margin: 2px 0;
  accent-color: var(--accent);
  cursor: pointer;
}

.intensity-scale {
  display: flex;
  justify-content: space-between;
  font-size: 0.74rem;
  color: var(--text-muted);
}

.intensity-meter {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
  padding: 2px 0;
}

.meter-segment {
  height: 8px;
  border-radius: 999px;
  background: var(--surface-subtle);
  border: 1px solid var(--border);
}

.meter-segment.filled {
  background: var(--accent);
  border-color: var(--accent);
}

.note-card {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.note-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.note-readonly-body {
  margin: 6px 0 0;
  font-size: 0.95rem;
  white-space: pre-wrap;
}

.tonight-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
}

.tonight-row.is-checked .tonight-row-title {
  text-decoration: line-through;
  color: var(--text-muted);
}

.tonight-row-main {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.tonight-row-title {
  font-weight: 600;
  font-size: 0.97rem;
}

.check-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1.5px solid var(--border);
  background: var(--bg);
  color: transparent;
  cursor: pointer;
  flex: 0 0 auto;
  font-size: 0.9rem;
}

.check-toggle.checked {
  background: var(--add);
  border-color: var(--add);
  color: #ffffff;
}

.archive-card {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.archive-date {
  font-weight: 600;
  font-size: 0.95rem;
}

.archive-items {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.archive-items li {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  font-size: 0.9rem;
  padding-top: 6px;
  border-top: 1px solid var(--border);
}

/* Library */
.library-controls {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.filter-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chip-btn {
  min-height: 32px;
  padding: 0 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  font: inherit;
  font-size: 0.8rem;
  cursor: pointer;
}

.chip-btn.active {
  background: var(--accent);
  color: var(--accent-text);
  border-color: var(--accent);
}

.library-row {
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
}

.library-row.inactive {
  opacity: 0.58;
}

/* Settings */
.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.setting-label {
  font-size: 0.92rem;
  font-weight: 600;
}

.invite-code-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.invite-code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: 0.08em;
}

.hairline {
  border: 0;
  border-top: 1px solid var(--border);
  margin: 4px 0;
}

.empty-state {
  text-align: center;
  padding: 36px 18px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}

.empty-title {
  margin: 0;
  font-weight: 600;
  font-size: 0.98rem;
}

/* Bottom Navigation */
.bottom-nav {
  flex: 0 0 auto;
  display: flex;
  align-items: stretch;
  justify-content: space-around;
  border-top: 1px solid var(--border);
  background: var(--surface);
  padding: 6px 6px calc(6px + env(safe-area-inset-bottom));
}

.nav-btn {
  flex: 1 1 0;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  border: 0;
  background: transparent;
  color: var(--text-muted);
  font: inherit;
  font-size: 0.82rem;
  font-weight: 500;
  border-radius: var(--radius-sm);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.nav-btn.active {
  color: var(--text);
  font-weight: 600;
  background: var(--surface-subtle);
}

.nav-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-text);
  font-size: 0.7rem;
  font-weight: 600;
}

/* Dialogs & Toast */
.modal-dialog {
  width: min(92vw, 420px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  padding: 18px;
  box-shadow: var(--shadow);
}

.modal-dialog::backdrop {
  background: rgba(0, 0, 0, 0.45);
}

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

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(68px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: var(--accent);
  color: var(--accent-text);
  padding: 10px 14px;
  border-radius: 999px;
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 0.85rem;
  box-shadow: var(--shadow);
  z-index: 50;
  max-width: calc(100vw - 32px);
}

.toast-action {
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  font-weight: 600;
  text-decoration: underline;
  cursor: pointer;
  padding: 0;
}
