:root {
  --bg: #0b1220;
  --panel: #0f1b2d;
  --panel-2: #132238;
  --text: #e6eef8;
  --muted: #8aa0bd;
  --accent: #0ea5e9;
  --accent-2: #38bdf8;
  --ok: #22c55e;
  --warn: #f59e0b;
  --danger: #ef4444;
  --radius: 14px;
  --gap: 12px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 17px;
  min-height: 100dvh;
}

#app {
  max-width: 720px;
  margin: 0 auto;
  padding: 16px;
  padding-bottom: calc(16px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: var(--gap);
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

h1 { font-size: 22px; margin: 0; }
h2 { font-size: 18px; margin: 0 0 8px; }

#settings-btn {
  background: transparent;
  color: var(--text);
  border: 1px solid #2a3a55;
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 18px;
  cursor: pointer;
}

.panels {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--gap);
}

.panel {
  background: var(--panel);
  border-radius: var(--radius);
  padding: 14px;
  border: 1px solid #1c2b46;
}

.panel .name { font-weight: 600; font-size: 18px; }
.panel .total { font-size: 28px; font-weight: 700; margin-top: 4px; }
.panel .goal  { color: var(--muted); font-size: 14px; }

.progress {
  margin-top: 10px;
  height: 12px;
  background: #1a2a42;
  border-radius: 8px;
  overflow: hidden;
}
.progress > div {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  transition: width 240ms ease-out;
}

.panel .meta {
  margin-top: 10px;
  color: var(--muted);
  font-size: 13px;
  display: flex;
  justify-content: space-between;
}

.panel.me { outline: 2px solid var(--accent); }

.log-buttons {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--gap);
}

.log-btn {
  padding: 18px 8px;
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid #23354f;
  border-radius: var(--radius);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  min-height: 64px;
  line-height: 1.2;
}
.log-btn span { color: var(--muted); font-weight: 500; font-size: 13px; }
.log-btn:active { transform: scale(0.97); }
.log-btn:disabled { opacity: 0.5; cursor: not-allowed; }

.nudge-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: stretch;
}

.nudge-btn {
  padding: 16px;
  border-radius: var(--radius);
  border: none;
  background: var(--accent);
  color: white;
  font-size: 17px;
  font-weight: 700;
  cursor: pointer;
}
.nudge-btn:disabled {
  background: #334a6b;
  color: var(--muted);
  cursor: not-allowed;
}
.muted { color: var(--muted); font-size: 13px; margin: 0; }

.history {
  background: var(--panel);
  border-radius: var(--radius);
  padding: 14px;
  border: 1px solid #1c2b46;
}

.chart {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
  align-items: end;
  height: 140px;
}
.chart .day {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  height: 100%;
  justify-content: end;
}
.chart .bars {
  display: flex;
  align-items: end;
  gap: 3px;
  height: 100%;
  width: 100%;
  justify-content: center;
}
.chart .bar {
  width: 14px;
  background: var(--accent);
  border-radius: 3px;
  min-height: 2px;
}
.chart .bar.other { background: #a78bfa; }
.chart .label { font-size: 11px; color: var(--muted); }

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  background: #1c2b46;
  color: var(--text);
  padding: 10px 14px;
  border-radius: 10px;
  border: 1px solid #2a3a55;
  display: flex;
  gap: 10px;
  align-items: center;
  box-shadow: 0 8px 24px rgba(0,0,0,0.35);
  z-index: 10;
}
.toast button {
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 6px;
  padding: 6px 10px;
  font-weight: 600;
  cursor: pointer;
}

dialog {
  background: var(--panel);
  color: var(--text);
  border: 1px solid #2a3a55;
  border-radius: var(--radius);
  padding: 18px;
  max-width: 420px;
}
dialog::backdrop { background: rgba(0,0,0,0.55); }
dialog input {
  width: 100%;
  padding: 10px;
  border-radius: 8px;
  border: 1px solid #2a3a55;
  background: #0b1220;
  color: var(--text);
  font-size: 15px;
  margin: 6px 0;
}
.dialog-actions {
  display: flex;
  gap: 8px;
  margin: 10px 0;
  flex-wrap: wrap;
}
.dialog-actions button, dialog button[value="close"] {
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 8px;
  padding: 10px 14px;
  font-weight: 600;
  cursor: pointer;
}
#sign-out { background: var(--danger); }

#app.loading > :not(header) { opacity: 0.4; pointer-events: none; }

@media (max-width: 520px) {
  .panels { grid-template-columns: 1fr; }
  .log-buttons { grid-template-columns: repeat(2, 1fr); }
}
