:root {
  --leather-deep: #2a0d0d;
  --leather-dark: #3e1414;
  --leather: #5c1f1f;
  --leather-light: #762b2b;
  --parchment: #efe3c8;
  --parchment-bright: #f7eed9;
  --parchment-shade: #e2d1ae;
  --parchment-line: rgba(92, 62, 38, 0.14);
  --ink: #2e2018;
  --ink-muted: #654e3e;
  --ink-faint: #8c735f;
  --verdigris: #3f8f7d;
  --verdigris-soft: rgba(63, 143, 125, 0.15);
  --amber: #d99a2b;
  --amber-soft: rgba(217, 154, 43, 0.18);
  --red: #b23a2e;
  --red-soft: rgba(178, 58, 46, 0.16);
  --gold: #c8a24a;
  --gold-bright: #e0be6b;
  --gold-soft: rgba(200, 162, 74, 0.22);

  --el-earth: #3b7a4c;
  --el-earth-bg: rgba(59, 122, 76, 0.13);
  --el-water: #2f6f8f;
  --el-water-bg: rgba(47, 111, 143, 0.13);
  --el-air: #9c7429;
  --el-air-bg: rgba(156, 116, 41, 0.14);
  --el-fire: #b84b27;
  --el-fire-bg: rgba(184, 75, 39, 0.13);
  --el-salt: #8f3b52;
  --el-salt-bg: rgba(143, 59, 82, 0.13);
  --el-quicksilver: #556278;
  --el-quicksilver-bg: rgba(85, 98, 120, 0.14);

  --font-heading: "Palatino Linotype", "Book Antiqua", Palatino, Georgia, serif;
  --font-body: Georgia, "Times New Roman", serif;
  --shadow-book: 0 18px 46px rgba(10, 4, 2, 0.65), inset 0 1px 0 rgba(224, 190, 107, 0.22);
  --shadow-page: 0 6px 22px rgba(24, 10, 6, 0.35);
}

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

html, body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(ellipse at 25% 15%, rgba(200, 162, 74, 0.14), transparent 55%),
    radial-gradient(ellipse at 80% 85%, rgba(92, 31, 31, 0.35), transparent 60%),
    #1b0d0a;
  color: var(--ink);
  font-family: var(--font-body);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

#app {
  max-width: 1320px;
  margin: 0 auto;
  padding: 20px;
  min-height: 100vh;
}

.num,
input[type="number"],
.qty-value,
.stat-num {
  font-variant-numeric: tabular-nums;
}

:focus-visible {
  outline: 2.5px solid var(--gold);
  outline-offset: 2px;
}

/* Grimoire Outer Frame */
.grimoire-shell {
  display: grid;
  grid-template-columns: 248px minmax(0, 1fr);
  min-height: calc(100vh - 40px);
  background: linear-gradient(160deg, var(--leather) 0%, var(--leather-dark) 52%, var(--leather-deep) 100%);
  border: 2px solid rgba(200, 162, 74, 0.45);
  border-radius: 14px;
  box-shadow: var(--shadow-book);
  overflow: hidden;
  position: relative;
}

/* Leather Sidebar */
.grimoire-sidebar {
  display: flex;
  flex-direction: column;
  padding: 22px 14px 18px;
  border-right: 1px solid rgba(200, 162, 74, 0.28);
  background:
    linear-gradient(180deg, rgba(200, 162, 74, 0.08) 0%, transparent 18%),
    linear-gradient(90deg, rgba(0, 0, 0, 0.25) 0%, transparent 16%, transparent 88%, rgba(0, 0, 0, 0.28) 100%);
  color: var(--parchment);
  gap: 14px;
}

.brand-plate {
  text-align: center;
  padding: 12px 10px 16px;
  border-bottom: 1px solid rgba(200, 162, 74, 0.3);
}

.brand-sigil {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1.5px solid var(--gold);
  background: rgba(200, 162, 74, 0.1);
  color: var(--gold-bright);
  margin-bottom: 8px;
}

.brand-title {
  margin: 0;
  font-family: var(--font-heading);
  font-variant: small-caps;
  letter-spacing: 0.08em;
  font-size: 1.35rem;
  color: var(--gold-bright);
  line-height: 1.15;
}

.brand-sub {
  margin: 4px 0 0;
  font-size: 0.78rem;
  color: rgba(239, 227, 200, 0.72);
  font-style: italic;
}

.nav-tabs {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.nav-tab {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 12px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: rgba(239, 227, 200, 0.86);
  font-family: var(--font-heading);
  font-variant: small-caps;
  letter-spacing: 0.04em;
  font-size: 0.98rem;
  cursor: pointer;
  text-align: left;
  transition: background 150ms ease, color 150ms ease, border-color 150ms ease;
}

.nav-tab:hover {
  background: rgba(200, 162, 74, 0.14);
  color: #fff6e0;
}

.nav-tab[aria-selected="true"] {
  background: linear-gradient(90deg, rgba(200, 162, 74, 0.25), rgba(200, 162, 74, 0.1));
  border-color: rgba(200, 162, 74, 0.65);
  color: var(--gold-bright);
  box-shadow: inset 3px 0 0 var(--gold);
}

.nav-tab-icon {
  display: inline-flex;
  flex-shrink: 0;
  color: var(--gold);
}

.nav-tab-label {
  flex: 1;
  min-width: 0;
}

.nav-tab-count {
  font-family: var(--font-body);
  font-variant: normal;
  font-size: 0.74rem;
  padding: 1px 7px;
  border-radius: 999px;
  background: rgba(239, 227, 200, 0.14);
  color: var(--parchment);
  font-variant-numeric: tabular-nums;
}

.nav-tab-count.alert {
  background: var(--red);
  color: #fff;
}

.sidebar-footer {
  margin-top: auto;
  padding-top: 12px;
  border-top: 1px solid rgba(200, 162, 74, 0.25);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.sidebar-hint {
  font-size: 0.78rem;
  color: rgba(239, 227, 200, 0.72);
  margin: 0;
  line-height: 1.4;
}

.kbd {
  display: inline-block;
  padding: 1px 5px;
  font-family: ui-monospace, SFMono-Regular, monospace;
  font-size: 0.72rem;
  border: 1px solid rgba(200, 162, 74, 0.45);
  border-radius: 4px;
  background: rgba(0, 0, 0, 0.25);
  color: var(--gold-bright);
}

/* Parchment Page Area */
.grimoire-main {
  padding: 18px 20px 24px;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.page-wrapper {
  position: relative;
  flex: 1;
  display: flex;
  flex-direction: column;
  filter: drop-shadow(0 6px 18px rgba(15, 5, 3, 0.45));
}

.page-torn-edge {
  display: block;
  width: 100%;
  height: 14px;
  color: var(--parchment);
  margin-bottom: -1px;
  pointer-events: none;
}

.parchment-page {
  position: relative;
  flex: 1;
  background-color: var(--parchment);
  background-image:
    radial-gradient(circle at 12% 10%, rgba(255, 250, 236, 0.5), transparent 40%),
    radial-gradient(circle at 88% 92%, rgba(168, 128, 72, 0.18), transparent 45%),
    repeating-linear-gradient(
      to bottom,
      transparent 0px,
      transparent 31px,
      var(--parchment-line) 31px,
      var(--parchment-line) 32px
    );
  border: 1px solid rgba(112, 78, 44, 0.35);
  border-top: none;
  border-radius: 0 0 10px 10px;
  padding: 26px 28px 34px;
  color: var(--ink);
  animation: pageTurn 240ms ease-out;
}

@keyframes pageTurn {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.corner-glyph {
  position: absolute;
  color: rgba(156, 118, 44, 0.52);
  pointer-events: none;
  user-select: none;
}

.corner-glyph.tl { top: 10px; left: 12px; }
.corner-glyph.tr { top: 10px; right: 12px; }
.corner-glyph.bl { bottom: 10px; left: 12px; }
.corner-glyph.br { bottom: 10px; right: 12px; }

/* Page Header */
.page-header {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 14px;
  margin-bottom: 18px;
  border-bottom: 2px double rgba(92, 31, 31, 0.32);
}

.page-title {
  margin: 0;
  font-family: var(--font-heading);
  font-variant: small-caps;
  letter-spacing: 0.06em;
  font-size: 1.85rem;
  color: var(--leather);
  line-height: 1.1;
}

.page-subtitle {
  margin: 4px 0 0;
  font-size: 0.92rem;
  color: var(--ink-muted);
  font-style: italic;
}

.page-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

/* Grimoire Controls (layered cleanly over forge.ui.theme) */
.grimoire-shell .fx-btn,
.g-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 7px 13px;
  border-radius: 6px;
  border: 1px solid var(--leather);
  background: var(--leather);
  color: var(--parchment-bright);
  font-family: var(--font-body);
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 140ms ease, border-color 140ms ease, transform 80ms ease;
}

.grimoire-shell .fx-btn:hover,
.g-btn:hover {
  background: var(--leather-light);
  border-color: var(--leather-light);
}

.grimoire-shell .fx-btn:active,
.g-btn:active {
  transform: translateY(1px);
}

.grimoire-shell .fx-btn.verdigris,
.g-btn.verdigris {
  background: var(--verdigris);
  border-color: #2f7061;
  color: #fff;
}

.grimoire-shell .fx-btn.verdigris:hover,
.g-btn.verdigris:hover {
  background: #357c6c;
}

.grimoire-shell .fx-btn.ghost,
.g-btn.ghost {
  background: rgba(255, 250, 238, 0.58);
  border-color: rgba(92, 62, 38, 0.34);
  color: var(--ink);
}

.grimoire-shell .fx-btn.ghost:hover,
.g-btn.ghost:hover {
  background: rgba(255, 250, 238, 0.9);
  border-color: var(--gold);
}

.grimoire-shell .fx-btn.danger,
.g-btn.danger {
  background: var(--red);
  border-color: #8f2a20;
  color: #fff;
}

.grimoire-shell .fx-btn.danger:hover,
.g-btn.danger:hover {
  background: #9c3025;
}

.grimoire-shell .fx-btn.sm,
.g-btn.sm {
  padding: 4px 9px;
  font-size: 0.8rem;
}

.grimoire-shell .fx-btn:disabled,
.g-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.grimoire-shell .fx-input,
.g-input,
.g-select,
.g-textarea {
  background: rgba(255, 252, 244, 0.85);
  border: 1px solid rgba(92, 62, 38, 0.36);
  border-radius: 6px;
  padding: 7px 10px;
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 0.9rem;
}

.grimoire-shell .fx-input::placeholder,
.g-input::placeholder,
.g-textarea::placeholder {
  color: var(--ink-faint);
}

.grimoire-shell .fx-input:focus,
.g-input:focus,
.g-select:focus,
.g-textarea:focus {
  border-color: var(--gold);
  background: #fffdf7;
}

.g-textarea {
  width: 100%;
  resize: vertical;
  min-height: 92px;
  line-height: 1.45;
}

.field-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.field-label {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--ink-muted);
  letter-spacing: 0.02em;
}

.field-error {
  font-size: 0.78rem;
  color: var(--red);
  font-weight: 600;
}

/* Cards & Panels */
.g-card {
  background: rgba(249, 242, 224, 0.84);
  border: 1px solid rgba(112, 78, 44, 0.28);
  border-radius: 8px;
  padding: 14px 16px;
  box-shadow: 0 2px 6px rgba(46, 32, 24, 0.07);
}

.g-card + .g-card {
  margin-top: 12px;
}

.section-heading {
  margin: 0 0 10px;
  font-family: var(--font-heading);
  font-variant: small-caps;
  letter-spacing: 0.05em;
  font-size: 1.18rem;
  color: var(--leather);
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Badges & Chips */
.seal-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  border: 1px solid transparent;
  white-space: nowrap;
}

.seal-badge.ready,
.seal-badge.have,
.seal-badge.ok {
  background: var(--verdigris-soft);
  border-color: rgba(63, 143, 125, 0.45);
  color: #215b4e;
}

.seal-badge.almost,
.seal-badge.short,
.seal-badge.soon {
  background: var(--amber-soft);
  border-color: rgba(217, 154, 43, 0.55);
  color: #7d5308;
}

.seal-badge.urgent,
.seal-badge.missing {
  background: var(--red-soft);
  border-color: rgba(178, 58, 46, 0.52);
  color: #822218;
}

.seal-badge.optional,
.seal-badge.neutral {
  background: rgba(92, 62, 38, 0.1);
  border-color: rgba(92, 62, 38, 0.24);
  color: var(--ink-muted);
}

.reagent-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 8px;
  border-radius: 6px;
  font-size: 0.78rem;
  border: 1px solid rgba(92, 62, 38, 0.22);
  background: rgba(255, 250, 238, 0.75);
  color: var(--ink);
}

.reagent-chip.el-earth { background: var(--el-earth-bg); border-color: rgba(59, 122, 76, 0.35); color: #244f30; }
.reagent-chip.el-water { background: var(--el-water-bg); border-color: rgba(47, 111, 143, 0.35); color: #1d4a61; }
.reagent-chip.el-air { background: var(--el-air-bg); border-color: rgba(156, 116, 41, 0.35); color: #614713; }
.reagent-chip.el-fire { background: var(--el-fire-bg); border-color: rgba(184, 75, 39, 0.35); color: #782c14; }
.reagent-chip.el-salt { background: var(--el-salt-bg); border-color: rgba(143, 59, 82, 0.35); color: #5c2031; }
.reagent-chip.el-quicksilver { background: var(--el-quicksilver-bg); border-color: rgba(85, 98, 120, 0.35); color: #313b4a; }

.reagent-chip.spoiling-glow {
  border-color: var(--red);
  box-shadow: 0 0 0 1px rgba(178, 58, 46, 0.28), 0 0 10px rgba(178, 58, 46, 0.24);
  background: rgba(178, 58, 46, 0.14);
  color: #7d1e15;
  font-weight: 700;
}

.example-tag {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 1px 5px;
  border-radius: 4px;
  background: var(--gold-soft);
  color: #6b4e13;
  border: 1px solid rgba(200, 162, 74, 0.45);
}

/* Shimmer animation when a recipe becomes brewable */
@keyframes brewShimmer {
  0% { box-shadow: 0 0 0 0 rgba(63, 143, 125, 0.55), inset 0 0 0 0 rgba(200, 162, 74, 0.3); }
  50% { box-shadow: 0 0 18px 4px rgba(63, 143, 125, 0.45), inset 0 0 16px rgba(200, 162, 74, 0.28); }
  100% { box-shadow: 0 2px 6px rgba(46, 32, 24, 0.07), inset 0 0 0 0 transparent; }
}

.shimmer-ready {
  animation: brewShimmer 1.4s ease-out;
}

/* Toolbar & Filters */
.toolbar-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-bottom: 14px;
}

.toolbar-row .grow {
  flex: 1 1 200px;
}

.quick-add-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  padding: 12px 14px;
  background: rgba(200, 162, 74, 0.12);
  border: 1px solid rgba(200, 162, 74, 0.45);
  border-radius: 8px;
  margin-bottom: 14px;
}

.quick-add-preview {
  width: 100%;
  font-size: 0.8rem;
  color: var(--ink-muted);
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

/* Undo Banner */
.undo-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px;
  margin-bottom: 14px;
  border-radius: 8px;
  background: rgba(46, 32, 24, 0.9);
  color: var(--parchment-bright);
  border: 1px solid var(--gold);
}

/* Empty State */
.empty-state {
  text-align: center;
  padding: 32px 20px;
  border: 1.5px dashed rgba(92, 62, 38, 0.35);
  border-radius: 10px;
  background: rgba(255, 250, 238, 0.45);
}

.empty-state h3 {
  margin: 8px 0 6px;
  font-family: var(--font-heading);
  font-variant: small-caps;
  color: var(--leather);
  font-size: 1.25rem;
}

.empty-state p {
  margin: 0 auto 16px;
  max-width: 480px;
  color: var(--ink-muted);
}

.empty-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
}

/* Reagent Shelves */
.location-group {
  margin-bottom: 18px;
}

.location-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-family: var(--font-heading);
  font-variant: small-caps;
  font-size: 1.08rem;
  color: var(--leather);
  padding: 4px 0 6px;
  border-bottom: 1px solid rgba(92, 31, 31, 0.25);
  margin: 0 0 8px;
}

.reagent-list {
  display: flex;
  flex-direction: column;
  gap: 7px;
  list-style: none;
  margin: 0;
  padding: 0;
}

.reagent-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  background: rgba(252, 246, 232, 0.85);
  border: 1px solid rgba(112, 78, 44, 0.24);
  border-radius: 7px;
}

.reagent-main {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1 1 190px;
  min-width: 0;
}

.reagent-name {
  font-weight: 700;
  color: var(--ink);
  word-break: break-word;
}

.qty-stepper {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: rgba(239, 227, 200, 0.7);
  border: 1px solid rgba(92, 62, 38, 0.28);
  border-radius: 6px;
  padding: 2px 4px;
}

.qty-stepper button {
  width: 26px;
  height: 26px;
  border: none;
  border-radius: 4px;
  background: transparent;
  color: var(--leather);
  font-weight: 700;
  font-size: 1rem;
  cursor: pointer;
}

.qty-stepper button:hover {
  background: rgba(200, 162, 74, 0.28);
}

.qty-value {
  min-width: 68px;
  text-align: center;
  font-size: 0.88rem;
  font-weight: 700;
  padding: 0 4px;
}

.reagent-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
}

.inline-form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(135px, 1fr));
  gap: 10px;
  width: 100%;
}

/* Transmutation Table (3 columns desktop, collapsible on mobile) */
.transmutation-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
  align-items: start;
}

.table-column {
  background: rgba(252, 246, 232, 0.72);
  border: 1px solid rgba(112, 78, 44, 0.28);
  border-radius: 9px;
  overflow: hidden;
}

.table-column.col-ready { border-top: 4px solid var(--verdigris); }
.table-column.col-almost { border-top: 4px solid var(--amber); }
.table-column.col-inspire { border-top: 4px solid var(--red); }

.table-col-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
  padding: 12px 14px;
  border: none;
  background: rgba(235, 220, 188, 0.65);
  border-bottom: 1px solid rgba(112, 78, 44, 0.2);
  color: var(--ink);
  text-align: left;
  cursor: default;
}

.table-col-title {
  margin: 0;
  font-family: var(--font-heading);
  font-variant: small-caps;
  font-size: 1.08rem;
  color: var(--leather);
}

.table-col-sub {
  display: block;
  font-size: 0.76rem;
  color: var(--ink-muted);
  font-style: italic;
}

.table-col-chevron {
  display: none;
  font-size: 0.9rem;
  color: var(--ink-muted);
}

.table-col-body {
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.brew-card {
  background: rgba(255, 252, 244, 0.9);
  border: 1px solid rgba(112, 78, 44, 0.24);
  border-radius: 8px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.brew-card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}

.brew-card-title {
  margin: 0;
  font-family: var(--font-heading);
  font-size: 1.04rem;
  color: var(--ink);
}

.brew-card-meta {
  font-size: 0.78rem;
  color: var(--ink-muted);
}

.chip-wrap {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.brew-card-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding-top: 4px;
}

/* Formulae View */
.formulae-layout {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 14px;
}

.formula-card {
  display: flex;
  flex-direction: column;
  gap: 8px;
  cursor: pointer;
  transition: border-color 140ms ease, transform 120ms ease;
}

.formula-card:hover {
  border-color: var(--gold);
  transform: translateY(-1px);
}

.formula-card.selected {
  border-color: var(--leather);
  box-shadow: 0 0 0 2px rgba(200, 162, 74, 0.45);
}

.formula-detail-panel {
  margin-bottom: 18px;
  border: 1.5px solid rgba(92, 31, 31, 0.42);
  background: rgba(255, 251, 240, 0.94);
}

.formula-detail-grid {
  display: grid;
  grid-template-columns: minmax(240px, 1fr) minmax(260px, 1.3fr);
  gap: 18px;
  margin-top: 12px;
}

.ing-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.ing-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 6px;
  background: rgba(239, 227, 200, 0.48);
  font-size: 0.88rem;
}

.steps-list {
  margin: 0;
  padding-left: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 0.92rem;
}

/* The Week Planner */
.week-layout {
  display: grid;
  grid-template-columns: 230px minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}

.week-palette {
  display: flex;
  flex-direction: column;
  gap: 7px;
  max-height: 560px;
  overflow-y: auto;
  padding-right: 4px;
}

.draggable-formula {
  padding: 8px 10px;
  border-radius: 7px;
  border: 1px solid rgba(112, 78, 44, 0.3);
  background: rgba(255, 251, 240, 0.92);
  cursor: grab;
  display: flex;
  flex-direction: column;
  gap: 3px;
  font-size: 0.86rem;
}

.draggable-formula:active {
  cursor: grabbing;
}

.week-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(175px, 1fr));
  gap: 10px;
}

.day-card {
  background: rgba(252, 246, 232, 0.82);
  border: 1px solid rgba(112, 78, 44, 0.28);
  border-radius: 8px;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.day-name {
  margin: 0;
  font-family: var(--font-heading);
  font-variant: small-caps;
  font-size: 1.02rem;
  color: var(--leather);
  border-bottom: 1px solid rgba(92, 31, 31, 0.2);
  padding-bottom: 4px;
}

.meal-slot {
  border: 1.5px dashed rgba(112, 78, 44, 0.34);
  border-radius: 6px;
  padding: 8px;
  min-height: 62px;
  background: rgba(255, 252, 244, 0.55);
  display: flex;
  flex-direction: column;
  gap: 4px;
  cursor: pointer;
  transition: border-color 140ms ease, background 140ms ease;
}

.meal-slot:hover,
.meal-slot.drag-over {
  border-color: var(--gold);
  background: rgba(200, 162, 74, 0.16);
}

.meal-slot.filled {
  border-style: solid;
  border-color: rgba(63, 143, 125, 0.45);
  background: rgba(255, 252, 244, 0.95);
}

.slot-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-faint);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.slot-recipe {
  font-weight: 700;
  font-size: 0.86rem;
  color: var(--ink);
}

.slot-empty {
  font-size: 0.78rem;
  color: var(--ink-faint);
  font-style: italic;
}

/* Shopping Scroll */
.shopping-group {
  margin-bottom: 16px;
}

.shopping-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  background: rgba(255, 252, 244, 0.85);
  border: 1px solid rgba(112, 78, 44, 0.22);
  border-radius: 7px;
  margin-bottom: 6px;
}

.shopping-item.checked {
  opacity: 0.65;
  text-decoration: line-through;
}

.shopping-item input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--verdigris);
  cursor: pointer;
}

/* History & Settings */
.stats-banner {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.stat-card {
  padding: 14px;
  border-radius: 8px;
  border: 1px solid rgba(112, 78, 44, 0.28);
  background: rgba(255, 251, 240, 0.88);
  text-align: center;
}

.stat-num {
  font-family: var(--font-heading);
  font-size: 1.9rem;
  color: var(--leather);
  line-height: 1.1;
}

.stat-card.saved .stat-num { color: var(--verdigris); }
.stat-card.wasted .stat-num { color: var(--red); }

.stat-label {
  font-size: 0.8rem;
  color: var(--ink-muted);
  margin-top: 4px;
}

.history-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(260px, 1fr);
  gap: 18px;
  align-items: start;
}

.history-entry {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 12px;
  border-bottom: 1px solid rgba(112, 78, 44, 0.18);
  font-size: 0.88rem;
}

.history-entry:last-child {
  border-bottom: none;
}

/* Mobile Bottom Bar & Responsive */
@media (max-width: 980px) {
  .transmutation-grid {
    grid-template-columns: 1fr;
  }
  .table-col-header {
    cursor: pointer;
  }
  .table-col-chevron {
    display: inline-block;
  }
  .table-column.collapsed .table-col-body {
    display: none;
  }
  .week-layout,
  .history-grid,
  .formula-detail-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 820px) {
  #app {
    padding: 0;
  }
  .grimoire-shell {
    grid-template-columns: 1fr;
    border-radius: 0;
    border-left: none;
    border-right: none;
    min-height: 100vh;
    padding-bottom: 72px;
  }
  .grimoire-sidebar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 40;
    flex-direction: row;
    padding: 6px 6px calc(6px + env(safe-area-inset-bottom, 0px));
    border-right: none;
    border-top: 2px solid rgba(200, 162, 74, 0.55);
    background: linear-gradient(180deg, var(--leather) 0%, var(--leather-deep) 100%);
    gap: 0;
  }
  .brand-plate,
  .sidebar-footer {
    display: none;
  }
  .nav-tabs {
    flex-direction: row;
    width: 100%;
    justify-content: space-around;
    gap: 2px;
  }
  .nav-tab {
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    padding: 6px 4px;
    font-size: 0.66rem;
    text-align: center;
    position: relative;
  }
  .nav-tab[aria-selected="true"] {
    box-shadow: inset 0 -3px 0 var(--gold);
  }
  .nav-tab-count {
    position: absolute;
    top: 2px;
    right: 6px;
    font-size: 0.64rem;
    padding: 0 5px;
  }
  .grimoire-main {
    padding: 10px 10px 18px;
  }
  .parchment-page {
    padding: 18px 14px 24px;
  }
  .page-title {
    font-size: 1.45rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  .parchment-page,
  .shimmer-ready {
    animation: none !important;
  }
  * {
    transition-duration: 0.01ms !important;
  }
}

@media print {
  body {
    background: #fff !important;
    color: #000 !important;
  }
  .grimoire-sidebar,
  .page-actions,
  .toolbar-row,
  .quick-add-bar,
  .corner-glyph,
  .page-torn-edge,
  .no-print {
    display: none !important;
  }
  .grimoire-shell {
    display: block;
    background: #fff;
    border: none;
    box-shadow: none;
  }
  .parchment-page {
    background: #fff;
    border: none;
    padding: 0;
  }
}
