:root {
  --bg: #f4f3ee;
  --card: #fbfaf7;
  --ink: #26302b;
  --muted: #7a847d;
  --line: #e2e0d8;
  --accent: #51705f;
  --accent-ink: #f7f8f4;
  --accent-soft: #e6ede8;
  --error: #b4533f;
  --shadow: 0 1px 2px rgba(38,48,43,.04), 0 8px 24px rgba(38,48,43,.05);
  --ease: cubic-bezier(.22,.61,.36,1);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #171c19;
    --card: #1e2421;
    --ink: #e4e8e3;
    --muted: #8b958e;
    --line: #2d3531;
    --accent: #8fb09c;
    --accent-ink: #15201a;
    --accent-soft: #263029;
    --error: #e08a74;
    --shadow: 0 1px 2px rgba(0,0,0,.2), 0 8px 24px rgba(0,0,0,.2);
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 15px/1.5 "DM Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}
.wrap { max-width: 520px; margin: 0 auto; padding: 28px 16px 64px; }

.top { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 600; letter-spacing: .01em; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--accent); }
.ghost-link { color: var(--muted); font-size: 13px; text-decoration: none; transition: color .25s var(--ease); }
.ghost-link:hover { color: var(--accent); }

.card {
  background: var(--card); border: 1px solid var(--line); border-radius: 14px;
  padding: 26px; box-shadow: var(--shadow); margin-bottom: 16px;
  animation: rise .5s var(--ease) both;
}
h1 { font-size: 20px; font-weight: 600; margin: 0 0 4px; letter-spacing: -.01em; }
h2 { font-size: 13px; font-weight: 600; margin: 0 0 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.sub { margin: 0 0 22px; color: var(--muted); }
.stack { display: grid; gap: 16px; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.field { display: grid; gap: 6px; }
.field > span { font-size: 13px; font-weight: 500; }
.field em { font-style: normal; font-weight: 400; color: var(--muted); margin-left: 4px; font-size: 12px; }
input {
  width: 100%; font: inherit; color: var(--ink); background: var(--bg);
  border: 1px solid var(--line); border-radius: 9px; padding: 11px 12px; outline: none;
  transition: border-color .25s var(--ease), box-shadow .25s var(--ease), background .25s var(--ease);
}
input::placeholder { color: color-mix(in srgb, var(--muted) 70%, transparent); }
input:hover { border-color: color-mix(in srgb, var(--accent) 40%, var(--line)); }
input:focus { border-color: var(--accent); box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 16%, transparent); background: var(--card); }
.hint { min-height: 0; color: var(--muted); font-size: 12px; max-height: 0; opacity: 0; overflow: hidden; transition: max-height .3s var(--ease), opacity .3s var(--ease); }
.hint.show { max-height: 24px; opacity: 1; }

.preview { background: var(--accent-soft); border-radius: 11px; padding: 14px 16px; }
.preview-head { display: flex; justify-content: space-between; align-items: center; font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.code { display: flex; align-items: center; gap: 8px; text-transform: none; letter-spacing: 0; font-size: 12px; }
.code input { width: 76px; padding: 4px 8px; font: 500 12px "DM Mono", monospace; text-transform: uppercase; text-align: center; border-radius: 6px; }
.code input:disabled { opacity: .6; cursor: not-allowed; }
.preview-sku { font: 500 20px "DM Mono", ui-monospace, monospace; margin-top: 6px; letter-spacing: .02em; color: var(--ink); transition: opacity .2s var(--ease); word-break: break-all; }
.preview-sku.dim { color: var(--muted); }
.preview-sku.tick { animation: tick .25s var(--ease); }

.btn {
  position: relative; display: inline-flex; align-items: center; justify-content: center;
  width: 100%; border: 0; border-radius: 10px; padding: 13px 16px; cursor: pointer;
  font: 500 15px "DM Sans", sans-serif; color: var(--accent-ink); background: var(--accent);
  transition: transform .2s var(--ease), box-shadow .3s var(--ease), filter .25s var(--ease);
}
.btn:hover { filter: brightness(1.06); box-shadow: 0 6px 16px color-mix(in srgb, var(--accent) 30%, transparent); }
.btn:active { transform: scale(.985); }
.btn:disabled { cursor: default; filter: none; box-shadow: none; opacity: .85; }
.btn:focus-visible, .sku-big:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 35%, transparent); outline-offset: 2px; }
.spinner { position: absolute; right: 16px; width: 16px; height: 16px; border-radius: 50%; border: 2px solid color-mix(in srgb, var(--accent-ink) 35%, transparent); border-top-color: var(--accent-ink); opacity: 0; transition: opacity .2s; }
.btn.loading .spinner { opacity: 1; animation: spin .8s linear infinite; }

.error { margin: 0; color: var(--error); font-size: 13px; max-height: 0; opacity: 0; overflow: hidden; transition: max-height .3s var(--ease), opacity .3s var(--ease); }
.error.show { max-height: 80px; opacity: 1; }

.result-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.chip { font-size: 12px; font-weight: 500; color: var(--accent); background: var(--accent-soft); padding: 3px 10px; border-radius: 99px; }
.sku-big {
  width: 100%; display: flex; justify-content: space-between; align-items: center; gap: 12px; text-align: left;
  background: var(--bg); border: 1px dashed var(--line); border-radius: 11px; padding: 18px; cursor: pointer; color: var(--ink);
  font: 500 24px "DM Mono", ui-monospace, monospace; letter-spacing: .02em;
  transition: border-color .25s var(--ease), background .25s var(--ease), transform .2s var(--ease);
}
.sku-big:hover { border-color: var(--accent); background: var(--accent-soft); }
.sku-big:active { transform: scale(.99); }
#skuText { word-break: break-all; }
.copy-hint { font: 500 12px "DM Sans", sans-serif; color: var(--muted); transition: color .25s var(--ease); flex: none; }
.sku-big.copied .copy-hint { color: var(--accent); }
.result .sub { margin: 14px 0 0; font-size: 13px; }
.result.pop { animation: rise .5s var(--ease) both; }

.recent ul { list-style: none; margin: 0; padding: 0; }
.recent li { display: flex; justify-content: space-between; gap: 12px; padding: 10px 0; border-top: 1px solid var(--line); animation: fade .4s var(--ease) both; }
.recent li:first-child { border-top: 0; padding-top: 0; }
.recent .s { font: 500 13px "DM Mono", monospace; }
.recent .m { color: var(--muted); font-size: 12px; text-align: right; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 16px); opacity: 0; pointer-events: none;
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 99px; font-size: 13px;
  transition: opacity .3s var(--ease), transform .3s var(--ease);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

[hidden] { display: none !important; }
@keyframes rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes tick { from { opacity: .3; transform: translateY(3px); } to { opacity: 1; transform: none; } }
@keyframes spin { to { transform: rotate(360deg); } }
@media (max-width: 440px) { .row { grid-template-columns: 1fr; } .card { padding: 20px; } .sku-big { font-size: 20px; } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; } }

/* ---------- v2: nav, options, previews, library ---------- */
.wrap { transition: max-width .45s var(--ease); }
.wrap.wide { max-width: 980px; }
.top { gap: 12px; }

.seg { position: relative; display: grid; grid-template-columns: 1fr 1fr; background: var(--accent-soft); border-radius: 99px; padding: 3px; }
.seg button { position: relative; z-index: 1; border: 0; background: none; font: 500 13px "DM Sans", sans-serif; color: var(--muted); padding: 6px 16px; border-radius: 99px; cursor: pointer; transition: color .3s var(--ease); }
.seg button.on { color: var(--ink); }
.seg-ind { position: absolute; top: 3px; bottom: 3px; left: 3px; width: calc(50% - 3px); background: var(--card); border-radius: 99px; box-shadow: 0 1px 3px rgba(0,0,0,.08); transition: transform .35s var(--ease); }
.seg[data-view="library"] .seg-ind { transform: translateX(100%); }
#sheetLink { white-space: nowrap; }
@media (max-width: 520px) { #sheetLink { display: none; } .top { flex-wrap: wrap; } }

.view-in { animation: rise .45s var(--ease) both; }

/* options builder */
.options { display: grid; gap: 8px; }
.opt { display: grid; grid-template-columns: 96px 1fr 28px; gap: 8px; align-items: start; animation: rise .35s var(--ease) both; }
.opt.leaving { animation: out .25s var(--ease) both; }
.opt-name { padding: 9px 10px; font-weight: 500; }
.tags { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; min-height: 42px; padding: 5px 8px; background: var(--bg); border: 1px solid var(--line); border-radius: 9px; cursor: text; transition: border-color .25s var(--ease), box-shadow .25s var(--ease), background .25s var(--ease); }
.tags:hover { border-color: color-mix(in srgb, var(--accent) 40%, var(--line)); }
.tags:focus-within { border-color: var(--accent); box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 16%, transparent); background: var(--card); }
.tags input { flex: 1; min-width: 80px; border: 0; background: none; padding: 5px 2px; box-shadow: none !important; }
.tag { display: inline-flex; align-items: center; gap: 4px; background: var(--accent-soft); color: var(--ink); font-size: 13px; padding: 3px 4px 3px 9px; border-radius: 99px; animation: pop .25s var(--ease) both; }
.tag button { border: 0; background: none; color: var(--muted); width: 18px; height: 18px; border-radius: 50%; cursor: pointer; line-height: 1; font-size: 14px; transition: background .2s, color .2s; }
.tag button:hover { background: color-mix(in srgb, var(--accent) 25%, transparent); color: var(--ink); }
.rm { border: 0; background: none; color: var(--muted); font-size: 20px; height: 42px; cursor: pointer; border-radius: 8px; transition: color .2s, background .2s; }
.rm:hover { color: var(--error); background: color-mix(in srgb, var(--error) 10%, transparent); }
.add { justify-self: start; border: 1px dashed var(--line); background: none; color: var(--accent); font: 500 13px "DM Sans", sans-serif; padding: 7px 12px; border-radius: 8px; cursor: pointer; transition: background .25s var(--ease), border-color .25s var(--ease); }
.add:hover { background: var(--accent-soft); border-color: var(--accent); }
@media (max-width: 440px) { .opt { grid-template-columns: 1fr 28px; } .opt .opt-name { grid-column: 1 / 2; } .opt .tags { grid-column: 1 / 3; grid-row: 2; } .opt .rm { grid-column: 2; grid-row: 1; height: 38px; } }

/* preview list */
.preview-list { list-style: none; margin: 8px 0 0; padding: 0; max-height: 188px; overflow: auto; display: grid; gap: 2px; }
.preview-list li { display: flex; justify-content: space-between; gap: 12px; font: 500 14px "DM Mono", ui-monospace, monospace; padding: 5px 0; animation: tick .25s var(--ease) both; }
.preview-list li span:last-child { font: 400 12px "DM Sans", sans-serif; color: var(--muted); text-align: right; }
.preview-list li.dim { color: var(--muted); }
.preview-list li.first { font-size: 20px; }

/* result list */
.made { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; max-height: 340px; overflow: auto; }
.made li { display: flex; align-items: center; justify-content: space-between; gap: 12px; background: var(--bg); border: 1px dashed var(--line); border-radius: 10px; padding: 12px 14px; cursor: pointer; animation: rise .4s var(--ease) both; transition: border-color .25s var(--ease), background .25s var(--ease); }
.made li:hover { border-color: var(--accent); background: var(--accent-soft); }
.made .s { font: 500 17px "DM Mono", monospace; word-break: break-all; }
.made .v { color: var(--muted); font-size: 12px; text-align: right; }
.made li.copied .v { color: var(--accent); }
.result-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 14px; }
.result-foot .sub { margin: 0; }
.pill { border: 1px solid var(--line); background: var(--card); color: var(--ink); font: 500 13px "DM Sans", sans-serif; padding: 7px 14px; border-radius: 99px; cursor: pointer; transition: border-color .25s var(--ease), background .25s var(--ease), transform .2s var(--ease); }
.pill:hover { border-color: var(--accent); background: var(--accent-soft); }
.pill:active { transform: scale(.97); }

/* library */
.lib { padding: 22px; }
.lib-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; }
.lib-head .sub { margin-bottom: 16px; }
.lib-actions { display: flex; gap: 8px; }
.filters { display: grid; grid-template-columns: 1fr 220px; gap: 10px; margin-bottom: 14px; }
select { font: inherit; color: var(--ink); background: var(--bg); border: 1px solid var(--line); border-radius: 9px; padding: 11px 12px; outline: none; cursor: pointer; transition: border-color .25s var(--ease), box-shadow .25s var(--ease); }
select:focus { border-color: var(--accent); box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 16%, transparent); }
@media (max-width: 560px) { .filters { grid-template-columns: 1fr; } }
.table-wrap { border: 1px solid var(--line); border-radius: 10px; overflow: auto; max-height: 62vh; background: var(--card); }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
thead th { position: sticky; top: 0; z-index: 1; background: var(--accent-soft); text-align: left; font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); padding: 10px 14px; cursor: pointer; user-select: none; white-space: nowrap; border-bottom: 1px solid var(--line); transition: color .2s; }
thead th:hover { color: var(--ink); }
thead th i { display: inline-block; width: 10px; margin-left: 4px; font-style: normal; opacity: 0; transition: opacity .2s; }
thead th.sorted { color: var(--ink); }
thead th.sorted i { opacity: 1; }
thead th.sorted.asc i::before { content: "↑"; }
thead th.sorted.desc i::before { content: "↓"; }
tbody td { padding: 10px 14px; border-bottom: 1px solid var(--line); vertical-align: top; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr { transition: background .2s var(--ease); animation: fade .3s var(--ease) both; }
tbody tr:hover { background: var(--accent-soft); }
td.sku { font: 500 13px "DM Mono", monospace; white-space: nowrap; cursor: copy; }
td.muted, th.num, td.num { color: var(--muted); }
td.num, th.num { text-align: right; white-space: nowrap; }
@media (max-width: 640px) { .hide-sm { display: none; } }
.empty { padding: 36px; text-align: center; color: var(--muted); }
.more { display: block; margin: 14px auto 0; }

@keyframes pop { from { opacity: 0; transform: scale(.85); } to { opacity: 1; transform: none; } }
@keyframes out { to { opacity: 0; transform: translateX(-8px); } }

.end { display: flex; align-items: center; gap: 14px; }
button.lock { border: 0; background: none; font: inherit; font-size: 13px; cursor: pointer; padding: 0; }
