:root {
  --bg: #0b0f19;
  --card: rgba(30, 41, 59, 0.6);
  --text: #f1f5f9;
  --muted: #94a3b8;
  --accent: #38bdf8;
  --accent-2: #818cf8;
  --success: #22d3ee;
  --danger: #f87171;
  --glass-border: rgba(255, 255, 255, 0.08);
  --shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.6);
  --radius: 16px;
  --quiet-panel: rgba(15, 23, 42, 0.28);
  --quiet-circle: rgba(56, 189, 248, 0.16);
  --quiet-circle-border: rgba(56, 189, 248, 0.55);
  --quiet-glow: rgba(56, 189, 248, 0.18);
  --quiet-dot: rgba(148, 163, 184, 0.35);
  --quiet-dot-active: rgba(56, 189, 248, 0.25);
  --quiet-input: rgba(15, 23, 42, 0.35);
  --phase-7: #1f5673;
  --phase-6: #256580;
  --phase-5: #2c758f;
  --phase-4: #34869f;
  --phase-3: #3f98ae;
  --phase-2: #52abbc;
  --phase-1: #6cbec9;
  --phase-0: #8ed2d5;
  --backdrop: rgba(2, 6, 23, 0.38);
  --card-overlay-bg: rgba(30, 41, 59, 0.26);
  --overlay-gloss: linear-gradient(150deg, rgba(255, 255, 255, 0.16), rgba(255, 255, 255, 0) 55%);
  --overlay-border: rgba(255, 255, 255, 0.24);
  --overlay-edge: rgba(255, 255, 255, 0.22);
}

[data-theme="light"] {
  --bg: #f8fafc;
  --card: rgba(255, 255, 255, 0.7);
  --text: #0f172a;
  --muted: #475569;
  --accent: #0ea5e9;
  --accent-2: #4f46e5;
  --success: #06b6d4;
  --danger: #ef4444;
  --glass-border: rgba(0, 0, 0, 0.1);
  --shadow: 0 20px 40px -12px rgba(0, 0, 0, 0.1);
  --quiet-panel: rgba(226, 232, 240, 0.55);
  --quiet-circle: rgba(14, 165, 233, 0.14);
  --quiet-circle-border: rgba(14, 165, 233, 0.55);
  --quiet-glow: rgba(14, 165, 233, 0.16);
  --quiet-dot: rgba(71, 85, 105, 0.30);
  --quiet-dot-active: rgba(14, 165, 233, 0.22);
  --quiet-input: rgba(255, 255, 255, 0.75);
  --phase-7: #8fb6cd;
  --phase-6: #7eaac5;
  --phase-5: #6d9ebd;
  --phase-4: #5c92b5;
  --phase-3: #4a86ad;
  --phase-2: #387ba6;
  --phase-1: #2371a0;
  --phase-0: #0ea5e9;
  --backdrop: rgba(15, 23, 42, 0.22);
  --card-overlay-bg: rgba(255, 255, 255, 0.38);
  --overlay-gloss: linear-gradient(150deg, rgba(255, 255, 255, 0.75), rgba(255, 255, 255, 0) 60%);
  --overlay-border: rgba(255, 255, 255, 0.8);
  --overlay-edge: rgba(255, 255, 255, 0.9);
}

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

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  line-height: 1.5;
  overflow-x: hidden;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  background:
    radial-gradient(circle at 15% 30%, rgba(56, 189, 248, 0.12) 0%, transparent 35%),
    radial-gradient(circle at 85% 70%, rgba(129, 140, 248, 0.10) 0%, transparent 35%);
  z-index: -1;
}

.wrap {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 72px 24px 48px;
}

.card {
  background: var(--card);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius);
  padding: 40px 32px;
  max-width: 560px;
  width: 100%;
  box-shadow: var(--shadow);
  text-align: center;
  animation: fadeIn 0.6s ease-out;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Server details as a gentle, translucent overlay over the Quiet Corner */
.card-overlay[hidden] { display: none; }
.card-overlay {
  position: fixed;
  inset: 0;
  z-index: 60;
}
.card-backdrop {
  position: absolute;
  inset: 0;
  background: var(--backdrop);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}
.card-overlay .card {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 61;
  max-width: min(560px, calc(100vw - 32px));
  max-height: calc(100vh - 48px);
  overflow-y: auto;
  background: var(--card-overlay-bg);
  background-image: var(--overlay-gloss);
  border: 1px solid var(--overlay-border);
  box-shadow: var(--shadow), inset 0 1px 0 var(--overlay-edge);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  padding: 34px 28px 28px;
  animation: overlayIn 0.25s ease-out;
}
@keyframes overlayIn {
  from { opacity: 0; transform: translate(-50%, -47%); }
  to { opacity: 1; transform: translate(-50%, -50%); }
}
.overlay-close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 32px;
  height: 32px;
  padding: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
  border: 1px solid var(--glass-border);
  font-size: 1.25rem;
  line-height: 1;
  justify-content: center;
}
[data-theme="light"] .overlay-close { background: rgba(0, 0, 0, 0.06); }
.overlay-close:hover { border-color: var(--accent); }
body.overlay-open { overflow: hidden; }
body.overlay-open .top-actions { opacity: 0; pointer-events: none; }

h1 {
  font-size: 1.9rem;
  letter-spacing: -0.02em;
  margin-bottom: 8px;
  background: linear-gradient(to right, var(--accent), var(--accent-2));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.subtitle {
  color: var(--muted);
  font-size: 0.95rem;
  margin-bottom: 24px;
}

/* Live clock */
.clock {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 1.35rem;
  font-weight: 600;
  margin: 16px 0 4px;
  letter-spacing: 0.05em;
  color: var(--success);
}

.clock-label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--muted);
  margin-bottom: 12px;
}

/* Quote */
.quote-box {
  margin: 26px 0;
  padding: 20px 24px;
  border-radius: 12px;
  background: rgba(15, 23, 42, 0.35);
  border: 1px solid var(--glass-border);
  font-style: italic;
  color: var(--text);
}

[data-theme="light"] .quote-box {
  background: rgba(226, 232, 242, 0.6);
  border-color: rgba(0, 0, 0, 0.08);
  color: #1e293b;
}

.quote-text {
  font-size: 1.1rem;
  margin-bottom: 8px;
  quotes: "\201c" "\201d" "\2018" "\2019";
}

.quote-text::before { content: open-quote; }
.quote-text::after { content: close-quote; }

.quote-attrib {
  display: block;
  font-style: normal;
  font-size: 0.85rem;
  color: var(--muted);
  text-align: right;
}

/* Controls */
.controls {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
  margin: 24px 0;
}

button {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 18px;
  border: none;
  border-radius: 10px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.12s, box-shadow 0.2s, opacity 0.2s;
  font-family: inherit;
}

button:active { transform: translateY(1px); }
button:disabled { opacity: 0.6; cursor: not-allowed; }

.btn-primary {
  background: var(--accent);
  color: #020617;
  box-shadow: 0 0 0 0 var(--accent);
}
.btn-primary:hover { box-shadow: 0 0 0 4px rgba(56, 189, 248, 0.35); }

.btn-ghost {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
  border: 1px solid var(--glass-border);
}
[data-theme="light"] .btn-ghost {
  background: rgba(0, 0, 0, 0.05);
  border-color: rgba(0, 0, 0, 0.12);
}
.btn-ghost:hover { background: rgba(255, 255, 255, 0.14); }

.btn-danger { background: var(--danger); color: #fff; }

.spinner {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid currentColor;
  border-bottom-color: transparent;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

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

/* Stats row */
.stats {
  display: flex;
  gap: 16px;
  justify-content: center;
  margin-top: 22px;
  padding-top: 20px;
  border-top: 1px solid var(--glass-border);
}

.stat {
  text-align: center;
}

.stat-value {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--accent);
}

.stat-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted);
  margin-top: 4px;
}

/* Corner icon buttons */
.top-actions {
  position: fixed;
  top: 18px;
  right: 18px;
  z-index: 50;
  display: flex;
  gap: 10px;
}
.icon-toggle {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid var(--glass-border);
  background: var(--card);
  color: var(--text);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  backdrop-filter: blur(8px);
}
.icon-toggle:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.icon-toggle:disabled { opacity: 0.3; cursor: default; }

/* Toast */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: var(--card);
  border: 1px solid var(--glass-border);
  color: var(--text);
  padding: 10px 18px;
  border-radius: 10px;
  font-size: 0.85rem;
  box-shadow: var(--shadow);
  opacity: 0;
  transition: transform 0.25s, opacity 0.25s;
  z-index: 100;
  backdrop-filter: blur(8px);
}
.toast.show { transform: translateX(-50%) translateY(0); opacity: 1; }

/* Signature */
.signature {
  margin-top: 30px;
  padding-top: 20px;
  border-top: 1px solid var(--glass-border);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.8rem;
  color: var(--muted);
}
.sig-label { color: var(--muted); font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.08em; }
.sig-value { color: var(--success); font-weight: 700; word-break: break-all; margin-top: 4px; cursor: pointer; }
.sig-value:hover { text-decoration: underline; }
.signature[hidden] { display: none; }

/* Copy feedback */
.copied { color: var(--success) !important; }

/* ---------- The Quiet Corner ---------- */
.quiet {
  max-width: 900px;
  width: 100%;
  text-align: center;
  animation: fadeIn 0.6s ease-out 0.1s both;
}

.quiet-title {
  font-size: 2.4rem;
  letter-spacing: -0.01em;
  margin-bottom: 8px;
  color: var(--text);
}

.quiet-intro {
  color: var(--muted);
  font-size: 1.1rem;
  margin-bottom: 28px;
}

.quiet-block {
  background: var(--quiet-panel);
  border: 1px solid var(--glass-border);
  border-radius: 22px;
  padding: 40px 36px;
  margin-top: 16px;
  min-height: 520px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.quiet-block h3 {
  font-size: 1.1rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--accent);
  margin-bottom: 18px;
}

.quiet-controls {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
  margin-top: 14px;
}

.quiet-controls button {
  font-size: 0.98rem;
  padding: 12px 18px;
}

.quiet-check {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-top: 14px;
  font-size: 1rem;
  color: var(--muted);
  cursor: pointer;
}

.quiet-check input { accent-color: var(--accent); }

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

/* Breathing pacer */
.breath-stage {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.breath-circle {
  width: 260px;
  height: 260px;
  box-sizing: border-box;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  text-align: center;
  --phase-color: var(--quiet-circle-border);
  background-color: color-mix(in srgb, var(--phase-color) 16%, transparent);
  border: 2px solid color-mix(in srgb, var(--phase-color) 72%, transparent);
  box-shadow: 0 0 34px color-mix(in srgb, var(--phase-color) 28%, transparent);
  transform: scale(var(--breath-scale, 0.9));
  transition: transform var(--breath-duration, 0.6s) ease-in-out,
              background-color 1s linear, border-color 1s linear, box-shadow 1s linear;
  /* The circle scales up to 1.14x; keep that overflow clear of the buttons. */
  margin-bottom: 24px;
}

/* The countdown, felt as color: the circle gently brightens as each phase runs
   down, then eases back to calm when the next one begins. No digits anywhere. */
.breath-circle[data-progress="7"] { --phase-color: var(--phase-7); }
.breath-circle[data-progress="6"] { --phase-color: var(--phase-6); }
.breath-circle[data-progress="5"] { --phase-color: var(--phase-5); }
.breath-circle[data-progress="4"] { --phase-color: var(--phase-4); }
.breath-circle[data-progress="3"] { --phase-color: var(--phase-3); }
.breath-circle[data-progress="2"] { --phase-color: var(--phase-2); }
.breath-circle[data-progress="1"] { --phase-color: var(--phase-1); }
.breath-circle[data-progress="0"] { --phase-color: var(--phase-0); }

.breath-circle[data-phase="inhale"],
.breath-circle[data-phase="hold-in"] { --breath-scale: 1.14; }
.breath-circle[data-phase="exhale"],
.breath-circle[data-phase="hold-out"] { --breath-scale: 0.82; }
.breath-circle[data-phase="idle"] { --breath-scale: 0.9; --breath-duration: 0.6s; }
.breath-circle[data-seconds="4"] { --breath-duration: 4s; }
.breath-circle[data-seconds="7"] { --breath-duration: 7s; }

.breath-cue {
  font-size: 1.6rem;
  font-weight: 600;
  line-height: 1.25;
  color: var(--text);
}

/* Grounding */
.quiet-step {
  font-size: 1rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--muted);
}

.ground-dots {
  display: flex;
  gap: 12px;
  justify-content: center;
  margin: 18px 0;
}

.dot {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: var(--quiet-dot);
}

.dot.active {
  background: var(--accent);
  box-shadow: 0 0 0 3px var(--quiet-dot-active);
}

.quiet-prompt {
  font-size: 1.6rem;
  font-weight: 600;
  margin-top: 4px;
}

/* One thing */
.one-line {
  font-size: 1.6rem;
  font-style: italic;
  line-height: 1.6;
  padding: 6px 4px;
}

/* Notepad */
#goodNotes {
  width: 100%;
  resize: vertical;
  border-radius: 10px;
  border: 1px solid var(--glass-border);
  background: var(--quiet-input);
  color: var(--text);
  padding: 12px;
  font: inherit;
  font-size: 0.9rem;
}

#goodNotes:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

/* Timer */
.timer-status {
  font-size: 1.5rem;
  font-style: italic;
  color: var(--success);
  margin-top: 18px;
}

.quiet-footer {
  font-size: 0.78rem;
  color: var(--muted);
  margin-top: 22px;
  line-height: 1.6;
}

/* One utility at a time, with a single large "next" button on the right */
.quiet-stage {
  display: flex;
  align-items: stretch;
  justify-content: center;
  gap: 18px;
  width: 100%;
  margin-top: 18px;
}
.quiet-panels { flex: 1 1 auto; min-width: 0; }
.quiet-next {
  flex: 0 0 130px;
  align-self: center;
  min-height: 240px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 18px 12px;
  border-radius: 22px;
  background: var(--quiet-panel);
  border: 1px solid var(--glass-border);
  color: var(--text);
  font-size: 1rem;
  font-weight: 600;
  text-align: center;
}
.quiet-next:hover { border-color: var(--accent); background: var(--quiet-dot-active); }
.quiet-next-arrow { font-size: 3.4rem; line-height: 1; color: var(--accent); }
.quiet-next-name { font-size: 1rem; }
.quiet-block[hidden] { display: none; }

@media (max-width: 640px) {
  .quiet-stage { flex-direction: column; align-items: stretch; }
  .quiet-block { min-height: auto; padding: 30px 22px; }
  .breath-circle { width: 200px; height: 200px; }
  .quiet-title { font-size: 2rem; }
  .quiet-prompt, .one-line, .breath-cue { font-size: 1.3rem; }
  .quiet-next {
    flex: 0 0 auto;
    width: 100%;
    min-height: 64px;
    flex-direction: row;
    gap: 14px;
  }
  .quiet-next-arrow { font-size: 2rem; }
}

@media (prefers-reduced-motion: reduce) {
  .breath-circle { transition: background-color 1s linear, border-color 1s linear, box-shadow 1s linear; }
  .quiet { animation: none; }
  .card-overlay .card { animation: none; }
}

/* Responsive */
@media (max-width: 480px) {
  .card { padding: 28px 20px; }
  h1 { font-size: 1.55rem; }
  .controls { flex-direction: column; align-items: stretch; }
  button { width: 100%; justify-content: center; }
}
