:root {
  --bg: #0a0a0b;
  --bg-warm: #0d0d0f;
  --surface: #131316;
  --surface-2: #1a1a1d;
  --surface-3: #222226;
  --border: #26262b;
  --border-strong: #34343a;

  --text: #f2f2f4;
  --text-mid: #a8a8b0;
  --text-dim: #6b6b74;

  --accent: #f5f5f7;
  --accent-fg: #0a0a0b;

  --delete: #ff6b6b;
  --delegate: #ffc04d;
  --automate: #5dd39e;
  --live: #5dd39e;

  --radius-sm: 8px;
  --radius: 12px;
  --radius-lg: 18px;

  --shadow-card: 0 1px 0 rgba(255,255,255,0.03) inset, 0 8px 24px -12px rgba(0,0,0,0.6);

  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.5;
  letter-spacing: -0.005em;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  overscroll-behavior-y: none;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  background:
    radial-gradient(1200px 600px at 50% -200px, rgba(93,211,158,0.04), transparent 60%),
    radial-gradient(800px 400px at 100% 100%, rgba(255,192,77,0.025), transparent 60%),
    var(--bg);
}

/* Subtle grid texture */
.bg-grid {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image:
    linear-gradient(rgba(255,255,255,0.012) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,0.012) 1px, transparent 1px);
  background-size: 40px 40px;
  mask-image: radial-gradient(ellipse at top, black 30%, transparent 80%);
  -webkit-mask-image: radial-gradient(ellipse at top, black 30%, transparent 80%);
  z-index: 0;
}

.app {
  position: relative;
  z-index: 1;
  max-width: 540px;
  margin: 0 auto;
  padding: max(20px, env(safe-area-inset-top)) 16px calc(48px + env(safe-area-inset-bottom)) 16px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* ========== HEADER ========== */
.header {
  padding: 12px 4px 4px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 18px;
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.14em;
  font-weight: 500;
}

.brand .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--live);
  box-shadow: 0 0 10px rgba(93,211,158,0.7);
  animation: pulse 2.5s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

.brand-name { color: var(--text-mid); }

.brand-status {
  margin-left: auto;
  padding: 3px 8px;
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--live);
  font-size: 10px;
  letter-spacing: 0.16em;
  background: rgba(93,211,158,0.06);
}

.title {
  font-size: 34px;
  font-weight: 700;
  letter-spacing: -0.03em;
  margin: 0 0 6px;
  line-height: 1.05;
  background: linear-gradient(180deg, #ffffff 0%, #b8b8c0 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.subtitle {
  margin: 0;
  color: var(--text-dim);
  font-size: 14px;
  font-weight: 400;
  max-width: 320px;
}

/* ========== KICKERS / LABELS ========== */
.kicker {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.18em;
  color: var(--text-dim);
  font-weight: 500;
  text-transform: uppercase;
  display: inline-block;
}
.kicker.centered {
  display: block;
  text-align: center;
  margin-bottom: 12px;
}

.hint {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.1em;
  color: var(--text-dim);
}

/* ========== CARDS ========== */
.card {
  background: linear-gradient(180deg, var(--surface) 0%, var(--bg-warm) 100%);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px;
  box-shadow: var(--shadow-card);
}

/* ========== COMPOSER ========== */
.composer {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.composer-label {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}

textarea, select {
  width: 100%;
  background: var(--bg-warm);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  font-size: 16px;
  font-family: var(--font-sans);
  outline: none;
  transition: border-color 0.18s ease, background 0.18s ease;
}
textarea {
  resize: none;
  min-height: 60px;
  line-height: 1.45;
}
textarea::placeholder, select:invalid { color: var(--text-dim); }
textarea:focus, select:focus {
  border-color: var(--border-strong);
  background: var(--surface-2);
}

.composer-row {
  display: flex;
  gap: 10px;
}

select {
  flex: 1;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'><path fill='%236b6b74' d='M5 6L0 0h10z'/></svg>");
  background-repeat: no-repeat;
  background-position: right 16px center;
  padding-right: 38px;
  font-family: var(--font-mono);
  font-size: 13px;
  letter-spacing: 0.04em;
  color: var(--text-mid);
}

button {
  font-family: var(--font-sans);
  font-size: 15px;
  font-weight: 500;
  border-radius: var(--radius);
  padding: 14px 18px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: opacity 0.15s ease, transform 0.08s ease, background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}
button:active:not(:disabled) { transform: scale(0.97); }
button:disabled { opacity: 0.4; cursor: not-allowed; }

.primary {
  background: var(--accent);
  color: var(--accent-fg);
  border: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-width: 96px;
  font-weight: 600;
}
.primary:hover:not(:disabled) { opacity: 0.92; }

/* ========== LOG ========== */
.log {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding-bottom: 14px;
}

.log-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 12px;
}
.log-title {
  margin: 4px 0 0;
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.log-tools {
  display: flex;
  gap: 6px;
}
.icon-btn {
  width: 36px;
  height: 36px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-mid);
  border-radius: var(--radius-sm);
}
.icon-btn:hover:not(:disabled) {
  border-color: var(--border-strong);
  color: var(--text);
}
.icon-btn.danger:hover:not(:disabled) {
  color: var(--delete);
  border-color: var(--delete);
}

.entries {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
  max-height: 44vh;
  overflow-y: auto;
  margin: 0 -2px;
  padding: 0 2px;
}
.entries::-webkit-scrollbar { width: 4px; }
.entries::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

.entries:empty::before {
  content: "Nothing logged yet. Start capturing.";
  display: block;
  color: var(--text-dim);
  font-size: 13px;
  font-family: var(--font-mono);
  letter-spacing: 0.04em;
  padding: 20px 0 8px;
  text-align: center;
}

.entry {
  background: transparent;
  border-top: 1px solid var(--border);
  padding: 12px 4px;
  display: flex;
  gap: 10px;
  align-items: flex-start;
  animation: slideIn 0.25s ease;
}
.entry:first-child { border-top: none; }
@keyframes slideIn {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: translateY(0); }
}

.entry-body { flex: 1; min-width: 0; }
.entry-task {
  font-size: 15px;
  line-height: 1.4;
  word-break: break-word;
  color: var(--text);
}
.entry-meta {
  margin-top: 4px;
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.08em;
  color: var(--text-dim);
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
}
.entry-cat {
  text-transform: uppercase;
  padding: 2px 6px;
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text-mid);
}
.entry-del {
  background: transparent;
  border: none;
  color: var(--text-dim);
  font-size: 18px;
  padding: 2px 8px;
  cursor: pointer;
  line-height: 1;
  border-radius: 6px;
}
.entry-del:hover { color: var(--delete); background: rgba(255,107,107,0.06); }

/* ========== AUDIT BUTTON ========== */
.audit-section {
  margin-top: 4px;
}

.audit-btn {
  width: 100%;
  background: linear-gradient(180deg, var(--surface-3) 0%, var(--surface) 100%);
  color: var(--text);
  border: 1px solid var(--border-strong);
  padding: 22px 18px;
  border-radius: var(--radius-lg);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  position: relative;
  overflow: hidden;
  box-shadow: 0 1px 0 rgba(255,255,255,0.04) inset, 0 12px 32px -16px rgba(93,211,158,0.15);
}
.audit-btn::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, transparent 30%, rgba(93,211,158,0.08) 70%, transparent 100%);
  opacity: 0;
  transition: opacity 0.3s ease;
}
.audit-btn:hover:not(:disabled)::before { opacity: 1; }
.audit-btn:hover:not(:disabled) { border-color: var(--automate); }

.audit-label {
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.01em;
  position: relative;
}
.audit-sub {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.18em;
  color: var(--text-dim);
  text-transform: uppercase;
  position: relative;
}

/* ========== RESULT ========== */
.result {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-top: 8px;
  animation: fadeUp 0.35s ease;
}
.result.hidden { display: none; }
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.bucket {
  background: linear-gradient(180deg, var(--surface) 0%, var(--bg-warm) 100%);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px;
  position: relative;
  overflow: hidden;
}
.bucket::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent 0%, currentColor 50%, transparent 100%);
  opacity: 0.4;
}

.bucket-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
}
.bucket-head h3 {
  margin: 0;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  font-family: var(--font-mono);
  font-weight: 600;
}
.bucket-count {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text-dim);
  letter-spacing: 0.1em;
  margin-left: auto;
}
.bucket-icon {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  border: 1px solid currentColor;
  background: rgba(255,255,255,0.02);
}

.bucket.delete { color: var(--delete); }
.bucket.delegate { color: var(--delegate); }
.bucket.automate { color: var(--automate); }

.bucket ul {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.bucket li {
  border-left: 2px solid currentColor;
  padding-left: 14px;
  color: inherit;
}
.bucket .b-task {
  font-weight: 600;
  font-size: 15px;
  color: var(--text);
  line-height: 1.35;
}
.bucket .b-reason {
  color: var(--text-mid);
  font-size: 14px;
  margin-top: 4px;
  line-height: 1.5;
}
.bucket .b-action {
  margin-top: 8px;
  font-size: 13px;
  color: var(--text);
  font-family: var(--font-mono);
  letter-spacing: 0.01em;
  padding: 8px 10px;
  background: rgba(255,255,255,0.025);
  border-radius: 6px;
  line-height: 1.45;
}
.bucket .b-action::before {
  content: "→  ";
  color: currentColor;
  font-weight: 600;
}
.bucket .empty {
  color: var(--text-dim);
  font-size: 13px;
  font-family: var(--font-mono);
  letter-spacing: 0.04em;
}

/* ========== FOOTER ========== */
.footer {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 14px;
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.14em;
  color: var(--text-dim);
  padding: 12px 0 0;
  text-transform: uppercase;
}
.signed-as {
  text-transform: none;
  letter-spacing: 0.04em;
  font-size: 11px;
}
.signout {
  background: transparent;
  border: none;
  color: var(--text-dim);
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  padding: 4px 6px;
  cursor: pointer;
}
.signout:hover { color: var(--text-mid); }

/* ========== GATE ========== */
.hidden { display: none !important; }

.gate {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 28px 20px calc(36px + env(safe-area-inset-bottom));
  background:
    radial-gradient(900px 500px at 50% -100px, rgba(93,211,158,0.07), transparent 60%),
    radial-gradient(700px 400px at 50% 110%, rgba(255,192,77,0.04), transparent 60%),
    var(--bg);
  animation: fadeIn 0.4s ease;
}
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}
.gate.fade-out {
  opacity: 0;
  transition: opacity 0.35s ease;
  pointer-events: none;
}

.gate-inner {
  width: 100%;
  max-width: 420px;
  display: flex;
  flex-direction: column;
  gap: 22px;
  text-align: left;
}

.gate-brand {
  margin-bottom: 4px;
}

.gate-title {
  font-size: 30px;
  font-weight: 700;
  letter-spacing: -0.025em;
  line-height: 1.1;
  margin: 0;
  background: linear-gradient(180deg, #ffffff 0%, #b8b8c0 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.gate-sub {
  margin: 0;
  color: var(--text-dim);
  font-size: 14px;
  line-height: 1.5;
}

.gate-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 4px;
}

.gate-form input[type="email"] {
  width: 100%;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  font-size: 16px;
  font-family: var(--font-sans);
  outline: none;
  transition: border-color 0.18s ease, background 0.18s ease;
}
.gate-form input[type="email"]::placeholder { color: var(--text-dim); }
.gate-form input[type="email"]:focus {
  border-color: var(--border-strong);
  background: var(--surface-2);
}
.gate-form input[type="email"].invalid {
  border-color: var(--delete);
  animation: shake 0.32s ease;
}
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-4px); }
  75% { transform: translateX(4px); }
}

.gate-submit {
  width: 100%;
  padding: 16px 18px;
  font-size: 16px;
}

.gate-foot {
  margin: 8px 0 0;
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--text-dim);
}

.gate-msg {
  margin: 4px 0 0;
  font-size: 13px;
  line-height: 1.5;
  color: var(--text-mid);
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}
.gate-msg.error {
  color: var(--delete);
  border-color: rgba(255,107,107,0.4);
  background: rgba(255,107,107,0.06);
}
.gate-msg.success {
  color: var(--automate);
  border-color: rgba(93,211,158,0.4);
  background: rgba(93,211,158,0.06);
}

.code-input {
  text-align: center;
  font-family: var(--font-mono);
  font-size: 28px !important;
  letter-spacing: 0.4em;
  padding: 18px 16px !important;
  font-weight: 500;
}
.code-input::placeholder {
  letter-spacing: 0.4em;
  opacity: 0.35;
}

.link-btn {
  background: transparent;
  border: none;
  color: var(--text-dim);
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  padding: 8px;
  cursor: pointer;
  margin-top: 4px;
}
.link-btn:hover { color: var(--text-mid); }

/* ========== INSTALL SHEET ========== */
.install-sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 200;
  display: flex;
  justify-content: center;
  padding: 0 12px calc(16px + env(safe-area-inset-bottom)) 12px;
  pointer-events: none;
  animation: slideUp 0.32s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.install-sheet::before {
  content: "";
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  z-index: -1;
  animation: fadeIn 0.32s ease;
}
@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

.install-inner {
  pointer-events: auto;
  width: 100%;
  max-width: 460px;
  background: linear-gradient(180deg, var(--surface) 0%, var(--bg-warm) 100%);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 14px 22px 22px;
  box-shadow: 0 -16px 40px -8px rgba(0,0,0,0.5);
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.install-handle {
  width: 40px;
  height: 4px;
  background: var(--border-strong);
  border-radius: 2px;
  margin: 0 auto 4px;
}

.install-title {
  font-size: 19px;
  font-weight: 600;
  letter-spacing: -0.015em;
  margin: 0;
  text-align: center;
}

.install-sub {
  margin: 0;
  color: var(--text-dim);
  font-size: 14px;
  text-align: center;
  line-height: 1.45;
}

.install-section { display: flex; flex-direction: column; gap: 12px; }
.install-section.hidden { display: none; }

.install-cta {
  width: 100%;
  padding: 15px 18px;
  font-size: 15px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.install-steps {
  margin: 0;
  padding: 14px 18px 14px 36px;
  background: var(--bg-warm);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  gap: 10px;
  font-size: 14px;
  line-height: 1.5;
}
.install-steps li::marker {
  font-family: var(--font-mono);
  color: var(--text-dim);
  font-size: 12px;
}
.install-steps strong { color: var(--text); font-weight: 600; }

.ios-share {
  display: inline-block;
  width: 14px;
  height: 18px;
  vertical-align: -3px;
  color: #4a9eff;
}

.install-dismiss {
  align-self: center;
  margin-top: 2px;
}

@media (min-width: 600px) {
  .gate-title { font-size: 36px; }
}

/* ========== TOAST ========== */
.toast {
  position: fixed;
  bottom: calc(28px + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--text);
  color: var(--bg);
  padding: 11px 18px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.01em;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
  z-index: 100;
  max-width: 80vw;
  text-align: center;
  box-shadow: 0 16px 32px -12px rgba(0,0,0,0.5);
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ========== SPINNER ========== */
.spinner {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  vertical-align: -2px;
  margin-right: 8px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ========== DESKTOP REFINEMENT ========== */
@media (min-width: 600px) {
  .app { padding-top: 40px; gap: 24px; }
  .title { font-size: 42px; }
  .subtitle { font-size: 15px; }
  .card { padding: 22px; }
}

/* ========== REDUCED MOTION ========== */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
