/* ── Reset & base ─────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:          #0a0a12;
  --card:        #13131e;
  --border:      #1e1e2e;
  --text:        #e8e8f0;
  --subtext:     #8888aa;
  --muted:       #44445a;
  --accent:      #d28c32;
  --accent-dim:  #8a5a1a;
  --red:         #c0392b;
  --green:       #27ae60;
  --safe-top:    env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', sans-serif;
  font-size: 15px;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

input, select, textarea, button {
  font-family: inherit;
  font-size: 15px;
  color: var(--text);
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
input[type=range] {
  background: transparent;
  border: none;
  flex: 1;
  accent-color: var(--accent);
}

/* ── Screen management ────────────────────────────────────────────────── */
.screen { display: none; flex-direction: column; height: 100vh; height: 100dvh; }
.screen.active { display: flex; }

/* ── Auth screen ─────────────────────────────────────────────────────── */
.auth-wrap {
  margin: auto;
  width: min(340px, 90vw);
  padding: 40px 0;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.auth-logo { font-size: 52px; text-align: center; }
.auth-title { font-size: 26px; font-weight: 700; text-align: center; color: var(--text); }
.auth-sub { font-size: 13px; color: var(--subtext); text-align: center; margin-top: -8px; }
.form-group input {
  width: 100%;
  padding: 12px 14px;
  font-size: 16px; /* prevent iOS zoom */
}

/* ── App header ──────────────────────────────────────────────────────── */
.app-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: calc(var(--safe-top) + 12px) 16px 10px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.app-title { flex: 1; font-size: 17px; font-weight: 700; }
.btn-icon-hdr {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 18px;
  padding: 4px 8px;
  cursor: pointer;
  border-radius: 6px;
}
.btn-icon-hdr:active { background: var(--border); }
.btn-text-hdr {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 15px;
  font-weight: 600;
  padding: 4px 8px;
  cursor: pointer;
  border-radius: 6px;
}
.btn-text-hdr:active { background: var(--border); }

/* ── Filter pills ────────────────────────────────────────────────────── */
.filter-bar {
  display: flex;
  gap: 8px;
  padding: 10px 16px;
  overflow-x: auto;
  flex-shrink: 0;
  scrollbar-width: none;
}
.filter-bar::-webkit-scrollbar { display: none; }
.pill {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 5px 12px;
  font-size: 12px;
  color: var(--subtext);
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
}
.pill.active { background: var(--accent); border-color: var(--accent); color: #000; font-weight: 600; }

/* ── Brew list ───────────────────────────────────────────────────────── */
.brew-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px 12px calc(var(--safe-bottom) + 80px);
  -webkit-overflow-scrolling: touch;
}
.brew-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
  margin-bottom: 10px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: border-color .15s;
}
.brew-card:active { border-color: var(--accent); }
.brew-card-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 4px;
}
.brew-coffee { font-weight: 700; font-size: 15px; }
.brew-method-badge {
  background: var(--border);
  border-radius: 6px;
  padding: 2px 8px;
  font-size: 11px;
  color: var(--subtext);
  white-space: nowrap;
  margin-left: 8px;
  flex-shrink: 0;
}
.brew-meta {
  font-size: 12px;
  color: var(--subtext);
  margin-bottom: 4px;
}
.brew-stats {
  display: flex;
  gap: 10px;
  font-size: 12px;
  color: var(--muted);
  flex-wrap: wrap;
}
.brew-stat-val { color: var(--text); font-weight: 600; }
.brew-notes-preview {
  font-size: 12px;
  color: var(--subtext);
  margin-top: 6px;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.brew-rating { color: var(--accent); font-size: 12px; }
.empty-state {
  text-align: center;
  color: var(--subtext);
  padding: 60px 24px;
  font-size: 14px;
  line-height: 1.8;
}

/* ── FAB ─────────────────────────────────────────────────────────────── */
.fab {
  position: fixed;
  bottom: calc(var(--safe-bottom) + 20px);
  right: 20px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--accent);
  border: none;
  color: #000;
  font-size: 28px;
  font-weight: 300;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(0,0,0,.5);
  display: flex;
  align-items: center;
  justify-content: center;
}
.fab-menu-wrap {
  position: fixed;
  bottom: calc(var(--safe-bottom) + 20px);
  right: 20px;
  z-index: 20;
}

.fab-menu {
  display: none;
  position: absolute;
  right: 0;
  bottom: 72px;
  min-width: 180px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: 0 18px 40px rgba(0,0,0,0.25);
  overflow: hidden;
}

.fab-menu.visible {
  display: block;
}

.fab-menu-item {
  width: 100%;
  border: none;
  background: transparent;
  color: var(--text);
  padding: 14px 16px;
  text-align: left;
  font-size: 14px;
  cursor: pointer;
}

.fab-menu-item:hover,
.fab-menu-item:focus {
  background: rgba(255,255,255,.05);
  outline: none;
}

.fab:active { transform: scale(.94); }

/* ── Form screen ─────────────────────────────────────────────────────── */
.form-scroll {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: calc(var(--safe-bottom) + 20px);
}

.ble-status-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.ble-status-text {
  font-size: 13px;
  line-height: 1.5;
  color: var(--subtext);
  padding: 10px 12px;
  background: rgba(255,255,255,.04);
  border: 1px solid var(--border);
  border-radius: 10px;
}

.ble-status-text.available {
  color: var(--text);
  border-color: #2a4b2f;
  background: rgba(39, 86, 55, 0.12);
}

.ble-status-text.unavailable {
  color: var(--subtext);
  border-color: #4b2f2f;
  background: rgba(86, 39, 39, 0.12);
}

.ble-device-info {
  font-size: 12px;
  color: var(--muted);
}

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

.ble-weight-row {
  font-size: 13px;
  color: var(--text);
}

.form-section {
  padding: 14px 16px 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.form-section label {
  font-size: 11px;
  font-weight: 600;
  color: var(--subtext);
  text-transform: uppercase;
  letter-spacing: .06em;
}
.form-section input,
.form-section select,
.form-section textarea {
  width: 100%;
  padding: 10px 12px;
  font-size: 16px; /* prevent iOS zoom on focus */
  line-height: 1.4;
}
.form-section textarea { resize: none; }
.form-section select { padding-right: 28px; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M0 0l6 8 6-8z' fill='%2388a'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 10px center; }

.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.time-field { display: flex; align-items: center; gap: 6px; }
.time-field input { flex: 1; }
.time-unit { color: var(--subtext); font-size: 13px; flex-shrink: 0; }

/* Method pills (in form) */
.method-pills-wrap {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.method-pill {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 5px 12px;
  font-size: 13px;
  color: var(--subtext);
  cursor: pointer;
}
.method-pill.active { background: var(--accent); border-color: var(--accent); color: #000; font-weight: 600; }

/* DYR row */
.dyr-row { display: flex; align-items: flex-end; gap: 10px; flex-wrap: wrap; }
.dyr-field { display: flex; flex-direction: column; gap: 4px; flex: 1; min-width: 80px; }
.dyr-lbl { font-size: 11px; color: var(--subtext); }
.dyr-field input { padding: 10px 10px; }
.dyr-toggle { display: flex; flex-direction: column; gap: 4px; flex-shrink: 0; padding-bottom: 1px; }
.dyr-mode {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 10px;
  font-size: 12px;
  color: var(--subtext);
  cursor: pointer;
}
.dyr-mode.active { background: var(--accent-dim); border-color: var(--accent); color: var(--accent); }

/* Tasting sliders */
.tasting-grid { display: flex; flex-direction: column; gap: 10px; }
.tasting-row {
  display: flex;
  align-items: center;
  gap: 10px;
}
.tasting-row > span:first-child { width: 72px; font-size: 13px; color: var(--subtext); flex-shrink: 0; }
.t-val { width: 24px; text-align: right; font-size: 13px; color: var(--accent); font-weight: 600; flex-shrink: 0; }

/* Rating stars */
.rating-stars { display: flex; gap: 6px; }
.star {
  font-size: 28px;
  cursor: pointer;
  color: var(--muted);
  transition: color .1s;
  -webkit-tap-highlight-color: transparent;
}
.star.on { color: var(--accent); }

/* Buttons */
.btn-primary {
  background: var(--accent);
  border: none;
  border-radius: 10px;
  color: #000;
  font-weight: 700;
  font-size: 16px;
  padding: 14px;
  cursor: pointer;
}
.btn-primary:active { opacity: .85; }
.btn-primary.full { width: 100%; }
.btn-danger {
  background: none;
  border: 1px solid var(--red);
  color: var(--red);
  border-radius: 10px;
  padding: 12px 20px;
  font-size: 14px;
  cursor: pointer;
}
.btn-danger:active { background: var(--red); color: #fff; }
.form-actions { padding: 16px 16px 0; }

.err-msg { color: #e74c3c; font-size: 13px; min-height: 18px; text-align: center; }

/* Loading skeleton */
.skeleton {
  background: linear-gradient(90deg, var(--card) 25%, var(--border) 50%, var(--card) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.2s infinite;
  border-radius: 8px;
  height: 80px;
  margin-bottom: 10px;
}
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }
