/* Design tokens mirror frontend/src/styles/global.css so the two apps read as
   siblings. Keep them in sync if that palette changes. */
:root {
    --color-bg: #f7f7f8;
    --color-surface: #ffffff;
    --color-surface-alt: #f0f1f3;
    --color-text: #1b1d21;
    --color-text-muted: #5b616b;
    --color-border: #dde1e6;
    --color-accent: #3b82f6;
    --color-accent-hover: #2f6fd8;
    --color-accent-contrast: #ffffff;
    --color-up: #15803d;
    --color-down: #dc2626;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.06);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.08);
    --ring: rgba(59, 130, 246, 0.28);

    --space-1: 4px;
    --space-2: 8px;
    --space-3: 12px;
    --space-4: 16px;
    --space-5: 24px;
    --space-6: 32px;
    --radius-sm: 4px;
    --radius-md: 8px;
    --radius-lg: 12px;

    --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

:root[data-theme='dark'] {
    --color-bg: #14161a;
    --color-surface: #1c1f24;
    --color-surface-alt: #23262c;
    --color-text: #e7e9ec;
    --color-text-muted: #9aa1ab;
    --color-border: #2e3238;
    --color-accent: #60a5fa;
    --color-accent-hover: #7cb4fb;
    --color-accent-contrast: #0b0d10;
    --color-up: #4ade80;
    --color-down: #f87171;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.5);
    --ring: rgba(96, 165, 250, 0.35);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: var(--font-sans);
    background: var(--color-bg);
    color: var(--color-text);
    -webkit-text-size-adjust: 100%;
}

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
}

/* Shell ------------------------------------------------------------------ */

.checkout {
    width: 100%;
    max-width: 480px;
    margin: 0 auto;
    padding: var(--space-4) var(--space-4) var(--space-6);
}

.checkout-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-4);
    padding: var(--space-2) var(--space-1);
}
.brand {
    font-size: 0.9375rem;
    font-weight: 600;
    letter-spacing: -0.01em;
}

.theme-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    padding: 0;
    border: 1px solid var(--color-border);
    border-radius: 50%;
    background: var(--color-surface);
    color: var(--color-text-muted);
    cursor: pointer;
}
.theme-toggle:hover {
    color: var(--color-text);
}
.theme-toggle svg {
    fill: none;
    stroke: currentColor;
    stroke-width: 1.75;
    stroke-linecap: round;
    stroke-linejoin: round;
}
.theme-toggle .icon-moon { display: none; }
:root[data-theme='dark'] .theme-toggle .icon-sun { display: none; }
:root[data-theme='dark'] .theme-toggle .icon-moon { display: block; }

/* Progress dots ---------------------------------------------------------- */

.progress {
    display: flex;
    gap: var(--space-2);
    justify-content: center;
    margin: var(--space-4) 0;
    padding: 0;
    list-style: none;
}
.progress-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--color-border);
    transition: background 0.2s ease, width 0.2s ease;
}
.progress-dot.is-done {
    background: var(--color-text-muted);
}
.progress-dot.is-current {
    width: 22px;
    border-radius: 4px;
    background: var(--color-accent);
}

/* Card ------------------------------------------------------------------- */

.card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    padding: var(--space-5) var(--space-5) var(--space-2);
}

.step[hidden] { display: none; }
.step {
    animation: step-in 0.22s ease both;
}
@keyframes step-in {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: none; }
}

.step-title {
    margin: 0 0 var(--space-2);
    font-size: 1.375rem;
    font-weight: 650;
    letter-spacing: -0.02em;
}
.step-sub {
    margin: 0 0 var(--space-5);
    font-size: 0.875rem;
    line-height: 1.5;
    color: var(--color-text-muted);
}
.step-title-centred,
.step-sub-centred { text-align: center; }

/* Step 1 — names --------------------------------------------------------- */

.name-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: var(--space-2);
    margin-bottom: var(--space-5);
}
.name-btn {
    min-height: 48px;
    padding: var(--space-3);
    font: inherit;
    font-size: 0.9375rem;
    font-weight: 500;
    color: var(--color-text);
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: border-color 0.15s ease, background 0.15s ease;
}
.name-btn:hover {
    border-color: var(--color-accent);
    background: var(--color-surface-alt);
}

/* Step 3 — sell or nominate ---------------------------------------------- */

.choice-grid {
    display: grid;
    gap: var(--space-2);
    margin-bottom: var(--space-5);
}
.choice-btn {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 2px;
    text-align: left;
    padding: var(--space-4) var(--space-3);
}
.choice-title {
    font-size: 1rem;
    font-weight: 600;
}
.choice-sub {
    font-size: 0.8125rem;
    font-weight: 400;
    color: var(--color-text-muted);
}

/* Step 4 — holdings ------------------------------------------------------ */

.holdings {
    margin: 0;
    padding: 0;
    list-style: none;
}
/* `display: flex` would otherwise beat the hidden attribute, as with .step. */
.holding[hidden] { display: none; }
.holding {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
    padding: var(--space-3) 0;
    border-top: 1px solid var(--color-border);
}
.holding:last-child {
    border-bottom: 1px solid var(--color-border);
}
.holding-info {
    min-width: 0;
}
.holding-name {
    font-size: 0.9375rem;
    font-weight: 500;
    /* Long game titles wrap rather than pushing the dropdown off-screen. */
    overflow-wrap: anywhere;
}
.holding-meta {
    margin-top: 2px;
    font-size: 0.8125rem;
    color: var(--color-text-muted);
    font-variant-numeric: tabular-nums;
}
.holding-controls {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    flex: 0 0 auto;
}
.holding-subtotal {
    min-width: 4.5ch;
    text-align: right;
    font-size: 0.8125rem;
    font-variant-numeric: tabular-nums;
    color: var(--color-text-muted);
}
.holding-subtotal.is-active {
    color: var(--color-up);
    font-weight: 600;
}

.qty {
    /* 16px keeps iOS from zooming the page when the control is focused. */
    font: inherit;
    font-size: 16px;
    min-height: 44px;
    padding: 0 var(--space-2);
    color: var(--color-text);
    background: var(--color-surface-alt);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
}

/* Step 4 — nominating ---------------------------------------------------- */

.search-row {
    margin-bottom: var(--space-3);
}
.bid {
    /* Same 16px rule as .qty — anything smaller zooms the page on iOS. */
    font: inherit;
    font-size: 16px;
    font-variant-numeric: tabular-nums;
    text-align: right;
    /* Fixed width so every row's input lines up regardless of title length. */
    width: 5.5rem;
    min-height: 44px;
    padding: 0 var(--space-2);
    color: var(--color-text);
    background: var(--color-surface-alt);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
}
.bid:focus {
    outline: none;
    border-color: var(--color-accent);
}
.games-none {
    padding: var(--space-4) 0;
    text-align: center;
}

.empty {
    padding: var(--space-5) 0;
    text-align: center;
}
.empty-title {
    margin: 0 0 var(--space-2);
    font-size: 0.9375rem;
    font-weight: 600;
}
.empty-sub {
    margin: 0;
    font-size: 0.875rem;
    line-height: 1.5;
    color: var(--color-text-muted);
}

/* Step 5/6 — summary lines ----------------------------------------------- */

.summary {
    margin: 0;
    padding: 0;
    list-style: none;
    border-top: 1px solid var(--color-border);
}
.summary-line {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: var(--space-3);
    padding: var(--space-3) 0;
    border-bottom: 1px solid var(--color-border);
    font-size: 0.875rem;
}
.summary-desc {
    overflow-wrap: anywhere;
}
.summary-qty {
    display: block;
    margin-top: 2px;
    color: var(--color-text-muted);
    font-variant-numeric: tabular-nums;
}
.summary-amount {
    flex: 0 0 auto;
    font-variant-numeric: tabular-nums;
}

.total-row {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: var(--space-3);
    padding: var(--space-3) 0;
    font-size: 0.875rem;
}
.total-row-lg {
    font-size: 1rem;
    border-bottom: 1px solid var(--color-border);
}
.total-label {
    color: var(--color-text-muted);
}
.total-value {
    font-weight: 650;
    font-variant-numeric: tabular-nums;
}
.total-value-up { color: var(--color-up); }

/* Password form ---------------------------------------------------------- */

.password-form {
    margin: var(--space-5) 0 0;
}
/* The sign-in step leads with the form, and .step-sub already spaces it. */
.password-form-lead {
    margin-top: 0;
}
.field-label {
    display: block;
    margin-bottom: var(--space-2);
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--color-text-muted);
}
.field {
    display: block;
    width: 100%;
    /* 16px keeps iOS from zooming the page when the field is focused. */
    font: inherit;
    font-size: 16px;
    min-height: 46px;
    padding: 0 var(--space-3);
    color: var(--color-text);
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
}
.field::placeholder { color: var(--color-text-muted); opacity: 0.7; }
.field.is-invalid { border-color: var(--color-down); }

.field-error {
    margin: var(--space-2) 0 0;
    font-size: 0.8125rem;
    color: var(--color-down);
}

/* Actions ---------------------------------------------------------------- */

.actions {
    position: sticky;
    bottom: 0;
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    margin-top: var(--space-4);
    padding-top: var(--space-3);
    padding-bottom: calc(var(--space-3) + env(safe-area-inset-bottom, 0px));
    background: var(--color-surface);
}
/* Fades the list out from under the sticky bar instead of a hard cut. */
.actions::before {
    content: '';
    position: absolute;
    left: 0;
    right: 0;
    bottom: 100%;
    height: 20px;
    background: linear-gradient(to top, var(--color-surface), transparent);
    pointer-events: none;
}
.actions .total-row {
    padding-top: 0;
}

.btn {
    font: inherit;
    font-size: 0.9375rem;
    font-weight: 550;
    min-height: 48px;
    padding: 0 var(--space-4);
    border-radius: var(--radius-md);
    border: 1px solid transparent;
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease;
}
.btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}
.btn-primary {
    background: var(--color-accent);
    color: var(--color-accent-contrast);
}
.btn-primary:hover:not(:disabled) {
    background: var(--color-accent-hover);
}
.btn-ghost {
    background: transparent;
    color: var(--color-text-muted);
}
.btn-ghost:hover {
    color: var(--color-text);
}

:where(.btn, .name-btn, .qty, .field, .theme-toggle):focus-visible {
    outline: none;
    border-color: var(--color-accent);
    box-shadow: 0 0 0 3px var(--ring);
}

/* Receipt ---------------------------------------------------------------- */

.receipt-mark {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 48px;
    height: 48px;
    margin: var(--space-2) auto var(--space-4);
    border-radius: 50%;
    background: color-mix(in srgb, var(--color-up) 14%, transparent);
    color: var(--color-up);
}
.receipt-mark svg {
    fill: none;
    stroke: currentColor;
    stroke-width: 2.5;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.footnote {
    margin: var(--space-4) 0 0;
    font-size: 0.75rem;
    text-align: center;
    color: var(--color-text-muted);
}

/* ------------------------------------------------------------------------ */

@media (min-width: 420px) {
    .name-grid { grid-template-columns: repeat(3, 1fr); }
}

@media (min-width: 560px) {
    .checkout { padding-top: var(--space-6); }
    .card { padding: var(--space-6) var(--space-6) var(--space-3); }
}

@media (prefers-reduced-motion: reduce) {
    .step { animation: none; }
    .progress-dot { transition: none; }
}
