/* Print Calc — calm Nordic workshop look.
   Birch-grey base, slate ink, spruce actions, filament-coloured layers. */
:root {
  --bg: #ECEEE9;
  --surface: #FFFFFF;
  --surface-2: #F5F6F2;
  --ink: #1D2A2E;
  --muted: #5F6D72;
  --faint: #8C979A;
  --line: #D8DDD5;
  --spruce: #2E6A5C;
  --spruce-dark: #23544A;
  --spruce-soft: #E1EEE8;
  --honey: #D9A441;
  --high: #2E6A5C;  --high-bg: #E1EEE8;
  --med: #7C5E0E;   --med-bg: #F5EBCB;
  --low: #9A4A1C;   --low-bg: #F7E4D6;
  --loss: #B3362C;  --loss-bg: #FBE7E3;
  --r-lg: 22px;
  --r-md: 14px;
  --r-sm: 10px;
  --shadow: 0 1px 0 rgba(29, 42, 46, .04), 0 8px 24px -16px rgba(29, 42, 46, .35);
  --font: "Schibsted Grotesk", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --tabbar: 68px;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { margin: 0; line-height: 1.15; letter-spacing: -0.015em; }
h1 { font-size: 30px; font-weight: 800; letter-spacing: -0.03em; }
h2 { font-size: 20px; font-weight: 700; }
h3 { font-size: 15px; font-weight: 700; }
p { margin: 0; }
a { color: inherit; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.neg { color: var(--loss) !important; }

/* ---------- Header + tabs ---------- */
.top {
  position: sticky; top: 0; z-index: 20;
  background: var(--bg);
  border-bottom: 1px solid rgba(29, 42, 46, .06);
  padding-top: env(safe-area-inset-top);
}
.top-inner { max-width: 760px; margin: 0 auto; padding: 12px 16px; display: flex; align-items: center; gap: 12px; }
.brand { display: flex; align-items: center; gap: 9px; text-decoration: none; font-weight: 800; font-size: 18px; letter-spacing: -0.02em; }
.brand svg { width: 26px; height: 26px; }
.keypill {
  margin-left: auto; display: inline-flex; align-items: center; gap: 7px;
  font: 600 14px var(--font); color: var(--muted);
  background: var(--surface); border: 1px solid var(--line); border-radius: 999px;
  padding: 0 14px; min-height: 40px; cursor: pointer;
}
.keypill::before { content: ""; width: 12px; height: 12px; background: currentColor; -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M7 10V7a5 5 0 0 1 10 0v3h1a1 1 0 0 1 1 1v9a1 1 0 0 1-1 1H6a1 1 0 0 1-1-1v-9a1 1 0 0 1 1-1zm2 0h6V7a3 3 0 0 0-6 0z'/%3E%3C/svg%3E") center/contain no-repeat; mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M7 10V7a5 5 0 0 1 10 0v3h1a1 1 0 0 1 1 1v9a1 1 0 0 1-1 1H6a1 1 0 0 1-1-1v-9a1 1 0 0 1 1-1zm2 0h6V7a3 3 0 0 0-6 0z'/%3E%3C/svg%3E") center/contain no-repeat; }
.keypill.on { color: var(--ink); }
.keypill.bad { color: var(--loss); border-color: #F1C2BB; background: var(--loss-bg); }
.keypill.bad::before { background: var(--loss); }

.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: grid; grid-template-columns: repeat(3, 1fr);
  background: var(--surface); border-top: 1px solid var(--line);
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
}
.tabs button {
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  background: none; border: 0; color: var(--faint); cursor: pointer;
  font: 600 12px var(--font); padding: 6px 0; min-height: 52px; border-radius: 12px;
}
.tabs svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.tabs button[aria-current="page"] { color: var(--ink); }
.tabs button[aria-current="page"] svg { stroke: var(--spruce); }

main { max-width: 760px; margin: 0 auto; padding: 8px 16px calc(var(--tabbar) + 40px + env(safe-area-inset-bottom)); }
.loading { color: var(--muted); padding: 40px 0; text-align: center; }

@media (min-width: 760px) {
  .tabs { position: static; display: flex; gap: 4px; background: none; border: 0; padding: 0; margin-left: 18px; }
  .tabs button { flex-direction: row; gap: 7px; font-size: 15px; padding: 0 14px; min-height: 40px; }
  .tabs svg { width: 19px; height: 19px; }
  .tabs button[aria-current="page"] { background: var(--surface); box-shadow: var(--shadow); }
  main { padding-bottom: 60px; }
}

/* ---------- Buttons + fields ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font: 700 16px var(--font); letter-spacing: -0.005em;
  min-height: 50px; padding: 0 20px; border-radius: var(--r-md);
  border: 1px solid transparent; cursor: pointer; touch-action: manipulation;
  background: var(--spruce); color: #fff; text-decoration: none;
  transition: background .15s, transform .08s;
}
.btn:hover { background: var(--spruce-dark); }
.btn:active { transform: scale(.985); }
.btn.quiet { background: var(--surface); color: var(--ink); border-color: var(--line); }
.btn.quiet:hover { background: var(--surface-2); }
.btn.ghost { background: transparent; color: var(--ink); border-color: transparent; padding: 0 10px; }
.btn.ghost:hover { background: rgba(29, 42, 46, .06); }
.btn.danger { background: var(--surface); color: var(--loss); border-color: #EFC4BD; }
.btn.danger:hover { background: var(--loss-bg); }
.btn.small { min-height: 40px; font-size: 14px; padding: 0 14px; border-radius: var(--r-sm); }
.btn.full { width: 100%; }
.btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
:focus-visible { outline: 3px solid #5B8DB8; outline-offset: 2px; }

.field { display: block; }
.field > span { display: block; font-size: 14px; font-weight: 600; color: var(--muted); margin-bottom: 6px; }
.field small { display: block; font-size: 13px; color: var(--faint); margin-top: 5px; }
input, select {
  width: 100%; min-height: 50px; padding: 0 14px;
  font: 500 17px var(--font); color: var(--ink);
  background: var(--surface); border: 1.5px solid var(--line); border-radius: var(--r-md);
  appearance: none; -webkit-appearance: none;
}
select { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M1 1l5 5 5-5' fill='none' stroke='%235F6D72' stroke-width='2'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 14px center; padding-right: 36px; }
input:focus, select:focus { border-color: var(--spruce); outline: none; box-shadow: 0 0 0 3px rgba(46, 106, 92, .18); }
input::placeholder { color: #A9B2B4; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.stackf { display: grid; gap: 14px; }

/* ---------- Banner + toast ---------- */
.banner { background: var(--loss-bg); color: #7E2620; border-radius: var(--r-md); padding: 12px 14px; margin: 8px 0 4px; font-weight: 600; font-size: 15px; }
.toast {
  position: fixed; left: 50%; z-index: 60;
  bottom: calc(var(--tabbar) + 18px + env(safe-area-inset-bottom));
  transform: translate(-50%, 24px); opacity: 0; pointer-events: none;
  background: var(--ink); color: #fff; font-weight: 600; font-size: 15px;
  padding: 12px 18px; border-radius: 999px; max-width: calc(100% - 32px);
  transition: transform .22s ease, opacity .22s ease;
}
.toast.show { transform: translate(-50%, 0); opacity: 1; }
@media (min-width: 760px) { .toast { bottom: 28px; } }

/* ---------- Page heads ---------- */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; padding: 18px 2px 14px; }
.page-head p { color: var(--muted); margin-top: 4px; }
.section { margin-top: 30px; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; padding: 0 2px; }

/* ---------- Search + chips ---------- */
.searchbox { position: relative; }
.searchbox svg { position: absolute; left: 14px; top: 50%; width: 19px; height: 19px; transform: translateY(-50%); fill: none; stroke: var(--faint); stroke-width: 2; }
.searchbox input { padding-left: 42px; }
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 12px 2px 4px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; font: 600 14px var(--font); color: var(--muted);
  background: transparent; border: 1.5px solid var(--line); border-radius: 999px;
  padding: 0 14px; min-height: 38px; cursor: pointer; white-space: nowrap;
}
.chip[aria-pressed="true"] { background: var(--ink); color: #fff; border-color: var(--ink); }

/* ---------- Filament layer bar (the signature) ---------- */
.layers { display: flex; gap: 3px; height: 14px; }
.layers i { display: block; height: 100%; border-radius: 4px; min-width: 6px; }
.layers.big { height: 26px; gap: 4px; margin: 18px 0 6px; }
.layers.big i { border-radius: 6px; transform-origin: left center; }
.layers.empty { background: repeating-linear-gradient(90deg, var(--line) 0 8px, transparent 8px 12px); border-radius: 4px; }
@media (prefers-reduced-motion: no-preference) {
  .layers.big.print i { animation: lay .5s cubic-bezier(.2, .7, .2, 1) both; }
  @keyframes lay { from { transform: scaleX(0); opacity: .4; } to { transform: scaleX(1); opacity: 1; } }
}

/* ---------- Session cards ---------- */
.cards { display: grid; gap: 12px; margin-top: 12px; }
@media (min-width: 620px) { .cards { grid-template-columns: 1fr 1fr; } }
.scard {
  display: block; width: 100%; text-align: left; cursor: pointer;
  background: var(--surface); color: inherit; font: inherit;
  border: 1.5px solid transparent; border-radius: var(--r-lg); padding: 16px 16px 14px;
  box-shadow: var(--shadow); transition: border-color .15s;
}
.scard:hover { border-color: var(--line); }
.scard.loss { border-color: #EBB5AD; background: linear-gradient(var(--loss-bg), var(--surface) 70%); }
.scard-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.scard-name { font-size: 18px; font-weight: 700; letter-spacing: -0.015em; line-height: 1.25; }
.scard-cat { color: var(--muted); font-size: 14px; margin: 2px 0 14px; }
.scard .layers { margin-bottom: 14px; }
.nums { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin: 0; }
.nums div { min-width: 0; }
.nums dt { font-size: 12px; color: var(--faint); font-weight: 600; }
.nums dd { margin: 1px 0 0; font-size: 17px; font-weight: 700; letter-spacing: -0.01em; }
.nums .noprice { grid-column: 2 / -1; align-self: end; color: var(--muted); font-size: 14px; font-weight: 600; padding-bottom: 2px; }
.scard-foot { margin-top: 12px; font-size: 13px; color: var(--faint); }

.pill { flex: none; display: inline-flex; align-items: center; font-size: 13px; font-weight: 700; border-radius: 999px; padding: 3px 10px; white-space: nowrap; }
.pill.High { color: var(--high); background: var(--high-bg); }
.pill.Medium { color: var(--med); background: var(--med-bg); }
.pill.Low { color: var(--low); background: var(--low-bg); }
.pill.Loss { color: #fff; background: var(--loss); }
.pill.none { color: var(--muted); background: var(--surface-2); }

.empty-state { background: var(--surface); border-radius: var(--r-lg); padding: 28px 20px; text-align: center; box-shadow: var(--shadow); }
.empty-state p { color: var(--muted); margin: 6px 0 16px; }

/* ---------- Ranking ---------- */
.seg { display: inline-flex; background: #DFE3DC; border-radius: 12px; padding: 3px; }
.seg button { font: 600 14px var(--font); color: var(--muted); background: none; border: 0; border-radius: 9px; padding: 0 12px; min-height: 36px; cursor: pointer; }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px rgba(29, 42, 46, .15); }
.extremes { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.extreme { background: var(--surface); border-radius: var(--r-lg); padding: 14px 16px; box-shadow: var(--shadow); min-width: 0; }
.extreme span { display: block; font-size: 13px; color: var(--muted); font-weight: 600; }
.extreme b { display: block; font-size: 24px; font-weight: 800; letter-spacing: -0.02em; margin-top: 2px; }
.extreme em { display: block; font-style: normal; font-size: 14px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bands { background: var(--surface); border-radius: var(--r-lg); box-shadow: var(--shadow); margin-top: 12px; overflow: hidden; }
.band { padding: 14px 16px; border-top: 1px solid var(--line); }
.band:first-child { border-top: 0; }
.band-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.band-head small { color: var(--faint); font-size: 13px; }
.band ul { list-style: none; margin: 8px 0 0; padding: 0; display: grid; gap: 2px; }
.band li a { display: flex; justify-content: space-between; gap: 10px; padding: 8px 0; text-decoration: none; font-weight: 600; }
.band li a span:last-child { color: var(--muted); font-weight: 500; white-space: nowrap; }
.band .none-yet { color: var(--faint); font-size: 14px; margin-top: 4px; }
.band.is-loss .band-head h3 { color: var(--loss); }

/* ---------- Session view ---------- */
.back { margin: 10px 0 0 -10px; }
.s-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 6px 2px 14px; }
.s-head p { color: var(--muted); margin-top: 4px; }

.calc { background: var(--ink); color: #fff; border-radius: 26px; padding: 22px 20px 18px; }
.calc-label { font-size: 15px; color: #B7C3C6; font-weight: 500; }
.cost-big { font-size: 64px; font-weight: 800; letter-spacing: -0.045em; line-height: 1; margin-top: 6px; }
.cost-big small { font-size: 0.42em; font-weight: 700; letter-spacing: -0.02em; vertical-align: 0.95em; margin-right: 2px; }
.cost-exact { font-size: 14px; color: #93A2A6; margin-top: 6px; }
.calc .layers.empty { background: repeating-linear-gradient(90deg, #3A4A4F 0 8px, transparent 8px 12px); }
.parts { list-style: none; margin: 12px 0 0; padding: 0; }
.parts li { border-top: 1px solid rgba(255, 255, 255, .09); }
.part { display: flex; align-items: center; gap: 12px; min-height: 52px; padding: 6px 0; cursor: pointer; }
.part input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.part .tick { flex: none; width: 24px; height: 24px; border-radius: 7px; border: 2px solid #4C5D62; display: grid; place-items: center; }
.part .tick svg { width: 14px; height: 14px; fill: none; stroke: var(--ink); stroke-width: 3.2; stroke-linecap: round; stroke-linejoin: round; opacity: 0; }
.part input:checked + .tick { background: var(--c); border-color: var(--c); }
.part input:checked + .tick svg { opacity: 1; }
.part input:focus-visible + .tick { outline: 3px solid #8FB6D9; outline-offset: 2px; }
.part-name { flex: 1; min-width: 0; font-weight: 600; }
.part-name em { font-style: normal; font-size: 12px; font-weight: 700; color: #C9D2D4; background: rgba(255, 255, 255, .1); border-radius: 6px; padding: 2px 7px; margin-left: 6px; vertical-align: 2px; }
.part-cost { font-weight: 700; }
.part.off .part-name, .part.off .part-cost { color: #7F8E92; }

.price { background: var(--surface); border-radius: 26px; padding: 20px; margin-top: 12px; box-shadow: var(--shadow); }
.price-input { position: relative; margin-top: 8px; }
.price-input span { position: absolute; left: 18px; top: 50%; transform: translateY(-50%); font-size: 28px; font-weight: 700; color: var(--faint); }
.price-input input { min-height: 68px; font-size: 32px; font-weight: 800; letter-spacing: -0.02em; padding-left: 42px; border-radius: 18px; }
.rounders { display: flex; gap: 8px; margin-top: 10px; align-items: center; flex-wrap: wrap; }
.rounders > span { font-size: 14px; color: var(--muted); font-weight: 600; margin-right: 2px; }
.rounders .chip { min-height: 40px; }
.result { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 16px; }
.result > div { background: var(--surface-2); border-radius: var(--r-md); padding: 12px 14px; }
.result span { display: block; font-size: 13px; color: var(--muted); font-weight: 600; }
.result b { display: block; font-size: 28px; font-weight: 800; letter-spacing: -0.03em; margin-top: 2px; }
.verdict { display: flex; align-items: center; gap: 10px; margin-top: 12px; border-radius: var(--r-md); padding: 12px 14px; font-weight: 600; font-size: 15px; }
.verdict.good { background: var(--high-bg); color: var(--high); }
.verdict.bad { background: var(--loss); color: #fff; }
.verdict.wait { background: var(--surface-2); color: var(--muted); font-weight: 500; }
.price-actions { display: grid; grid-template-columns: 1fr; gap: 10px; margin-top: 16px; }
.price-actions.two { grid-template-columns: 1fr auto; }
.save-check { margin-top: 18px; padding-top: 18px; border-top: 1px solid var(--line); display: grid; gap: 10px; }

/* Items list */
.items { background: var(--surface); border-radius: var(--r-lg); box-shadow: var(--shadow); overflow: hidden; }
.item { display: grid; grid-template-columns: 14px 1fr auto; gap: 4px 12px; padding: 14px 16px; border-top: 1px solid var(--line); align-items: start; }
.item:first-child { border-top: 0; }
.item .dot { width: 14px; height: 14px; border-radius: 4px; margin-top: 4px; background: var(--c); }
.item-name { font-weight: 700; font-size: 16px; }
.item-name em { font-style: normal; font-size: 12px; font-weight: 700; color: #3F4B87; background: #E7E9F6; border-radius: 6px; padding: 2px 7px; margin-left: 6px; vertical-align: 2px; }
.facts { grid-column: 2 / -1; display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; }
.facts span { font-size: 13px; color: var(--muted); background: var(--surface-2); border-radius: 7px; padding: 3px 8px; }
.item-cost { text-align: right; }
.item-cost b { display: block; font-size: 17px; }
.item-cost small { display: block; font-size: 12px; color: var(--faint); }
.item-actions { grid-column: 2 / -1; display: flex; gap: 8px; margin-top: 8px; }

/* History */
.checks { background: var(--surface); border-radius: var(--r-lg); box-shadow: var(--shadow); overflow: hidden; }
.check { padding: 14px 16px; border-top: 1px solid var(--line); }
.check:first-child { border-top: 0; }
.check-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.check-top b { font-size: 16px; }
.check-top small { display: block; color: var(--faint); font-size: 13px; font-weight: 500; }
.check-note { margin-top: 4px; color: var(--muted); font-size: 14px; }
.check .nums { margin-top: 10px; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.toolbar .btn { flex: 1 1 auto; }

/* Settings */
.panel { background: var(--surface); border-radius: var(--r-lg); box-shadow: var(--shadow); padding: 20px; }
.rate-now { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 16px 0; }
.rate-now div { background: var(--surface-2); border-radius: var(--r-md); padding: 12px 14px; }
.rate-now span { display: block; font-size: 13px; color: var(--muted); font-weight: 600; }
.rate-now b { font-size: 20px; font-weight: 800; }

/* ---------- Bottom sheet ---------- */
dialog#sheet {
  border: 0; padding: 0; margin: auto auto 0; width: 100%; max-width: 560px;
  max-height: 92vh; overflow: auto;
  background: var(--surface); color: var(--ink);
  border-radius: 26px 26px 0 0;
  padding-bottom: env(safe-area-inset-bottom);
}
dialog#sheet::backdrop { background: rgba(20, 29, 32, .45); }
@media (min-width: 760px) { dialog#sheet { margin: auto; border-radius: 26px; } }
@media (prefers-reduced-motion: no-preference) {
  dialog#sheet[open] { animation: rise .26s cubic-bezier(.2, .8, .2, 1); }
  @keyframes rise { from { transform: translateY(40px); opacity: .6; } to { transform: none; opacity: 1; } }
}
.sheet-grip { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 10px auto 0; }
.sheet-body { padding: 14px 20px 22px; }
.sheet-body h2 { font-size: 22px; margin-bottom: 4px; }
.sheet-body > p { color: var(--muted); margin-bottom: 16px; }
.sheet-actions { display: grid; gap: 10px; margin-top: 20px; }
.sheet-actions.split { grid-template-columns: 1fr 1fr; }
.scope { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; background: var(--surface-2); padding: 4px; border-radius: var(--r-md); }
.scope label { display: block; }
.scope input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.scope span { display: flex; align-items: center; justify-content: center; min-height: 42px; border-radius: 10px; font-weight: 600; font-size: 15px; color: var(--muted); cursor: pointer; }
.scope input:checked + span { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px rgba(29, 42, 46, .15); }
.scope input:focus-visible + span { outline: 3px solid #5B8DB8; }
.divider { border: 0; border-top: 1px solid var(--line); margin: 22px 0 16px; }

@media (max-width: 380px) {
  .cost-big { font-size: 54px; }
  .nums dd { font-size: 15px; }
  .result b { font-size: 24px; }
  h1 { font-size: 26px; }
}

/* ---------- Lock screen ---------- */
body.locked .top, body.locked .tabs { display: none; }
body.locked main { padding-bottom: 40px; }
.lock { max-width: 400px; margin: 14vh auto 0; background: var(--surface); border-radius: 28px; box-shadow: var(--shadow); padding: 30px 22px 24px; text-align: center; }
.lock-mark { display: grid; gap: 5px; width: 56px; margin: 0 auto 18px; }
.lock-mark i { display: block; height: 10px; border-radius: 5px; }
.lock h1 { font-size: 30px; }
.lock > p { color: var(--muted); margin: 6px 0 22px; }
.lock form { text-align: left; display: grid; gap: 12px; }
.lock-msg { color: var(--loss); font-weight: 600; font-size: 15px; }
.lock small { display: block; color: var(--faint); font-size: 13px; margin-top: 16px; }
.btn:disabled { opacity: .6; cursor: progress; }
@media (prefers-reduced-motion: no-preference) {
  .lock { animation: rise .3s cubic-bezier(.2, .8, .2, 1); }
}
