/* Halden design system: tokens + components.
   Every screen in the prototype and every page of the case study is built only from these.
   Naming mirrors how a dev team would ship it: --color-*, --space-*, --radius-*, --motion-*. */

:root {
  color-scheme: light;
  /* colour: cool slate neutrals, one jade accent, semantic money colours */
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --surface-3: #e9ecf0;
  --line: #e4e7ec;
  --line-2: #d5dae1;
  --ink: #0c1116;
  --ink-2: #4a5361;
  --ink-3: #87909d;
  --accent: #0d7a61;
  --accent-hover: #0a6852;
  --accent-ink: #ffffff;
  --accent-soft: #e2f3ee;
  --accent-bright: #17b58c;
  --pos: #0c8a5d;
  --pos-soft: #e3f5ec;
  --neg: #cf3f3a;
  --neg-soft: #fcebea;
  --warn: #a8690c;
  --warn-soft: #fbf1df;
  --info: #2a64d6;
  --info-soft: #e7eefc;
  --chart-2: #2a64d6;
  --chart-3: #e3a33a;
  --chart-4: #8a6de0;
  --scrim: rgba(12, 17, 22, 0.32);
  --card-a: #0f1a17;
  --card-b: #1d3a31;

  --shadow-1: 0 1px 2px rgba(12, 17, 22, 0.05), 0 1px 1px rgba(12, 17, 22, 0.03);
  --shadow-2: 0 10px 28px -10px rgba(12, 17, 22, 0.14), 0 2px 6px rgba(12, 17, 22, 0.04);
  --shadow-3: 0 30px 80px -20px rgba(12, 17, 22, 0.28), 0 4px 12px rgba(12, 17, 22, 0.06);
  --ring: 0 0 0 4px color-mix(in srgb, var(--accent) 20%, transparent);

  /* type */
  --font: "Manrope", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-display: "Fraunces", "Iowan Old Style", Georgia, serif;
  --font-mono: "IBM Plex Mono", ui-monospace, Menlo, Consolas, monospace;
  --text-xs: 12px; --text-sm: 13px; --text-md: 14px; --text-lg: 16px; --text-xl: 20px; --text-2xl: 28px; --text-3xl: 40px;

  /* space (4px base), radius, motion */
  --space-1: 4px; --space-2: 8px; --space-3: 12px; --space-4: 16px; --space-5: 20px; --space-6: 24px; --space-8: 32px; --space-10: 40px;
  --radius-sm: 8px; --radius-md: 12px; --radius-lg: 16px; --radius-xl: 22px; --radius-full: 999px;
  --motion-fast: 120ms; --motion-base: 200ms; --motion-slow: 360ms;
  --ease-out: cubic-bezier(0.2, 0.8, 0.2, 1);
  --ease-spring: cubic-bezier(0.34, 1.4, 0.64, 1);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0a0c0f; --surface: #111418; --surface-2: #171b20; --surface-3: #1e2329; --line: #22272e; --line-2: #2d333b;
    --ink: #eef1f4; --ink-2: #a3acb8; --ink-3: #6c7581;
    --accent: #37cfa4; --accent-hover: #5fdcb8; --accent-ink: #03140e; --accent-soft: rgba(55, 207, 164, 0.12); --accent-bright: #37cfa4;
    --pos: #3fd09a; --pos-soft: rgba(63, 208, 154, 0.12); --neg: #ff6f69; --neg-soft: rgba(255, 111, 105, 0.12);
    --warn: #f0b44c; --warn-soft: rgba(240, 180, 76, 0.12); --info: #72a1ff; --info-soft: rgba(114, 161, 255, 0.12);
    --chart-2: #72a1ff; --chart-3: #f0b44c; --chart-4: #a891ff; --scrim: rgba(0, 0, 0, 0.6);
    --card-a: #0b1411; --card-b: #1c3a30;
    --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.4); --shadow-2: 0 12px 30px -10px rgba(0, 0, 0, 0.6); --shadow-3: 0 30px 80px -20px rgba(0, 0, 0, 0.8);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0a0c0f; --surface: #111418; --surface-2: #171b20; --surface-3: #1e2329; --line: #22272e; --line-2: #2d333b;
  --ink: #eef1f4; --ink-2: #a3acb8; --ink-3: #6c7581;
  --accent: #37cfa4; --accent-hover: #5fdcb8; --accent-ink: #03140e; --accent-soft: rgba(55, 207, 164, 0.12); --accent-bright: #37cfa4;
  --pos: #3fd09a; --pos-soft: rgba(63, 208, 154, 0.12); --neg: #ff6f69; --neg-soft: rgba(255, 111, 105, 0.12);
  --warn: #f0b44c; --warn-soft: rgba(240, 180, 76, 0.12); --info: #72a1ff; --info-soft: rgba(114, 161, 255, 0.12);
  --chart-2: #72a1ff; --chart-3: #f0b44c; --chart-4: #a891ff; --scrim: rgba(0, 0, 0, 0.6);
  --card-a: #0b1411; --card-b: #1c3a30;
  --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.4); --shadow-2: 0 12px 30px -10px rgba(0, 0, 0, 0.6); --shadow-3: 0 30px 80px -20px rgba(0, 0, 0, 0.8);
}

/* ---------- base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 500 var(--text-md)/1.5 var(--font); -webkit-font-smoothing: antialiased; }
img, svg { display: block; max-width: 100%; }
[hidden] { display: none !important; }
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, h3, h4 { margin: 0; letter-spacing: -0.02em; line-height: 1.15; font-weight: 700; text-wrap: balance; }
p { margin: 0; text-wrap: pretty; }
:focus-visible { outline: none; box-shadow: var(--ring); border-radius: 6px; }
.num, .money { font-variant-numeric: tabular-nums; font-feature-settings: "tnum"; }
.mono { font-family: var(--font-mono); font-weight: 400; }
.muted { color: var(--ink-2); }
.subtle { color: var(--ink-3); }
.pos { color: var(--pos); } .neg { color: var(--neg); }
.theme-fade, .theme-fade * { transition: background-color var(--motion-slow) var(--ease-out), border-color var(--motion-slow) var(--ease-out), color var(--motion-slow) var(--ease-out) !important; }

/* ---------- button ---------- */
.btn {
  --h: 38px;
  position: relative; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: var(--h); padding: 0 14px; border-radius: var(--radius-sm); border: 1px solid transparent;
  font-size: var(--text-md); font-weight: 650; letter-spacing: -0.005em; white-space: nowrap; user-select: none;
  transition: background var(--motion-base) var(--ease-out), border-color var(--motion-base), box-shadow var(--motion-base), transform var(--motion-fast) var(--ease-out), color var(--motion-base);
}
.btn:active:not([disabled]) { transform: scale(0.97); }
.btn svg { width: 16px; height: 16px; flex: none; }
.btn-sm { --h: 32px; padding: 0 10px; font-size: var(--text-sm); }
.btn-lg { --h: 46px; padding: 0 20px; font-size: 15px; border-radius: 10px; }
.btn-primary { background: var(--ink); color: var(--surface); box-shadow: 0 1px 0 rgba(255,255,255,.12) inset, var(--shadow-1); }
.btn-primary:hover { background: color-mix(in srgb, var(--ink) 86%, var(--surface)); }
.btn-accent { background: var(--accent); color: var(--accent-ink); box-shadow: 0 1px 0 rgba(255,255,255,.18) inset, var(--shadow-1); }
.btn-accent:hover { background: var(--accent-hover); }
.btn-secondary { background: var(--surface); border-color: var(--line-2); color: var(--ink); box-shadow: var(--shadow-1); }
.btn-secondary:hover { background: var(--surface-2); }
.btn-ghost { background: transparent; color: var(--ink-2); }
.btn-ghost:hover { background: var(--surface-2); color: var(--ink); }
.btn-danger { background: var(--neg-soft); color: var(--neg); }
.btn-danger:hover { background: color-mix(in srgb, var(--neg) 18%, transparent); }
.btn[disabled] { opacity: 0.45; cursor: not-allowed; }
.btn.is-loading { color: transparent !important; pointer-events: none; }
.btn.is-loading::after { content: ""; position: absolute; width: 16px; height: 16px; border-radius: 50%; border: 2px solid currentColor; border-color: var(--surface) var(--surface) transparent transparent; animation: spin 0.7s linear infinite; }
.btn-secondary.is-loading::after, .btn-ghost.is-loading::after { border-color: var(--ink) var(--ink) transparent transparent; }
.btn-accent.is-loading::after { border-color: var(--accent-ink) var(--accent-ink) transparent transparent; }
.btn-danger.is-loading::after { border-color: var(--neg) var(--neg) transparent transparent; }
.btn-icon { width: var(--h); padding: 0; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- inputs ---------- */
.field { display: grid; gap: 6px; }
.label { font-size: var(--text-sm); font-weight: 650; color: var(--ink); }
.hint { font-size: var(--text-xs); color: var(--ink-3); font-weight: 500; }
.field.has-error .hint { color: var(--neg); }
.input {
  height: 42px; width: 100%; padding: 0 12px; border-radius: 10px; border: 1px solid var(--line-2); background: var(--surface); color: var(--ink);
  font-weight: 550; transition: border-color var(--motion-base), box-shadow var(--motion-base); box-shadow: var(--shadow-1);
}
.input::placeholder { color: var(--ink-3); font-weight: 500; }
.input:hover { border-color: color-mix(in srgb, var(--ink) 22%, var(--line-2)); }
.input:focus { outline: none; border-color: var(--accent); box-shadow: var(--ring); }
.field.has-error .input { border-color: var(--neg); }
.input-wrap { position: relative; display: flex; align-items: center; }
.input-wrap .pre { position: absolute; left: 12px; color: var(--ink-3); pointer-events: none; }
.input-wrap .input { padding-left: 28px; }
select.input { appearance: none; padding-right: 34px; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2387909d' stroke-width='2.4'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; }

/* ---------- badge / chip / avatar / kbd ---------- */
.badge { display: inline-flex; align-items: center; gap: 6px; height: 22px; padding: 0 8px; border-radius: var(--radius-full); font-size: 11.5px; font-weight: 700; white-space: nowrap; background: var(--surface-2); color: var(--ink-2); }
.badge i { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge-pos { background: var(--pos-soft); color: var(--pos); }
.badge-neg { background: var(--neg-soft); color: var(--neg); }
.badge-warn { background: var(--warn-soft); color: var(--warn); }
.badge-info { background: var(--info-soft); color: var(--info); }
.badge-accent { background: var(--accent-soft); color: var(--accent); }
.chip { display: inline-flex; align-items: center; gap: 6px; height: 30px; padding: 0 12px; border-radius: var(--radius-full); border: 1px solid var(--line-2); background: var(--surface); font-size: var(--text-sm); font-weight: 600; color: var(--ink-2); transition: all var(--motion-base) var(--ease-out); }
.chip:hover { color: var(--ink); border-color: color-mix(in srgb, var(--ink) 25%, var(--line-2)); }
.chip[aria-pressed="true"] { background: var(--ink); color: var(--surface); border-color: var(--ink); }
.avatar { width: 32px; height: 32px; border-radius: 50%; object-fit: cover; flex: none; background: var(--surface-3); display: inline-grid; place-items: center; font-size: 12px; font-weight: 700; color: var(--ink-2); }
.avatar-sm { width: 24px; height: 24px; font-size: 10px; }
.avatar-lg { width: 44px; height: 44px; }
.merchant { width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; font-size: 13px; font-weight: 800; flex: none; color: #fff; letter-spacing: -0.02em; }
.kbd { display: inline-grid; place-items: center; min-width: 20px; height: 20px; padding: 0 5px; border-radius: 5px; border: 1px solid var(--line-2); border-bottom-width: 2px; font: 600 11px var(--font); color: var(--ink-3); background: var(--surface); }

/* ---------- switch / segmented / tabs ---------- */
.switch { position: relative; width: 38px; height: 22px; border-radius: var(--radius-full); background: var(--line-2); border: 0; padding: 0; transition: background var(--motion-base) var(--ease-out); flex: none; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.25); transition: transform var(--motion-slow) var(--ease-spring); }
.switch[aria-checked="true"] { background: var(--accent); }
.switch[aria-checked="true"]::after { transform: translateX(16px); }
.seg { position: relative; display: inline-flex; padding: 3px; border-radius: 10px; background: var(--surface-2); border: 1px solid var(--line); }
.seg button { position: relative; z-index: 1; height: 28px; padding: 0 12px; border: 0; background: transparent; border-radius: 7px; font-size: var(--text-sm); font-weight: 650; color: var(--ink-3); transition: color var(--motion-base); }
.seg button[aria-pressed="true"] { color: var(--ink); }
.seg .thumb { position: absolute; top: 3px; bottom: 3px; border-radius: 7px; background: var(--surface); box-shadow: var(--shadow-1); transition: left var(--motion-slow) var(--ease-spring), width var(--motion-slow) var(--ease-spring); }
.tabs { display: flex; gap: 20px; border-bottom: 1px solid var(--line); overflow-x: auto; scrollbar-width: none; }
.tabs button { position: relative; height: 40px; border: 0; background: none; padding: 0; font-size: var(--text-md); font-weight: 650; color: var(--ink-3); white-space: nowrap; }
.tabs button[aria-selected="true"] { color: var(--ink); }
.tabs button[aria-selected="true"]::after { content: ""; position: absolute; left: 0; right: 0; bottom: -1px; height: 2px; border-radius: 2px; background: var(--ink); }

/* ---------- surfaces ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); box-shadow: var(--shadow-1); }
.card-h { display: flex; align-items: center; gap: 12px; padding: 16px 20px; }
.card-h h3 { font-size: 15px; font-weight: 700; letter-spacing: -0.01em; }
.card-h .right { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.divider { height: 1px; background: var(--line); border: 0; margin: 0; }

/* ---------- table ---------- */
.table { width: 100%; border-collapse: collapse; font-size: var(--text-md); }
.table th { text-align: left; font-size: var(--text-xs); font-weight: 650; color: var(--ink-3); padding: 10px 20px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.table td { padding: 12px 20px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tbody tr { transition: background var(--motion-fast); }
.table tbody tr:hover { background: color-mix(in srgb, var(--surface-2) 70%, transparent); }
.table tbody tr:last-child td { border-bottom: 0; }
.table .r { text-align: right; }
.table-scroll { overflow-x: auto; }

/* ---------- progress, skeleton ---------- */
.progress { height: 6px; border-radius: var(--radius-full); background: var(--surface-3); overflow: hidden; }
.progress i { display: block; height: 100%; border-radius: inherit; background: var(--accent); transition: width 900ms var(--ease-out); }
.skeleton { position: relative; overflow: hidden; background: var(--surface-2); border-radius: 8px; }
.skeleton::after { content: ""; position: absolute; inset: 0; transform: translateX(-100%); background: linear-gradient(90deg, transparent, color-mix(in srgb, var(--surface) 70%, transparent), transparent); animation: shimmer 1.2s infinite; }
@keyframes shimmer { to { transform: translateX(100%); } }

/* ---------- toast ---------- */
.toasts { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); z-index: 100; display: grid; gap: 8px; justify-items: center; pointer-events: none; padding-bottom: env(safe-area-inset-bottom, 0px); }
.toast { pointer-events: auto; display: flex; align-items: center; gap: 12px; padding: 10px 10px 10px 14px; border-radius: 12px; background: var(--ink); color: var(--surface); font-size: var(--text-md); font-weight: 600; box-shadow: var(--shadow-3); animation: toastIn var(--motion-slow) var(--ease-spring); white-space: nowrap; }
.toast .ic { width: 20px; height: 20px; border-radius: 50%; background: var(--accent-bright); color: #03140e; display: grid; place-items: center; }
.toast button { height: 28px; padding: 0 10px; border-radius: 7px; border: 0; background: color-mix(in srgb, var(--surface) 16%, transparent); color: var(--surface); font-weight: 700; font-size: var(--text-sm); }
.toast.out { animation: toastOut 220ms var(--ease-out) forwards; }
@keyframes toastIn { from { opacity: 0; transform: translateY(16px) scale(0.96); } }
@keyframes toastOut { to { opacity: 0; transform: translateY(8px) scale(0.98); } }

/* ---------- modal / drawer ---------- */
.scrim { position: fixed; inset: 0; background: var(--scrim); z-index: 60; opacity: 0; transition: opacity var(--motion-slow) var(--ease-out); backdrop-filter: blur(2px); -webkit-backdrop-filter: blur(2px); }
.scrim.open { opacity: 1; }
.scrim:not(.open) { pointer-events: none; }
.modal { position: fixed; left: 50%; top: 50%; z-index: 61; width: min(520px, calc(100vw - 32px)); max-height: calc(100vh - 48px); overflow: auto; transform: translate(-50%, -46%) scale(0.97); opacity: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-xl); box-shadow: var(--shadow-3); transition: transform var(--motion-slow) var(--ease-spring), opacity var(--motion-base) var(--ease-out); }
.modal.open { transform: translate(-50%, -50%) scale(1); opacity: 1; }
.drawer { position: fixed; top: 8px; right: 8px; bottom: 8px; z-index: 61; width: min(440px, calc(100vw - 16px)); background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-xl); box-shadow: var(--shadow-3); transform: translateX(calc(100% + 24px)); transition: transform 420ms var(--ease-out); display: flex; flex-direction: column; overflow: hidden; }
.drawer.open { transform: none; }

/* ---------- payment card ---------- */
.ccard { --w: 100%; position: relative; aspect-ratio: 1.586; width: var(--w); border-radius: 14px; perspective: 1200px; }
.ccard .flip { position: absolute; inset: 0; transform-style: preserve-3d; transition: transform 700ms var(--ease-out); }
.ccard.flipped .flip { transform: rotateY(180deg); }
.ccard .face { position: absolute; inset: 0; border-radius: inherit; backface-visibility: hidden; -webkit-backface-visibility: hidden; overflow: hidden; color: #fff; padding: 7% 7.5%; display: flex; flex-direction: column; justify-content: space-between; background: radial-gradient(120% 90% at 100% 0%, var(--card-b), var(--card-a) 60%); box-shadow: 0 1px 0 rgba(255,255,255,.14) inset, 0 20px 40px -20px rgba(0,0,0,.6); }
.ccard .face::before { content: ""; position: absolute; inset: 0; background: repeating-linear-gradient(115deg, rgba(255,255,255,.035) 0 2px, transparent 2px 7px); mix-blend-mode: overlay; pointer-events: none; }
.ccard .face::after { content: ""; position: absolute; inset: -40%; background: linear-gradient(115deg, transparent 40%, rgba(255,255,255,.14) 50%, transparent 60%); transform: translateX(-30%); transition: transform 900ms var(--ease-out); pointer-events: none; }
.ccard:hover .face::after { transform: translateX(30%); }
.ccard.v-sand .face { background: radial-gradient(120% 90% at 100% 0%, #e9dcc5, #cbb693 70%); color: #2b2418; }
.ccard.v-ink .face { background: radial-gradient(120% 90% at 100% 0%, #3a3f4a, #121418 65%); }
.ccard.v-sky .face { background: radial-gradient(120% 90% at 100% 0%, #8fb6ff, #3d63d8 70%); }
.ccard .top { display: flex; justify-content: space-between; align-items: flex-start; font-weight: 800; letter-spacing: -0.02em; position: relative; z-index: 1; }
.ccard .top svg { width: 9%; height: auto; opacity: .85; }
.ccard .chip { width: 15%; aspect-ratio: 1.3; border-radius: 4px; background: linear-gradient(135deg, #e8d7a6, #b8a06a); position: relative; z-index: 1; box-shadow: inset 0 0 0 1px rgba(0,0,0,.15); }
.ccard .bot { display: flex; justify-content: space-between; align-items: flex-end; position: relative; z-index: 1; font-size: clamp(10px, 1.1vw, 13px); font-weight: 700; }
.ccard .bot .pan { font-family: var(--font-mono); letter-spacing: 0.08em; font-weight: 500; }
.ccard .bot .net { font-size: 1.5em; font-style: italic; font-weight: 900; letter-spacing: -0.04em; }
.ccard .back { transform: rotateY(180deg); justify-content: flex-end; gap: 6%; }
.ccard .back .stripe { position: absolute; left: 0; right: 0; top: 12%; height: 18%; background: #05080a; }
.ccard .back .full { font-family: var(--font-mono); font-size: clamp(12px, 1.6vw, 17px); letter-spacing: 0.12em; font-weight: 500; position: relative; z-index: 1; }
.ccard .back .row { display: flex; gap: 22px; font-size: 12px; position: relative; z-index: 1; }
.ccard .back .row small { display: block; opacity: 0.6; font-size: 10px; letter-spacing: 0.06em; text-transform: uppercase; }
.ccard .frost { position: absolute; inset: 0; border-radius: inherit; z-index: 3; display: grid; place-items: center; background: rgba(210, 230, 255, 0.28); backdrop-filter: blur(6px) saturate(0.4); -webkit-backdrop-filter: blur(6px) saturate(0.4); opacity: 0; transform: scale(1.04); transition: opacity 420ms var(--ease-out), transform 420ms var(--ease-out); pointer-events: none; color: #fff; }
.ccard .frost svg { width: 22%; height: auto; filter: drop-shadow(0 2px 8px rgba(0,0,0,.3)); transform: rotate(-90deg) scale(0.6); transition: transform 600ms var(--ease-spring); }
.ccard.frozen .frost { opacity: 1; transform: none; }
.ccard.frozen .frost svg { transform: none; }
.ccard.new { animation: cardIn 700ms var(--ease-spring) both; }
@keyframes cardIn { from { opacity: 0; transform: translateY(20px) rotate(-4deg) scale(0.92); } }

/* ---------- empty state ---------- */
.empty { display: grid; justify-items: center; text-align: center; gap: 10px; padding: 40px 24px; color: var(--ink-2); }
.empty .ill { width: 56px; height: 56px; border-radius: 16px; background: var(--surface-2); display: grid; place-items: center; color: var(--ink-3); }
.empty h4 { color: var(--ink); font-size: 15px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 1ms !important; animation-iteration-count: 1 !important; transition-duration: 1ms !important; }
}
