:root {
  --bg:       #ffffff;
  --surface:  #f3f4f6;
  --border:   #e5e7eb;
  --text:     #111827;
  --text-sub: #6b7280;
  --accent:   #3b82f6;
  --accent-dim: #93c5fd;
  --danger:   #ef4444;
  --warn:     #f59e0b;
  --radius:   12px;
  --font:     -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg:       #0f172a;
    --surface:  #1e293b;
    --border:   #334155;
    --text:     #f1f5f9;
    --text-sub: #94a3b8;
  }
}

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

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  font-size: clamp(15px, 4vw, 17px);
}

.screen { display: none; flex-direction: column; min-height: 100dvh; padding: 1.5rem 1rem; max-width: 520px; margin: 0 auto; }
.screen.active { display: flex; }

/* Header */
.app-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1.5rem; }
.app-header h1 { font-size: 1.25rem; font-weight: 700; }
.btn-icon { background: none; border: none; cursor: pointer; color: var(--text-sub); font-size: 1.4rem; padding: 0.25rem; }

/* Login */
#screen-login { align-items: center; justify-content: center; gap: 1.5rem; text-align: center; }
#screen-login h1 { font-size: 2rem; font-weight: 800; color: var(--accent); }
#screen-login p { color: var(--text-sub); }

/* Moods */
.mood-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 0.75rem; }
@media (min-width: 480px) { .mood-grid { grid-template-columns: repeat(3, 1fr); } }
.mood-card {
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem 0.75rem;
  text-align: center;
  cursor: pointer;
  transition: border-color .15s, transform .1s;
}
.mood-card:hover, .mood-card:active { border-color: var(--accent); transform: scale(1.02); }
.mood-card .mood-icon { font-size: 2rem; margin-bottom: 0.4rem; }
.mood-card .mood-name { font-weight: 600; font-size: 0.95rem; }
.mood-card .mood-desc { font-size: 0.78rem; color: var(--text-sub); margin-top: 0.2rem; }

/* Technique list */
.technique-list { display: flex; flex-direction: column; gap: 0.75rem; }
.technique-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  cursor: pointer;
  transition: border-color .15s;
}
.technique-card:hover { border-color: var(--accent); }
.technique-card-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 0.5rem; }
.technique-card h3 { font-size: 1rem; font-weight: 600; }
.technique-meta { display: flex; gap: 0.4rem; flex-wrap: wrap; margin-top: 0.4rem; }
.tag { font-size: 0.72rem; padding: 2px 8px; border-radius: 999px; background: var(--border); color: var(--text-sub); }
.tag-warn { background: #fef3c7; color: #92400e; }
.tag-danger { background: #fee2e2; color: #991b1b; }
.technique-desc { font-size: 0.85rem; color: var(--text-sub); margin-top: 0.4rem; }

/* Pacer */
#screen-pacer { align-items: center; }
.pacer-header { display: flex; justify-content: space-between; align-items: center; width: 100%; margin-bottom: 2rem; }
.pacer-header h2 { font-size: 1rem; font-weight: 600; }

.circle-wrap { display: flex; align-items: center; justify-content: center; width: 200px; height: 200px; }
#pacer-circle {
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: width .1s, height .1s;
  width: 80px;
  height: 80px;
  background: rgba(59,130,246,.15);
  border: 3px solid var(--accent);
}
#pacer-circle.exhale, #pacer-circle.hold_out {
  background: rgba(147,197,253,.12);
  border-color: var(--accent-dim);
}
#pacer-countdown { font-size: 1.6rem; font-weight: 700; color: var(--text); user-select: none; }

.pacer-label { font-size: 1.2rem; font-weight: 600; letter-spacing: .05em; text-transform: uppercase; margin: 1.25rem 0 0.5rem; color: var(--accent); }
.pacer-progress { font-size: 0.85rem; color: var(--text-sub); }
.pacer-stage { font-size: 0.9rem; color: var(--text-sub); margin-top: 0.25rem; font-style: italic; }
.guided-prompt {
  margin-top: 1.25rem;
  padding: 0.75rem 1rem;
  background: var(--surface);
  border-left: 3px solid var(--accent);
  border-radius: 0 var(--radius) var(--radius) 0;
  font-size: 0.9rem;
  color: var(--text);
  max-width: 340px;
  opacity: 0;
  transition: opacity .6s;
}
.guided-prompt.visible { opacity: 1; }
.safety-note { font-size: 0.8rem; color: var(--warn); margin-top: 0.5rem; text-align: center; max-width: 300px; }

/* Finish */
#screen-finish { align-items: center; justify-content: center; gap: 1rem; text-align: center; }
#screen-finish h2 { font-size: 1.5rem; font-weight: 700; }
.finish-stats { display: flex; gap: 1.5rem; }
.stat-box { background: var(--surface); border-radius: var(--radius); padding: 0.75rem 1.25rem; }
.stat-box .val { font-size: 1.5rem; font-weight: 700; color: var(--accent); }
.stat-box .lbl { font-size: 0.75rem; color: var(--text-sub); }

/* History */
.history-list { display: flex; flex-direction: column; gap: 0.5rem; }
.history-item { background: var(--surface); border-radius: var(--radius); padding: 0.75rem 1rem; font-size: 0.88rem; }
.history-item .hi-top { display: flex; justify-content: space-between; font-weight: 600; }
.history-item .hi-sub { color: var(--text-sub); font-size: 0.78rem; margin-top: 0.2rem; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem;
  padding: 0.75rem 1.5rem; border-radius: var(--radius); border: none; cursor: pointer;
  font-size: 1rem; font-weight: 600; transition: opacity .15s;
}
.btn:active { opacity: .8; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-secondary { background: var(--surface); color: var(--text); border: 1px solid var(--border); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-row { display: flex; gap: 0.75rem; flex-wrap: wrap; justify-content: center; }

/* Modal */
.modal-overlay {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,.6); z-index: 100;
  align-items: center; justify-content: center; padding: 1rem;
}
.modal-overlay.open { display: flex; }
.modal {
  background: var(--bg); border-radius: var(--radius);
  padding: 1.5rem; max-width: 420px; width: 100%;
  max-height: 80dvh; overflow-y: auto;
}
.modal h2 { color: var(--danger); margin-bottom: 1rem; font-size: 1.1rem; }
.modal ul { padding-left: 1.25rem; margin-bottom: 1rem; }
.modal ul li { margin-bottom: 0.4rem; font-size: 0.9rem; }
.modal-confirm { display: flex; align-items: center; gap: 0.5rem; margin-bottom: 1rem; font-size: 0.9rem; cursor: pointer; }

/* Nav */
.bottom-nav { display: flex; justify-content: space-around; padding: 0.75rem 0 0.5rem; border-top: 1px solid var(--border); margin-top: auto; }
.nav-btn { background: none; border: none; cursor: pointer; color: var(--text-sub); font-size: 0.75rem; display: flex; flex-direction: column; align-items: center; gap: 0.2rem; padding: 0.25rem 0.75rem; }
.nav-btn.active { color: var(--accent); }
.nav-btn svg { width: 22px; height: 22px; }

/* Misc */
.back-btn { display: flex; align-items: center; gap: 0.3rem; background: none; border: none; cursor: pointer; color: var(--text-sub); font-size: 0.9rem; margin-bottom: 1rem; padding: 0; }
.section-title { font-size: 1.1rem; font-weight: 700; margin-bottom: 1rem; }
.empty { color: var(--text-sub); text-align: center; padding: 2rem 0; }

/* Settings */
.settings-section { margin-bottom: 1.5rem; }
.settings-label { font-size: 0.7rem; font-weight: 700; letter-spacing: 0.08em; color: var(--text-sub); margin-bottom: 0.6rem; }
.settings-card { background: var(--surface); border-radius: var(--radius); padding: 0.875rem 1rem; }
.settings-card-sub { font-size: 0.72rem; color: var(--text-sub); margin-bottom: 0.2rem; }
.settings-card-val { font-size: 0.9rem; color: var(--text); }
.lang-grid { display: flex; gap: 0.5rem; }
.lang-btn {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 0.3rem;
  padding: 0.75rem 0.5rem; border-radius: var(--radius); border: 1px solid var(--border);
  background: var(--surface); cursor: pointer; transition: border-color .15s, background .15s;
}
.lang-btn.active { background: #4f46e5; border-color: #4f46e5; color: #fff; }
.lang-flag { font-size: 1.5rem; }
.lang-name { font-size: 0.72rem; font-weight: 500; color: inherit; }
.changelog-list { padding: 0; }
.changelog-entry { display: flex; align-items: flex-start; gap: 0.75rem; padding: 0.625rem 0; border-bottom: 1px solid var(--border); }
.changelog-entry:last-child { border-bottom: none; }
.changelog-date { font-size: 0.72rem; color: var(--text-sub); white-space: nowrap; padding-top: 0.1rem; min-width: 5rem; }
.changelog-text { font-size: 0.85rem; color: var(--text); }
.btn-logout { width: 100%; margin-top: 0.5rem; background: rgba(239,68,68,.15); color: #f87171; border: 1px solid rgba(239,68,68,.3); }

/* ── Detail Screen ─────────────────────────────────────────────────────────── */
#screen-detail { padding-bottom: 0; }
#detail-content { flex: 1; overflow-y: auto; padding-bottom: 2rem; }
.detail-meta-row { display: flex; gap: 0.4rem; flex-wrap: wrap; margin-bottom: 0.6rem; min-height: 1.4rem; }
.detail-header-row { display: flex; justify-content: space-between; align-items: flex-start; gap: 0.5rem; margin-bottom: 0.4rem; }
.detail-title { font-size: 1.3rem; font-weight: 700; line-height: 1.25; }
.detail-duration { font-size: 0.8rem; color: var(--text-sub); white-space: nowrap; padding-top: 0.3rem; }
.detail-description { font-size: 0.9rem; color: var(--text-sub); margin-bottom: 1.25rem; line-height: 1.5; }
.detail-section-title { font-size: 0.68rem; font-weight: 700; letter-spacing: 0.09em; color: var(--text-sub); text-transform: uppercase; margin-bottom: 0.5rem; margin-top: 1.1rem; }
.detail-phases { background: var(--surface); border-radius: var(--radius); padding: 0.875rem 1rem; margin-bottom: 0.25rem; }
.detail-phase-row { display: flex; justify-content: space-between; align-items: center; padding: 0.4rem 0; border-bottom: 1px solid var(--border); font-size: 0.88rem; }
.detail-phase-row:last-child { border-bottom: none; }
.detail-phase-left { display: flex; align-items: center; gap: 0.5rem; }
.detail-phase-icon { width: 1.4rem; text-align: center; font-size: 0.95rem; }
.detail-phase-dur { color: var(--text-sub); font-variant-numeric: tabular-nums; white-space: nowrap; }
.detail-cycle-count { text-align: right; font-size: 0.78rem; color: var(--accent); font-weight: 600; margin-top: 0.6rem; }
.detail-stage { margin-bottom: 0.6rem; }
.detail-stage-name { font-weight: 600; font-size: 0.88rem; margin-bottom: 0.25rem; }
.detail-stage-instr { font-size: 0.78rem; color: var(--text-sub); margin-bottom: 0.3rem; font-style: italic; }
.detail-stage-phases { padding-left: 0.75rem; border-left: 2px solid var(--border); }
.detail-warnings { background: #fef3c7; border-radius: var(--radius); padding: 0.875rem 1rem; margin-top: 0.25rem; }
@media (prefers-color-scheme: dark) { .detail-warnings { background: rgba(245,158,11,.12); } }
.detail-warning-item { font-size: 0.82rem; color: #92400e; padding: 0.2rem 0; display: flex; gap: 0.5rem; line-height: 1.4; }
@media (prefers-color-scheme: dark) { .detail-warning-item { color: #fbbf24; } }
.detail-long-desc { font-size: 0.88rem; line-height: 1.7; color: var(--text); }
.detail-long-desc p { margin-bottom: 0.75rem; }
.detail-long-desc p:last-child { margin-bottom: 0; }
.detail-start-btn { margin-top: 1.5rem; display: flex; flex-direction: column; gap: 0.5rem; }

/* ── Create Screen ─────────────────────────────────────────────────────────── */
#screen-create { padding-bottom: 2rem; }
.create-form { display: flex; flex-direction: column; gap: 1.25rem; }
.form-group { display: flex; flex-direction: column; gap: 0.4rem; }
.form-label { font-size: 0.68rem; font-weight: 700; letter-spacing: 0.09em; color: var(--text-sub); text-transform: uppercase; }
.form-input {
  padding: 0.65rem 0.75rem; border: 1px solid var(--border); border-radius: var(--radius);
  font-size: 0.9rem; background: var(--bg); color: var(--text); font-family: var(--font);
  width: 100%;
}
.form-input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 2px rgba(59,130,246,.15); }
textarea.form-input { resize: vertical; min-height: 80px; }
.mood-checkboxes { display: grid; grid-template-columns: repeat(2, 1fr); gap: 0.4rem; }
.mood-checkbox-item {
  display: flex; align-items: center; gap: 0.4rem; font-size: 0.85rem; cursor: pointer;
  padding: 0.45rem 0.65rem; border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface); transition: border-color .12s, background .12s;
  user-select: none;
}
.mood-checkbox-item:has(input:checked) { border-color: var(--accent); background: rgba(59,130,246,.08); }
.mood-checkbox-item input { accent-color: var(--accent); cursor: pointer; }
.phase-list { display: flex; flex-direction: column; gap: 0.5rem; }
.phase-row {
  display: grid; grid-template-columns: 1fr 1.4fr 3.5rem auto;
  gap: 0.35rem; align-items: center;
  background: var(--surface); border-radius: 8px; padding: 0.5rem 0.6rem;
}
.phase-row select, .phase-row input[type="text"], .phase-row input[type="number"] {
  padding: 0.4rem 0.5rem; border: 1px solid var(--border); border-radius: 6px;
  font-size: 0.82rem; background: var(--bg); color: var(--text); font-family: var(--font);
  width: 100%;
}
.phase-row input[type="number"] { text-align: center; }
.phase-remove-btn {
  padding: 0.3rem 0.45rem; border: none; background: none;
  color: var(--danger); cursor: pointer; font-size: 1.1rem; line-height: 1; border-radius: 4px;
}
.phase-remove-btn:hover { background: rgba(239,68,68,.1); }
.btn-add-phase {
  display: flex; align-items: center; gap: 0.4rem; justify-content: center;
  padding: 0.55rem; border: 1px dashed var(--border); border-radius: var(--radius);
  background: none; color: var(--accent); font-size: 0.85rem; font-weight: 500;
  cursor: pointer; transition: border-color .12s, background .12s;
}
.btn-add-phase:hover { border-color: var(--accent); background: rgba(59,130,246,.05); }
.safety-radio-group { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.safety-opt {
  flex: 1; min-width: 5rem; display: flex; align-items: center; justify-content: center;
  gap: 0.3rem; padding: 0.5rem 0.6rem; border: 1px solid var(--border);
  border-radius: 8px; cursor: pointer; font-size: 0.82rem; background: var(--surface);
  transition: border-color .12s, background .12s;
}
.safety-opt.active-none { border-color: var(--accent); background: rgba(59,130,246,.1); color: var(--accent); font-weight: 600; }
.safety-opt.active-moderate { border-color: var(--warn); background: #fef3c7; color: #92400e; font-weight: 600; }
.safety-opt.active-high { border-color: var(--danger); background: #fee2e2; color: #991b1b; font-weight: 600; }
.create-error { color: var(--danger); font-size: 0.82rem; margin-top: 0.25rem; display: none; }
.create-success { color: #16a34a; font-size: 0.88rem; text-align: center; padding: 0.5rem; display: none; }

/* ── My Techniques in settings ─────────────────────────────────────────────── */
.my-tech-item {
  display: flex; justify-content: space-between; align-items: flex-start;
  padding: 0.6rem 0; border-bottom: 1px solid var(--border); gap: 0.5rem;
}
.my-tech-item:last-child { border-bottom: none; }
.my-tech-info { flex: 1; min-width: 0; }
.my-tech-name { font-size: 0.88rem; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.my-tech-status { font-size: 0.72rem; color: var(--text-sub); margin-top: 0.1rem; }
.my-tech-status.pending { color: var(--warn); }
.my-tech-actions { display: flex; gap: 0.35rem; align-items: center; flex-shrink: 0; }
.btn-approve-tech {
  background: rgba(34,197,94,.12); border: 1px solid rgba(34,197,94,.35);
  color: #15803d; border-radius: 6px; cursor: pointer; font-size: 0.75rem;
  padding: 0.25rem 0.55rem; white-space: nowrap;
}
@media (prefers-color-scheme: dark) { .btn-approve-tech { color: #4ade80; } }
.btn-delete-tech {
  background: none; border: none; color: var(--danger); cursor: pointer;
  font-size: 0.82rem; padding: 0.2rem 0.4rem; border-radius: 4px;
}
.btn-delete-tech:hover { background: rgba(239,68,68,.1); }
.pending-creator { font-size: 0.7rem; color: var(--text-sub); word-break: break-all; }

/* ── Mood screen intro ──────────────────────────────────────────────────────── */
.app-tagline {
  font-size: 0.8rem; font-weight: 600; letter-spacing: 0.12em; text-transform: uppercase;
  color: var(--accent); margin-bottom: 0.35rem; margin-top: -0.75rem;
}
.mood-intro {
  font-size: 0.88rem; color: var(--text-sub); margin-bottom: 1.25rem;
  line-height: 1.55; max-width: 400px;
}
.feature-strip {
  display: flex; flex-wrap: wrap; gap: 0.5rem; margin-top: 1.25rem;
}
.feature-chip {
  font-size: 0.75rem; font-weight: 500; color: var(--text-sub);
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 999px; padding: 0.3rem 0.75rem;
  white-space: nowrap;
}
