:root {
  color-scheme: light;

  /* ---- surfaces & ink ------------------------------------------------ */
  --bg: #f5f3ee;
  --surface: #ffffff;
  --surface-2: #efece3;
  --ink: #201f1c;
  --muted: #6b6a62;
  --muted-2: #918f84;
  --border: #ddd7c9;
  --border-strong: #c6bfac;

  /* ---- accent (primary brand green) ----------------------------------- */
  --accent: #1a6b50;
  --accent-dark: #124e3a;
  --accent-light: #e3f0e9;
  --accent-ink: #ffffff;

  /* ---- secondary hues, decorative (icon chips, not interactive state) - */
  --hue-order-bg: #e7ecfb;
  --hue-order-ink: #35479f;
  --hue-payment-bg: #fbf0da;
  --hue-payment-ink: #93630a;

  /* ---- semantic: warning / near-match attention ----------------------- */
  --warning-bg: #fef2c7;
  --warning-border: #e5a010;
  --warning-strong: #a45b06;
  --warning-ink: #6b3c04;

  /* ---- semantic: info (plain "create new", no near match) ------------- */
  --info-bg: #e3f0e9;
  --info-border: #7fb59d;
  --info-ink: #124e3a;

  /* ---- semantic: error -------------------------------------------------- */
  --error: #ab241b;
  --error-bg: #fbeceb;
  --error-border: #e3a49d;

  /* ---- semantic: success ------------------------------------------------ */
  --success: #1a6b50;
  --success-bg: #e3f0e9;

  /* ---- spacing scale (4px base) ---------------------------------------- */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-7: 32px;
  --space-8: 40px;

  /* ---- type scale -------------------------------------------------------- */
  --text-xs: 0.75rem;
  --text-sm: 0.8125rem;
  --text-base: 1rem;
  --text-md: 1.0625rem;
  --text-lg: 1.25rem;
  --text-xl: 1.75rem;

  /* ---- radius scale -------------------------------------------------------- */
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-pill: 999px;

  /* ---- elevation ---------------------------------------------------------- */
  --shadow-xs: 0 1px 2px rgba(24, 22, 14, 0.07);
  --shadow-sm: 0 2px 8px rgba(24, 22, 14, 0.09);
  --shadow-md: 0 10px 24px rgba(24, 22, 14, 0.14);
  --shadow-warning: 0 8px 20px rgba(164, 91, 6, 0.28);

  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 16px;
  line-height: 1.45;
  -webkit-tap-highlight-color: transparent;
}

#app {
  max-width: 480px;
  margin: 0 auto;
  padding: var(--space-5) var(--space-4) var(--space-6);
  min-height: 100vh;
}

.screen { display: flex; flex-direction: column; gap: var(--space-5); }

h1 { font-size: var(--text-xl); font-weight: 800; margin: 0; letter-spacing: -0.01em; }
h2 { font-size: var(--text-lg); font-weight: 700; margin: 0; letter-spacing: -0.01em; }
.subtitle { color: var(--muted); margin: 0; font-size: var(--text-base); }

:focus-visible {
  outline: 2.5px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

/* ==================================================== buttons: hierarchy */

.btn {
  font: inherit;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  border-radius: var(--radius-md);
  border: 1.5px solid transparent;
  cursor: pointer;
  min-height: 48px;
  font-weight: 700;
  font-size: var(--text-md);
  transition: transform 80ms ease, box-shadow 120ms ease, background-color 120ms ease;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

button { font: inherit; }
/* Universal fallback: several real buttons (Continue, Review, Confirm &
   save, Back to home) are styled via the [data-role] attribute-selector
   list below, not the .btn/.btn-primary classes those two rely on — so
   without this, disabling or pressing them showed no visual change at
   all. Class-specific rules like .action-button:active still win where
   they exist (higher specificity); this just guarantees every button has
   SOME feedback. */
button:active:not(:disabled) { transform: translateY(1px); }
button:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary,
[data-role="pin-form"] button[type="submit"],
[data-role="entry-form"] button[type="submit"],
[data-role="confirm-submit"],
[data-role="done-continue"] {
  background: linear-gradient(180deg, var(--accent) 0%, var(--accent-dark) 100%);
  color: var(--accent-ink);
  border: 1.5px solid var(--accent-dark);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  width: 100%;
  min-height: 48px;
  font-weight: 700;
  font-size: var(--text-md);
  cursor: pointer;
  padding: var(--space-4) var(--space-5);
}
.btn-primary:disabled { box-shadow: none; }

.btn-secondary {
  background: var(--surface);
  color: var(--accent);
  border-color: var(--accent);
  padding: var(--space-3) var(--space-4);
}

.link-button, .btn-tertiary {
  background: none;
  border: none;
  color: var(--accent);
  padding: var(--space-2) 0;
  font-weight: 600;
  font-size: var(--text-base);
  text-decoration: underline;
  text-underline-offset: 2px;
  text-align: left;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
}

/* Its own class rather than .link-button: a bare underlined arrow was a
   ~12px tap target, small enough on a phone to read as "there is no back
   button at all". 44px is the usual minimum for a thumb. */
.back-button {
  background: none;
  border: none;
  color: var(--accent);
  font-size: var(--text-base);
  font-weight: 600;
  padding: var(--space-2) var(--space-3) var(--space-2) var(--space-1);
  margin-left: calc(var(--space-1) * -1);
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  border-radius: var(--radius-sm);
  text-align: left;
}
.back-button .icon-back { width: 20px; height: 20px; flex: 0 0 auto; }

/* ==================================================================== forms */

input, textarea, select {
  font: inherit;
  width: 100%;
  padding: var(--space-3) var(--space-3);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
  color: var(--ink);
  min-height: 48px;
}
textarea { min-height: 72px; }

input:focus-visible, textarea:focus-visible, select:focus-visible {
  border-color: var(--accent);
  outline: 2.5px solid var(--accent);
  outline-offset: 0;
}

label {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--muted);
}

fieldset { border: none; padding: 0; margin: 0; }
fieldset legend { font-size: var(--text-sm); font-weight: 600; color: var(--muted); padding: 0 0 var(--space-2); }
fieldset .direction-options { display: flex; gap: var(--space-3); }
fieldset label {
  flex: 1 1 0;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  color: var(--ink);
  font-size: var(--text-base);
  font-weight: 600;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--space-3) var(--space-3);
  min-height: 48px;
  background: var(--surface);
}
fieldset label:has(input:checked) {
  background: var(--accent-light);
  border-color: var(--accent);
  color: var(--accent-dark);
}
fieldset input[type="radio"] { width: auto; min-height: 0; accent-color: var(--accent); }

.error {
  background: var(--error-bg);
  color: var(--error);
  border: 1px solid var(--error-border);
  border-radius: var(--radius-md);
  padding: var(--space-3) var(--space-4);
  font-size: var(--text-sm);
  font-weight: 600;
  margin: 0;
}

.home-header, .form-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
}
.form-header h2 { flex: 1; }

/* ===================================================================== home */

.home-header { padding-bottom: var(--space-2); }
.home-greeting { display: flex; align-items: center; gap: var(--space-3); }
.home-avatar {
  width: 40px; height: 40px; border-radius: var(--radius-pill);
  background: var(--accent);
  color: var(--accent-ink);
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: var(--text-base);
  flex: 0 0 auto;
  text-transform: uppercase;
}
.home-greeting-text { display: flex; flex-direction: column; }
.home-greeting-hi { font-size: var(--text-xs); color: var(--muted); font-weight: 600; }
.home-greeting-name { font-size: var(--text-md); font-weight: 700; }

.home-actions { display: flex; flex-direction: column; gap: var(--space-3); }

.action-button {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
  box-shadow: var(--shadow-xs);
  text-align: left;
  min-height: 68px;
  cursor: pointer;
}
.action-button:active { transform: translateY(1px); box-shadow: none; }

.action-icon {
  flex: 0 0 auto;
  width: 44px; height: 44px;
  border-radius: var(--radius-md);
  display: flex; align-items: center; justify-content: center;
  background: var(--accent-light);
  color: var(--accent);
}
.action-icon svg { width: 22px; height: 22px; }
.action-icon--order { background: var(--hue-order-bg); color: var(--hue-order-ink); }
.action-icon--payment { background: var(--hue-payment-bg); color: var(--hue-payment-ink); }

.action-text { flex: 1 1 auto; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.action-title { font-weight: 700; font-size: var(--text-md); color: var(--ink); }
.action-subtitle { font-size: var(--text-sm); color: var(--muted); font-weight: 500; }

.action-chevron { flex: 0 0 auto; width: 20px; height: 20px; color: var(--muted-2); }

.outbox-button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  align-self: stretch;
  font-size: var(--text-sm);
  font-weight: 700;
  color: var(--muted);
  background: var(--surface-2);
  border: 1.5px dashed var(--border-strong);
  border-radius: var(--radius-md);
  padding: var(--space-3) var(--space-4);
  min-height: 44px;
}
.outbox-button svg { width: 18px; height: 18px; flex: 0 0 auto; }
.outbox-button[data-has-items="true"] { color: var(--ink); border-style: solid; border-color: var(--border-strong); }
.outbox-button [data-role="outbox-count"] {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 20px; height: 20px; padding: 0 var(--space-2);
  background: var(--accent); color: var(--accent-ink);
  border-radius: var(--radius-pill); font-size: var(--text-xs); font-weight: 800;
}

/* =================================================================== line items */

.line-item {
  border: 1.5px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  background: var(--surface);
  box-shadow: var(--shadow-xs);
}

/* ================================================== vocabulary attention card
   ADR-0008: staff must consciously resolve a possible duplicate name rather
   than click through blindly. This card is the entire mechanism for that,
   so it has to visually outrank the quiet form fields around it — an icon,
   a saturated warning color reserved for the near-match case, elevation and
   a motion-in entrance — while stopping short of a blocking modal. */

@keyframes vocab-in {
  from { opacity: 0; transform: translateY(-6px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.vocab-create {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  padding: var(--space-4) var(--space-4) var(--space-4) calc(var(--space-4) + 30px);
  border-radius: var(--radius-lg);
  font-size: var(--text-sm);
  animation: vocab-in 220ms cubic-bezier(0.2, 0.8, 0.2, 1) both;
  background: var(--info-bg);
  border: 1.5px solid var(--info-border);
  color: var(--info-ink);
}
.vocab-create::before {
  content: "";
  position: absolute;
  left: var(--space-4);
  top: var(--space-4);
  width: 20px;
  height: 20px;
  background-color: currentColor;
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='12' r='9'/%3E%3Cpath d='M12 8v4M12 16h.01'/%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' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='12' r='9'/%3E%3Cpath d='M12 8v4M12 16h.01'/%3E%3C/svg%3E") center / contain no-repeat;
}
.vocab-create p { margin: 0; font-weight: 700; font-size: var(--text-base); color: inherit; }

.vocab-create--nearmatch {
  background: var(--warning-bg);
  border: 2px solid var(--warning-border);
  color: var(--warning-ink);
  box-shadow: var(--shadow-warning);
}
.vocab-create--nearmatch::before {
  -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M10.29 3.86 1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0Z'/%3E%3Cpath d='M12 9v4M12 17h.01'/%3E%3C/svg%3E");
  mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M10.29 3.86 1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0Z'/%3E%3Cpath d='M12 9v4M12 17h.01'/%3E%3C/svg%3E");
}

.vocab-create button {
  font: inherit;
  border-radius: var(--radius-sm);
  border: 1.5px solid currentColor;
  background: transparent;
  color: inherit;
  padding: var(--space-2) var(--space-3);
  font-weight: 700;
  font-size: var(--text-sm);
  align-self: flex-start;
  min-height: 40px;
  cursor: pointer;
}
.vocab-create button:active { transform: translateY(1px); }

/* The confirm/create action is always appended last (see app.mjs
   wireVocabCreate), so :last-child reaches it without needing a class. */
.vocab-create button:last-child {
  align-self: stretch;
  min-height: 46px;
  border: none;
  color: #fff;
  font-size: var(--text-base);
  box-shadow: var(--shadow-xs);
}
.vocab-create:not(.vocab-create--nearmatch) button:last-child { background: var(--accent); }
.vocab-create--nearmatch button:last-child { background: var(--warning-strong); }

/* =================================================================== confirm */

.confirm-summary {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: var(--space-3) var(--space-4);
  margin: 0;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-4) var(--space-5);
  box-shadow: var(--shadow-xs);
}
.confirm-summary dt { color: var(--muted); font-size: var(--text-sm); font-weight: 600; align-self: start; padding-top: 2px; }
.confirm-summary dd { margin: 0; font-weight: 700; font-size: var(--text-base); }

.confirm-actions { display: flex; flex-direction: column; gap: var(--space-2); }

/* ===================================================================== done */

.screen-done { align-items: center; text-align: center; padding-top: 12vh; gap: var(--space-6); }
.done-check {
  width: 88px; height: 88px;
  border-radius: var(--radius-pill);
  background: var(--success-bg);
  color: var(--success);
  display: flex; align-items: center; justify-content: center;
  margin: 0;
  animation: vocab-in 260ms cubic-bezier(0.2, 0.8, 0.2, 1);
}
.done-check svg { width: 48px; height: 48px; }
.screen-done p.done-message { font-size: var(--text-lg); font-weight: 700; margin: 0; }
.screen-done .btn-primary { max-width: 320px; }

/* =================================================================== outbox */

.outbox-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: var(--space-3); }
.outbox-item {
  border: 1.5px solid var(--border);
  border-left: 4px solid var(--border-strong);
  border-radius: var(--radius-md);
  padding: var(--space-4);
  background: var(--surface);
  box-shadow: var(--shadow-xs);
}
.outbox-item-summary { font-weight: 700; font-size: var(--text-base); }
.outbox-item-status {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--muted);
  margin-top: var(--space-1);
  display: flex;
  align-items: center;
  gap: var(--space-2);
}
.outbox-item-status::before {
  content: "";
  width: 8px; height: 8px;
  border-radius: var(--radius-pill);
  background: var(--muted-2);
  flex: 0 0 auto;
}
.outbox-item-status.status-pending::before { background: #6b83c9; }
.outbox-item-status.status-stale { color: var(--warning-strong); }
.outbox-item-status.status-stale::before { background: var(--warning-border); }
.outbox-item.status-stale { border-left-color: var(--warning-border); }
.outbox-item-status.status-failed { color: var(--error); }
.outbox-item-status.status-failed::before { background: var(--error); }
.outbox-item.status-failed { border-left-color: var(--error); }

.outbox-item-actions { display: flex; gap: var(--space-3); margin-top: var(--space-3); }
.outbox-item-actions button {
  font: inherit;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--border-strong);
  background: var(--surface);
  color: var(--ink);
  padding: var(--space-2) var(--space-3);
  font-weight: 600;
  font-size: var(--text-sm);
  min-height: 40px;
  cursor: pointer;
}
.outbox-item-actions button:first-child { border-color: var(--accent); color: var(--accent); }

.empty-state { color: var(--muted); text-align: center; margin-top: var(--space-8); font-size: var(--text-base); }

/* ====================================================================== toast */

#toast {
  position: fixed;
  bottom: calc(var(--space-4) + env(safe-area-inset-bottom, 0px));
  left: var(--space-4);
  right: var(--space-4);
  max-width: 448px;
  margin: 0 auto;
  background: var(--ink);
  color: #fff;
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  text-align: center;
  font-weight: 600;
  font-size: var(--text-sm);
  box-shadow: var(--shadow-md);
  z-index: 10;
}
[hidden] { display: none !important; }

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #16171a;
    --surface: #232427;
    --surface-2: #1c1d20;
    --ink: #f1efe9;
    --muted: #a6a49a;
    --muted-2: #85837a;
    --border: #3a3b3e;
    --border-strong: #4b4c50;

    --accent: #35a37e;
    --accent-dark: #1f6f54;
    --accent-light: #163229;
    --accent-ink: #08120d;

    --hue-order-bg: #1e2440;
    --hue-order-ink: #a7b3f2;
    --hue-payment-bg: #3a2c11;
    --hue-payment-ink: #f0c463;

    --warning-bg: #3a2a0c;
    --warning-border: #c8871c;
    --warning-strong: #e5a010;
    --warning-ink: #f5cf85;

    --info-bg: #163229;
    --info-border: #2f6b53;
    --info-ink: #8fd4b6;

    --error-bg: #3a2422;
    --error-border: #7a3a34;

    --success-bg: #163229;
  }
  .vocab-create--nearmatch button:last-child { color: #1a1203; }
}
