/* ===== Base ===== */
html {
  background: #0d0a14;
  min-height: 100dvh;
  overflow: hidden;
  /* Phủ nền tối lên toàn vùng safe area (notch, status bar) khi dùng PWA */
  padding-top: constant(safe-area-inset-top);
  padding-top: env(safe-area-inset-top);
}

body {
  font-family: var(--font-ui);
  font-weight: 300;
  color: var(--text);
  background-color: var(--bg-deep);
  min-height: 100dvh;
  overflow: hidden;
  padding-top: 0;
}

/* ===== Landing page (index.html) ===== */
.landing {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-lg);
  padding: var(--space-lg);
  background: radial-gradient(ellipse at center, var(--bg-warm) 0%, var(--bg-deep) 70%);
}

.landing__title {
  font-size: clamp(3rem, 15vw, 6rem);
  font-weight: 200;
  letter-spacing: 0.4em;
  color: var(--amber);
  text-indent: 0.4em; /* bù letter-spacing cho căn giữa thật */
}

.landing__subtitle {
  font-size: clamp(0.85rem, 3.5vw, 1rem);
  font-weight: 300;
  color: var(--text-dim);
  letter-spacing: 0.08em;
}

.landing__actions {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-md);
  width: 100%;
  max-width: 300px;
  margin-top: var(--space-sm);
}

.btn-pill {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 52px;
  padding: 0 var(--space-lg);
  border: 1px solid rgba(168, 120, 80, 0.4);
  border-radius: 999px;
  font-family: var(--font-ui);
  font-size: 0.8rem;
  font-weight: 400;
  letter-spacing: 0.15em;
  color: var(--text);
  transition: border-color var(--ease-slow), background-color var(--ease-slow), color var(--ease-slow);
}

.btn-pill:hover,
.btn-pill:focus-visible {
  border-color: var(--amber);
  background-color: rgba(168, 120, 80, 0.1);
  color: var(--amber);
  outline: none;
}

.btn-pill:active {
  background-color: rgba(168, 120, 80, 0.2);
}

/* ===== App page (app.html) ===== */
.stage {
  position: fixed;
  inset: 0;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-md);
}

#stars {
  position: fixed;
  inset: 0;
  z-index: 1;
  pointer-events: none;
}

/* Vòng tròn thở */
.breath-wrapper {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 220px;
  height: 220px;
}

.breath-glow {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(168, 120, 80, 0.15) 0%, transparent 70%);
  transition: transform 0.3s ease;
}

.breath-circle {
  width: 120px;
  height: 120px;
  border-radius: 50%;
  border: 1px solid rgba(168, 120, 80, 0.5);
  background: radial-gradient(circle, rgba(168, 120, 80, 0.08) 0%, transparent 70%);
  transition: transform 0.3s ease;
}

.breath-text {
  font-size: 0.9rem;
  font-weight: 300;
  letter-spacing: 0.1em;
  color: var(--text-dim);
  transition: color var(--ease-slow);
}

.breath-count {
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  color: var(--text-dim);
  opacity: 0.6;
}

/* Controls cố định dưới */
.controls {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 10;
  display: flex;
  justify-content: center;
  gap: var(--space-sm);
  padding: var(--space-sm) var(--space-md);
  padding-bottom: max(var(--space-sm), env(safe-area-inset-bottom));
}

.btn-control {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 44px;
  padding: var(--space-sm) var(--space-md);
  border: 1px solid rgba(255, 240, 220, 0.15);
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 300;
  letter-spacing: 0.06em;
  white-space: nowrap;
  color: var(--text-dim);
  transition: border-color var(--ease-slow), color var(--ease-slow);
}

.btn-control:hover,
.btn-control:focus-visible {
  border-color: rgba(255, 240, 220, 0.35);
  color: var(--text);
  outline: none;
}

/* Làm mờ dần toàn màn hình sau 8 nhịp để dẫn vào giấc ngủ */
body.dimming {
  filter: brightness(0.4);
  transition: filter 60s ease-out;
}

/* Fade toàn màn hình khi phát hiện đã ngủ — 5 phút rồi navigate về landing */
body.sleeping {
  opacity: 0;
  transition: opacity 300s linear;
}

/* Debug overlay — chỉ hiện khi ?debug=1 */
#debug {
  position: fixed;
  top: var(--space-md);
  left: var(--space-md);
  z-index: 100;
  font-family: monospace;
  font-size: 0.7rem;
  line-height: 1.6;
  color: var(--text-dim);
  white-space: pre;
  pointer-events: none;
  background: rgba(13, 10, 20, 0.6);
  padding: var(--space-sm) var(--space-md);
  border-radius: 6px;
}

/* ===== Ca dao ===== */
.poetry-line {
  position: fixed;
  bottom: 14vh;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 90vw;
  display: flex;
  flex-direction: column;
  align-items: center;
  font-family: var(--font-poetry);
  font-style: italic;
  color: var(--text-dim);
  opacity: 0;
  transition: opacity 4s ease;
  pointer-events: none;
  z-index: 2;
}

.verse-row {
  display: block;
  width: 100%;
  text-align: center;
  font-size: min(3.8vw, 1.1rem);
  line-height: 1.7;
}

.verse-row:first-child {
  margin-bottom: 0.2rem;
}

/* Màn hình thấp: đẩy lên thêm để tránh controls */
@media (max-height: 700px) {
  .poetry-line {
    bottom: 10vh;
  }
}

.verse-source {
  display: block;
  margin-top: 0.4em;
  font-size: 0.7rem;
  font-style: normal;
  letter-spacing: 0.08em;
  opacity: 0.6;
}

/* ===== Modal âm thanh ===== */
.audio-modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: rgba(13, 10, 20, 0.7);
  padding-bottom: max(var(--space-lg), env(safe-area-inset-bottom));
}

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

.audio-modal__box {
  width: 100%;
  max-width: 320px;
  background: var(--bg-warm);
  border-radius: 16px 16px 0 0;
  padding: var(--space-lg);
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
}

.audio-modal__title {
  font-size: 0.85rem;
  font-weight: 300;
  letter-spacing: 0.15em;
  color: var(--text-dim);
  text-align: center;
}

.audio-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-md);
}

.audio-label {
  font-size: 0.8rem;
  font-weight: 300;
  color: var(--text-dim);
  letter-spacing: 0.05em;
}

.audio-divider {
  border: none;
  border-top: 1px solid rgba(255, 240, 220, 0.08);
}

.sample-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
}

.sample-item {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  cursor: pointer;
}

.sample-item input[type="radio"] {
  accent-color: var(--amber);
  width: 16px;
  height: 16px;
}

.sample-item label {
  font-size: 0.8rem;
  font-weight: 300;
  color: var(--text);
  letter-spacing: 0.05em;
  cursor: pointer;
}

/* Range slider chung */
input[type="range"] {
  flex: 1;
  accent-color: var(--amber);
  height: 2px;
}

/* Checkbox */
input[type="checkbox"] {
  accent-color: var(--amber);
  width: 18px;
  height: 18px;
}

/* ===== Install banner (index.html) ===== */
@keyframes slideUp {
  from { transform: translateY(100%); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}

.install-banner {
  position: fixed;
  bottom: 1rem;
  left: 1rem;
  right: 1rem;
  max-width: 400px;
  margin: 0 auto;
  background: var(--bg-warm);
  border: 1px solid rgba(168, 120, 80, 0.4);
  border-radius: 12px;
  padding: var(--space-md);
  z-index: 100;
  animation: slideUp 0.4s ease;
}

.install-text {
  font-size: 0.82rem;
  font-weight: 300;
  color: var(--text-dim);
  line-height: 1.5;
  margin-bottom: var(--space-sm);
}

.install-actions {
  display: flex;
  gap: var(--space-sm);
  justify-content: flex-end;
}

.install-actions button {
  padding: 0.4rem 1rem;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 300;
  letter-spacing: 0.08em;
  cursor: pointer;
  transition: background-color 0.3s ease, color 0.3s ease;
}

#install-yes {
  border: 1px solid var(--amber);
  color: var(--amber);
  background: transparent;
}

#install-yes:hover {
  background: rgba(168, 120, 80, 0.15);
}

#install-no {
  border: 1px solid rgba(255, 240, 220, 0.15);
  color: var(--text-dim);
  background: transparent;
}

/* ===== Chấm trung tâm vòng tròn thở ===== */
.breath-center {
  position: absolute;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--amber);
  opacity: 0.3;
  pointer-events: none;
}

/* ===== Hold phase: glow nhấp nháy nhẹ ===== */
@keyframes breath-hold-pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.55; }
}

.breath-hold {
  animation: breath-hold-pulse 2s ease-in-out infinite;
}

/* ===== Stop confirm dialog ===== */
.stop-confirm {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(13, 10, 20, 0.7);
}

.stop-confirm[hidden] { display: none; }

.stop-confirm__box {
  background: var(--bg-warm);
  border: 1px solid rgba(168, 120, 80, 0.25);
  border-radius: 14px;
  padding: var(--space-lg);
  text-align: center;
  max-width: 280px;
  width: 90vw;
}

.stop-confirm__msg {
  font-size: 0.9rem;
  font-weight: 300;
  color: var(--text);
  margin-bottom: var(--space-md);
  letter-spacing: 0.04em;
}

.stop-confirm__actions {
  display: flex;
  gap: var(--space-md);
  justify-content: center;
}

.stop-confirm__btn {
  min-width: 70px;
  min-height: 40px;
  padding: 0.4rem 1.2rem;
  border: 1px solid rgba(255, 240, 220, 0.2);
  border-radius: 999px;
  font-size: 0.82rem;
  font-weight: 300;
  color: var(--text-dim);
  cursor: pointer;
  transition: border-color 0.3s, color 0.3s;
}

.stop-confirm__btn--yes {
  border-color: rgba(168, 120, 80, 0.5);
  color: var(--amber);
}

.stop-confirm__btn--yes:hover { background: rgba(168, 120, 80, 0.12); }

/* ===== In-app browser banner ===== */
@keyframes slideDown {
  from { transform: translateY(-100%); opacity: 0; }
  to   { transform: translateY(0);     opacity: 1; }
}

.inapp-banner {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 1000;
  background: var(--bg-warm);
  border-bottom: 1px solid rgba(168, 120, 80, 0.4);
  padding-top: env(safe-area-inset-top);
  animation: slideDown 0.35s ease;
}

.inapp-banner[hidden] { display: none; }

.inapp-inner {
  max-width: 500px;
  margin: 0 auto;
  padding: 1rem;
}

.inapp-title {
  font-size: 0.9rem;
  font-weight: 400;
  color: var(--text);
  margin-bottom: 0.5rem;
  line-height: 1.5;
}

.inapp-steps {
  list-style: decimal;
  padding-left: 1.4em;
  margin-bottom: 0.6rem;
  font-size: 0.9rem;
  color: var(--text);
  line-height: 1.5;
}

.inapp-alt {
  font-size: 0.82rem;
  color: var(--text-dim);
  margin-bottom: 0.8rem;
  line-height: 1.5;
}

.inapp-actions {
  display: flex;
  gap: var(--space-sm);
}

.inapp-btn {
  padding: 0.4rem 1rem;
  border: 1px solid rgba(168, 120, 80, 0.5);
  border-radius: 999px;
  font-size: 0.82rem;
  font-weight: 300;
  color: var(--amber);
  cursor: pointer;
  transition: background-color 0.2s;
}

.inapp-btn:active { background: rgba(168, 120, 80, 0.15); }

.inapp-btn--dismiss {
  border-color: rgba(255, 240, 220, 0.15);
  color: var(--text-dim);
}

/* Toast nhỏ sau khi copy */
.inapp-toast {
  margin-top: 0.5rem;
  font-size: 0.78rem;
  color: var(--text-dim);
  line-height: 1.4;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.inapp-toast.visible { opacity: 1; }

/* ===== Onboard modal (lần đầu vào) ===== */
.onboard-overlay {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(13, 10, 20, 0.85);
  opacity: 0;
  transition: opacity 0.5s ease;
}

.onboard-box {
  background: var(--bg-warm);
  border: 1px solid rgba(168, 120, 80, 0.25);
  border-radius: 16px;
  padding: var(--space-xl) var(--space-lg);
  max-width: 300px;
  width: 88vw;
  text-align: center;
}

.onboard-title {
  font-size: 1rem;
  font-weight: 300;
  letter-spacing: 0.12em;
  color: var(--amber);
  margin-bottom: var(--space-md);
}

.onboard-list {
  list-style: none;
  padding: 0;
  margin-bottom: var(--space-lg);
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
}

.onboard-list li {
  font-size: 0.84rem;
  font-weight: 300;
  color: var(--text-dim);
  line-height: 1.5;
  padding-left: 1em;
  text-indent: -1em;
}

.onboard-list li::before { content: '• '; color: var(--amber); }

.onboard-btn { width: 100%; }

/* ===== iOS PWA hint ===== */
.ios-hint {
  position: fixed;
  bottom: max(5rem, calc(env(safe-area-inset-bottom) + 4rem));
  left: var(--space-md);
  right: var(--space-md);
  z-index: 30;
  background: rgba(26, 15, 10, 0.92);
  border: 1px solid rgba(168, 120, 80, 0.3);
  border-radius: 10px;
  padding: var(--space-sm) var(--space-md);
  font-size: 0.78rem;
  color: var(--text-dim);
  line-height: 1.5;
  opacity: 0;
  transition: opacity 0.5s ease;
  pointer-events: none;
}

/* ===== Text "Đến giờ dậy rồi" ===== */
.wakeup-text {
  position: fixed;
  inset: 0;
  z-index: 15;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-poetry);
  font-style: italic;
  font-size: 1.5rem;
  color: var(--amber);
  opacity: 0;
  transition: opacity 3s ease;
  pointer-events: none;
}

/* ===== Nút "Tôi đã dậy" ===== */
.wakeup-btn {
  position: fixed;
  bottom: max(3rem, env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  z-index: 20;
  min-width: 160px;
  opacity: 0;
  transition: opacity 1s ease;
}

/* ===== Text "Chúc ngủ ngon" ===== */
.goodnight-text {
  position: fixed;
  inset: 0;
  z-index: 15;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-poetry);
  font-style: italic;
  font-size: 1.3rem;
  color: var(--text-dim);
  opacity: 0;
  transition: opacity 3s ease;
  pointer-events: none;
}

/* ===== Sound indicator dot trên nút Âm thanh ===== */
.btn-control.has-audio::after {
  content: '';
  display: inline-block;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--amber);
  margin-left: 6px;
  vertical-align: middle;
  opacity: 0.8;
}
