:root {
  --bg: #16110e;
  --surface: #211a16;
  --surface-2: #2c231e;
  --line: #3a2f28;
  --text: #f4ece4;
  --muted: #a8998c;
  --accent: #d4955a;
  --accent-2: #f0b97f;
  --accent-ink: #1b120b;
  --danger: #e2675a;
  --good: #8cc084;
  --radius: 18px;
  --radius-sm: 12px;
  --shadow: 0 10px 30px rgba(0, 0, 0, .35);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f6f1ec;
    --surface: #ffffff;
    --surface-2: #f1e9e1;
    --line: #e4d8cc;
    --text: #2a1d15;
    --muted: #85725f;
    --accent: #b36b2c;
    --accent-2: #8f5220;
    --accent-ink: #ffffff;
    --shadow: 0 10px 30px rgba(80, 50, 20, .12);
    color-scheme: light;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body { margin: 0; background: var(--bg); color: var(--text); }

body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Inter", "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.45;
  min-height: 100dvh;
  padding-bottom: calc(110px + var(--safe-bottom));
  -webkit-font-smoothing: antialiased;
}

svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- Top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 8px;
  padding: calc(10px + var(--safe-top)) 16px 10px;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid color-mix(in srgb, var(--line) 60%, transparent);
}
.topbar h1 { flex: 1; margin: 0; font-size: 22px; font-weight: 750; letter-spacing: -.02em; }
.icon-btn {
  display: grid; place-items: center; width: 40px; height: 40px;
  border: 0; border-radius: 12px; background: var(--surface-2); color: var(--text); cursor: pointer;
}
.icon-btn[hidden] { display: none; }

main { max-width: 640px; margin: 0 auto; padding: 16px; }

/* ---------- FAB ---------- */
.fab {
  position: fixed; right: 20px; bottom: calc(24px + var(--safe-bottom)); z-index: 20;
  width: 62px; height: 62px; border-radius: 20px; border: 0; cursor: pointer;
  display: grid; place-items: center;
  background: linear-gradient(145deg, var(--accent-2), var(--accent));
  color: var(--accent-ink); box-shadow: 0 12px 28px rgba(212, 149, 90, .4);
  transition: transform .15s ease;
}
.fab:active { transform: scale(.94); }
.fab svg { width: 28px; height: 28px; stroke-width: 2.5; }
.fab[hidden] { display: none; }

/* ---------- Stats ---------- */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 18px; }
.stat {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 12px; text-align: center;
}
.stat b { display: block; font-size: 22px; font-weight: 750; letter-spacing: -.02em; }
.stat span { font-size: 12px; color: var(--muted); }

/* ---------- Filter ---------- */
.filters { display: flex; gap: 8px; overflow-x: auto; margin: 0 -16px 14px; padding: 0 16px; scrollbar-width: none; }
.filters::-webkit-scrollbar { display: none; }

/* ---------- Shot cards ---------- */
.list { display: flex; flex-direction: column; gap: 12px; }
.day { font-size: 13px; font-weight: 650; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; margin: 10px 4px 0; }
.card {
  display: block; width: 100%; text-align: left; font: inherit; color: inherit; cursor: pointer;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 16px; box-shadow: var(--shadow);
  transition: transform .12s ease;
}
.card:active { transform: scale(.985); }
.card-head { display: flex; align-items: center; gap: 10px; }
.swatch { width: 34px; height: 34px; border-radius: 50%; flex: none; border: 2px solid var(--line); }
.card-title { flex: 1; min-width: 0; }
.card-title strong { display: block; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-title small { color: var(--muted); font-size: 13px; }
.stars-sm { color: var(--accent); font-size: 15px; letter-spacing: 1px; white-space: nowrap; }
.metrics { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }
.metric { background: var(--surface-2); border-radius: 8px; padding: 4px 9px; font-size: 13px; font-variant-numeric: tabular-nums; }
.metric em { font-style: normal; color: var(--muted); margin-right: 3px; }
.card-tags { margin-top: 8px; font-size: 13px; color: var(--muted); }

.empty { text-align: center; padding: 60px 20px; color: var(--muted); }
.empty .cup { font-size: 56px; margin-bottom: 10px; }
.empty h2 { color: var(--text); margin: 0 0 6px; font-size: 20px; }

/* ---------- Form ---------- */
.section {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; margin-bottom: 14px;
}
.section h2 { margin: 0 0 14px; font-size: 13px; font-weight: 700; color: var(--accent); text-transform: uppercase; letter-spacing: .08em; display: flex; align-items: center; justify-content: space-between; }
.grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 12px; }
.field { min-width: 0; }
.grid .full { grid-column: 1 / -1; }

.field label { display: block; font-size: 13px; color: var(--muted); margin: 0 0 6px 2px; }
.field label .unit { opacity: .7; }

input, select, textarea {
  width: 100%; font: inherit; font-size: 16px; color: var(--text);
  background: var(--surface-2); border: 1px solid transparent; border-radius: var(--radius-sm);
  padding: 12px 14px; outline: none; appearance: none; -webkit-appearance: none;
  transition: border-color .15s;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
textarea { min-height: 90px; resize: vertical; }
select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23a8998c' stroke-width='2.5' stroke-linecap='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center; background-size: 16px;
  padding-right: 36px;
}
input[type="date"], input[type="datetime-local"] { min-height: 48px; min-width: 0; max-width: 100%; display: block; }
input::-webkit-date-and-time-value { text-align: left; }

/* Stepper */
.stepper { display: flex; align-items: stretch; background: var(--surface-2); border-radius: var(--radius-sm); overflow: hidden; border: 1px solid transparent; }
.stepper:focus-within { border-color: var(--accent); }
.stepper input { background: transparent; border: 0; text-align: center; padding: 12px 4px; font-weight: 650; font-variant-numeric: tabular-nums; min-width: 0; }
.stepper button {
  flex: none; width: 42px; border: 0; background: transparent; color: var(--accent);
  font-size: 22px; font-weight: 600; cursor: pointer;
}
.stepper button:active { background: color-mix(in srgb, var(--accent) 18%, transparent); }

/* Ratio pill */
.ratio {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  margin-top: 14px; padding: 12px 14px; border-radius: var(--radius-sm);
  background: color-mix(in srgb, var(--accent) 12%, var(--surface-2));
  font-size: 14px;
}
.ratio b { font-size: 18px; font-variant-numeric: tabular-nums; }

/* Chips */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  font: inherit; font-size: 14px; color: var(--text); cursor: pointer; white-space: nowrap;
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 999px; padding: 7px 13px;
  transition: all .12s;
}
.chip[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }

/* Color picker */
.colors { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
.color-opt {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  font: inherit; font-size: 11px; color: var(--muted); background: none; border: 0; cursor: pointer; padding: 4px 0;
}
.color-opt i { width: 42px; height: 42px; border-radius: 50%; border: 3px solid transparent; outline: 1px solid var(--line); transition: transform .12s; }
.color-opt[aria-pressed="true"] { color: var(--text); font-weight: 600; }
.color-opt[aria-pressed="true"] i { border-color: var(--bg); outline: 2px solid var(--accent); transform: scale(1.08); }

/* Stars */
.stars { display: flex; gap: 6px; justify-content: center; padding: 4px 0; }
.star { font-size: 38px; line-height: 1; background: none; border: 0; cursor: pointer; color: var(--line); padding: 2px; transition: transform .1s; }
.star.on { color: var(--accent); }
.star:active { transform: scale(1.2); }

/* Toggle */
.toggle { display: flex; align-items: center; gap: 10px; font-size: 14px; color: var(--muted); text-transform: none; letter-spacing: 0; font-weight: 500; cursor: pointer; }
.toggle input { display: none; }
.toggle span { width: 44px; height: 26px; border-radius: 99px; background: var(--surface-2); border: 1px solid var(--line); position: relative; transition: .2s; }
.toggle span::after { content: ""; position: absolute; top: 2px; left: 2px; width: 20px; height: 20px; border-radius: 50%; background: var(--muted); transition: .2s; }
.toggle input:checked + span { background: var(--accent); border-color: var(--accent); }
.toggle input:checked + span::after { left: 20px; background: var(--accent-ink); }

/* Hint */
.hint {
  display: flex; gap: 10px; padding: 12px 14px; margin-top: 14px; border-radius: var(--radius-sm);
  background: var(--surface-2); font-size: 14px; border-left: 3px solid var(--accent);
}
.hint:empty { display: none; }

/* Buttons */
.actions { display: flex; flex-direction: column; gap: 10px; margin-top: 6px; }
.btn {
  font: inherit; font-weight: 650; font-size: 16px; cursor: pointer; border: 0;
  border-radius: var(--radius-sm); padding: 15px; width: 100%;
  background: var(--surface-2); color: var(--text);
}
.btn.primary { background: linear-gradient(145deg, var(--accent-2), var(--accent)); color: var(--accent-ink); }
.btn.danger { background: transparent; color: var(--danger); }
.btn:active { opacity: .85; }
.row { display: flex; gap: 10px; }
.row .btn { flex: 1; }

.muted { color: var(--muted); font-size: 14px; }
.settings p { margin: 0 0 12px; }

/* Toast */
.toast {
  position: fixed; left: 50%; bottom: calc(100px + var(--safe-bottom)); transform: translate(-50%, 20px);
  background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 999px;
  font-size: 14px; font-weight: 600; opacity: 0; pointer-events: none; transition: .25s; z-index: 50;
  max-width: calc(100% - 32px); text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (min-width: 700px) {
  .fab { right: calc(50% - 320px + 4px); }
}
[hidden] { display: none !important; }
