:root {
  --bg-main: #020617;
  --bg-card: #020617;
  --bg-card-soft: #020617;
  --border-subtle: rgba(148, 163, 184, 0.45);
  --border-strong: rgba(148, 163, 184, 0.7);
  --text-main: #e5e7eb;
  --text-soft: #9ca3af;
  --accent: #38bdf8;
  --accent-soft: rgba(56, 189, 248, 0.25);
  --danger: #f97373;
  --radius-lg: 20px;
  --radius-md: 10px;
  --radius-pill: 999px;
  --shadow-card: 0 18px 40px rgba(15, 23, 42, 0.8);
  --bg-gradient: radial-gradient(circle at top left, #0f172a, #020617 55%, #000 100%);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "SF Pro Text",
    "Segoe UI", sans-serif;
  color: var(--text-main);
  background: var(--bg-gradient);
}

body {
  min-height: 100vh;
}

.app {
  max-width: 960px;
  margin: 24px auto 40px;
  padding: 0 16px 40px;
}

/* HEADER */

.app-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 12px;
  margin-bottom: 16px;
}

.app-header h1 {
  margin: 0;
  font-size: 1.6rem;
  letter-spacing: 0.02em;
}

.subheading {
  margin: 4px 0 0;
  font-size: 0.9rem;
  color: var(--text-soft);
}

.version-pill {
  align-self: flex-start;
  padding: 4px 10px;
  border-radius: var(--radius-pill);
  border: 1px solid rgba(148, 163, 184, 0.4);
  background: radial-gradient(circle at top left, #0f172a, #020617);
  font-size: 0.7rem;
  color: var(--text-soft);
}

/* CARDS */

.card {
  background: radial-gradient(circle at top left, #020617, #020617 60%, #000);
  border-radius: var(--radius-lg);
  border: 1px solid rgba(148, 163, 184, 0.45);
  box-shadow: var(--shadow-card);
  padding: 16px 18px 18px;
  margin-bottom: 16px;
  position: relative;
}

/* RESULT CARD */

.result-card {
  margin-top: 8px;
}

.result-header {
  font-size: 0.8rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-soft);
  margin-bottom: 8px;
}

.result-main {
  display: flex;
  align-items: baseline;
  gap: 6px;
  font-size: 2.2rem;
  font-weight: 600;
}

.result-main span#bulk-min {
  font-feature-settings: "tnum" 1;
}

.result-main-unit {
  font-size: 1rem;
  color: var(--text-soft);
}

.result-lines {
  margin-top: 6px;
  font-size: 0.85rem;
  color: var(--text-soft);
}

.result-lines div + div {
  margin-top: 2px;
}

/* TEMP RISE CARD */

.temp-rise-card {
  border-style: dashed;
  border-radius: 16px;
}

.card-title-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
}

.card-title-main {
  font-weight: 500;
  font-size: 0.9rem;
}

.card-title-pill {
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid rgba(148, 163, 184, 0.4);
  font-size: 0.7rem;
  color: var(--text-soft);
}

.card-muted {
  margin: 0 0 4px;
  font-size: 0.8rem;
  color: var(--text-soft);
}

.temp-rise-footer {
  margin-top: 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-size: 0.85rem;
  color: var(--text-soft);
}

.temp-rise-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.temp-rise-label input {
  width: 68px;
  padding: 4px 6px;
  border-radius: 6px;
  border: 1px solid rgba(148, 163, 184, 0.5);
  background: rgba(15, 23, 42, 0.8);
  color: #e5e7eb;
  font-size: 0.8rem;
}

.temp-rise-label input:focus {
  outline: 1px solid var(--accent);
  outline-offset: 1px;
  border-color: var(--accent);
}

.temp-rise-value {
  font-weight: 600;
  color: #e5e7eb;
  font-feature-settings: "tnum" 1;
}

/* SMALL SUMMARY LINES */

.setup-summary,
.grain-summary {
  margin: 6px 0;
  font-size: 0.8rem;
  color: var(--text-soft);
}

/* TABS */

.tabs-card {
  padding-top: 12px;
}

.tab-header {
  display: flex;
  background: radial-gradient(circle at top left, #020617, #000);
  border-radius: var(--radius-pill);
  border: 1px solid rgba(148, 163, 184, 0.45);
  padding: 2px;
  margin-bottom: 10px;
}

/* Fix iPhone / Safari weirdness on tab buttons */
.tab-button {
  -webkit-appearance: none; /* kill default iOS button look */
  appearance: none;
  border: none;             /* you already mostly have this */
  background-clip: padding-box;
}

/* Make the pill container clip child buttons cleanly */
.tab-header {
  position: relative;
  overflow: hidden;         /* prevents active tab glow from spilling */
  border-radius: var(--radius-pill);
}

/* Optional: nicer layout on narrow screens (iPhone) */
@media (max-width: 600px) {
  .tab-header {
    flex-direction: column;
  }

  .tab-button {
    width: 100%;
    justify-content: center;
    border-radius: 0;                  /* flat edges between rows */
  }

  .tab-button:first-child {
    border-top-left-radius: var(--radius-pill);
    border-top-right-radius: var(--radius-pill);
  }

  .tab-button:last-child {
    border-bottom-left-radius: var(--radius-pill);
    border-bottom-right-radius: var(--radius-pill);
  }
}

.tab-button {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text-soft);
  font-size: 0.82rem;
  padding: 6px 10px;
  border-radius: var(--radius-pill);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.tab-button-active {
  background: radial-gradient(circle at top left, rgba(56, 189, 248, 0.18), #020617);
  color: var(--text-main);
  box-shadow: 0 0 0 1px rgba(56, 189, 248, 0.5);
}

.tab-panel {
  display: none;
  padding-top: 4px;
}

.tab-panel-active {
  display: block;
}

/* FIELDS */

.inline-row {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
}

.field-group {
  flex: 1 1 220px;
  min-width: 0;
  margin-bottom: 10px;
}

.field-group label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.82rem;
  margin-bottom: 4px;
}

.field-tag {
  font-size: 0.7rem;
  padding: 1px 6px;
  border-radius: 999px;
  border: 1px solid rgba(148, 163, 184, 0.4);
  color: var(--text-soft);
}

.field-group input[type="number"],
.field-group input[type="text"],
.field-group select {
  width: 100%;
  max-width: 260px;        /* smaller “text boxes” */
  height: 34px;
  padding: 4px 10px;
  border-radius: var(--radius-md);
  border: 1px solid rgba(148, 163, 184, 0.55);
  background: rgba(15, 23, 42, 0.9);
  color: var(--text-main);
  font-size: 0.86rem;
}

.field-group select {
  padding-right: 30px;
}

.field-group input:focus,
.field-group select:focus {
  outline: 1px solid var(--accent);
  outline-offset: 1px;
  border-color: var(--accent);
}

.field-group small {
  display: block;
  margin-top: 3px;
  font-size: 0.75rem;
  color: var(--text-soft);
}

/* TAG ROWS */

.tag-row {
  margin-top: 6px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.tag {
  border-radius: 999px;
  border: 1px solid rgba(148, 163, 184, 0.45);
  background: rgba(15, 23, 42, 0.9);
  color: var(--text-soft);
  font-size: 0.74rem;
  padding: 4px 10px;
  cursor: pointer;
}

.tag.active {
  background: radial-gradient(circle at top left, rgba(56, 189, 248, 0.2), #020617);
  color: var(--text-main);
  border-color: rgba(56, 189, 248, 0.8);
}

/* GRAINS */

.grain-rows {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.grain-row {
  display: flex;
  gap: 6px;
  flex-wrap: nowrap;
}

.grain-row .grain-select {
  max-width: 220px;
}

.grain-row .grain-percent {
  max-width: 80px;
}

.grain-warning {
  margin-top: 6px;
  font-size: 0.75rem;
}

.grain-warning-low {
  color: #fbbf24;
}

.grain-warning-high {
  color: #f97373;
}

.grain-warning-ok {
  color: #22c55e;
}

.grain-grams-output {
  font-size: 0.8rem;
}

.grain-grams-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
}

.grain-grams-table th,
.grain-grams-table td {
  padding: 4px 6px;
  border-bottom: 1px solid rgba(30, 64, 175, 0.6);
}

.grain-grams-table th {
  text-align: left;
  color: var(--text-soft);
}

.grain-grams-table .total-row td {
  border-top: 1px solid rgba(148, 163, 184, 0.7);
}

/* DOUGH FORMULA */

.formula-box {
  padding: 8px 10px;
  border-radius: 12px;
  background: radial-gradient(circle at top left, rgba(15, 23, 42, 0.95), #000);
  border: 1px solid rgba(148, 163, 184, 0.5);
  font-size: 0.82rem;
}

.formula-box-title {
  font-weight: 500;
  margin-bottom: 4px;
}

.formula-box-line + .formula-box-line {
  margin-top: 2px;
}

/* BUTTONS */

.primary-btn,
.secondary-btn,
.danger-btn {
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 0.8rem;
  border: none;
  cursor: pointer;
  font-weight: 500;
}

.primary-btn {
  background: linear-gradient(135deg, #38bdf8, #0ea5e9);
  color: #0b1120;
}

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

.secondary-btn {
  background: rgba(15, 23, 42, 0.9);
  color: var(--text-main);
  border: 1px solid rgba(148, 163, 184, 0.7);
}

.secondary-btn:hover {
  border-color: var(--accent);
}

.danger-btn {
  background: rgba(248, 113, 113, 0.15);
  color: #fecaca;
  border: 1px solid rgba(248, 113, 113, 0.6);
}

.danger-btn:hover {
  background: rgba(248, 113, 113, 0.25);
}

/* TIMER */

.timer-card {
  margin-top: 4px;
}

.timer-header h2 {
  margin: 0 0 4px;
  font-size: 1rem;
}

.timer-card p {
  margin: 2px 0;
  font-size: 0.8rem;
}

.timer-help {
  display: block;
  margin-top: 6px;
  font-size: 0.75rem;
  color: var(--text-soft);
}

.timer-actions {
  margin-top: 10px;
  display: flex;
  gap: 8px;
}

.timer-progress-wrapper {
  margin-top: 8px;
  height: 6px;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.95);
  border: 1px solid rgba(56, 189, 248, 0.25);
  overflow: hidden;
}

.timer-progress-bar {
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, #22c55e, #38bdf8);
  transition: width 0.25s linear;
}

/* Fold counter pills under "Folds done" */
.fold-counter {
  margin: 6px 0 4px;
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.fold-counter-pill {
  min-width: 28px;
  padding: 2px 6px;
  border-radius: 999px;
  border: 1px solid rgba(148, 163, 184, 0.5);
  font-size: 0.72rem;
  text-align: center;
}

.fold-counter-pill-pending {
  background: rgba(15, 23, 42, 0.95);
  color: var(--text-soft);
}

.fold-counter-pill-done {
  background: rgba(34, 197, 94, 0.18);
  color: #bbf7d0;
  border-color: rgba(34, 197, 94, 0.7);
}

/* HANDLING WARNING */

.handling-warning {
  font-size: 0.8rem;
  color: var(--text-soft);
}

/* PRESETS / NOTES */

.preset-actions {
  margin: 8px 0;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.clear-row {
  margin-top: 6px;
}

textarea#notes {
  width: 100%;
  max-width: 100%;
  min-height: 110px; /* smaller but comfortable */
  padding: 8px 10px;
  border-radius: 12px;
  border: 1px solid rgba(148, 163, 184, 0.6);
  background: rgba(15, 23, 42, 0.95);
  color: var(--text-main);
  font-size: 0.86rem;
  resize: vertical;
}

/* ACCORDION */

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
}

.card-header-left {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.card-header h2 {
  margin: 0;
  font-size: 0.9rem;
}

.card-header-icon {
  font-size: 1rem;
}

.card-collapse-toggle {
  border: none;
  background: transparent;
  padding: 4px;
  border-radius: 999px;
  cursor: pointer;
}

.chevron {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-right: 2px solid var(--text-soft);
  border-bottom: 2px solid var(--text-soft);
  transform: rotate(45deg);
  transition: transform 0.2s ease, border-color 0.2s ease;
}

.card-collapse-toggle.collapsed .chevron {
  transform: rotate(-135deg);
}

.card-collapsible .card-body {
  transition: opacity 0.18s ease;
}

.card-collapsible.card-collapsed .card-body {
  opacity: 0;
}

/* NOTES LABEL TEXT */

.card[data-section="notes"] small {
  display: block;
  margin-top: 4px;
  font-size: 0.75rem;
  color: var(--text-soft);
}

/* ALARM OVERLAY */

.alarm-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 40;
}

.alarm-overlay.hidden {
  display: none;
}

.alarm-modal {
  background: radial-gradient(circle at top left, #020617, #000);
  border-radius: 16px;
  border: 1px solid rgba(248, 250, 252, 0.25);
  padding: 18px 20px 16px;
  min-width: 260px;
  max-width: 340px;
  box-shadow: var(--shadow-card);
}

.alarm-title {
  font-weight: 600;
  margin-bottom: 6px;
}

.alarm-message {
  font-size: 0.9rem;
  margin-bottom: 10px;
}

/* RESPONSIVE */

@media (max-width: 600px) {
  .app {
    padding: 0 10px 28px;
  }

  .result-main {
    font-size: 1.9rem;
  }

  .tab-header {
    flex-direction: column;
  }

  .field-group input[type="number"],
  .field-group input[type="text"],
  .field-group select {
    max-width: 100%;
  }
}

.config-lock-indicator {
  position: fixed;
  top: 0.75rem;
  right: 0.75rem;
  padding: 0.4rem 0.75rem;
  border-radius: 999px;
  font-size: 0.8rem;
  background: rgba(15, 23, 42, 0.92); /* dark slate */
  color: #e5e7eb;
  display: flex;
  align-items: center;
  gap: 0.35rem;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.4);
  z-index: 999;
}

.config-lock-indicator.hidden {
  display: none;
}

.config-lock-dot {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: #22c55e; /* green-ish */
}

/* Optional: dim the top card when locked (adjust selector to your layout) */
.config-locked .top-config-card {
  opacity: 0.5;
  pointer-events: none; /* inputs already disabled in JS, this is just a visual hint */
}

.bulk-curve-wrapper {
  margin-top: 0.75rem;
  position: relative;
}

.bulk-curve-title {
  font-size: 0.8rem;
  opacity: 0.8;
  margin-bottom: 0.25rem;
}

.bulk-curve-chart {
  width: 100%;
  height: 120px;
  display: block;
  touch-action: none;
  cursor: pointer; /* tap to preview */
}

.you-are-here {
  margin-top: 0.35rem;
  font-size: 0.78rem;
  color: var(--text-soft);
}

.bulk-curve-legend {
  margin-top: 0.35rem;
  font-size: 0.75rem;
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  align-items: center;
  color: var(--text-soft);
}

.legend-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 999px;
  margin-right: 0.35rem;
}

.legend-dot-green {
  background: #22c55e;
}

.legend-dot-gold {
  background: #eab308;
}

.legend-dot-red {
  background: #ef4444;
}

.bulk-curve-bg {
  /* default: teal-ish glow for active handling */
  fill: rgba(45, 212, 191, 0.16);
  transition: width 0.25s ease-out, fill 0.3s ease-out;
}

/* Quiet bulk – gold tint */
.bulk-phase-quiet .bulk-curve-bg {
  fill: rgba(250, 204, 21, 0.18);
}

/* Over-bulk – red tint */
.bulk-phase-over .bulk-curve-bg {
  fill: rgba(248, 113, 113, 0.2);
}

.bulk-curve-line {
  stroke: #4caf50;
  stroke-width: 2;
  fill: none;
  transition: stroke 0.3s ease-out, fill 0.3s ease-out;
}

/* ====== PHASE COLORING ====== */

/* Quiet bulk (after last fold) */
.bulk-phase-quiet .bulk-curve-line {
  stroke: #facc15 !important;
  /* yellow/gold */
}

/* Quiet bulk dot color (optional) */
.bulk-phase-quiet .bulk-curve-dot {
  fill: #fef9c3 !important;
  /* soft pale yellow */
  stroke: #facc15 !important;
  /* gold stroke */
}

.bulk-curve-dot {
  fill: #a5f3fc;
  stroke: #0ea5e9;
  stroke-width: 1.5;
  filter: drop-shadow(0 0 4px rgba(56, 189, 248, 0.7));
  transition: stroke 0.3s ease-out, fill 0.3s ease-out;
}

/* Over bulk (after estimated completion) */
.bulk-phase-over .bulk-curve-line {
  stroke: #f87171 !important;
  /* red */
}

.bulk-phase-over .bulk-curve-dot {
  fill: #fecaca !important;
  stroke: #f87171 !important;
}

.bulk-curve-marker {
  stroke: rgba(255, 255, 255, 0.4);
  stroke-width: 1;
  stroke-dasharray: 3 3;
}

/* Hover/drag feedback */
.bulk-curve-chart {
  cursor: crosshair;
}

/* Highlight dot / guide line */
.bulk-curve-guide {
  stroke: rgba(255, 255, 255, 0.35);
  stroke-width: 1;
  stroke-dasharray: 3 2;
  opacity: 0;
  transition: opacity 0.15s ease-out;
}

.bulk-curve-highlight {
  fill: #fff;
  stroke: rgba(255, 255, 255, 0.6);
  stroke-width: 2;
  opacity: 0;
  transition: opacity 0.15s ease-out;
}

.bulk-curve-guide,
.bulk-curve-highlight {
  transition: opacity 0.08s ease-out;
}

#bulkCurve {
  touch-action: none;
}

.bulk-curve-tooltip {
  position: fixed;
  z-index: 9999;
  background: rgba(15, 23, 42, 0.95);
  color: #e5e7eb;
  font-size: 0.75rem;
  padding: 4px 8px;
  border-radius: 4px;
  pointer-events: none;
  white-space: nowrap;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.35);
  transform: translate(-50%, -130%);
  opacity: 0;
  transition: opacity 0.12s ease-out;
}

/* Fold / phase timeline under the curve */
.fold-timeline {
  margin-top: 0.35rem;
  position: relative;
  height: 24px;
  font-size: 0.72rem;
}

.fold-timeline-track {
  position: absolute;
  left: 0;
  right: 0;
  top: 9px;
  height: 4px;
  border-radius: 999px;
  background: linear-gradient(to right,
      rgba(34, 197, 94, 0.45),
      rgba(234, 179, 8, 0.55));
  /* green → gold */
  opacity: 0.9;
}

.fold-timeline-tick {
  position: absolute;
  top: 4px;
  width: 1px;
  height: 12px;
  background: rgba(248, 250, 252, 0.9);
}

.fold-timeline-label {
  position: absolute;
  top: 14px;
  transform: translateX(-50%);
  white-space: nowrap;
  color: rgba(226, 232, 240, 0.88);
}