:root {
  --bg: #060606;
  --bg-soft: #121110;
  --panel: #0d0d0c;
  --panel-2: #181715;
  --line: #2a2724;
  --line-soft: #1c1a18;
  --text: #f6f4f1;
  --muted: #9b938a;
  --muted-2: #6a635b;
  --accent: #ff5a2e;
  --accent-soft: rgba(255, 90, 46, 0.14);
  --accent-line: rgba(255, 90, 46, 0.45);
  --star-off: #4f4c48;
  --star-off-hover: #6b6660;
  --danger: #ff4d57;
  --radius: 16px;
  --shadow: 0 18px 60px rgba(0, 0, 0, 0.6);
}

* { box-sizing: border-box; }

/* Author rules with `display` would otherwise override the [hidden] attribute */
[hidden] { display: none !important; }

html, body { margin: 0; height: 100%; }

body {
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

button { font-family: inherit; cursor: pointer; }

/* ---------- Starfield ---------- */
.starfield { position: fixed; inset: 0; z-index: 0; pointer-events: none; overflow: hidden; }
.starfield i { position: absolute; border-radius: 50%; background: #fff; animation: twinkle 4s ease-in-out infinite; }
@keyframes twinkle {
  0%, 100% { opacity: var(--o, 0.5); }
  50% { opacity: calc(var(--o, 0.5) * 0.25); }
}

/* Occasional shooting star */
.shoot {
  position: absolute;
  width: 3px;
  height: 3px;
  border-radius: 50%;
  background: #fff;
  opacity: 0;
  filter: drop-shadow(0 0 6px rgba(255, 255, 255, 0.9));
  animation: shoot var(--dur, 9s) cubic-bezier(0.4, 0, 0.5, 1) infinite;
  animation-delay: var(--delay, 0s);
}
.shoot::before {
  content: "";
  position: absolute;
  left: 2px;
  top: 50%;
  width: var(--len, 120px);
  height: 1.5px;
  background: linear-gradient(90deg, rgba(255, 255, 255, 0.85), rgba(255, 255, 255, 0));
  transform-origin: left center;
  transform: translateY(-50%) rotate(var(--tail, 200deg));
}
@keyframes shoot {
  0% { opacity: 0; transform: translate(0, 0); }
  4% { opacity: 1; }
  16% { opacity: 1; }
  22% { opacity: 0; transform: translate(var(--dx, -360px), var(--dy, 210px)); }
  100% { opacity: 0; transform: translate(var(--dx, -360px), var(--dy, 210px)); }
}
@media (prefers-reduced-motion: reduce) { .shoot { display: none; } }

#app {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  height: 100dvh;
}

/* ---------- Top bar: title centered, ring + settings aligned on the same row ---------- */
.topbar {
  display: grid;
  grid-template-columns: 1fr minmax(0, auto) 1fr;
  align-items: center;
  gap: clamp(6px, 1.5vw, 14px);
  padding: 14px clamp(14px, 3.5vw, 34px);
  padding-top: max(14px, env(safe-area-inset-top));
}
.top-spacer { min-width: 0; }
.topbar-actions { display: flex; align-items: center; justify-content: flex-end; gap: 10px; }

.habit-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: clamp(8px, 2vw, 18px);
  min-width: 0;
}
.habit-name {
  margin: 0;
  flex: 0 1 auto;
  min-width: 0;
  text-align: center;
  border: none;
  background: none;
  color: var(--text);
  font-size: clamp(30px, 6.5vw, 58px);
  font-weight: 800;
  line-height: 1.03;
  letter-spacing: -0.02em;
  padding: 4px 10px;
  border-radius: 12px;
  cursor: pointer;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  transition: color 0.15s;
}
.habit-name:hover { color: var(--accent); }

/* ---------- Stats row ---------- */
.stats-row {
  display: flex;
  align-items: flex-start;
  justify-content: center;
  gap: clamp(20px, 5vw, 52px);
  padding: 2px 16px 14px;
  flex-wrap: wrap;
}
.stat { display: flex; flex-direction: column; align-items: center; gap: 3px; }
.stat-value {
  font-size: clamp(18px, 2.3vw, 23px);
  font-weight: 800;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  color: var(--text);
  transition: color 0.2s;
}
.stat.hot .stat-value { color: var(--accent); }
.stat-label {
  font-size: 10px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 600;
}

/* ---------- Buttons ---------- */
.nav-arrow, .icon-btn {
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.015);
  color: var(--text);
  transition: transform 0.12s, background 0.15s, border-color 0.15s, color 0.15s;
}
.nav-arrow:hover, .icon-btn:hover {
  background: var(--accent-soft);
  border-color: var(--accent-line);
  color: var(--accent);
  transform: translateY(-1px);
}
.nav-arrow:active, .icon-btn:active { transform: translateY(0) scale(0.95); }
.nav-arrow svg, .icon-btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn svg path[d^="M12 15"], .icon-btn svg path[d^="M19.4"] { stroke-width: 1.7; }
.nav-arrow:disabled { opacity: 0.25; pointer-events: none; }

/* ---------- Progress ring (orange / white only) ---------- */
.ring-wrap { position: relative; width: 50px; height: 50px; border: none; background: none; padding: 0; flex: none; }
.ring { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring-track { fill: none; stroke: rgba(255, 255, 255, 0.1); stroke-width: 9; }
.ring-progress {
  fill: none;
  stroke: var(--accent);
  stroke-width: 9;
  stroke-linecap: round;
  stroke-dasharray: 326.7;
  stroke-dashoffset: 326.7;
  transition: stroke-dashoffset 0.7s cubic-bezier(0.22, 1, 0.36, 1);
}
.ring-label {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--text);
  letter-spacing: -0.02em;
}

/* All habits done today: ring just reads orange (the celebration plays out in
   the calendar, not on the ring) */
.ring-wrap.complete .ring-progress { filter: drop-shadow(0 0 4px rgba(255, 90, 46, 0.7)); }
.ring-wrap.complete .ring-label { color: var(--accent); }
.ring-wrap.pop { animation: ringPop 0.5s cubic-bezier(0.34, 1.56, 0.64, 1); }
@keyframes ringPop {
  0% { transform: scale(1); }
  45% { transform: scale(1.18); }
  100% { transform: scale(1); }
}

/* ---------- Calendar ---------- */
.calendar-area {
  flex: 1;
  min-height: 0;
  position: relative;
  overflow: auto;
  padding: clamp(6px, 1.5vh, 16px) clamp(12px, 3vw, 30px) max(18px, env(safe-area-inset-bottom));
  scrollbar-width: thin;
  scrollbar-color: var(--line) transparent;
}
.calendar-area::-webkit-scrollbar { width: 9px; height: 9px; }
.calendar-area::-webkit-scrollbar-thumb { background: var(--line); border-radius: 9px; }
.calendar-area::-webkit-scrollbar-track { background: transparent; }

/* grid-template-columns is set inline by app.js (varies by view/orientation) */
.calendar {
  display: grid;
  gap: clamp(3px, 0.5vw, 6px);
  margin: 0 auto;
  width: max-content;
  max-width: 100%;
}

/* Month navigator (monthly view) */
.month-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 0 16px 12px;
}
.month-nav #monthLabel {
  font-weight: 700;
  font-size: 16px;
  min-width: 150px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.cal-corner { position: sticky; top: 0; left: 0; z-index: 3; background: var(--bg); }

.col-head {
  position: sticky;
  top: 0;
  z-index: 2;
  text-align: center;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--muted);
  padding: 2px 0 8px;
  background: linear-gradient(180deg, var(--bg) 64%, transparent);
}
.row-head {
  position: sticky;
  left: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding-right: 6px;
  font-size: 10px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  color: var(--muted-2);
  background: var(--bg);
}

/* Star buttons */
.star {
  aspect-ratio: 1 / 1;
  border: none;
  background: none;
  padding: 0;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
  scroll-margin: 60px 44px;
}
.star::before {
  content: "";
  width: 100%;
  height: 100%;
  background: var(--star-off);
  clip-path: polygon(50% 2%, 61% 35%, 98% 35%, 68% 57%, 79% 91%, 50% 70%, 21% 91%, 32% 57%, 2% 35%, 39% 35%);
  transition: background 0.2s, transform 0.15s, filter 0.2s;
}
.star:hover::before { transform: scale(1.12); background: var(--star-off-hover); }
.star.empty { visibility: hidden; pointer-events: none; }

.star.done::before {
  background: var(--accent);
  filter: drop-shadow(0 0 4px rgba(255, 90, 46, 0.55));
}

/* Today: highlighted white until it's completed (then it turns orange like the rest) */
.star.today:not(.done)::before {
  background: #fff;
  filter: drop-shadow(0 0 4px rgba(255, 255, 255, 0.45));
}

/* Light show — temporarily repaints the EXISTING calendar stars (no new stars).
   While a show runs, every star dims to gray; the animation lights a subset. */
.calendar.showing .star::before {
  background: var(--star-off);
  filter: none;
  transition: none;
}
.calendar.showing .star.show-on::before {
  background: var(--accent);
  filter: drop-shadow(0 0 4px rgba(255, 90, 46, 0.6));
}
.calendar.showing .star.show-hi::before {
  background: #fff;
  filter: drop-shadow(0 0 5px rgba(255, 255, 255, 0.75));
}

/* Locked (past day, editing disabled) — quick shake to signal it's locked */
.star.locked::before { animation: lockShake 0.3s ease; }
@keyframes lockShake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-2px); }
  75% { transform: translateX(2px); }
}

/* Star tap animation */
.star.pop::before { animation: starPop 0.45s cubic-bezier(0.34, 1.56, 0.64, 1); }
@keyframes starPop {
  0% { transform: scale(1); }
  30% { transform: scale(0.8); }
  60% { transform: scale(1.35); }
  100% { transform: scale(1); }
}

/* Burst particles on completion */
.burst { position: absolute; width: 5px; height: 5px; border-radius: 50%; background: var(--accent); pointer-events: none; opacity: 0; }

/* ---------- Empty state ---------- */
.empty-state {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 8px;
  padding: 24px;
}
.empty-star { font-size: 56px; filter: drop-shadow(0 6px 18px rgba(255, 90, 46, 0.4)); }
.empty-state h2 { margin: 6px 0 0; font-size: 24px; }
.empty-state p { margin: 0 0 14px; color: var(--muted); }

.primary-btn {
  border: none;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  font-size: 15px;
  padding: 12px 22px;
  border-radius: 12px;
  transition: transform 0.12s, box-shadow 0.15s, filter 0.15s;
  box-shadow: 0 8px 24px rgba(255, 90, 46, 0.3);
}
.primary-btn:hover { transform: translateY(-1px); filter: brightness(1.08); }
.primary-btn:active { transform: translateY(0) scale(0.97); }

/* ---------- First-visit legend ---------- */
.intro {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(0, 0, 0, 0.62);
  backdrop-filter: blur(4px);
  animation: fade 0.25s ease;
}
.intro-card {
  max-width: 400px;
  width: 100%;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 24px;
  box-shadow: var(--shadow);
  animation: slideUp 0.3s cubic-bezier(0.22, 1, 0.36, 1);
}
.intro-card h3 { margin: 0 0 10px; font-size: 22px; font-weight: 800; }
.intro-card p { margin: 0 0 12px; color: var(--muted); line-height: 1.55; font-size: 14.5px; }
.intro-card b { color: var(--text); font-weight: 700; }
.intro-card .primary-btn { width: 100%; margin-top: 4px; }
@keyframes slideUp { from { transform: translateY(16px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

/* ---------- Settings / admin panel ---------- */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(3px);
  z-index: 20;
  animation: fade 0.2s ease;
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.admin-panel {
  position: fixed;
  top: 0;
  right: 0;
  height: 100dvh;
  width: min(420px, 100vw);
  background: var(--panel);
  border-left: 1px solid var(--line);
  box-shadow: var(--shadow);
  z-index: 21;
  display: flex;
  flex-direction: column;
  padding: 0 18px 18px;
  padding-top: max(18px, env(safe-area-inset-top));
  overflow-y: auto;
  animation: slideIn 0.28s cubic-bezier(0.22, 1, 0.36, 1);
}
@keyframes slideIn { from { transform: translateX(100%); } to { transform: translateX(0); } }

.admin-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 0 8px;
  position: sticky;
  top: 0;
  background: var(--panel);
  z-index: 1;
}
.admin-header h2 { margin: 0; font-size: 22px; font-weight: 800; letter-spacing: -0.01em; }
.close-btn { width: 40px; height: 40px; }

.admin-section { padding: 14px 0; border-top: 1px solid var(--line-soft); }
.admin-section:first-of-type { border-top: none; }
.admin-section-title {
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 700;
  margin-bottom: 12px;
}

/* Segmented toggle */
.toggle-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.toggle-row + .toggle-row { margin-top: 12px; }
.toggle-label { font-size: 14px; color: var(--text); font-weight: 500; }

/* On/off switch */
.switch {
  flex: none;
  position: relative;
  width: 46px;
  height: 26px;
  border: none;
  border-radius: 999px;
  background: var(--line);
  cursor: pointer;
  padding: 0;
  transition: background 0.2s;
}
.switch[aria-checked="true"] { background: var(--accent); }
.switch .knob {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.switch[aria-checked="true"] .knob { transform: translateX(20px); }

/* Time-zone search combobox */
.admin-field { display: flex; flex-direction: column; gap: 8px; }
.tz-combo { position: relative; }
.tz-input {
  width: 100%;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  color: var(--text);
  padding: 11px 13px;
  border-radius: 11px;
  font-size: 16px; /* 16px keeps iOS Safari from zooming in on focus */
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.tz-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.tz-input::placeholder { color: var(--muted-2); }
.tz-list {
  list-style: none;
  margin: 6px 0 0;
  padding: 4px;
  position: absolute;
  left: 0;
  right: 0;
  top: 100%;
  z-index: 6;
  max-height: 244px;
  overflow-y: auto;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  scrollbar-color: var(--line) transparent;
}
.tz-opt {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 11px;
  border-radius: 8px;
  font-size: 15px;
  cursor: pointer;
}
.tz-opt.active { background: var(--accent-soft); }
.tz-opt[aria-selected="true"] .tz-opt-name { color: var(--accent); font-weight: 700; }
.tz-opt-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tz-opt-off { color: var(--muted-2); font-size: 12px; font-variant-numeric: tabular-nums; flex: none; }
.tz-empty { padding: 10px 11px; color: var(--muted-2); font-size: 14px; }
@media (hover: hover) { .tz-opt:hover { background: var(--accent-soft); } }
.seg { display: inline-flex; background: var(--bg-soft); border: 1px solid var(--line); border-radius: 11px; padding: 3px; gap: 3px; }
.seg-btn {
  border: none;
  background: none;
  color: var(--muted);
  font-weight: 600;
  font-size: 13px;
  padding: 7px 14px;
  border-radius: 8px;
  transition: background 0.15s, color 0.15s;
}
.seg-btn:hover { color: var(--text); }
.seg-btn.active { background: var(--accent); color: #fff; }

/* Year control */
.year-control { display: flex; align-items: center; gap: 10px; }
.year-btn {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.02);
  color: var(--text);
  width: 38px;
  height: 38px;
  border-radius: 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.year-btn:hover { background: var(--accent-soft); border-color: var(--accent-line); color: var(--accent); }
.year-btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
#yearLabel { font-variant-numeric: tabular-nums; font-weight: 800; font-size: 20px; min-width: 64px; text-align: center; }
.text-btn {
  margin-left: auto;
  border: none;
  background: none;
  color: var(--accent);
  font-weight: 700;
  font-size: 13px;
  padding: 8px 6px;
  border-radius: 8px;
}
.text-btn:hover { text-decoration: underline; }

/* Habits */
.admin-add { display: flex; gap: 8px; margin-bottom: 14px; }
.admin-add input,
.habit-list input {
  flex: 1;
  min-width: 0;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  color: var(--text);
  padding: 11px 13px;
  border-radius: 11px;
  font-size: 15px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.admin-add input:focus,
.habit-list input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.habit-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.habit-item {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 6px 8px;
  transition: border-color 0.15s, opacity 0.15s, transform 0.12s;
}
.habit-item.active { border-color: var(--accent-line); }
.habit-item.dragging { opacity: 0.5; }

.drag-handle { cursor: grab; color: var(--muted-2); display: flex; align-items: center; touch-action: none; padding: 4px 2px; }
.drag-handle:active { cursor: grabbing; }
.drag-handle svg { width: 18px; height: 18px; fill: currentColor; }

.habit-item input { border: 1px solid transparent; background: transparent; padding: 8px; font-weight: 600; }
.habit-item input:hover { border-color: var(--line); }
.habit-item .count { font-size: 12px; color: var(--muted-2); white-space: nowrap; font-variant-numeric: tabular-nums; }

.item-actions { display: flex; gap: 0; }
.mini-btn {
  border: none;
  background: transparent;
  color: var(--muted);
  width: 30px;
  height: 30px;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, color 0.15s;
}
.mini-btn:hover { background: rgba(255, 255, 255, 0.06); color: var(--text); }
.mini-btn:disabled { opacity: 0.25; pointer-events: none; }
.mini-btn svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.mini-btn.danger:hover { background: rgba(255, 77, 87, 0.16); color: var(--danger); }

/* Delete confirm */
.habit-item.confirming { border-color: var(--danger); background: rgba(255, 77, 87, 0.08); }
.confirm-row { display: flex; align-items: center; gap: 8px; width: 100%; font-size: 14px; }
.confirm-row .msg { flex: 1; color: #ffb0b5; font-weight: 600; }
.confirm-row button { border: none; border-radius: 9px; padding: 7px 12px; font-weight: 700; font-size: 13px; }
.confirm-row .yes { background: var(--danger); color: #fff; }
.confirm-row .no { background: var(--panel-2); color: var(--text); }

.admin-tip { font-size: 12px; color: var(--muted-2); margin: 12px 0 0; line-height: 1.5; }

/* Ghost buttons (data + about) */
.data-row { display: flex; gap: 8px; }
.ghost-btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  text-decoration: none;
  border: 1px solid var(--line);
  background: var(--bg-soft);
  color: var(--text);
  font-weight: 600;
  font-size: 13px;
  padding: 12px 10px;
  border-radius: 11px;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
}
.ghost-btn:hover { border-color: var(--accent-line); color: var(--accent); }
.ghost-btn.full { width: 100%; flex: none; }

/* About */
.made-by {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  margin-top: 16px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 500;
  text-decoration: none;
  transition: color 0.15s;
}
.made-by .heart { font-size: 13px; }
.made-by .name {
  color: var(--accent);
  font-weight: 700;
  text-decoration: underline;
  text-decoration-style: dotted;
  text-underline-offset: 3px;
}
.made-by .go { color: var(--muted-2); transition: transform 0.2s, color 0.15s; }
.made-by:hover { color: var(--text); }
.made-by:hover .name { text-decoration-style: solid; }
.made-by:hover .go { color: var(--accent); transform: translate(2px, -2px); }
.made-by .astronaut {
  height: 38px;
  width: auto;
  margin-left: 2px;
  animation: floaty 4s ease-in-out infinite;
  transition: transform 0.25s;
}
.made-by:hover .astronaut { transform: scale(1.14) rotate(-5deg); }
@keyframes floaty {
  0%, 100% { transform: translateY(0) rotate(0); }
  50% { transform: translateY(-5px) rotate(-2deg); }
}

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

/* Tablet & phone: keep the three stats on one line — shrink, and scroll
   horizontally rather than ever stacking vertically */
@media (max-width: 720px) {
  .stats-row {
    flex-wrap: nowrap;
    overflow-x: auto;
    justify-content: flex-start;
    gap: 18px;
    padding: 2px 14px 14px;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }
  .stats-row::-webkit-scrollbar { display: none; }
  .stats-row .stat { flex: 0 0 auto; }
  .stats-row .stat:first-child { margin-left: auto; }
  .stats-row .stat:last-child { margin-right: auto; }
  .stat-value { font-size: 19px; }
  .stat-label { font-size: 9.5px; white-space: nowrap; }
}

/* Small screens */
@media (max-width: 560px) {
  .topbar { padding: 12px 10px; padding-top: max(12px, env(safe-area-inset-top)); gap: 4px; }
  .nav-arrow { width: 34px; height: 34px; }
  .icon-btn { width: 38px; height: 38px; }
  .ring-wrap { width: 42px; height: 42px; }
  .ring-label { font-size: 11px; }
  .topbar-actions { gap: 6px; }
  .habit-bar { gap: 2px; }
  .habit-name { font-size: clamp(20px, 6vw, 28px); }
  .stats-row { gap: 14px; padding: 2px 12px 14px; }
  .stat-value { font-size: 16px; }
  .stat-label { font-size: 8.5px; letter-spacing: 0.05em; }
  .calendar { gap: 3px; }
  .col-head { font-size: 9.5px; }
  .row-head { font-size: 8.5px; padding-right: 3px; }
}

/* Full-screen settings on phones & tablets */
@media (max-width: 900px) {
  .admin-panel { width: 100vw; max-width: 100vw; border-left: none; }
}

/* Touch devices: don't let :hover styles "stick" highlighted after a tap */
@media (hover: none) {
  .nav-arrow:hover, .icon-btn:hover {
    background: rgba(255, 255, 255, 0.015);
    border-color: var(--line);
    color: var(--text);
    transform: none;
  }
  .star:hover::before { transform: none; background: var(--star-off); }
  .habit-name:hover { color: var(--text); }
  .year-btn:hover { background: rgba(255, 255, 255, 0.02); border-color: var(--line); color: var(--text); }
  .seg-btn:not(.active):hover { color: var(--muted); }
  .mini-btn:hover, .mini-btn.danger:hover { background: transparent; color: var(--muted); }
  .text-btn:hover { text-decoration: none; }
  .ghost-btn:hover { border-color: var(--line); color: var(--text); }
}
