* { box-sizing: border-box; }

html { overflow-x: hidden; }

body {
  font-family: 'Manrope', system-ui, -apple-system, sans-serif;
  text-align: center;
  padding: 2rem max(1.25rem, env(safe-area-inset-right)) 3rem max(1.25rem, env(safe-area-inset-left));
  background: var(--bg-body, #f5f5f4);
  color: var(--text-primary, #1a1a1a);
  min-height: 100vh;
  transition: background 0.3s ease, color 0.3s ease;
}

main { max-width: 640px; margin: 0 auto; position: relative; }
.main-header {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 0.75rem; margin-bottom: 2rem;
}
.main-header h1 { flex: 1; min-width: 0; margin: 0; text-align: center; }
.theme-toggle {
  flex-shrink: 0;
  padding: 0.4rem 0.6rem; font-size: 1.2rem; line-height: 1;
  background: var(--bg-card, #fff); border: 1px solid var(--border, rgba(0,0,0,0.08));
  border-radius: 8px; cursor: pointer; transition: background 0.2s, border-color 0.2s, transform 0.2s;
}
.theme-toggle:hover { transform: scale(1.05); }
h1 { font-size: clamp(1.1rem, 3.5vw, 1.4rem); font-weight: 600; line-height: 1.4; }

.countdown { display: flex; flex-wrap: wrap; justify-content: center; gap: 1rem; }
.countdown-unit {
  background: var(--bg-card, #fff);
  border-radius: 16px;
  padding: 1rem;
  min-width: 100px;
  box-shadow: var(--shadow-card, 0 2px 12px rgba(0, 0, 0, 0.06));
  transition: transform 0.2s ease, background 0.3s, box-shadow 0.3s;
}
.countdown-unit:hover { transform: translateY(-2px); }
.unit-inner { position: relative; display: flex; align-items: center; justify-content: center; width: 96px; height: 96px; margin: 0 auto; }
.ring { position: absolute; inset: -2px; overflow: visible; }
.ring svg { width: 100%; height: 100%; transform: rotate(-90deg); shape-rendering: geometricPrecision; }
.ring-track { fill: none; stroke: var(--ring-track, #e5e7eb); stroke-width: 10; stroke-linecap: round; }
.ring-fill {
  fill: none; stroke: url(#ringGradient); stroke-width: 10; stroke-linecap: round;
  stroke-dasharray: 276.5; stroke-dashoffset: calc(276.5 * (1 - var(--fill, 0)));
  transition: stroke-dashoffset 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}
.ring-shadow { filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.08)); }
.countdown-value {
  position: relative; z-index: 1; font-size: clamp(1.5rem, 5vw, 2.25rem); font-weight: 700;
  line-height: 1.1; color: var(--text-primary, #1a1a1a); font-variant-numeric: tabular-nums;
}
.countdown-label { font-size: 0.8rem; color: var(--text-muted, #666); margin-top: 0.5rem; text-transform: lowercase; }
.message-done { font-size: 1.5rem; font-weight: 600; color: var(--accent, #22c55e); margin-top: 2rem; }
.target-date { font-size: 0.95rem; color: var(--text-muted, #666); margin-top: 0.5rem; }

.grid-section { margin-top: 3rem; padding-top: 2rem; border-top: 1px solid var(--border, rgba(0, 0, 0, 0.08)); }
.legend { display: flex; justify-content: center; gap: 1.5rem; margin-bottom: 1rem; font-size: 0.85rem; color: var(--text-muted, #555); }
.legend-item { display: flex; align-items: center; gap: 0.4rem; }
.legend-dot { width: 10px; height: 10px; border-radius: 50%; }
.legend-dot.passed { background: var(--dot-passed, #22c55e); }
.legend-dot.today { background: var(--dot-today, #3b82f6); border: 2px solid #1d4ed8; }
.legend-dot.remaining { background: var(--dot-remaining, #d4d4d4); }
.grid { display: grid; grid-template-columns: repeat(auto-fill, 12px); gap: 4px; justify-content: center; max-width: 100%; }
.circle {
  position: relative; width: 12px; height: 12px; border-radius: 50%;
  background: var(--dot-remaining, #d4d4d4); transition: background 0.3s ease, transform 0.2s ease; cursor: default;
}
.circle.active { background: var(--dot-passed, #22c55e); }
.circle.today { background: var(--dot-today, #3b82f6); border: 2px solid #1d4ed8; transform: scale(1.1); animation: today-pulse 2s ease-in-out infinite; }
.circle:hover { transform: scale(1.2); }
@keyframes today-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(59, 130, 246, 0.4); }
  50% { box-shadow: 0 0 0 6px rgba(59, 130, 246, 0); }
}
.circle[data-tooltip]::after {
  content: attr(data-tooltip); position: absolute; bottom: calc(100% + 6px); left: 50%; transform: translateX(-50%);
  padding: 0.35rem 0.5rem; font-size: 0.7rem; white-space: nowrap; background: var(--tooltip-bg, #1a1a1a); color: #fff;
  border-radius: 4px; opacity: 0; pointer-events: none; transition: opacity 0.2s ease; z-index: 10;
}
.circle:hover[data-tooltip]::after { opacity: 1; }

.btn-settings {
  display: block; margin: 2rem auto 0; padding: 0.5rem 1rem; font-size: 0.9rem;
  color: var(--text-muted, #666); background: transparent; border: 1px solid var(--border-input, #d4d4d4);
  border-radius: 8px; cursor: pointer; transition: color 0.2s, border-color 0.2s, background 0.2s;
}
.btn-settings:hover { color: var(--text-primary, #1a1a1a); border-color: var(--accent, #22c55e); background: var(--accent-subtle, rgba(34, 197, 94, 0.08)); }

.modal {
  padding: 1.5rem; border-radius: 12px; border: 1px solid var(--border, rgba(0,0,0,0.1));
  box-shadow: 0 8px 32px rgba(0,0,0,0.12); max-width: 320px; background: var(--bg-card, #fff);
}
.modal h2 { font-size: 1.2rem; margin-bottom: 1rem; }
.modal label { display: block; font-size: 0.9rem; color: var(--text-muted, #555); margin-bottom: 0.35rem; }
.modal input[type="date"] {
  width: 100%; padding: 0.5rem 0.75rem; font-size: 1rem; border: 1px solid var(--border-input, #d4d4d4);
  border-radius: 8px; margin-bottom: 1rem; background: var(--bg-body); color: var(--text-primary);
}
.modal-actions { display: flex; gap: 0.75rem; justify-content: flex-end; }
.modal-actions button { padding: 0.5rem 1rem; font-size: 0.9rem; border-radius: 8px; cursor: pointer; }
.modal-actions button[type="submit"] { background: var(--accent, #22c55e); color: #fff; border: none; }
.modal-actions button[type="button"] { background: var(--bg-body, #f5f5f4); border: 1px solid var(--border-input, #d4d4d4); color: var(--text-primary, #333); }

.milestone { margin-top: 1rem; padding: 0.75rem 1rem; background: var(--accent-subtle, rgba(34, 197, 94, 0.12)); border-radius: 10px; font-size: 0.95rem; color: var(--text-primary); }
.message-done.celebration { animation: celebrate-in 0.6s ease-out; }
@keyframes celebrate-in { from { opacity: 0; transform: scale(0.9); } to { opacity: 1; transform: scale(1); } }

[data-theme="dark"] {
  --bg-body: #1a1a1a; --bg-card: #252525; --text-primary: #f5f5f4; --text-muted: #a3a3a3;
  --border: rgba(255,255,255,0.08); --border-input: #404040; --shadow-card: 0 2px 12px rgba(0,0,0,0.3);
  --ring-track: #404040; --dot-passed: #22c55e; --dot-today: #3b82f6; --dot-remaining: #404040;
  --accent: #22c55e; --accent-subtle: rgba(34, 197, 94, 0.2); --tooltip-bg: #333;
}

/* Мобильная версия */
@media (max-width: 640px) {
  body {
    padding: 1.25rem max(1rem, env(safe-area-inset-right)) 2rem max(1rem, env(safe-area-inset-left));
    padding-bottom: calc(2rem + env(safe-area-inset-bottom, 0px));
  }
  .main-header { gap: 0.5rem; margin-bottom: 1.5rem; }
  .main-header h1 { font-size: 1rem; }
  .theme-toggle { padding: 0.5rem; min-width: 44px; min-height: 44px; }
  .countdown { gap: 0.75rem; }
  .countdown-unit { min-width: 72px; padding: 0.75rem; }
  .unit-inner { width: 72px; height: 72px; }
  .countdown-value { font-size: 1.35rem; }
  .countdown-label { font-size: 0.7rem; }
  .grid-section { margin-top: 2rem; padding-top: 1.5rem; }
  .legend { flex-wrap: wrap; justify-content: center; gap: 0.75rem; font-size: 0.8rem; }
  .message-done { font-size: 1.25rem; margin-top: 1.5rem; }
}

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