:root {
  color-scheme: light;
  --bg: #f3ecdf;
  --bg-deep: #e7dccb;
  --paper: #fffaf3;
  --ink: #241910;
  --muted: #6b5c50;
  --line: #e4d5c4;
  --caramel: #8f3d12;
  --caramel-soft: #f8e6d8;
  --good: #1f7a4d;
  --good-bg: #e7f6ee;
  --mid: #8a5a00;
  --mid-bg: #fff4d8;
  --bad: #a61e36;
  --bad-bg: #fdecef;
  --unknown: #5c534c;
  --shadow: 0 16px 40px rgba(60, 36, 16, 0.08);
  --radius: 22px;
  --header: 76px;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family: "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  font-size: 16.5px;
  line-height: 1.5;
  background:
    radial-gradient(900px 420px at -10% -10%, #ffe7c2 0%, transparent 55%),
    radial-gradient(800px 380px at 110% 0%, #f7d5c6 0%, transparent 50%),
    var(--bg);
}

h1, h2, h3, .total, .stat__num {
  font-family: Georgia, "Iowan Old Style", "Palatino Linotype", Palatino, serif;
  font-weight: 700;
  letter-spacing: -0.02em;
}

h1 { font-size: clamp(1.7rem, 2vw, 2.15rem); margin: 0; line-height: 1.1; }
h2 { font-size: clamp(1.7rem, 3vw, 2.3rem); margin: 0 0 8px; }
h3 { font-size: 1.25rem; margin: 0 0 8px; }

p { margin: 0 0 10px; }

button, input, select { font: inherit; color: inherit; }

button { cursor: pointer; }

img, svg { max-width: 100%; }

.skip {
  position: absolute;
  left: 12px;
  top: -40px;
  background: var(--ink);
  color: white;
  padding: 8px 12px;
  z-index: 50;
}

.skip:focus { top: 12px; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.wrap {
  width: min(1120px, calc(100% - 28px));
  margin: 0 auto;
}

.header {
  position: sticky;
  top: 0;
  z-index: 30;
  background: var(--bg);
  border-bottom: 1px solid rgba(228, 213, 196, 0.9);
}

.header__inner {
  min-height: var(--header);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 10px 0;
}

.brand { display: flex; gap: 12px; align-items: center; min-width: 0; }
.brand p { margin: 0; color: var(--muted); }

.brand__mark {
  width: 46px;
  height: 46px;
  flex: 0 0 auto;
}

.nav {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.nav__short { display: none; }

.nav button {
  border: 1px solid transparent;
  background: transparent;
  border-radius: 999px;
  min-height: 42px;
  padding: 8px 12px;
}

.nav button[aria-selected="true"] {
  background: var(--ink);
  color: #fffaf3;
}

.nav button:hover { background: rgba(36, 25, 16, 0.06); }
.nav button[aria-selected="true"]:hover { background: var(--ink); }

.mobile-total {
  display: none;
  margin: 0;
  padding: 8px 14px;
  background: var(--ink);
  color: #fffaf3;
  font-weight: 650;
}

main { padding: 22px 0 72px; }

.layout {
  display: grid;
  gap: 18px;
}

.layout__main { min-width: 0; }

.hero, .tool-card, .product-card, .summary-card, .day-item, .library-card, .history-card, .stat, .quiz-start, .empty, .fatal {
  background: var(--paper);
  border: 1px solid rgba(228, 213, 196, 0.95);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.hero, .tool-card, .summary-card, .empty, .fatal { padding: 18px; }

.hero { margin-bottom: 14px; }

.lead { font-size: 1.08rem; }

.example {
  margin: 0;
  padding: 12px 14px;
  border-radius: 16px;
  background: var(--caramel-soft);
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--caramel);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.hint, .meta { color: var(--muted); font-size: 0.95rem; }
.meta { margin-bottom: 6px; }

.tools, .form-grid, .settings-grid, .stat-grid {
  display: grid;
  gap: 12px;
}

.tools { margin: 14px 0; }

.field { display: grid; gap: 6px; margin: 0 0 12px; }
.field span { font-size: 0.92rem; font-weight: 650; }

input[type="text"], input[type="search"], input:not([type="checkbox"]):not([type="radio"]), select {
  width: 100%;
  min-height: 46px;
  padding: 10px 12px;
  border-radius: 14px;
  border: 1px solid #ddcbb8;
  background: #fff;
}

.searchbar { display: grid; gap: 6px; margin: 8px 0; font-weight: 650; }

.mode-switch, .checkline { border: 0; margin: 0 0 10px; padding: 0; }
.mode-switch legend { font-weight: 650; margin-bottom: 6px; }
.checkline { display: flex; gap: 8px; align-items: flex-start; margin-bottom: 8px; }
.checkline input { margin-top: 4px; }

.segmented { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.segmented__btn {
  border: 1px solid #ddcbb8;
  background: #fff;
  border-radius: 999px;
  min-height: 42px;
  padding: 8px 12px;
}
.segmented__btn[aria-pressed="true"] { background: var(--caramel); color: white; border-color: var(--caramel); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 46px;
  padding: 10px 16px;
  border-radius: 999px;
  border: 1px solid var(--caramel);
  background: var(--caramel);
  color: white;
  font-weight: 700;
  text-decoration: none;
}

.btn--ghost { background: transparent; color: var(--ink); border-color: #ddcbb8; }
.btn--danger { background: var(--bad-bg); color: var(--bad); border-color: #f3c3cb; }
.btn--small { min-height: 40px; padding: 8px 12px; font-size: 0.95rem; }
.row-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }

.preview {
  padding: 10px 12px;
  border-radius: 14px;
  background: #f7f1e8;
  margin: 0 0 10px;
}

.field__error {
  color: var(--bad);
  background: var(--bad-bg);
  border-radius: 12px;
  padding: 8px 10px;
  margin: 0 0 10px;
}

.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 6px; margin: 8px 0 14px; }
.chip {
  flex: 0 0 auto;
  border: 1px solid #ddcbb8;
  background: #fff;
  border-radius: 999px;
  min-height: 40px;
  padding: 8px 12px;
}
.chip[aria-pressed="true"] { background: var(--ink); color: white; border-color: var(--ink); }

.product-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 250px), 1fr)); gap: 14px; }
.product-card { overflow: hidden; display: flex; flex-direction: column; }
.product-card__body { padding: 14px; display: flex; flex-direction: column; gap: 0; flex: 1; }
.product-card .btn { margin-top: auto; }

.art {
  position: relative;
  height: 112px;
  display: grid;
  place-items: center;
  background:
    radial-gradient(circle at 30% 20%, rgba(255, 255, 255, 0.8), transparent 55%),
    hsl(var(--hue) 42% 88%);
}
.art svg { width: 92px; height: 74px; }
.art__tag {
  position: absolute;
  top: 10px;
  left: 10px;
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  background: rgba(255, 250, 243, 0.9);
  border-radius: 999px;
  padding: 3px 8px;
}

.card-badges, .badge { display: inline-flex; }
.card-badges { flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.badge {
  border-radius: 999px;
  padding: 3px 8px;
  font-size: 0.78rem;
  font-weight: 700;
  background: var(--caramel-soft);
}
.badge--free { background: #f8e6d8; color: #7a320e; }
.badge--estimated { background: var(--mid-bg); color: var(--mid); }
.badge--intrinsic { background: var(--good-bg); color: var(--good); }
.badge--unknown { background: #eeeae6; color: var(--unknown); }

.list-head { display: flex; justify-content: space-between; gap: 10px; align-items: center; flex-wrap: wrap; margin: 22px 0 8px; }
.day-items, .library-card, .history-card { margin-top: 12px; }
.day-item, .library-card, .history-card { padding: 14px; margin-bottom: 12px; }
.day-item__top { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 10px; align-items: center; }
.day-item__top svg { width: 48px; height: 40px; }
.day-item__name { margin: 0; }

.summary-card h3, .tool-card h3 { margin-top: 4px; }
.total { font-size: clamp(3rem, 8vw, 4.4rem); line-height: 0.9; margin: 6px 0; }
.total__unit { font-size: 0.42em; }
.total__caption { color: var(--muted); margin-bottom: 12px; }
.equivalents { display: grid; gap: 8px; margin: 0 0 14px; }
.equivalents div { display: flex; justify-content: space-between; gap: 12px; padding-bottom: 6px; border-bottom: 1px solid var(--line); }
.equivalents dt { color: var(--muted); }
.equivalents dd { margin: 0; font-weight: 800; }

.viz { margin: 8px 0 16px; }
.spoons, .cubes { display: flex; flex-wrap: wrap; gap: 4px; margin: 8px 0; }
.spoon svg { width: 34px; height: 28px; }
.spoon--partial { opacity: 0.45; }
.cube {
  width: 26px;
  height: 26px;
  border-radius: 7px;
  background: linear-gradient(145deg, #fff 0%, #f3d2b0 42%, #e0a36a 100%);
  box-shadow: inset 0 0 0 1px rgba(141, 62, 22, 0.28);
}
.cube--partial {
  background: linear-gradient(90deg, #e0a36a var(--p), #f4efe6 var(--p));
}
.viz__empty { color: var(--muted); }

.who { margin: 8px 0 16px; padding: 12px; border-radius: 16px; background: #f7f1e8; }
.who--low { background: var(--good-bg); }
.who--mid { background: var(--mid-bg); }
.who--high { background: var(--bad-bg); }
.who__track {
  position: relative;
  height: 16px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.8);
  overflow: hidden;
  margin: 10px 0 8px;
}
.who__fill { display: block; height: 100%; width: 0; border-radius: inherit; background: #8d8075; transition: width 0.35s ease; }
.who--low .who__fill { background: var(--good); }
.who--mid .who__fill { background: #d08900; }
.who--high .who__fill { background: var(--bad); }
.who__mark {
  position: absolute;
  top: -3px;
  width: 2px;
  height: 22px;
  background: var(--ink);
}

.chart { display: grid; gap: 12px; justify-items: center; }
.donut {
  width: 180px;
  height: 180px;
  border-radius: 50%;
  display: grid;
  place-items: center;
}
.donut__hole {
  width: 108px;
  height: 108px;
  border-radius: 50%;
  background: var(--paper);
  display: grid;
  place-items: center;
  text-align: center;
}
.donut__hole strong { font-size: 1.2rem; }
.donut__hole span { color: var(--muted); font-size: 0.85rem; }
.legend { list-style: none; padding: 0; margin: 0; width: 100%; }
.legend li { display: grid; grid-template-columns: 12px minmax(0, 1fr) auto; gap: 8px; align-items: center; margin-bottom: 6px; }
.legend__name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.swatch { width: 12px; height: 12px; border-radius: 99px; }

.empty { padding: 16px; color: var(--muted); }
.empty--flat { box-shadow: none; }
.confirm { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 10px 0; }
.confirm p { margin: 0; flex: 1 1 220px; }

.stat-grid { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); margin: 12px 0; }
.stat { padding: 14px; }
.stat__num { font-size: 2rem; margin: 0; }
.stat__num span { font-size: 1rem; }

.bars {
  height: 160px;
  display: flex;
  align-items: flex-end;
  gap: 6px;
  padding-top: 8px;
}
.bar-col { flex: 1; min-width: 0; height: 100%; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; gap: 4px; }
.bar { width: 100%; max-width: 28px; background: var(--caramel); border-radius: 8px 8px 3px 3px; }
.bar-col span { font-size: 0.75rem; color: var(--muted); }

.detail-list, .review { padding-left: 18px; }
.detail-list li, .review li { margin: 0 0 8px; }
.review { list-style: none; padding: 0; }
.review li { background: var(--paper); border-radius: 16px; padding: 12px 14px; border: 1px solid var(--line); }
.review .is-correct { border-color: #b7e0c8; }
.review .is-wrong { border-color: #f3c3cb; }

.progress { height: 8px; background: #efe4d6; border-radius: 99px; overflow: hidden; margin-bottom: 12px; }
.progress span { display: block; height: 100%; background: var(--caramel); }

.quiz__question { font-size: 1.45rem; }
.quiz__options { display: grid; gap: 8px; margin-bottom: 12px; }
.quiz__option {
  display: grid;
  grid-template-columns: auto auto minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  padding: 12px;
  border-radius: 16px;
  border: 1px solid var(--line);
  background: #fff;
}
.quiz__option:has(input:checked) { border-color: var(--caramel); background: #fff7f1; }
.quiz__option.is-correct { border-color: var(--good); background: var(--good-bg); }
.quiz__option.is-wrong { border-color: var(--bad); background: var(--bad-bg); }
.quiz__letter { font-weight: 800; }
.quiz__explain { padding: 12px; border-radius: 16px; background: #f7f1e8; margin-bottom: 12px; }

.prose { display: grid; gap: 14px; }
.prose section { background: var(--paper); border-radius: var(--radius); padding: 18px; border: 1px solid var(--line); }
.prose h3 { margin-top: 0; }
.prose ul, .prose ol { margin-top: 0; }
.formula {
  font-family: Georgia, Palatino, serif;
  font-size: 1.15rem;
  background: var(--caramel-soft);
  border-radius: 14px;
  padding: 12px;
}

.fatal { margin-bottom: 16px; border-color: #f3c3cb; }

.footer { padding: 8px 0 28px; color: var(--muted); }

.toast {
  position: fixed;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%);
  z-index: 40;
  width: min(560px, calc(100% - 24px));
  display: flex;
  justify-content: center;
}
.toast:empty { display: none; }
.toast span, .toast {
  background: var(--ink);
  color: #fffaf3;
}
.toast {
  gap: 10px;
  align-items: center;
  padding: 12px 14px;
  border-radius: 16px;
  box-shadow: var(--shadow);
}
.toast .btn { background: transparent; color: white; border-color: rgba(255, 255, 255, 0.4); }

:focus-visible { outline: 3px solid var(--caramel); outline-offset: 2px; }

@media (min-width: 800px) {
  .form-grid, .settings-grid { grid-template-columns: 1fr 1fr; }
  .tools { grid-template-columns: 1fr 1fr; align-items: start; }
}

@media (min-width: 861px) {
  .header {
    background: rgba(243, 236, 223, 0.92);
    backdrop-filter: blur(12px);
  }
}

@media (min-width: 980px) {
  .layout { grid-template-columns: minmax(0, 1fr) 340px; align-items: start; }
  .summary-wrap { position: sticky; top: 16px; }
}

@media (max-width: 860px) {
  .nav {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 35;
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 0;
    padding: 6px 6px calc(6px + env(safe-area-inset-bottom));
    background: rgba(255, 250, 243, 0.96);
    border-top: 1px solid var(--line);
  }
  .nav button { border-radius: 12px; padding: 6px 4px; font-size: 0.78rem; min-height: 48px; }
  .nav__long { display: none; }
  .nav__short { display: inline; }
  .mobile-total { display: block; position: sticky; top: var(--header); z-index: 25; }
  .toast { bottom: 74px; }
  body { padding-bottom: 24px; }
  .day-item__top { grid-template-columns: auto minmax(0, 1fr); }
  .day-item__top .btn { grid-column: 1 / -1; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation: none !important;
    transition: none !important;
    scroll-behavior: auto !important;
  }
}

@media print {
  .header, .nav, .mobile-total, .tools, .searchbar, .chips, .product-grid, .toast, .footer, .btn { display: none !important; }
  .summary-wrap { position: static; }
  body { background: white; }
}
