:root {
  --bg: #0f172a;
  --bg-soft: #1e293b;
  --card: #1e293b;
  --card-2: #273449;
  --line: #334155;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --primary: #38bdf8;
  --primary-ink: #0b2233;
  --good: #34d399;
  --bad: #fb7185;
  --shadow: 0 6px 20px rgba(0, 0, 0, 0.35);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica,
    Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  line-height: 1.45;
}

.hidden {
  display: none !important;
}

.muted {
  color: var(--muted);
  font-weight: 400;
}

.error {
  color: var(--bad);
  font-size: 0.9rem;
}

/* ---------- Gate / picker ---------- */
.gate {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.gate-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 32px 24px;
  width: 100%;
  max-width: 360px;
  text-align: center;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.gate-emoji {
  font-size: 44px;
}

.gate-card h1 {
  margin: 0;
  font-size: 1.5rem;
}

.gate-card p {
  margin: 0;
}

.who-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 8px;
}

.who-btn {
  padding: 18px 8px;
  font-size: 1.1rem;
  font-weight: 600;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: var(--card-2);
  color: var(--text);
  cursor: pointer;
  transition: transform 0.08s ease, border-color 0.15s ease;
}

.who-btn:active {
  transform: scale(0.97);
}

.who-btn:hover {
  border-color: var(--primary);
}

/* ---------- Layout ---------- */
#app {
  max-width: 640px;
  margin: 0 auto;
  padding: 0 16px calc(40px + env(safe-area-inset-bottom));
}

/* Layout: single column on mobile; two columns (sticky form + stacked
   charts/history) once there's room on tablet/desktop. */
.layout,
.stack {
  display: grid;
  gap: 16px;
}
.stack {
  align-content: start;
}

@media (min-width: 860px) {
  #app {
    max-width: 1100px;
  }
  .layout {
    grid-template-columns: 360px minmax(0, 1fr);
    align-items: start;
  }
  .form-card {
    position: sticky;
    top: 80px;
  }
  .chart-wrap {
    height: 300px;
  }
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  background: rgba(15, 23, 42, 0.85);
  backdrop-filter: blur(10px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 4px;
  margin-bottom: 8px;
  border-bottom: 1px solid var(--line);
}

.brand {
  font-weight: 700;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.who-pill {
  background: var(--card-2);
  border: 1px solid var(--line);
  padding: 5px 12px;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 600;
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 18px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}

.card h2 {
  margin: 0 0 14px;
  font-size: 1.15rem;
}

/* ---------- Form ---------- */
.field {
  margin-bottom: 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field label {
  font-size: 0.9rem;
  font-weight: 600;
}

input,
textarea {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 12px;
  color: var(--text);
  padding: 13px 14px;
  font-size: 1rem;
  font-family: inherit;
  width: 100%;
}

input:focus,
textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.18);
}

/* iOS Safari: stop type=date from using its intrinsic width / centered
   value and overflowing the rounded field. */
input[type="date"] {
  -webkit-appearance: none;
  appearance: none;
  min-width: 0;
  max-width: 100%;
  min-height: 1.4em; /* iOS collapses empty/native date inputs without this */
  text-align: left;
}

input[type="date"]::-webkit-date-and-time-value {
  text-align: left;
  margin: 0;
}

input[type="date"]::-webkit-calendar-picker-indicator {
  margin-left: auto;
}

textarea {
  resize: vertical;
}

.form-actions {
  display: flex;
  gap: 10px;
  align-items: center;
}

.btn-primary {
  background: var(--primary);
  color: var(--primary-ink);
  border: none;
  border-radius: 12px;
  padding: 13px 20px;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  flex: 1;
  transition: transform 0.08s ease, filter 0.15s ease;
}

.btn-primary:active {
  transform: scale(0.98);
}

.btn-primary:hover {
  filter: brightness(1.05);
}

.btn-ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 14px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
}

.btn-ghost:hover {
  color: var(--text);
  border-color: var(--primary);
}

.cheer {
  margin: 14px 0 0;
  padding: 12px 14px;
  background: rgba(52, 211, 153, 0.12);
  border: 1px solid rgba(52, 211, 153, 0.35);
  border-radius: 12px;
  color: var(--good);
  font-weight: 600;
  text-align: center;
  animation: pop 0.25s ease;
}

@keyframes pop {
  from {
    transform: scale(0.96);
    opacity: 0;
  }
  to {
    transform: scale(1);
    opacity: 1;
  }
}

/* ---------- Chart ---------- */
.chart-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.chart-head h2 {
  margin: 0;
}

.seg {
  display: inline-flex;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
}

.seg button {
  background: transparent;
  border: none;
  color: var(--muted);
  padding: 7px 14px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
}

.seg button.active {
  background: var(--primary);
  color: var(--primary-ink);
}

.chart-wrap {
  position: relative;
  height: 240px;
  margin-bottom: 10px;
}

/* ---------- History ---------- */
.history {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.entry {
  background: var(--card-2);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px 14px;
}

.entry-top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
}

.entry-date {
  font-weight: 700;
}

.name-badge {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--c);
  background: color-mix(in srgb, var(--c) 18%, transparent);
  border: 1px solid color-mix(in srgb, var(--c) 45%, transparent);
  padding: 1px 8px;
  border-radius: 999px;
  margin-right: 8px;
  vertical-align: 1px;
}

.entry-stats {
  display: flex;
  gap: 14px;
  font-size: 0.95rem;
}

.stat-w {
  color: var(--primary);
  font-weight: 700;
}

.stat-d {
  color: var(--muted);
}

.stat-d.has-drinks {
  color: var(--bad);
  font-weight: 600;
}

.entry-notes {
  margin: 8px 0 0;
  font-size: 0.92rem;
  color: var(--text);
  white-space: pre-wrap;
}

.entry-actions {
  display: flex;
  gap: 14px;
  margin-top: 10px;
}

.entry-actions button {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  padding: 0;
}

.entry-actions button:hover {
  color: var(--primary);
}

.entry-actions .del:hover {
  color: var(--bad);
}

.empty {
  color: var(--muted);
  text-align: center;
  padding: 18px;
}

.foot {
  text-align: center;
  font-size: 0.82rem;
  margin-top: 8px;
}

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: var(--card-2);
  border: 1px solid var(--line);
  color: var(--text);
  padding: 12px 18px;
  border-radius: 12px;
  box-shadow: var(--shadow);
  z-index: 50;
  font-weight: 600;
  max-width: 90vw;
  text-align: center;
}
