:root {
  --blue-1: #dff3ff;
  --blue-2: #7cc8f0;
  --blue-3: #2f9be0;
  --blue-4: #1670b3;
  --ink: #1c2b36;
  --ink-soft: #5a6b78;
  --bg: #f4f9fc;
  --card-bg: #ffffff;
  --card-border: #e1edf4;
  --green-bg: #e6f8ed;
  --green-fg: #1f9d55;
  --yellow-bg: #fff6dd;
  --yellow-fg: #b8860b;
  --red-bg: #fde8e8;
  --red-fg: #d0342c;
  --neutral-bg: #eef2f6;
  --neutral-fg: #5a6b78;
  --shadow: 0 4px 16px rgba(22, 112, 179, 0.08);
}

@media (prefers-color-scheme: dark) {
  :root {
    --blue-1: #123049;
    --blue-2: #1d5b85;
    --blue-3: #3fa7e8;
    --blue-4: #7cd0ff;
    --ink: #eaf3fa;
    --ink-soft: #9db2c2;
    --bg: #0f1a22;
    --card-bg: #16232d;
    --card-border: #223440;
    --green-bg: #12321f;
    --green-fg: #4fd07f;
    --yellow-bg: #392c0d;
    --yellow-fg: #e5b73b;
    --red-bg: #3a1414;
    --red-fg: #ff6b62;
    --neutral-bg: #1c2933;
    --neutral-fg: #9db2c2;
    --shadow: 0 4px 20px rgba(0, 0, 0, 0.35);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Segoe UI", "Noto Sans TC", "Microsoft JhengHei", sans-serif;
  background: var(--bg);
  color: var(--ink);
  display: flex;
  justify-content: center;
  padding: 24px 16px 60px;
}

.app {
  width: 100%;
  max-width: 480px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.app-header { display: flex; flex-direction: column; gap: 6px; }

.title-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
}

.title-row h1 { font-size: 22px; margin: 0; }
.date { font-size: 13px; color: var(--ink-soft); }

.goal-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  color: var(--ink-soft);
}

.goal-row input {
  width: 80px;
  padding: 6px 8px;
  border-radius: 8px;
  border: 1px solid var(--card-border);
  background: var(--card-bg);
  color: var(--ink);
  font-size: 14px;
}

.status-banner {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  border-radius: 14px;
  font-weight: 600;
  font-size: 15px;
  background: var(--neutral-bg);
  color: var(--neutral-fg);
  transition: background 0.4s, color 0.4s;
}

.status-banner.good { background: var(--green-bg); color: var(--green-fg); }
.status-banner.warn { background: var(--yellow-bg); color: var(--yellow-fg); }
.status-banner.danger {
  background: var(--red-bg);
  color: var(--red-fg);
  animation: pulse 1.6s ease-in-out infinite;
}

.status-icon { font-size: 22px; }

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(208, 52, 44, 0.35); }
  50% { box-shadow: 0 0 0 8px rgba(208, 52, 44, 0); }
}

.cup-section {
  display: flex;
  align-items: center;
  gap: 20px;
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 18px;
  padding: 20px;
  box-shadow: var(--shadow);
}

.big-cup {
  position: relative;
  width: 110px;
  height: 150px;
  flex-shrink: 0;
}

.cup-body {
  position: absolute;
  inset: 0;
  border-radius: 14px 14px 26px 26px;
  border: 4px solid var(--blue-4);
  overflow: hidden;
  background: var(--blue-1);
}

.water-fill {
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 0%;
  background: linear-gradient(180deg, var(--blue-3), var(--blue-4));
  transition: height 0.7s cubic-bezier(.4,1.4,.6,1);
}

.wave {
  position: absolute;
  top: -8px;
  left: 0;
  width: 200%;
  height: 16px;
  background: radial-gradient(ellipse at center, var(--blue-2) 0%, var(--blue-2) 60%, transparent 62%);
  background-size: 40px 32px;
  background-repeat: repeat-x;
  opacity: 0.8;
  animation: waveMove 3.2s linear infinite;
}

.wave2 {
  top: -5px;
  height: 12px;
  opacity: 0.5;
  animation-duration: 4.6s;
  animation-direction: reverse;
}

@keyframes waveMove {
  from { background-position-x: 0; }
  to { background-position-x: -80px; }
}

.cup-overlay {
  position: absolute;
  inset: 0;
  border-radius: 14px 14px 26px 26px;
  box-shadow: inset 0 0 12px rgba(0,0,0,0.08);
  pointer-events: none;
}

.cup-stats { display: flex; flex-direction: column; gap: 4px; }
.stat-main { font-size: 30px; font-weight: 700; color: var(--blue-4); }
.stat-main .unit { font-size: 14px; font-weight: 500; color: var(--ink-soft); }
.stat-sub { font-size: 13px; color: var(--ink-soft); }
.stat-remain { font-size: 13px; font-weight: 600; color: var(--blue-3); margin-top: 4px; }

h2 {
  font-size: 14px;
  color: var(--ink-soft);
  margin: 0 0 10px;
  font-weight: 600;
}

.mini-cups-section,
.add-section,
.log-section,
.history-section {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 18px;
  padding: 16px 18px;
  box-shadow: var(--shadow);
}

.mini-cups {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.mini-cup {
  position: relative;
  width: 34px;
  height: 44px;
  border: 2.5px solid var(--blue-3);
  border-radius: 6px 6px 12px 12px;
  overflow: hidden;
  background: var(--blue-1);
  flex-shrink: 0;
}

.mini-cup-fill {
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 0%;
  background: var(--blue-3);
  transition: height 0.5s ease;
}

.quick-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.qty-btn {
  padding: 9px 14px;
  border-radius: 10px;
  border: none;
  background: var(--blue-3);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.12s, background 0.2s;
}

.qty-btn:hover { background: var(--blue-4); }
.qty-btn:active { transform: scale(0.94); }

.custom-row { display: flex; gap: 8px; flex-wrap: wrap; }

.custom-row input {
  flex: 1;
  min-width: 100px;
  padding: 9px 12px;
  border-radius: 10px;
  border: 1px solid var(--card-border);
  background: var(--bg);
  color: var(--ink);
  font-size: 14px;
}

.custom-row button {
  padding: 9px 16px;
  border-radius: 10px;
  border: none;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

#addCustomBtn { background: var(--blue-4); color: #fff; }
.undo-btn { background: var(--neutral-bg); color: var(--ink-soft); }
.undo-btn:hover { background: var(--red-bg); color: var(--red-fg); }

.log-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 220px;
  overflow-y: auto;
}

.log-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px;
  border-radius: 10px;
  background: var(--bg);
  font-size: 14px;
}

.log-list .empty-log {
  color: var(--ink-soft);
  justify-content: center;
  background: transparent;
}

.log-time { color: var(--ink-soft); font-size: 12px; }
.log-amt { font-weight: 600; color: var(--blue-4); }

.log-del {
  border: none;
  background: transparent;
  color: var(--ink-soft);
  cursor: pointer;
  font-size: 14px;
  padding: 2px 6px;
  border-radius: 6px;
}
.log-del:hover { background: var(--red-bg); color: var(--red-fg); }

.history-chart {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  height: 120px;
  padding-top: 10px;
}

.history-bar-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  height: 100%;
  gap: 6px;
}

.history-bar-track {
  width: 100%;
  max-width: 28px;
  height: 100%;
  background: var(--neutral-bg);
  border-radius: 6px;
  display: flex;
  align-items: flex-end;
  overflow: hidden;
  position: relative;
}

.history-bar {
  width: 100%;
  border-radius: 6px;
  transition: height 0.4s ease;
}

.history-bar.good { background: var(--green-fg); }
.history-bar.warn { background: var(--yellow-fg); }
.history-bar.danger { background: var(--red-fg); }
.history-bar.today { outline: 2px solid var(--blue-4); outline-offset: -2px; }

.history-label {
  font-size: 11px;
  color: var(--ink-soft);
  text-align: center;
}

.app-footer {
  text-align: center;
  font-size: 12px;
  color: var(--ink-soft);
  margin-top: 4px;
}
