/* Theme colours are set from JS (applyTheme); the rest derive from them. */
:root {
  --c1: #9333ea;
  --c2: #4f46e5;
  --accent: #7e22ce;
  --bg: #f6f3fb;
  --grad: linear-gradient(110deg, var(--c1), var(--c2));
  --tint: color-mix(in srgb, var(--c1) 10%, #fff);
  --border: color-mix(in srgb, var(--c1) 20%, #fff);
  --card: #ffffff;
  --text: #22201f;
  --muted: #6e6a66;
}

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

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none;
  user-select: none;
  -webkit-user-select: none;
}
body { display: flex; flex-direction: column; }
button { font: inherit; cursor: pointer; }
[hidden] { display: none !important; }

/* Header */
.header {
  position: relative;
  background: var(--grad);
  color: #fff;
  text-align: center;
  padding: calc(env(safe-area-inset-top) + 16px) 16px 14px;
  border-radius: 0 0 26px 26px;
  box-shadow: 0 6px 18px color-mix(in srgb, var(--c2) 28%, transparent);
}
.brand { display: flex; align-items: center; justify-content: center; gap: 10px; }
.logo {
  width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center;
  background: rgba(255,255,255,.2); box-shadow: 0 0 0 1.5px rgba(255,255,255,.35);
}
.logo svg, .rel-card svg {
  width: 24px; height: 24px; fill: none; stroke: currentColor;
  stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round;
}
.header h1 { margin: 0; font-size: 23px; font-weight: 700; letter-spacing: .3px; }
.timer { margin-top: 4px; font-size: 16px; letter-spacing: 2px; font-variant-numeric: tabular-nums; opacity: .9; }
.top-btns {
  position: absolute; inset-inline-end: 12px; top: calc(env(safe-area-inset-top) + 12px);
  display: flex; flex-direction: column; gap: 6px;
  z-index: 1; /* above .timer, whose opacity puts it on its own layer */
}
.round-btn {
  width: 32px; height: 32px; border-radius: 50%; border: 0;
  background: rgba(255,255,255,.22); color: #fff; font-size: 17px; font-weight: 700; line-height: 1;
}

/* Tabs */
.tabs {
  display: flex; gap: 4px; margin: 12px auto 0; max-width: 360px;
  background: rgba(255,255,255,.18); border-radius: 12px; padding: 4px;
}
.tab { flex: 1; border: 0; background: transparent; color: #fff; font-size: 15px; font-weight: 600; padding: 8px 0; border-radius: 9px; }
.tab.active { background: #fff; color: var(--accent); }

/* Page container */
.main {
  flex: 1; display: flex; flex-direction: column; gap: 18px;
  padding: 18px 16px calc(env(safe-area-inset-bottom) + 12px);
  max-width: 520px; width: 100%; margin: 0 auto;
}

/* Counter */
.stats { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 10px; }
.stat {
  background: var(--card); border: 1.5px solid var(--border); border-radius: 16px;
  padding: 12px 6px; text-align: center; display: flex; flex-direction: column; gap: 4px; min-width: 0;
}
.label { color: var(--accent); font-size: 13px; font-weight: 600; letter-spacing: 1px; }
/* .fit: JS shrinks the font until the number fits on one line */
.fit { white-space: nowrap; overflow: hidden; }
.value { font-size: 24px; font-weight: 600; font-variant-numeric: tabular-nums; }

.ring { position: relative; width: 108px; height: 108px; }
.ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring circle { fill: none; stroke-width: 7; }
.ring .track { stroke: var(--tint); }
.ring .progress {
  stroke: var(--c1); stroke-linecap: round;
  stroke-dasharray: 339.29; stroke-dashoffset: 339.29;
  transition: stroke-dashoffset .25s ease;
}
.count {
  position: absolute; inset: 0; display: grid; place-items: center;
  font-size: 36px; font-weight: 700; color: var(--accent); font-variant-numeric: tabular-nums;
}
.ring.bump .count { animation: bump .18s ease; }
.ring.complete { animation: glow 1s ease; border-radius: 50%; }
@keyframes bump { 50% { transform: scale(1.12); } }
@keyframes glow {
  0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--c1) 60%, transparent); }
  100% { box-shadow: 0 0 0 28px transparent; }
}

.naam {
  align-self: center; min-width: 140px; max-width: 80%; text-align: center;
  font: inherit; font-size: 18px; font-weight: 600; font-style: italic; color: var(--text);
  background: transparent; border: 0; border-bottom: 1.5px dashed var(--border);
  padding: 4px 8px; outline: none; user-select: text; -webkit-user-select: text;
}
.naam:focus { border-bottom-color: var(--c1); }

.tap-btn {
  flex: 1; min-height: 170px; border: 0; border-radius: 24px;
  background: var(--grad); color: #fff;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px;
  box-shadow: 0 10px 24px color-mix(in srgb, var(--c2) 30%, transparent);
  touch-action: manipulation; transition: transform .08s ease, filter .08s ease;
}
.tap-btn:active { transform: scale(.97); filter: brightness(1.06); }
.tap-icon { font-size: 44px; line-height: 1; }
.tap-text { font-size: 22px; font-weight: 700; letter-spacing: 2px; }
/* Letter-spacing breaks joined letters of Indic/Arabic scripts: keep it for English/Hinglish only */
html:not([lang^="en"]) .tap-text, html:not([lang^="en"]) .label { letter-spacing: 0; }

.actions { display: flex; justify-content: space-between; align-items: center; padding: 0 6px; }
.link-btn { border: 0; background: transparent; color: var(--muted); font-size: 15px; padding: 6px 10px; border-radius: 8px; }
.link-btn:active { background: var(--tint); }
.pill-btn {
  border: 1.5px solid var(--border); background: var(--card); color: var(--accent);
  font-size: 14px; padding: 6px 14px; border-radius: 999px;
}

/* Calendar + report */
.month-nav { display: flex; align-items: center; justify-content: space-between; }
.month-title { font-size: 19px; font-weight: 700; }
.nav-btn {
  width: 44px; height: 44px; border: 1.5px solid var(--border); border-radius: 12px;
  background: var(--card); color: var(--accent); font-size: 26px; line-height: 1;
}
[dir="rtl"] .nav-btn { transform: scaleX(-1); }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal-wd { min-width: 0; text-align: center; font-size: 12px; font-weight: 600; color: var(--muted); padding: 4px 0; }
.cal-day {
  background: var(--card); border: 1.5px solid var(--border); border-radius: 10px;
  min-height: 54px; padding: 4px 2px; text-align: center;
  display: flex; flex-direction: column; gap: 2px; min-width: 0;
}
.cal-day .d { font-size: 12px; color: var(--muted); }
.cal-day .c { font-size: 12px; font-weight: 700; color: var(--accent); }
.cal-day.has { background: var(--tint); }
.cal-day.today { border-color: var(--c1); box-shadow: 0 0 0 1.5px var(--c1) inset; }
.month-sum, .report { background: var(--card); border: 1.5px solid var(--border); border-radius: 16px; padding: 12px 14px; }
.month-sum { text-align: center; font-size: 16px; }
.month-sum b { color: var(--accent); }
.report { padding: 4px 14px; }
.report-row {
  display: grid; grid-template-columns: 1.3fr 1fr .8fr; gap: 8px;
  padding: 10px 0; border-bottom: 1px solid var(--tint); font-size: 15px; font-variant-numeric: tabular-nums;
}
.report-row span:not(:first-child) { text-align: end; overflow-wrap: anywhere; }
.report-row.head { font-size: 13px; font-weight: 600; color: var(--accent); }
.report-row.foot { border-bottom: 0; font-weight: 700; color: var(--accent); }
.lifetime { padding-bottom: 6px; }
.life-row {
  display: flex; justify-content: space-between; gap: 12px;
  padding: 8px 0; border-bottom: 1px solid var(--tint); font-size: 15px;
}
.life-row:last-child { border-bottom: 0; }
.life-row b { color: var(--accent); font-variant-numeric: tabular-nums; white-space: nowrap; }
.report-empty { padding: 18px 0; text-align: center; color: var(--muted); }

/* Settings / setup */
.settings { gap: 10px; overflow-y: auto; }
.settings h3 { margin: 10px 0 0; font-size: 14px; color: var(--accent); letter-spacing: .5px; }
.intro { text-align: center; }
.intro h2 { margin: 4px 0; font-size: 22px; color: var(--accent); }
.intro p { margin: 0; color: var(--muted); font-size: 15px; line-height: 1.4; }
.rel-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; }
.rel-card {
  border: 1.5px solid var(--border); background: var(--card); color: var(--text); border-radius: 14px;
  padding: 10px 4px; display: flex; flex-direction: column; align-items: center; gap: 6px; font-size: 13px;
}
.rel-card svg { width: 28px; height: 28px; color: var(--accent); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.chip {
  border: 1.5px solid var(--border); background: var(--card); color: var(--text);
  padding: 8px 14px; border-radius: 999px; font-size: 15px;
}
.rel-card.on, .chip.on { border-color: var(--c1); background: var(--tint); color: var(--accent); font-weight: 700; }
.swatch { width: 44px; height: 44px; padding: 0; border-radius: 50%; border: 3px solid #fff; box-shadow: 0 0 0 1.5px var(--border); }
.swatch.on { box-shadow: 0 0 0 3px var(--c1); }
.size-input {
  width: 90px; padding: 8px 12px; border-radius: 999px; border: 1.5px solid var(--border);
  font: inherit; font-size: 15px; background: var(--card); color: var(--text);
}
.toggles { display: flex; flex-direction: column; margin-top: 10px; background: var(--card); border: 1.5px solid var(--border); border-radius: 16px; }
.trow { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 14px; border-bottom: 1px solid var(--tint); font-size: 15px; }
.trow:last-child { border-bottom: 0; }
.switch { width: 46px; height: 28px; border-radius: 14px; border: 0; background: #d6d3d1; position: relative; flex: none; transition: background .2s; }
.switch::after { content: ''; position: absolute; top: 3px; inset-inline-start: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; transition: inset-inline-start .2s; }
.switch[aria-pressed="true"] { background: var(--c1); }
.switch[aria-pressed="true"]::after { inset-inline-start: 21px; }
/* First-launch setup reuses the settings view */
body.setup .header .tabs, body.setup .top-btns, body.setup .timer, body.setup .settings-only { display: none; }
body:not(.setup) .setup-only { display: none; }

/* Toast */
.toast {
  position: fixed; left: 50%; top: 30%; transform: translate(-50%, -10px);
  background: rgba(30, 28, 26, .9); color: #fff; padding: 12px 20px; border-radius: 14px;
  font-size: 17px; font-weight: 600; opacity: 0; pointer-events: none;
  transition: opacity .25s, transform .25s; white-space: nowrap; z-index: 30;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* Bottom sheets */
.modal { position: fixed; inset: 0; background: rgba(20, 16, 12, .45); display: flex; align-items: flex-end; justify-content: center; z-index: 10; }
.sheet {
  background: #fff; width: 100%; max-width: 520px; border-radius: 22px 22px 0 0;
  padding: 20px 16px calc(env(safe-area-inset-bottom) + 16px); display: flex; flex-direction: column; gap: 10px;
}
.sheet h2 { margin: 0 0 6px; font-size: 19px; text-align: center; }
.sheet-btn { border: 1.5px solid var(--border); background: var(--tint); color: var(--text); font-size: 16px; padding: 14px; border-radius: 14px; }
.sheet-btn.danger { color: #b42318; border-color: #f3c7c3; background: #fff5f4; }
.sheet-btn.primary { background: var(--grad); color: #fff; border: 0; font-weight: 700; }
.sheet-btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.sheet.help { max-height: 85vh; overflow-y: auto; }
.sheet.help ul { margin: 0 0 6px; padding-inline-start: 20px; display: flex; flex-direction: column; gap: 9px; font-size: 15px; line-height: 1.45; }

/* Dhyan Mode */
.dhyan {
  position: fixed; inset: 0; z-index: 40; background: #000;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 24px;
  touch-action: none;
}
.dhyan-count { font-size: 64px; font-weight: 700; color: #2a2a2a; font-variant-numeric: tabular-nums; }
.dhyan-hint { color: #3a3a3a; font-size: 14px; text-align: center; padding: 0 24px; transition: opacity 1s; }
.dhyan.quiet .dhyan-hint { opacity: 0; }

@media (max-width: 360px) {
  .ring { width: 96px; height: 96px; }
  .count { font-size: 32px; }
}
