:root {
  color-scheme: light;
  --paper: #f9f8f6;
  --sheet: #fffefa;
  --ink: #25241f;
  --muted: #686862;
  --line: #cecbc2;
  --amber: #a75220;
  --amber-light: #f2dfcf;
  --serif: "Noto Serif CJK SC", "Songti SC", "SimSun", Georgia, serif;
  --sans: Inter, "Microsoft YaHei", "PingFang SC", system-ui, sans-serif;
  --mono: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-family: var(--sans);
  color: var(--ink);
  background: var(--paper);
  font-synthesis: none;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body { min-width: 320px; margin: 0; background: var(--paper); }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .48; }
a { color: inherit; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--amber); outline-offset: 3px; }
.muted { color: var(--muted); }
.eyebrow, .field-hint, .product-id, .preview-index, .data-header, .platform-sidebar h2 {
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0;
}
.eyebrow { margin: 0 0 9px; color: var(--amber); }
.text-link { border: 0; padding: 0; background: none; color: var(--amber); font-size: 13px; font-weight: 700; text-decoration: underline; text-underline-offset: 3px; }
.text-link:hover, .auth-help:hover { color: #743512; }

.boot-screen { display: flex; min-height: 100dvh; align-items: center; justify-content: center; gap: 16px; color: var(--muted); font-size: 14px; }
.brand-mark {
  display: inline-grid; flex: 0 0 38px; width: 38px; height: 38px; place-items: center;
  border: 1px solid var(--ink); border-radius: 2px; background: var(--amber); color: white;
  font-family: var(--serif); font-size: 21px; font-weight: 800; line-height: 1;
  box-shadow: 3px 3px 0 var(--ink);
}
.brand { display: flex; align-items: center; gap: 14px; min-width: 200px; font-family: var(--serif); font-size: 18px; font-weight: 800; white-space: nowrap; }
.brand-suffix { margin-left: 3px; color: var(--muted); font-family: var(--mono); font-size: 10px; font-weight: 500; }

.auth-screen { display: grid; min-height: 100dvh; align-items: center; padding: 60px max(24px, calc((100vw - 1140px) / 2)); }
.auth-wrap { display: grid; grid-template-columns: minmax(0, 1fr) minmax(320px, 430px); gap: 48px; align-items: center; width: 100%; }
.auth-heading { display: flex; gap: 17px; align-self: start; align-items: center; border-top: 4px solid var(--ink); padding-top: 22px; }
.auth-heading p { margin: 0; }
.auth-heading .brand-name { font-family: var(--serif); font-size: 34px; font-weight: 800; }
.auth-heading .muted { margin-top: 5px; font-family: var(--mono); font-size: 10px; }
.auth-panel { grid-column: 2; grid-row: 1 / 3; border: 1px solid var(--ink); border-radius: 2px; padding: 30px 32px 34px; background: var(--sheet); box-shadow: 8px 8px 0 var(--ink); }
.auth-tabs { display: flex; gap: 24px; border-bottom: 1px solid var(--line); }
.auth-tab { position: relative; border: 0; padding: 0 2px 14px; background: none; color: var(--muted); font-weight: 700; }
.auth-tab.active { color: var(--amber); }
.auth-tab.active::after { position: absolute; right: 0; bottom: -1px; left: 0; height: 3px; background: var(--amber); content: ""; }
.auth-panel h1 { margin: 27px 0 8px; font-family: var(--serif); font-size: 27px; font-weight: 800; }
.auth-panel > .muted { margin: 0 0 24px; font-size: 13px; }
.auth-help { align-self: end; color: var(--amber); font-size: 13px; font-weight: 700; text-decoration: underline; text-underline-offset: 3px; }
.form-error { margin: 13px 0; color: #a32c20; font-size: 13px; line-height: 1.6; }

label { display: block; margin: 17px 0 7px; color: var(--ink); font-size: 13px; font-weight: 700; }
input, select, textarea { width: 100%; min-height: 44px; border: 1px solid #aaa79e; border-radius: 2px; padding: 10px 12px; outline: none; background: var(--sheet); color: var(--ink); }
input:focus, select:focus, textarea:focus { border-color: var(--amber); box-shadow: 3px 3px 0 var(--amber-light); }
input::placeholder, textarea::placeholder { color: #88877f; }
textarea { resize: vertical; line-height: 1.7; }
.button {
  display: inline-flex; min-height: 42px; align-items: center; justify-content: center;
  border: 1px solid var(--ink); border-radius: 2px; padding: 9px 17px;
  font-size: 13px; font-weight: 750; line-height: 1.3; text-align: center; white-space: nowrap;
  transition: transform .16s ease, box-shadow .16s ease, background-color .16s ease;
}
.button:hover:not(:disabled) { transform: translate(-2px, -2px); box-shadow: 3px 3px 0 var(--ink); }
.button:active:not(:disabled) { transform: translate(1px, 1px); box-shadow: none; }
.button-primary { border-color: var(--ink); background: var(--amber); color: #fff; }
.button-primary:hover:not(:disabled) { background: #8e451b; }
.button-secondary { background: var(--sheet); color: var(--ink); }
.button-secondary:hover:not(:disabled) { background: #f1eee7; }
.button-danger { border-color: #862c21; background: #9e3529; color: white; }
.button-small { min-height: 34px; padding: 6px 10px; font-size: 12px; }
.button-block { width: 100%; margin-top: 23px; }

.topbar { position: sticky; z-index: 12; top: 0; min-height: 76px; border-bottom: 2px solid var(--ink); background: var(--paper); }
.topbar-inner { display: flex; width: min(100% - 48px, 1220px); min-height: 74px; align-items: center; margin: auto; }
.desktop-nav { display: flex; align-self: stretch; gap: 2px; align-items: stretch; margin-left: 30px; }
.nav-button { position: relative; border: 0; padding: 0 12px; background: none; color: var(--muted); font-size: 13px; font-weight: 700; white-space: nowrap; }
.nav-button:hover { color: var(--amber); }
.nav-button.active { color: var(--ink); }
.nav-button.active::after { position: absolute; right: 12px; bottom: -2px; left: 12px; height: 4px; background: var(--amber); content: ""; }
.topbar-actions { position: relative; display: flex; align-items: center; gap: 16px; margin-left: auto; }
.balance-mini { display: grid; gap: 0; color: var(--muted); font-family: var(--mono); font-size: 10px; white-space: nowrap; }
.balance-mini strong { color: var(--ink); font-family: var(--serif); font-size: 19px; line-height: 1.1; }
.account-button { border: 1px solid var(--ink); border-radius: 2px; padding: 8px 12px; background: transparent; color: var(--ink); font-size: 12px; font-weight: 700; }
.account-button:hover { background: var(--amber-light); }
.account-menu { position: absolute; z-index: 20; top: calc(100% + 18px); right: 0; display: grid; min-width: 200px; gap: 8px; border: 1px solid var(--ink); border-radius: 2px; padding: 18px; background: var(--sheet); box-shadow: 5px 5px 0 var(--ink); font-size: 13px; }
.account-menu button { margin-top: 8px; border: 0; border-top: 1px solid var(--line); padding: 12px 0 0; background: none; color: #a32c20; text-align: left; }
.account-support { color: var(--amber); font-weight: 700; text-decoration: underline; }

.main-content { width: min(100% - 48px, 1160px); margin: 0 auto; padding: 42px 0 100px; }
.view { display: none; }
.view.active { display: block; }
.page-heading { display: flex; min-height: 72px; align-items: end; justify-content: space-between; gap: 18px; margin-bottom: 26px; }
.page-heading h1 { margin: 0; font-family: var(--serif); font-size: 30px; font-weight: 800; line-height: 1.35; }
.heading-actions { display: flex; gap: 9px; align-items: center; }
.account-strip { display: flex; align-items: baseline; justify-content: space-between; gap: 20px; border-top: 1px solid var(--ink); border-bottom: 1px solid var(--line); padding: 18px 2px 19px; }
.account-strip > div { display: flex; align-items: baseline; gap: 20px; }
.account-strip span, .ledger-summary .muted { font-family: var(--mono); font-size: 11px; }
.account-strip strong, .ledger-summary strong { font-family: var(--serif); font-size: 27px; line-height: 1; font-weight: 750; font-variant-numeric: tabular-nums; }
.catalog-controls { width: min(100%, 630px); margin: 27px 0 34px; }
.catalog-controls label { margin-top: 0; }
.search-row { display: flex; gap: 9px; }
.search-row input { min-width: 0; }
.catalog-browser { display: grid; grid-template-columns: 185px minmax(0, 1fr); gap: 34px; }
.platform-sidebar { border-right: 1px solid var(--line); padding-right: 20px; }
.platform-sidebar h2 { margin: 4px 0 18px; color: var(--amber); }
.platform-tabs { display: grid; align-content: start; gap: 2px; }
.platform-tab { width: 100%; min-height: 41px; border: 0; border-left: 2px solid transparent; padding: 7px 10px; background: none; color: #55554e; font-size: 13px; font-weight: 700; text-align: left; overflow-wrap: anywhere; }
.platform-tab:hover { background: #efece6; }
.platform-tab.active { border-left-color: var(--amber); background: var(--amber-light); color: #743512; }
.catalog-results { min-width: 0; }
.list-heading { display: flex; align-items: baseline; justify-content: space-between; gap: 15px; margin-bottom: 13px; }
.list-heading h2 { margin: 0; font-family: var(--serif); font-size: 19px; font-weight: 750; }
.list-heading .muted { font-family: var(--mono); font-size: 11px; }
.catalog-tools { display: flex; align-items: center; gap: 10px; }
.catalog-tools label { margin: 0; color: var(--muted); font-family: var(--mono); font-size: 11px; }
.catalog-tools select { width: min(320px, 30vw); min-height: 37px; padding: 6px 9px; font-size: 12px; }
.catalog-list, .data-list { border-top: 2px solid var(--ink); }
.catalog-row { display: grid; grid-template-columns: minmax(0, 1fr) 132px 150px 90px; gap: 15px; align-items: center; min-height: 85px; border-bottom: 1px solid var(--line); padding: 15px 3px; transition: background-color .15s ease, padding-left .15s ease; }
.catalog-row:hover, .data-row:hover { background: #f0eee9; }
.catalog-row:hover { padding-left: 10px; }
.catalog-main { min-width: 0; }
.catalog-main strong { display: block; font-size: 13px; font-weight: 700; line-height: 1.55; overflow-wrap: anywhere; }
.catalog-main .muted { display: block; margin-top: 7px; font-family: var(--mono); font-size: 11px; }
.catalog-category { color: var(--muted); font-size: 12px; overflow-wrap: anywhere; }
.catalog-price { color: var(--ink); font-family: var(--serif); font-size: 14px; font-weight: 800; font-variant-numeric: tabular-nums; white-space: nowrap; }
.catalog-row .button { min-width: 90px; justify-self: end; }
.catalog-row .button:disabled { background: #ebe9e4; color: #77766e; opacity: 1; }
.pagination { display: flex; min-height: 66px; align-items: center; justify-content: flex-end; gap: 13px; color: var(--muted); font-family: var(--mono); font-size: 11px; }
.pagination .button { min-height: 34px; padding: 6px 10px; }
.state-message { border-bottom: 1px solid var(--line); padding: 38px 12px; color: var(--muted); font-size: 13px; text-align: center; }
.state-message.error { color: #a32c20; }

.segmented { display: inline-flex; gap: 2px; align-items: center; border: 1px solid var(--ink); border-radius: 2px; padding: 3px; margin: 0 0 22px; background: #ece9e3; }
.segmented button { min-height: 35px; border: 0; border-radius: 1px; padding: 6px 17px; background: none; color: var(--muted); font-size: 12px; font-weight: 700; white-space: nowrap; }
.segmented button.active { background: var(--ink); color: white; }
.work-form { max-width: 900px; border-top: 2px solid var(--ink); border-bottom: 1px solid var(--line); padding: 7px 0 25px; }
.work-form > label { margin-top: 18px; }
.work-form textarea { min-height: 190px; font-family: var(--mono); font-size: 13px; }
.form-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.form-footer { display: flex; align-items: center; justify-content: space-between; gap: 18px; margin-top: 18px; }
.field-hint { margin: 6px 0 0; color: var(--muted); line-height: 1.5; }
.form-footer .button { flex: 0 0 auto; }
.order-preview { max-width: 900px; padding-top: 28px; }
.preview-list { border-top: 2px solid var(--ink); }
.preview-row { display: grid; grid-template-columns: 34px minmax(0, 1fr) 130px; gap: 14px; align-items: start; border-bottom: 1px solid var(--line); padding: 16px 4px; }
.preview-index { color: var(--amber); }
.preview-main { min-width: 0; }
.preview-main strong { display: block; font-size: 13px; overflow-wrap: anywhere; }
.preview-main .muted { display: block; margin-top: 5px; font-size: 12px; overflow-wrap: anywhere; }
.preview-right { display: grid; gap: 4px; justify-items: end; text-align: right; }
.preview-right strong { font-family: var(--serif); font-size: 17px; font-variant-numeric: tabular-nums; }
.preview-right .muted, .preview-status { font-family: var(--mono); font-size: 11px; }
.preview-status.done, .amount-positive { color: #5c5230; }
.preview-status.failed, .amount-negative { color: #a32c20; }
.preview-total { display: flex; align-items: center; gap: 28px; border-top: 1px solid var(--ink); padding: 19px 0; }
.preview-total > div { display: grid; gap: 3px; }
.preview-total span { color: var(--muted); font-family: var(--mono); font-size: 11px; }
.preview-total strong { font-family: var(--serif); font-size: 23px; font-variant-numeric: tabular-nums; }
.preview-total .button { margin-left: auto; }

.data-header, .data-row { display: grid; gap: 14px; align-items: center; padding: 15px 7px; }
.orders-grid { grid-template-columns: 100px minmax(0, 1.6fr) minmax(0, 1.4fr) 75px 95px 100px 125px; }
.recurring-grid { grid-template-columns: 85px minmax(0, 1.6fr) minmax(0, 1.3fr) 76px 100px 94px 94px; }
.ledger-grid { grid-template-columns: 130px minmax(0, 1.5fr) minmax(0, 1.4fr) 105px 105px 135px; }
.data-header { border-bottom: 1px solid var(--line); color: var(--muted); }
.data-row { min-height: 74px; border-bottom: 1px solid var(--line); font-size: 12px; }
.data-cell { min-width: 0; overflow-wrap: anywhere; }
.data-cell .muted { display: block; margin-top: 4px; font-size: 11px; }
.cell-emphasis { font-weight: 750; }
.cell-link { overflow: hidden; color: var(--amber); text-overflow: ellipsis; white-space: nowrap; }
.status { display: inline-block; border: 1px solid var(--line); border-radius: 2px; padding: 5px 7px; background: #efede8; color: var(--ink); font-size: 11px; font-weight: 700; white-space: nowrap; }
.status.done { border-color: #beb49a; background: #eee9dc; color: #51472f; }
.status.pending { border-color: #d2ac84; background: #f8e9d5; color: #74401e; }
.status.failed { border-color: #dcaca4; background: #f6e8e5; color: #942f24; }
.amount-positive, .amount-negative { font-weight: 750; }
.ledger-summary { display: flex; align-items: baseline; gap: 18px; border-top: 1px solid var(--ink); border-bottom: 1px solid var(--line); margin-bottom: 24px; padding: 19px 2px; }
.ledger-summary a { margin-left: auto; }
.recurring-actions { text-align: right; }
.mobile-nav { display: none; }

.dialog { width: min(100% - 36px, 540px); max-height: min(88dvh, 850px); border: 1px solid var(--ink); border-radius: 2px; padding: 24px 28px 28px; background: var(--sheet); color: var(--ink); box-shadow: 8px 8px 0 var(--ink); overflow: auto; }
.dialog::backdrop { background: #25241fb3; }
.product-dialog { width: min(100% - 36px, 640px); }
.dialog-header { display: flex; align-items: start; justify-content: space-between; }
.dialog-close { display: grid; width: 32px; height: 32px; place-items: center; border: 1px solid var(--line); border-radius: 2px; background: transparent; color: var(--ink); font-size: 24px; line-height: 1; }
.dialog-close:hover { background: var(--amber-light); }
.dialog h2 { margin: 12px 0 8px; font-family: var(--serif); font-size: 23px; line-height: 1.4; overflow-wrap: anywhere; }
.product-id { margin: 0 0 18px; color: var(--amber); }
.product-dialog #product-category { margin: 10px 0 0; font-size: 12px; }
.product-facts { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); padding: 17px 0; }
.product-facts div { display: grid; gap: 5px; }
.product-facts span { color: var(--muted); font-family: var(--mono); font-size: 11px; }
.product-facts strong { font-family: var(--serif); font-size: 17px; font-variant-numeric: tabular-nums; }
.product-description { margin: 20px 0 22px; color: #45433d; font-size: 13px; line-height: 1.75; white-space: pre-wrap; overflow-wrap: anywhere; }
.product-description:empty { display: none; }
.product-actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px; margin-top: 22px; }
.product-actions .button { width: 100%; }
.confirm-list { margin: 22px 0 0; border-top: 2px solid var(--ink); }
.confirm-list div { display: grid; grid-template-columns: 88px minmax(0, 1fr); gap: 10px; border-bottom: 1px solid var(--line); padding: 12px 0; font-size: 13px; }
.confirm-list dt { color: var(--muted); }
.confirm-list dd { margin: 0; font-weight: 700; overflow-wrap: anywhere; }
.confirm-list .confirm-charge dd { color: var(--amber); font-family: var(--serif); font-size: 20px; }
.confirm-note { margin: 18px 0; color: var(--muted); font-size: 12px; line-height: 1.6; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }
.toast { position: fixed; z-index: 50; right: 22px; bottom: 24px; max-width: min(440px, calc(100% - 32px)); border: 1px solid var(--ink); border-radius: 2px; padding: 12px 16px; background: var(--sheet); box-shadow: 5px 5px 0 var(--ink); color: var(--ink); font-size: 13px; line-height: 1.5; }
.toast.error { border-color: #a32c20; color: #a32c20; }

@media (max-width: 1060px) {
  .brand-suffix { display: none; }
  .brand { min-width: auto; }
  .desktop-nav { margin-left: 20px; }
  .nav-button { padding: 0 9px; font-size: 12px; }
  .catalog-row { grid-template-columns: minmax(0, 1fr) 150px 90px; }
  .catalog-category { display: none; }
  .data-header { display: none; }
  .data-row { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 13px; }
  .data-cell::before { display: block; margin-bottom: 4px; color: var(--muted); content: attr(data-label); font-family: var(--mono); font-size: 10px; }
  .data-cell:first-child { grid-column: 1 / -1; }
  .cell-link { white-space: normal; }
}

@media (max-width: 680px) {
  .topbar { position: static; min-height: 60px; }
  .topbar-inner { width: min(100% - 28px, 1160px); min-height: 58px; }
  .brand { gap: 10px; font-size: 15px; }
  .brand-mark { width: 32px; height: 32px; flex-basis: 32px; font-size: 18px; box-shadow: 2px 2px 0 var(--ink); }
  .desktop-nav, .balance-mini { display: none; }
  .main-content { width: min(100% - 28px, 1160px); padding: 27px 0 105px; }
  .page-heading { min-height: 0; align-items: flex-start; margin-bottom: 21px; }
  .page-heading h1 { font-size: 25px; }
  .heading-actions { align-self: end; }
  .heading-actions .button { min-height: 35px; padding: 6px 9px; font-size: 11px; }
  .account-strip { padding: 16px 0; }
  .account-strip > div { gap: 11px; }
  .account-strip strong, .ledger-summary strong { font-size: 23px; }
  .catalog-controls { margin: 23px 0 27px; }
  .catalog-browser { display: block; }
  .platform-sidebar { border: 0; padding: 0; margin-bottom: 25px; }
  .platform-sidebar h2 { margin-bottom: 10px; }
  .platform-tabs { display: flex; gap: 7px; overflow-x: auto; padding-bottom: 4px; scrollbar-width: none; }
  .platform-tabs::-webkit-scrollbar { display: none; }
  .platform-tab { width: auto; flex: 0 0 auto; border: 1px solid var(--line); padding: 7px 11px; white-space: nowrap; }
  .platform-tab.active { border-color: var(--amber); }
  .catalog-list-heading { align-items: center; }
  .catalog-tools label, .catalog-tools .muted { display: none; }
  .catalog-tools select { width: min(190px, 43vw); }
  .catalog-row { grid-template-columns: minmax(0, 1fr) auto; gap: 7px 12px; padding: 15px 1px; }
  .catalog-main { grid-column: 1 / -1; }
  .catalog-category { display: block; grid-column: 1; font-size: 11px; }
  .catalog-price { grid-column: 1; grid-row: 3; }
  .catalog-row .button { grid-column: 2; grid-row: 2 / 4; }
  .catalog-row:hover { padding-left: 1px; }
  .mobile-nav { position: fixed; z-index: 10; right: 0; bottom: 0; left: 0; display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); height: calc(62px + env(safe-area-inset-bottom)); border-top: 2px solid var(--ink); padding-bottom: env(safe-area-inset-bottom); background: var(--paper); }
  .mobile-nav button { border: 0; background: none; color: var(--muted); font-size: 12px; font-weight: 700; }
  .mobile-nav button.active { color: var(--amber); box-shadow: inset 0 3px var(--amber); }
  .ledger-summary { flex-wrap: wrap; gap: 7px 13px; }
  .ledger-summary a { width: 100%; margin: 4px 0 0; }
  .form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 10px; }
  .form-grid > div:last-child { grid-column: 1 / -1; }
  .form-footer { align-items: stretch; flex-direction: column; gap: 12px; }
  .form-footer .button { width: 100%; }
  .preview-row { grid-template-columns: 26px minmax(0, 1fr) 98px; gap: 8px; }
  .preview-total { flex-wrap: wrap; gap: 12px 18px; }
  .preview-total .button { width: 100%; margin: 5px 0 0; }
  .data-row { grid-template-columns: repeat(2, minmax(0, 1fr)); padding: 16px 0; }
  .dialog { width: min(100% - 20px, 540px); padding: 21px 19px 24px; box-shadow: 5px 5px 0 var(--ink); }
  .toast { right: 16px; bottom: calc(78px + env(safe-area-inset-bottom)); }
  .auth-screen { padding: 40px 20px; }
  .auth-wrap { grid-template-columns: 1fr; gap: 22px; }
  .auth-heading { border-top-width: 3px; padding-top: 15px; }
  .auth-heading .brand-name { font-size: 26px; }
  .auth-panel { grid-column: 1; grid-row: auto; padding: 24px 22px 27px; box-shadow: 5px 5px 0 var(--ink); }
  .auth-help { justify-self: start; }
}

@media (max-width: 390px) {
  .page-heading { flex-wrap: wrap; }
  .heading-actions { width: 100%; }
  .heading-actions .button { flex: 1; }
  .account-strip strong { font-size: 20px; }
  .catalog-tools select { width: 140px; }
  .product-actions { grid-template-columns: 1fr; }
}

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