@import url('https://fonts.googleapis.com/css2?family=Manrope:wght@400;500;600&family=Sora:wght@600;700&display=swap');

/* ================================================================
   RESET & BASE
   ================================================================ */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: 'Manrope', -apple-system, BlinkMacSystemFont, sans-serif;
  font-weight: 400;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
  min-height: 100dvh;
  padding-top: env(safe-area-inset-top);
  padding-bottom: calc(80px + env(safe-area-inset-bottom));
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  transition: background 0.3s ease, color 0.3s ease;
}

h1, h2, h3 {
  font-family: 'Sora', -apple-system, BlinkMacSystemFont, sans-serif;
}

h1 { font-size: 1.5rem; font-weight: 600; }
h2 { font-size: 1.1rem; font-weight: 600; }

a { color: inherit; text-decoration: none; }
button { cursor: pointer; font-family: inherit; }
input, select { font-family: inherit; font-size: inherit; }
svg { display: block; }

/* ================================================================
   THEME: Thermal Spring (warm, spa-like)
   ================================================================ */
[data-theme="thermal-spring"] {
  --bg: #FBF7F0;
  --surface: #FFFFFF;
  --accent: #1A6B5A;
  --accent-warm: #C47B5A;
  --highlight: #8FBCBB;
  --text: #3D3432;
  --text-secondary: #8B7B75;
  --border: #E8DDD4;
  --water-start: #1A6B5A;
  --water-end: #3DA892;
  --shadow: rgba(61, 52, 50, 0.08);
  --fill-shimmer-1: #1A6B5A;
  --fill-shimmer-2: #2D8B76;
  --modal-overlay: rgba(61, 52, 50, 0.5);
}

/* ================================================================
   THEME: Deep Ocean (dark, technical)
   ================================================================ */
[data-theme="deep-ocean"] {
  --bg: #0B1929;
  --surface: #12253A;
  --accent: #00D4FF;
  --accent-warm: #3399FF;
  --highlight: #00E5A0;
  --text: #E8F0F8;
  --text-secondary: #6B8AAA;
  --border: #1A3450;
  --water-start: #00D4FF;
  --water-end: #0066CC;
  --shadow: rgba(0, 0, 0, 0.3);
  --fill-shimmer-1: #00D4FF;
  --fill-shimmer-2: #0088EE;
  --modal-overlay: rgba(0, 0, 0, 0.6);
}

/* ================================================================
   THEME: Morning Dew (botanical, airy)
   ================================================================ */
[data-theme="morning-dew"] {
  --bg: #FAF7F2;
  --surface: #FFFFFF;
  --accent: #6B8F71;
  --accent-warm: #8BB8D6;
  --highlight: #C5DBC4;
  --text: #2D3A2C;
  --text-secondary: #7A8B75;
  --border: #EDE8E0;
  --water-start: #6B8F71;
  --water-end: #A8D5A2;
  --shadow: rgba(45, 58, 44, 0.08);
  --fill-shimmer-1: #6B8F71;
  --fill-shimmer-2: #8DC292;
  --modal-overlay: rgba(45, 58, 44, 0.5);
}

/* ================================================================
   DARK MODE OVERRIDES (applied when html has .dark class)
   ================================================================ */
[data-theme="thermal-spring"].dark {
  --bg: #1E1815;
  --surface: #2A211D;
  --accent: #3DA892;
  --accent-warm: #D4956E;
  --highlight: #6BABA8;
  --text: #F0E8E2;
  --text-secondary: #9E8D85;
  --border: #3A2E28;
  --water-start: #3DA892;
  --water-end: #1A6B5A;
  --shadow: rgba(0, 0, 0, 0.4);
  --fill-shimmer-1: #3DA892;
  --fill-shimmer-2: #50C4AA;
  --modal-overlay: rgba(0, 0, 0, 0.7);
}

[data-theme="deep-ocean"].dark {
  /* Deep Ocean is dark by default — these are the same values */
}

[data-theme="morning-dew"].dark {
  --bg: #151A14;
  --surface: #1E241D;
  --accent: #8DC292;
  --accent-warm: #6B8F71;
  --highlight: #A8D5A2;
  --text: #E8EDE4;
  --text-secondary: #9AAA94;
  --border: #2A3428;
  --water-start: #8DC292;
  --water-end: #6B8F71;
  --shadow: rgba(0, 0, 0, 0.4);
  --fill-shimmer-1: #8DC292;
  --fill-shimmer-2: #A8D5A2;
  --modal-overlay: rgba(0, 0, 0, 0.7);
}

/* Global dark modifier for Deep Ocean (already dark, slightly enhanced) */
[data-theme="deep-ocean"] .dark-force {
  --bg: #060E18;
  --surface: #0D1C2E;
  --border: #152A44;
}

/* ================================================================
   VIEW ROUTING
   ================================================================ */
.view {
  display: none;
  padding: 16px 20px 24px;
  animation: viewEnter 0.25s ease-out;
}

.view--active {
  display: block;
}

@keyframes viewEnter {
  from { opacity: 0; transform: translateX(6px); }
  to { opacity: 1; transform: translateX(0); }
}

.view-header {
  text-align: center;
  margin-bottom: 20px;
}

.view-date {
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-top: 2px;
}

/* ================================================================
   WATER COLUMN
   ================================================================ */
.water-column {
  position: relative;
  height: 300px;
  width: 100%;
  max-width: 160px;
  margin: 0 auto 16px;
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: 8px 8px 4px 4px;
  overflow: hidden;
}

.water-column__fill {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 0%;
  background: linear-gradient(180deg, var(--water-start), var(--water-end));
  transition: height 4s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

.water-column__shimmer {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 0%;
  background: linear-gradient(
    180deg,
    transparent 0%,
    rgba(255,255,255,0.12) 30%,
    rgba(255,255,255,0.06) 60%,
    transparent 100%
  );
  transition: height 4s cubic-bezier(0.25, 0.46, 0.45, 0.94);
  pointer-events: none;
  animation: shimmer 2.5s ease-in-out infinite;
}

@keyframes shimmer {
  0%, 100% { opacity: 0.5; }
  50% { opacity: 1; }
}

/* Pour animation trigger — 4s to match water sound */
.water-column__fill--pour {
  animation: pourWave 4s ease-out;
}

@keyframes pourWave {
  0%   { clip-path: polygon(0% 100%, 10% 92%, 25% 88%, 40% 95%, 55% 85%, 70% 91%, 85% 82%, 100% 100%, 100% 100%, 0% 100%); }
  15%  { clip-path: polygon(0% 100%, 12% 80%, 28% 86%, 42% 76%, 58% 88%, 72% 79%, 88% 85%, 100% 100%, 100% 100%, 0% 100%); }
  30%  { clip-path: polygon(0% 100%, 8%  70%, 22% 78%, 38% 68%, 52% 80%, 68% 71%, 82% 77%, 100% 100%, 100% 100%, 0% 100%); }
  50%  { clip-path: polygon(0% 100%, 14% 55%, 26% 65%, 44% 54%, 56% 68%, 74% 58%, 86% 64%, 100% 100%, 100% 100%, 0% 100%); }
  70%  { clip-path: polygon(0% 100%, 10% 35%, 24% 45%, 40% 38%, 54% 48%, 70% 40%, 84% 42%, 100% 100%, 100% 100%, 0% 100%); }
  85%  { clip-path: polygon(0% 100%, 12% 15%, 28% 22%, 42% 14%, 58% 20%, 72% 12%, 88% 18%, 100% 100%, 100% 100%, 0% 100%); }
  100% { clip-path: polygon(0% 100%, 0% 0%, 20% 0%, 40% 0%, 60% 0%, 80% 0%, 100% 0%, 100% 100%, 0% 100%); }
}

.water-column__percent {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-family: 'Sora', sans-serif;
  font-size: 3rem;
  font-weight: 700;
  color: var(--text);
  text-shadow: 0 1px 2px rgba(0,0,0,0.1);
  z-index: 2;
  pointer-events: none;
}

.water-column__volume {
  position: absolute;
  bottom: 12px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.8rem;
  color: var(--text-secondary);
  z-index: 2;
  pointer-events: none;
  white-space: nowrap;
}

.last-drink {
  text-align: center;
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-bottom: 16px;
  min-height: 1.2em;
}

/* ================================================================
   FAVORITES ROW
   ================================================================ */
.fav-row {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
  padding: 0 20px 8px;
  margin: 0 -20px 12px;
}

.fav-row::-webkit-scrollbar { display: none; }

.fav-btn {
  flex-shrink: 0;
  scroll-snap-align: center;
  width: 80px;
  height: 100px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 0.8rem;
  font-weight: 500;
  transition: background 0.15s ease, transform 0.1s ease, border-color 0.15s ease;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.fav-btn:active {
  transform: scale(0.93);
  background: var(--highlight);
  border-color: var(--accent);
}

.fav-btn svg {
  stroke: var(--accent);
}

/* ================================================================
   BUTTONS
   ================================================================ */
.btn-manual {
  display: block;
  width: 100%;
  max-width: 280px;
  margin: 0 auto;
  padding: 12px 20px;
  background: var(--surface);
  border: 1.5px dashed var(--border);
  border-radius: 8px;
  color: var(--text-secondary);
  font-size: 0.95rem;
  font-weight: 500;
  text-align: center;
  transition: border-color 0.2s ease, color 0.2s ease, background 0.2s ease;
}

.btn-manual:active {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--highlight);
}

/* ================================================================
   BOTTOM NAVIGATION
   ================================================================ */
#bottom-nav {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 480px;
  display: flex;
  justify-content: space-around;
  align-items: center;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
  z-index: 100;
}

.nav-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  min-width: 44px;
  min-height: 44px;
  padding: 6px 10px;
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 0.65rem;
  font-weight: 500;
  border-radius: 8px;
  transition: color 0.2s ease, background 0.2s ease;
  -webkit-tap-highlight-color: transparent;
}

.nav-btn svg {
  stroke: var(--text-secondary);
  transition: stroke 0.2s ease;
}

.nav-btn--active {
  color: var(--accent);
}

.nav-btn--active svg {
  stroke: var(--accent);
}

/* ================================================================
   HISTORY LIST
   ================================================================ */
.history-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.history-group {
  margin-bottom: 12px;
}

.history-date-header {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 4px;
  cursor: pointer;
  user-select: none;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.history-group--collapsed .history-entry {
  display: none;
}

.history-entry {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 4px;
  margin-bottom: 2px;
  font-size: 0.9rem;
  transition: background 0.15s ease;
}

.history-entry:active {
  background: var(--highlight);
}

.history-entry__time {
  color: var(--text-secondary);
  font-size: 0.8rem;
}

.history-entry__volume {
  font-weight: 600;
  color: var(--accent);
}

.history-goal-badge {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 4px;
  margin-left: 8px;
}

.history-goal-badge--met {
  background: var(--highlight);
  color: var(--accent);
}

.history-goal-badge--missed {
  background: var(--border);
  color: var(--text-secondary);
}

.empty-state {
  text-align: center;
  color: var(--text-secondary);
  font-size: 0.9rem;
  padding: 40px 20px;
}

/* ================================================================
   ACHIEVEMENTS
   ================================================================ */
.ach-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
  margin-bottom: 16px;
}

.ach-section h2 {
  margin-bottom: 12px;
  color: var(--text);
}

.ach-streak-display {
  display: flex;
  gap: 16px;
  margin-bottom: 16px;
}

.ach-streak-card {
  flex: 1;
  text-align: center;
  padding: 12px 8px;
  background: var(--bg);
  border-radius: 4px;
  border: 1px solid var(--border);
}

.ach-streak-card__value {
  font-family: 'Sora', sans-serif;
  font-size: 2rem;
  font-weight: 700;
  color: var(--accent);
}

.ach-streak-card__label {
  font-size: 0.7rem;
  color: var(--text-secondary);
  margin-top: 2px;
}

.ach-streak-chain {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: center;
}

.ach-streak-dot {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--border);
  transition: background 0.3s ease;
}

.ach-streak-dot--filled {
  background: var(--accent);
}

.ach-milestones-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}

.ach-milestone {
  text-align: center;
  padding: 12px 8px;
  background: var(--bg);
  border-radius: 4px;
  border: 1.5px solid var(--border);
  transition: border-color 0.3s ease, background 0.3s ease;
}

.ach-milestone--unlocked {
  border-color: var(--accent);
  background: var(--highlight);
}

.ach-milestone__icon {
  font-size: 1.8rem;
  margin-bottom: 4px;
}

.ach-milestone__label {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--text);
}

.ach-milestone--unlocked .ach-milestone__label {
  color: var(--accent);
}

/* Weekly chart */
.ach-chart {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  height: 150px;
  padding: 0 8px;
}

.ach-chart__bar-wrapper {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  height: 100%;
  justify-content: flex-end;
}

.ach-chart__bar {
  width: 100%;
  max-width: 40px;
  background: var(--accent);
  border-radius: 2px 2px 0 0;
  transition: height 0.4s ease;
  min-height: 4px;
}

.ach-chart__label {
  font-size: 0.6rem;
  color: var(--text-secondary);
  margin-top: 4px;
  text-align: center;
}

.ach-chart__vol {
  font-size: 0.6rem;
  color: var(--text-secondary);
  margin-bottom: 2px;
}

/* ================================================================
   SETTINGS
   ================================================================ */
.settings-group {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
  margin-bottom: 12px;
}

.settings-group h2 {
  margin-bottom: 10px;
  font-size: 0.95rem;
  color: var(--text);
}

.setting-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 4px 0;
  font-size: 0.9rem;
}

.setting-hint {
  font-size: 0.75rem;
  color: var(--text-secondary);
  margin-bottom: 10px;
}

.goal-adjust {
  display: flex;
  align-items: center;
  gap: 12px;
}

.goal-adjust button {
  width: 32px;
  height: 32px;
  border: 1.5px solid var(--border);
  border-radius: 4px;
  background: var(--surface);
  color: var(--text);
  font-size: 1.1rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.goal-adjust button:active {
  border-color: var(--accent);
  background: var(--highlight);
}

#goal-display {
  font-weight: 600;
  min-width: 80px;
  text-align: center;
}

select {
  width: 100%;
  padding: 10px 12px;
  background: var(--bg);
  border: 1.5px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  font-size: 0.9rem;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M3 5l3 3 3-3' fill='none' stroke='%23888' stroke-width='2'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
}

input[type="number"] {
  width: 80px;
  padding: 8px 10px;
  background: var(--bg);
  border: 1.5px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  font-size: 0.9rem;
  text-align: center;
}

.toggle-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
  font-size: 0.9rem;
  cursor: pointer;
  min-height: 44px;
}

.toggle-row input[type="checkbox"] {
  width: 44px;
  height: 26px;
  appearance: none;
  background: var(--border);
  border-radius: 13px;
  position: relative;
  transition: background 0.2s ease;
  cursor: pointer;
}

.toggle-row input[type="checkbox"]::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  background: white;
  border-radius: 50%;
  transition: transform 0.2s ease;
}

.toggle-row input[type="checkbox"]:checked {
  background: var(--accent);
}

.toggle-row input[type="checkbox"]:checked::after {
  transform: translateX(18px);
}

/* Favorites options grid */
.fav-options-grid {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 12px;
}

.fav-option {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  background: var(--bg);
  border: 1.5px solid var(--border);
  border-radius: 4px;
  font-size: 0.85rem;
  cursor: pointer;
  min-height: 44px;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.fav-option:has(input:checked) {
  border-color: var(--accent);
  background: var(--highlight);
}

.fav-option input[type="checkbox"] {
  width: 20px;
  height: 20px;
  accent-color: var(--accent);
}

.fav-option svg {
  stroke: var(--accent);
  flex-shrink: 0;
}

/* ================================================================
   SETTINGS BUTTONS (Data / Update)
   ================================================================ */
#btn-export, #btn-import, #btn-update {
  display: inline-block;
  padding: 10px 18px;
  margin: 4px 8px 4px 0;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  font-size: 0.85rem;
  font-weight: 500;
  transition: border-color 0.15s ease, background 0.15s ease;
}

#btn-export:active, #btn-import:active, #btn-update:active {
  border-color: var(--accent);
  background: var(--highlight);
}

#data-status, #update-status {
  font-size: 0.75rem;
  color: var(--text-secondary);
  margin-top: 6px;
}

.version-text {
  font-size: 0.7rem;
  color: var(--text-secondary);
  margin-top: 8px;
}

/* ================================================================
   MODALS
   ================================================================ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: var(--modal-overlay);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: env(safe-area-inset-top) 20px env(safe-area-inset-bottom);
  animation: modalFadeIn 0.2s ease-out;
}

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

.modal-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 24px 20px;
  width: 100%;
  max-width: 360px;
  animation: modalScaleIn 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.modal-box--small {
  max-width: 300px;
}

@keyframes modalScaleIn {
  from { transform: scale(0.92); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.modal-box h2 {
  margin-bottom: 12px;
  text-align: center;
}

.modal-box p {
  font-size: 0.9rem;
  color: var(--text-secondary);
  text-align: center;
  margin-bottom: 16px;
}

.modal-box label {
  display: block;
  font-size: 0.85rem;
  color: var(--text);
  margin-bottom: 10px;
}

.modal-box input[type="number"] {
  width: 100%;
  padding: 10px 12px;
  margin-bottom: 12px;
  font-size: 1.1rem;
  text-align: center;
  background: var(--bg);
  border: 1.5px solid var(--border);
  border-radius: 4px;
  color: var(--text);
}

.modal-box select {
  margin-bottom: 10px;
}

.modal-box input[type="range"] {
  width: 100%;
  margin: 8px 0 12px;
  accent-color: var(--accent);
}

.modal-actions {
  display: flex;
  gap: 8px;
  margin-top: 16px;
}

.modal-actions .fl-btn {
  flex: 1;
}

/* First launch / modal buttons */
.fl-btn {
  display: block;
  width: 100%;
  padding: 12px 16px;
  margin-bottom: 8px;
  background: var(--bg);
  border: 1.5px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 0.9rem;
  font-weight: 500;
  text-align: center;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.fl-btn--primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}

.fl-btn--primary:active {
  filter: brightness(0.9);
}

.fl-btn--danger {
  border-color: #D64045;
  color: #D64045;
}

.fl-btn--danger:active {
  background: #D64045;
  color: #fff;
}

.fl-btn:active {
  background: var(--highlight);
  border-color: var(--accent);
}

/* ================================================================
   UTILITY
   ================================================================ */
input[type="file"] {
  display: none;
}

/* ================================================================
   iOS PWA safe area & touch optimization
   ================================================================ */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
  body {
    padding-bottom: calc(80px + env(safe-area-inset-bottom));
  }
}

/* Prevent pull-to-refresh and overscroll behavior */
html {
  overscroll-behavior: none;
}

body {
  overscroll-behavior-y: none;
}
