/* Until — cinematic countdown PWA */
:root {
  --ink: #07080a;
  --ink-2: #101218;
  --mist: #e8e4dc;
  --mist-dim: rgba(232, 228, 220, 0.55);
  --mist-faint: rgba(232, 228, 220, 0.18);
  --gold: #d4a574;
  --gold-soft: rgba(212, 165, 116, 0.35);
  --danger: #c45c3a;
  --ok: #8fa896;
  --font-display: "Fraunces", Georgia, serif;
  --font-body: "Manrope", system-ui, sans-serif;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --radius: 18px;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --theme-a: #d4a574;
  --theme-b: #3d4a5c;
}

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

html,
body {
  margin: 0;
  height: 100%;
  height: 100dvh;
  background: var(--ink);
  color: var(--mist);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

body {
  overflow: hidden;
}

button,
input {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  border: none;
  background: none;
}

.hidden {
  display: none !important;
}

/* Living atmosphere */
.atmosphere {
  position: fixed;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  pointer-events: none;
  background: radial-gradient(120% 80% at 50% -10%, #1a1c22 0%, var(--ink) 55%);
  transition: background 1.2s var(--ease);
}

.orb {
  position: absolute;
  border-radius: 50%;
  filter: blur(80px);
  opacity: 0.45;
  animation: drift 18s var(--ease) infinite alternate;
  will-change: transform;
}

.orb-a {
  width: 55vw;
  height: 55vw;
  top: -10%;
  left: -15%;
  background: var(--theme-a);
  opacity: 0.28;
}

.orb-b {
  width: 45vw;
  height: 45vw;
  bottom: 5%;
  right: -10%;
  background: var(--theme-b);
  opacity: 0.35;
  animation-duration: 24s;
  animation-delay: -4s;
}

.orb-c {
  width: 30vw;
  height: 30vw;
  top: 40%;
  left: 40%;
  background: var(--gold);
  opacity: 0.12;
  animation-duration: 20s;
  animation-delay: -8s;
}

.grain {
  position: absolute;
  inset: 0;
  opacity: 0.07;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  mix-blend-mode: overlay;
}

@keyframes drift {
  from { transform: translate3d(0, 0, 0) scale(1); }
  to { transform: translate3d(4%, -6%, 0) scale(1.08); }
}

.app {
  position: relative;
  z-index: 1;
  height: 100%;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  padding-top: var(--safe-top);
  padding-bottom: var(--safe-bottom);
  overflow: hidden;
}

.view {
  flex: 1;
  min-height: 0;
  width: 100%;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 20px 22px 24px;
  animation: fadeRise 0.55s var(--ease) both;
}

.view-home {
  padding-bottom: calc(96px + var(--safe-bottom));
}

.view-detail {
  position: relative;
  padding-bottom: calc(24px + var(--safe-bottom));
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

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

/* Home */
.home-header {
  padding: 28px 4px 8px;
  text-align: center;
}

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

.brand-mark {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 1.5px solid var(--gold);
  border-right-color: transparent;
  position: relative;
  animation: spinSlow 12s linear infinite;
}

.brand-mark::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 50%;
  width: 2px;
  height: 6px;
  margin-left: -1px;
  background: var(--gold);
  border-radius: 1px;
}

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

.brand-name {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 500;
  font-size: clamp(2.6rem, 10vw, 3.4rem);
  letter-spacing: -0.03em;
  line-height: 1;
}

.brand-tagline {
  margin: 10px 0 0;
  color: var(--mist-dim);
  font-size: 0.95rem;
  font-weight: 500;
  letter-spacing: 0.02em;
}

.home-toolbar {
  display: flex;
  justify-content: center;
  margin: 28px 0 18px;
}

.sort-pills {
  display: inline-flex;
  gap: 4px;
  padding: 4px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--mist-faint);
}

.pill {
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--mist-dim);
  transition: background 0.25s var(--ease), color 0.25s;
}

.pill.is-active {
  background: rgba(212, 165, 116, 0.18);
  color: var(--gold);
}

.timer-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-width: 520px;
  margin: 0 auto;
}

.timer-card {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px 20px;
  align-items: center;
  padding: 18px 18px 16px;
  border-radius: var(--radius);
  background: linear-gradient(145deg, rgba(255, 255, 255, 0.06), rgba(255, 255, 255, 0.02));
  border: 1px solid var(--mist-faint);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  text-align: left;
  width: 100%;
  overflow: hidden;
  transition: transform 0.3s var(--ease), border-color 0.3s;
  animation: fadeRise 0.5s var(--ease) both;
}

.timer-card::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 3px;
  background: var(--card-accent, var(--gold));
}

.timer-card:active {
  transform: scale(0.985);
}

.timer-card.is-done {
  opacity: 0.72;
}

.timer-card .card-info {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
  padding-right: 4px;
}

.timer-card .card-title {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.35rem;
  font-weight: 500;
  letter-spacing: -0.02em;
  line-height: 1.15;
}

.timer-card .card-meta {
  margin: 0;
  font-size: 0.78rem;
  color: var(--mist-dim);
  line-height: 1.35;
}

.timer-card .card-count {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  text-align: right;
  font-family: var(--font-display);
  font-variant-numeric: tabular-nums;
  flex-shrink: 0;
}

.timer-card .card-count-main {
  display: flex;
  align-items: baseline;
  gap: 6px;
}

.timer-card .card-count .big {
  font-size: clamp(2rem, 7vw, 2.6rem);
  font-weight: 500;
  letter-spacing: -0.04em;
  line-height: 1;
  color: var(--card-accent, var(--gold));
}

.timer-card .card-count .count-unit {
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--mist-dim);
}

.timer-card .card-count .sub {
  margin-top: 6px;
  font-size: 0.82rem;
  color: var(--mist);
  font-family: var(--font-display);
  font-weight: 500;
  letter-spacing: -0.01em;
  white-space: nowrap;
}

.pin-dot {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--gold);
  box-shadow: 0 0 8px var(--gold-soft);
}

.empty-state {
  text-align: center;
  padding: 48px 24px;
  max-width: 320px;
  margin: 40px auto 0;
}

.empty-ring {
  width: 72px;
  height: 72px;
  margin: 0 auto 24px;
  border-radius: 50%;
  border: 1.5px solid var(--gold);
  border-bottom-color: transparent;
  animation: spinSlow 8s linear infinite;
}

.empty-state h2 {
  margin: 0 0 10px;
  font-family: var(--font-display);
  font-weight: 500;
  font-size: 1.6rem;
}

.empty-state p {
  margin: 0;
  color: var(--mist-dim);
  line-height: 1.5;
  font-size: 0.95rem;
}

.fab {
  position: fixed;
  right: max(22px, env(safe-area-inset-right, 0px));
  bottom: max(12px, env(safe-area-inset-bottom, 0px));
  z-index: 30;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: linear-gradient(145deg, #e0b888, var(--gold));
  color: var(--ink);
  box-shadow: 0 12px 32px rgba(212, 165, 116, 0.35);
  display: grid;
  place-items: center;
  transition: transform 0.25s var(--ease);
}

#view-home.hidden ~ .fab,
#view-home[hidden] ~ .fab {
  display: none;
}

.fab:active {
  transform: scale(0.94);
}

.fab-plus {
  width: 18px;
  height: 18px;
  position: relative;
}

.fab-plus::before,
.fab-plus::after {
  content: "";
  position: absolute;
  background: currentColor;
  border-radius: 2px;
}

.fab-plus::before {
  width: 18px;
  height: 2.5px;
  top: 8px;
  left: 0;
}

.fab-plus::after {
  width: 2.5px;
  height: 18px;
  left: 8px;
  top: 0;
}

/* Detail */
.detail-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.detail-actions {
  display: flex;
  gap: 4px;
}

.icon-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: var(--mist);
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--mist-faint);
  transition: background 0.2s;
}

.icon-btn:active {
  background: rgba(255, 255, 255, 0.1);
}

.icon-btn.danger {
  color: var(--danger);
}

.icon-btn.is-on {
  color: var(--gold);
  border-color: var(--gold-soft);
  background: rgba(212, 165, 116, 0.12);
}

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

body.is-capturing .detail-top,
body.is-capturing .detail-mode-bar,
body.is-capturing #toast,
body.is-capturing #sheet-backdrop,
body.is-capturing #editor-sheet {
  visibility: hidden !important;
}

.detail-stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding-top: 8px;
  min-height: 0;
}

.detail-eyebrow {
  margin: 0;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--gold);
}

.detail-title {
  margin: 10px 0 6px;
  font-family: var(--font-display);
  font-weight: 500;
  font-size: clamp(2rem, 8vw, 2.8rem);
  letter-spacing: -0.03em;
  line-height: 1.1;
  max-width: 16ch;
}

.detail-when {
  margin: 0;
  color: var(--mist-dim);
  font-size: 0.9rem;
}

.detail-started {
  margin: 4px 0 0;
  color: var(--mist-dim);
  font-size: 0.78rem;
  opacity: 0.85;
}

.detail-mode-bar {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin: 14px 0 4px;
  max-width: min(100%, 320px);
}

.mode-toggle {
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--gold);
  background: rgba(212, 165, 116, 0.1);
  border: 1px solid var(--gold-soft);
  transition: background 0.2s var(--ease);
}

.mode-toggle:active {
  background: rgba(212, 165, 116, 0.18);
}

.ring-wrap {
  position: relative;
  width: min(280px, 72vw, 52dvh);
  aspect-ratio: 1;
  margin: 12px auto 20px;
  flex-shrink: 0;
}

.progress-ring {
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);
}

.ring-track {
  fill: none;
  stroke: rgba(255, 255, 255, 0.06);
  stroke-width: 3.5;
}

.ring-progress {
  fill: none;
  stroke: var(--theme-a, var(--gold));
  stroke-width: 3.5;
  stroke-linecap: round;
  stroke-dasharray: 653.45;
  stroke-dashoffset: 653.45;
  transition: stroke-dashoffset 0.8s var(--ease), stroke 0.6s;
  filter: drop-shadow(0 0 8px var(--gold-soft));
}

.ring-center {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 28px;
}

.units {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px 18px;
  width: 100%;
}

.units-compact {
  grid-template-columns: repeat(3, 1fr);
  gap: 10px 8px;
}

.units-stacked {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  width: 100%;
}

.units-stacked .stack-big {
  font-family: var(--font-display);
  font-size: clamp(3rem, 12vw, 4rem);
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.04em;
  line-height: 1;
  color: var(--theme-a, var(--gold));
}

.units-stacked .stack-label {
  margin-top: 6px;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--mist-dim);
}

.units-stacked .stack-sub {
  margin-top: 10px;
  font-family: var(--font-display);
  font-size: clamp(1.1rem, 4.5vw, 1.35rem);
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
  color: var(--mist);
}

.unit {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.unit .num {
  font-family: var(--font-display);
  font-size: clamp(1.7rem, 6.5vw, 2.15rem);
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
  line-height: 1;
  transition: transform 0.2s var(--ease);
}

.unit .num.tick {
  animation: tickPulse 0.35s var(--ease);
}

@keyframes tickPulse {
  0% { transform: scale(1); }
  40% { transform: scale(1.06); }
  100% { transform: scale(1); }
}

.unit .label {
  margin-top: 4px;
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--mist-dim);
}

.pct {
  margin: 14px 0 0;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--mist-dim);
  letter-spacing: 0.04em;
}

.detail-note {
  margin: 0;
  max-width: 28ch;
  color: var(--mist-dim);
  font-size: 0.95rem;
  line-height: 1.45;
  min-height: 1.4em;
}

.milestone {
  margin: 16px 0 0;
  min-height: 1.4em;
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--gold);
  opacity: 0;
  transform: translateY(6px);
  transition: opacity 0.5s var(--ease), transform 0.5s var(--ease);
}

.milestone.is-on {
  opacity: 1;
  transform: translateY(0);
}

.celebrate {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 40px;
  background: rgba(7, 8, 10, 0.72);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  animation: fadeRise 0.6s var(--ease);
}

.celebrate h2 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 3rem;
  font-weight: 500;
}

.celebrate p {
  margin: 10px 0 0;
  color: var(--mist-dim);
}

.celebrate-burst {
  width: 100px;
  height: 100px;
  margin-bottom: 20px;
  border-radius: 50%;
  border: 2px solid var(--gold);
  animation: burst 1.4s var(--ease) infinite;
}

@keyframes burst {
  0% { transform: scale(0.6); opacity: 1; }
  100% { transform: scale(1.4); opacity: 0; }
}

/* Sheet */
.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  animation: fadeIn 0.25s ease;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 50;
  max-height: min(92dvh, 720px);
  overflow: auto;
  padding: 12px 22px calc(28px + var(--safe-bottom));
  border-radius: 28px 28px 0 0;
  background: linear-gradient(180deg, #15171c 0%, #0c0d10 100%);
  border: 1px solid var(--mist-faint);
  border-bottom: none;
  animation: sheetUp 0.4s var(--ease);
}

@keyframes sheetUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

.sheet-handle {
  width: 40px;
  height: 4px;
  margin: 4px auto 18px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.18);
}

.sheet h2 {
  margin: 0 0 20px;
  font-family: var(--font-display);
  font-weight: 500;
  font-size: 1.7rem;
  text-align: center;
}

.timer-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
  max-width: 480px;
  margin: 0 auto;
}

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

.field > span {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--mist-dim);
}

.field em {
  font-style: normal;
  font-weight: 500;
  opacity: 0.7;
  text-transform: none;
  letter-spacing: 0;
}

.field-section {
  margin: 4px 0 -4px;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--mist-dim);
}

.field-section em {
  font-style: normal;
  font-weight: 500;
  opacity: 0.7;
  text-transform: none;
  letter-spacing: 0;
}

.field input {
  width: 100%;
  padding: 14px 16px;
  border-radius: 14px;
  border: 1px solid var(--mist-faint);
  background: rgba(255, 255, 255, 0.04);
  outline: none;
  color-scheme: dark;
  transition: border-color 0.2s;
}

.field input:focus {
  border-color: var(--gold-soft);
}

.field-row {
  display: grid;
  grid-template-columns: 1.2fr 1fr;
  gap: 12px;
}

.theme-field {
  margin: 0;
  padding: 0;
  border: none;
}

.theme-field legend {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--mist-dim);
  margin-bottom: 10px;
}

.theme-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 10px;
}

.theme-swatch {
  aspect-ratio: 1;
  border-radius: 14px;
  border: 2px solid transparent;
  position: relative;
  overflow: hidden;
  padding: 0;
}

.theme-swatch span {
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, var(--a), var(--b));
}

.theme-swatch.is-selected {
  border-color: var(--mist);
  box-shadow: 0 0 0 2px rgba(232, 228, 220, 0.15);
}

.sheet-actions {
  display: grid;
  grid-template-columns: 1fr 1.4fr;
  gap: 10px;
  margin-top: 8px;
}

.btn {
  padding: 15px 18px;
  border-radius: 14px;
  font-weight: 700;
  font-size: 0.95rem;
  letter-spacing: 0.02em;
}

.btn.ghost {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--mist-faint);
}

.btn.primary {
  background: linear-gradient(145deg, #e0b888, var(--gold));
  color: var(--ink);
}

.btn.danger {
  width: 100%;
  margin-top: 16px;
  background: rgba(196, 92, 74, 0.12);
  border: 1px solid rgba(196, 92, 74, 0.35);
  color: #e8a090;
}

.sheet-delete.hidden {
  display: none;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(28px + var(--safe-bottom));
  transform: translateX(-50%);
  z-index: 60;
  padding: 12px 18px;
  border-radius: 999px;
  background: rgba(20, 22, 28, 0.92);
  border: 1px solid var(--mist-faint);
  font-size: 0.85rem;
  font-weight: 600;
  white-space: nowrap;
  animation: fadeRise 0.35s var(--ease);
}

/* Desktop polish */
@media (min-width: 720px) {
  .view-home,
  .view-detail {
    max-width: 560px;
    margin-left: auto;
    margin-right: auto;
  }

  .fab {
    right: calc(50% - 280px + 22px);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
