/* ===========================================================================
   DoughDeck — sage & terracotta visual identity
   Cool sage-mist surfaces, deep-pine ink, warm terracotta accent, ivory cards.
   Space Grotesk for headings/numerals, Inter for body. Calm, botanical, modern.
   (Variable names kept generic so the whole sheet recolours from this block.)
   ========================================================================= */

:root {
  /* Palette */
  --cream: #eef1e9; /* app background — sage mist */
  --cream-deep: #e2e7da;
  --surface: #fbfcf8; /* ivory cards */
  --surface-2: #f2f4ec;
  --ink: #283128; /* deep pine text */
  --ink-soft: #4a574a;
  --ink-mute: #7c887a;
  --crust: #3a4838; /* dark pine (headings / strong text) */
  --crust-deep: #283128;
  --amber: #c9603f; /* terracotta accent */
  --amber-deep: #a84b2d;
  --amber-wash: #f6e3db;
  --line: #dde3d6;
  --line-strong: #ccd4c3;
  --green: #54704f; /* sage (levain) */
  --green-wash: #e3eadf;
  --blue: #4f7e92; /* muted teal (water) */
  --blue-wash: #e0ebf0;
  --rose: #b5443a; /* clay red (danger) */
  --rose-wash: #f4dedb;

  /* Type */
  --serif: 'Space Grotesk', 'Inter', system-ui, -apple-system, 'Segoe UI',
    Roboto, Helvetica, Arial, sans-serif; /* display/heading face */
  --sans: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, Helvetica,
    Arial, sans-serif;

  /* Shape */
  --r-sm: 8px;
  --r: 14px;
  --r-lg: 22px;
  --shadow: 0 1px 2px rgba(79, 47, 24, 0.06), 0 6px 18px rgba(79, 47, 24, 0.07);
  --shadow-lg: 0 10px 40px rgba(79, 47, 24, 0.16);
  --maxw: 680px;
}

* {
  box-sizing: border-box;
}

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

body {
  font-family: var(--sans);
  color: var(--ink);
  background-color: var(--cream);
  /* Subtle flour-dusting grain so the cream isn't a flat fill. */
  background-image: radial-gradient(
      circle at 18% 12%,
      rgba(201, 96, 63, 0.05) 0,
      transparent 38%
    ),
    radial-gradient(
      circle at 84% 78%,
      rgba(110, 139, 106, 0.07) 0,
      transparent 42%
    );
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
  line-height: 1.5;
  min-height: 100vh;
}

h1,
h2,
h3 {
  font-family: var(--serif);
  font-weight: 600;
  line-height: 1.15;
  margin: 0;
  color: var(--crust-deep);
  letter-spacing: -0.01em;
}

button {
  font-family: inherit;
  cursor: pointer;
}

a {
  color: var(--amber-deep);
}

/* --- Layout shell -------------------------------------------------------- */
#app {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 0 16px calc(96px + env(safe-area-inset-bottom));
  min-height: 100vh;
}

.appbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: calc(12px + env(safe-area-inset-top)) 2px 12px;
  margin-bottom: 8px;
  background: linear-gradient(
    var(--cream) 72%,
    rgba(250, 244, 232, 0)
  );
}

.appbar .brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: var(--serif);
  font-weight: 700;
  font-size: 1.35rem;
  color: var(--crust-deep);
  letter-spacing: -0.02em;
  text-decoration: none;
}

.appbar .brand .logo {
  width: 34px;
  height: 34px;
  flex: none;
  filter: drop-shadow(0 2px 3px rgba(107, 66, 38, 0.25));
}

.appbar .spacer {
  flex: 1;
}

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: none;
  border: none;
  color: var(--ink-soft);
  font-size: 0.95rem;
  font-weight: 500;
  padding: 8px 4px;
  margin-left: -4px;
}
.back-link:hover {
  color: var(--crust);
}

/* --- Buttons ------------------------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 11px 18px;
  font-size: 0.95rem;
  font-weight: 600;
  background: var(--surface);
  color: var(--crust);
  border-color: var(--line-strong);
  transition: transform 0.06s ease, background 0.15s ease, box-shadow 0.15s ease;
}
.btn:hover {
  background: var(--surface-2);
}
.btn:active {
  transform: translateY(1px);
}
.btn.primary {
  background: linear-gradient(180deg, var(--amber), var(--amber-deep));
  color: #fff;
  border-color: var(--amber-deep);
  box-shadow: 0 4px 12px rgba(181, 111, 30, 0.32);
}
.btn.primary:hover {
  background: linear-gradient(180deg, #d6724f, var(--amber-deep));
}
.btn.crust {
  background: var(--crust);
  color: #fdf6ea;
  border-color: var(--crust-deep);
}
.btn.crust:hover {
  background: var(--crust-deep);
}
.btn.ghost {
  background: transparent;
  border-color: transparent;
  color: var(--ink-soft);
}
.btn.ghost:hover {
  background: var(--surface-2);
}
.btn.danger {
  color: var(--rose);
  border-color: var(--rose-wash);
  background: var(--rose-wash);
}
.btn.block {
  width: 100%;
}
.btn.sm {
  padding: 7px 13px;
  font-size: 0.85rem;
}
.btn[disabled] {
  opacity: 0.5;
  pointer-events: none;
}

.btn-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

/* Floating compose action on the home screen. */
.fab {
  position: fixed;
  right: max(18px, calc(50% - var(--maxw) / 2 + 18px));
  bottom: calc(20px + env(safe-area-inset-bottom));
  z-index: 30;
  border-radius: 999px;
  padding: 15px 22px;
  font-size: 1rem;
  box-shadow: var(--shadow-lg);
}

/* --- Cards --------------------------------------------------------------- */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow);
  padding: 18px;
  margin-bottom: 14px;
}

.section-label {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--ink-mute);
  margin: 22px 2px 10px;
}

/* --- Category tabs ------------------------------------------------------- */
.tabs {
  display: flex;
  gap: 6px;
  background: var(--cream-deep);
  border-radius: 999px;
  padding: 5px;
  margin: 6px 0 18px;
}
.tabs button {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border: none;
  background: transparent;
  color: var(--ink-soft);
  font-family: var(--serif);
  font-weight: 600;
  font-size: 0.95rem;
  letter-spacing: -0.01em;
  padding: 11px 8px;
  border-radius: 999px;
  transition: background 0.18s, color 0.18s, box-shadow 0.18s;
}
.tabs button .count {
  font-family: var(--sans);
  font-size: 0.72rem;
  font-weight: 700;
  background: var(--line);
  color: var(--ink-mute);
  border-radius: 999px;
  padding: 1px 8px;
  min-width: 20px;
}
.tabs button.active {
  background: var(--surface);
  color: var(--crust-deep);
  box-shadow: var(--shadow);
}
.tabs button.active .count {
  background: var(--amber-wash);
  color: var(--amber-deep);
}

/* --- Recipe list --------------------------------------------------------- */
.recipe-card {
  display: block;
  width: 100%;
  text-align: left;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow);
  padding: 16px 18px;
  margin-bottom: 12px;
  transition: transform 0.08s ease, box-shadow 0.15s ease, border-color 0.15s;
}
.recipe-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
  border-color: var(--line-strong);
}
.recipe-card:active {
  transform: translateY(0);
}
.recipe-card .title-row {
  display: flex;
  align-items: baseline;
  gap: 10px;
}
.recipe-card h3 {
  font-size: 1.3rem;
  flex: 1;
}
.recipe-card .meta {
  color: var(--ink-mute);
  font-size: 0.9rem;
  margin-top: 4px;
}
.recipe-card .chips {
  margin-top: 10px;
}
.recipe-card .chips:empty {
  display: none;
}

/* --- Lineage tree (home) ------------------------------------------------- */
.tree-row {
  display: flex;
  align-items: center;
  gap: 4px;
}
.tree-row .recipe-card {
  flex: 1;
  margin-bottom: 0;
}
.caret {
  flex: none;
  width: 36px;
  height: 36px;
  align-self: center;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--amber-wash);
  border: 1px solid #ecd2c4;
  color: var(--amber-deep);
  font-size: 1.35rem;
  line-height: 1;
  border-radius: 50%;
  padding: 0;
  box-shadow: var(--shadow);
  transition: background 0.15s, transform 0.08s;
}
.caret:not(.leaf):hover {
  background: #f0d6c6;
}
.caret:not(.leaf):active {
  transform: scale(0.92);
}
.caret.leaf {
  width: 12px;
  background: none;
  border: none;
  box-shadow: none;
  cursor: default;
}
.tree-node {
  margin-bottom: 12px;
}
.tree-node .tree-node {
  margin-bottom: 10px;
}
/* Indented children with a guide rail. */
.tree-children {
  margin: 2px 0 0 18px;
  padding-left: 14px;
  border-left: 2px solid var(--line-strong);
}
.variant-note {
  color: var(--amber-deep);
  font-weight: 600;
}

/* --- Chips / tags -------------------------------------------------------- */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 0.76rem;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--ink-soft);
  border: 1px solid var(--line);
  margin: 0 6px 6px 0;
}
.chip.flour {
  background: var(--amber-wash);
  color: var(--amber-deep);
  border-color: #ecd6b0;
}
.chip.water {
  background: var(--blue-wash);
  color: var(--blue);
  border-color: #cfe0eb;
}
.chip.levain {
  background: var(--green-wash);
  color: var(--green);
  border-color: #cfe2cb;
}
.chip.branch {
  background: #efe7f5;
  color: #7a5a99;
  border-color: #e0d2ee;
}
.chip.builtin {
  background: var(--cream-deep);
  color: var(--ink-mute);
}

/* --- Recipe view --------------------------------------------------------- */
.recipe-hero {
  padding: 6px 2px 4px;
}
.hero-title {
  display: flex;
  align-items: center;
  gap: 12px;
}
.version-badge {
  flex: none;
  font-family: var(--sans);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--amber-deep);
  background: var(--amber-wash);
  border: 1px solid #ecd2c4;
  border-radius: 999px;
  padding: 3px 10px;
  align-self: center;
  transform: translateY(2px);
}
.recipe-hero h1 {
  font-size: 2.1rem;
  font-weight: 700;
}
.recipe-hero .sub {
  color: var(--ink-mute);
  margin-top: 6px;
  font-size: 0.95rem;
}
.lineage {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  margin-top: 10px;
  font-size: 0.9rem;
  color: #7a5a99;
  background: #efe7f5;
  border: 1px solid #e0d2ee;
  padding: 6px 12px;
  border-radius: 999px;
}
.lineage button {
  background: none;
  border: none;
  color: #6b4a8c;
  font-weight: 600;
  text-decoration: underline;
  cursor: pointer;
  padding: 0;
}

/* Ingredient table */
.ingredients {
  width: 100%;
  border-collapse: collapse;
}
.ingredients th {
  text-align: left;
  font-size: 0.72rem;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--ink-mute);
  font-weight: 700;
  padding: 0 0 8px;
}
.ingredients td {
  padding: 10px 0;
  border-top: 1px solid var(--line);
  vertical-align: middle;
}
.ingredients .name {
  font-weight: 600;
  color: var(--ink);
}
.ingredients .num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.ingredients .pct {
  color: var(--ink-mute);
  text-align: right;
  font-variant-numeric: tabular-nums;
  width: 64px;
}
.ingredients .grams {
  font-weight: 700;
  color: var(--crust-deep);
  width: 88px;
}
.ingredients tr.total td {
  border-top: 2px solid var(--line-strong);
  padding-top: 12px;
  font-weight: 700;
  color: var(--crust-deep);
}
.dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 8px;
  vertical-align: middle;
}
.dot.flour {
  background: var(--amber);
}
.dot.water {
  background: var(--blue);
}
.dot.levain {
  background: var(--green);
}
.dot.other {
  background: var(--line-strong);
}

/* Hydration readout */
.readout {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 4px;
}
.stat {
  flex: 1 1 120px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 12px 14px;
}
.stat .k {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-mute);
  font-weight: 700;
}
.stat .v {
  font-family: var(--serif);
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--crust-deep);
  margin-top: 2px;
  font-variant-numeric: tabular-nums;
}
.stat .v small {
  font-size: 0.8rem;
  color: var(--ink-mute);
  font-family: var(--sans);
}
.stat.highlight {
  background: var(--amber-wash);
  border-color: #ecd6b0;
}

/* --- Calculator ---------------------------------------------------------- */
.seg {
  display: flex;
  background: var(--cream-deep);
  border-radius: 999px;
  padding: 4px;
  gap: 4px;
}
.seg button {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--ink-soft);
  font-weight: 600;
  font-size: 0.9rem;
  padding: 9px 6px;
  border-radius: 999px;
  transition: background 0.15s, color 0.15s, box-shadow 0.15s;
}
.seg button.active {
  background: var(--surface);
  color: var(--crust-deep);
  box-shadow: var(--shadow);
}

.big-input {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 16px 0 6px;
}
.big-input input {
  flex: 1;
  width: 100%;
  font-family: var(--serif);
  font-size: 2.2rem;
  font-weight: 600;
  text-align: center;
  color: var(--crust-deep);
  background: var(--surface-2);
  border: 1.5px solid var(--line-strong);
  border-radius: var(--r);
  padding: 10px 14px;
  font-variant-numeric: tabular-nums;
}
.big-input input:focus {
  outline: none;
  border-color: var(--amber);
  box-shadow: 0 0 0 3px var(--amber-wash);
}
.input-suffix {
  font-size: 1rem;
  color: var(--ink-mute);
  min-width: 64px;
}

/* --- Forms --------------------------------------------------------------- */
label.field {
  display: block;
  margin-bottom: 14px;
}
label.field .lab {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--ink-soft);
  margin-bottom: 6px;
}
input[type='text'],
input[type='number'],
input[type='email'],
input[type='date'],
textarea,
select {
  width: 100%;
  font-family: var(--sans);
  font-size: 1rem;
  color: var(--ink);
  background: var(--surface);
  border: 1.5px solid var(--line-strong);
  border-radius: var(--r-sm);
  padding: 11px 13px;
}
input:focus,
textarea:focus,
select:focus {
  outline: none;
  border-color: var(--amber);
  box-shadow: 0 0 0 3px var(--amber-wash);
}
textarea {
  resize: vertical;
  min-height: 80px;
}
.row2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

/* Ingredient editor rows */
.ing-edit {
  display: grid;
  grid-template-columns: 1fr 78px auto;
  gap: 8px;
  align-items: center;
  padding: 10px 0;
  border-top: 1px solid var(--line);
}
.ing-edit .flags {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}
.flags-lead {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-mute);
  margin-right: 2px;
}
/* Unselected type options read as a choice, not a label. */
.flag-toggle {
  cursor: pointer;
  border-style: dashed;
}
.flag-toggle.on {
  border-style: solid;
}
.flag-toggle {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 0.78rem;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--ink-mute);
  user-select: none;
}
.flag-toggle.on.flour {
  background: var(--amber-wash);
  color: var(--amber-deep);
  border-color: #ecd6b0;
}
.flag-toggle.on.water {
  background: var(--blue-wash);
  color: var(--blue);
  border-color: #cfe0eb;
}
.flag-toggle.on.levain {
  background: var(--green-wash);
  color: var(--green);
  border-color: #cfe2cb;
}
.icon-btn {
  background: none;
  border: none;
  color: var(--ink-mute);
  font-size: 1.1rem;
  padding: 6px 8px;
  border-radius: var(--r-sm);
  line-height: 1;
}
.icon-btn:hover {
  background: var(--rose-wash);
  color: var(--rose);
}

/* --- Bake notes ---------------------------------------------------------- */
.note {
  border-left: 3px solid var(--amber);
  padding: 4px 0 4px 14px;
  margin-bottom: 16px;
}
.note .date {
  font-weight: 700;
  color: var(--crust-deep);
  font-family: var(--serif);
}
.note .body {
  color: var(--ink-soft);
  margin-top: 4px;
  white-space: pre-wrap;
}
.note .snap {
  font-size: 0.78rem;
  color: var(--ink-mute);
  margin-top: 6px;
}

/* --- Empty state --------------------------------------------------------- */
.empty {
  text-align: center;
  padding: 48px 20px;
  color: var(--ink-mute);
}
.empty .big {
  font-size: 3rem;
  margin-bottom: 8px;
}
.empty h2 {
  margin-bottom: 6px;
}

/* --- Toast --------------------------------------------------------------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(28px + env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(24px);
  background: var(--crust-deep);
  color: #fdf6ea;
  padding: 12px 20px;
  border-radius: 999px;
  font-size: 0.9rem;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 100;
  max-width: 90vw;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* --- Modal --------------------------------------------------------------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(46, 32, 19, 0.42);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 90;
  padding: 0;
  animation: fade 0.15s ease;
}
@media (min-width: 560px) {
  .modal-backdrop {
    align-items: center;
    padding: 20px;
  }
}
.modal {
  background: var(--surface);
  border-radius: var(--r-lg) var(--r-lg) 0 0;
  width: 100%;
  max-width: 480px;
  padding: 22px 20px calc(22px + env(safe-area-inset-bottom));
  box-shadow: var(--shadow-lg);
  animation: rise 0.2s ease;
}
@media (min-width: 560px) {
  .modal {
    border-radius: var(--r-lg);
  }
}
.modal h2 {
  font-size: 1.4rem;
  margin-bottom: 12px;
}
.modal p {
  color: var(--ink-soft);
  margin: 0 0 16px;
}
@keyframes rise {
  from {
    transform: translateY(24px);
    opacity: 0;
  }
}
@keyframes fade {
  from {
    opacity: 0;
  }
}

/* --- Settings list ------------------------------------------------------- */
.setting-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 0;
  border-top: 1px solid var(--line);
}
.setting-row:first-child {
  border-top: none;
}
.setting-row .grow {
  flex: 1;
}
.setting-row .desc {
  font-size: 0.85rem;
  color: var(--ink-mute);
  margin-top: 2px;
}

/* --- Misc ---------------------------------------------------------------- */
.muted {
  color: var(--ink-mute);
}
.hint {
  font-size: 0.85rem;
  color: var(--ink-mute);
  margin-top: 6px;
}
.banner-ad {
  /* Phase-9 AdMob slot lives here when premium is inactive. Never overlaps or
     gates content. */
  display: none;
}
hr.soft {
  border: none;
  border-top: 1px solid var(--line);
  margin: 18px 0;
}
.fadein {
  animation: fade 0.2s ease;
}
