/* Components: buttons, links, tags, the physical card, form controls. */

/* ---- buttons ---- */
.btn { --bx: 50%; --by: 50%; --sweep: var(--bone); position: relative; isolation: isolate; overflow: hidden; display: inline-flex; align-items: center; justify-content: center; gap: 14px; min-height: 52px; padding: 0 26px; border: 1px solid transparent; border-radius: var(--radius); font: 600 15px/1 var(--font-body); white-space: nowrap; text-decoration: none; cursor: pointer; transition: color var(--dur-ui), transform var(--dur-press) var(--ease-out), border-color var(--dur-ui); }
.btn::before { content: ""; position: absolute; inset: 0; z-index: -1; background: var(--sweep); clip-path: circle(0% at var(--bx) var(--by)); transition: clip-path 300ms var(--ease-out); }
.btn:focus-visible::before { clip-path: circle(150% at var(--bx) var(--by)); }
@media (hover: hover) and (pointer: fine) { .btn:hover::before { clip-path: circle(150% at var(--bx) var(--by)); } }
.btn:active { transform: scale(0.97); }
.btn .arrow { flex: none; transition: transform var(--dur-ui) var(--ease-out); }
@media (hover: hover) and (pointer: fine) { .btn:hover .arrow { transform: translateX(4px); } }
.btn--primary { background: var(--accent); color: var(--accent-ink); }
.btn--ghost { border-color: oklch(0.94 0.012 80 / 0.5); color: var(--bone); }
.btn--ghost:focus-visible { color: var(--wine-900); border-color: var(--bone); }
@media (hover: hover) and (pointer: fine) { .btn--ghost:hover { color: var(--wine-900); border-color: var(--bone); } }
.btn--small { min-height: 42px; padding: 0 18px; font-size: 14px; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn:disabled::before { display: none; }

/* ---- text links ---- */
.link { color: var(--bone); text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 0.32em; text-decoration-color: oklch(0.94 0.012 80 / 0.4); transition: color 0.25s, text-decoration-color 0.25s; }
/* Press feedback for every input, since hover is gated to mice. */
.link:active { color: var(--accent); text-decoration-color: currentColor; }
@media (hover: hover) and (pointer: fine) { .link:hover { color: var(--accent); text-decoration-color: currentColor; } }

.link--accent { color: var(--accent); font-weight: 500; text-decoration-color: currentColor; }
@media (hover: hover) and (pointer: fine) { .link--accent:hover { color: var(--bone); } }

.tag { display: inline-block; padding: 4px 12px; border: 1px solid var(--wine-600); border-radius: 999px; font: 400 13px/1.4 var(--font-body); color: var(--bone-dim); }
.tag--on { border-color: var(--accent); color: var(--accent); }

/* ---- the physical card ---- */
.card { --cw: clamp(150px, 18vw, 280px); position: relative; display: block; width: var(--cw); aspect-ratio: 5 / 8; margin: 0; padding: 0; border: 0; background: none; color: inherit; text-align: inherit; perspective: 1400px; -webkit-tap-highlight-color: transparent; }
button.card { cursor: pointer; }
.card-tilt { display: block; width: 100%; height: 100%; transform-style: preserve-3d; }
.card-inner { position: relative; display: block; width: 100%; height: 100%; transform-style: preserve-3d; transition: transform 1.1s cubic-bezier(0.65, 0, 0.2, 1); }
.card.is-flipped .card-inner { transform: rotateY(180deg); }
.card-face { position: absolute; inset: 0; display: block; overflow: hidden; border-radius: 10px; background: var(--wine-800); backface-visibility: hidden; -webkit-backface-visibility: hidden; box-shadow: inset 0 0 0 1px oklch(0.94 0.012 80 / 0.2), 0 28px 40px -24px oklch(0.06 0.04 18 / 0.9); }
.card-face::after { content: ""; position: absolute; inset: 0; background: radial-gradient(circle at var(--gx, 50%) var(--gy, 25%), oklch(0.94 0.012 80 / 0.16), transparent 55%); opacity: 0; transition: opacity 0.5s; pointer-events: none; }
@media (hover: hover) and (pointer: fine) { .card:hover .card-face::after { opacity: 1; } }
.card-back img { width: 100%; height: 100%; object-fit: cover; }
.card-front { transform: rotateY(180deg); }
.card-front::before { content: ""; position: absolute; inset: 5% 8% 19% 8%; border: 1px solid oklch(0.94 0.012 80 / 0.28); pointer-events: none; }
.card-art { position: absolute; inset: 5% 8% 19% 8%; width: 84%; height: 76%; object-fit: cover; object-position: center top; mix-blend-mode: screen; }
.card-name { position: absolute; inset: auto 6% 6.5% 6%; text-align: center; font: italic 400 clamp(16px, 1.6vw, 24px)/1.1 var(--font-italic); color: var(--bone); }
.card-num { display: none; }
.card:focus-visible { outline: none; }
.card:focus-visible .card-face { outline: 2px solid var(--accent); outline-offset: 4px; }

/* ---- forms ---- */
fieldset { margin: 0; padding: 0; border: 0; min-width: 0; }
legend { padding: 0; margin-bottom: 20px; font: 400 var(--fs-h3)/1.2 var(--font-display); }
.check { display: grid; grid-template-columns: auto 1fr; gap: 14px; align-items: start; cursor: pointer; }
.check input, .scenario input { appearance: none; margin: 2px 0 0; width: 22px; height: 22px; border: 1px solid var(--bone-dim); background: transparent; display: grid; place-items: center; cursor: pointer; transition: border-color 0.25s, background-color 0.25s; }
.check input { border-radius: var(--radius); }
.scenario input { border-radius: 50%; }
.check input:checked, .scenario input:checked { border-color: var(--accent); background: var(--accent); }
.check input:checked::after { content: ""; width: 10px; height: 6px; border-left: 2px solid var(--accent-ink); border-bottom: 2px solid var(--accent-ink); transform: translateY(-1px) rotate(-45deg); }
.scenario input:checked::after { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--accent-ink); }
.form-error { min-height: 1.5em; color: var(--danger); font-size: var(--fs-small); }
.field { display: grid; gap: 8px; width: 100%; margin: 0; padding: 0; border: 0; min-width: 0; }
.field > span, .field > legend { font-size: 15px; font-weight: 500; color: var(--bone); }
.field > span em { font-style: normal; font-weight: 400; color: var(--bone-faint); margin-left: 6px; font-size: 13px; }
.field small { font-size: 13px; line-height: 1.5; color: var(--bone-faint); }
.field input, .field select { width: 100%; min-height: 48px; padding: 0 14px; border: 1px solid var(--wine-600); border-radius: var(--radius); background: var(--wine-950); color: var(--bone); font-size: 16px; color-scheme: dark; }
.field input:focus-visible, .field select:focus-visible, .field textarea:focus-visible { outline-offset: 2px; border-color: var(--accent); }
.field textarea { min-height: 120px; }
textarea { width: 100%; min-height: 360px; padding: 18px 20px; border: 1px solid var(--wine-600); border-radius: var(--radius); background: var(--wine-950); color: var(--bone); line-height: 1.7; resize: vertical; }
textarea:focus-visible { outline-offset: 2px; }

/* ---- form controls: a soft focus, a calm hover, an error that is noticed once ---- */
.field input, .field select, .field textarea, textarea { transition: border-color var(--dur-ui) var(--ease-out), background-color var(--dur-ui) var(--ease-out), box-shadow var(--dur-ui) var(--ease-out); }
.field > span { transition: color var(--dur-ui) var(--ease-out); }
.field:focus-within > span { color: var(--accent); }
.field input::placeholder, .field textarea::placeholder, textarea::placeholder { color: var(--bone-faint); opacity: 0.65; transition: opacity var(--dur-ui) var(--ease-out); }
.field input:focus::placeholder, .field textarea:focus::placeholder, textarea:focus::placeholder { opacity: 0.3; }
@media (hover: hover) and (pointer: fine) {
  .field input:hover:not(:focus), .field select:hover:not(:focus), .field textarea:hover:not(:focus), textarea:hover:not(:focus) { border-color: color-mix(in oklch, var(--wine-600), var(--bone) 30%); }
}
/* The ring replaces the outline; a transparent outline stays for forced-colors mode. */
.field input:focus-visible, .field select:focus-visible, .field textarea:focus-visible, textarea:focus-visible {
  outline: 2px solid transparent; outline-offset: 2px; border-color: var(--accent); background-color: var(--wine-900);
  box-shadow: 0 0 0 3px color-mix(in oklch, var(--accent) 24%, transparent);
}
.field input:user-invalid, .field select:user-invalid, .field textarea:user-invalid, textarea:user-invalid {
  border-color: var(--danger); box-shadow: 0 0 0 3px color-mix(in oklch, var(--danger) 18%, transparent); animation: field-nudge 340ms var(--ease-out);
}
@keyframes field-nudge { 20% { transform: translateX(-5px); } 45% { transform: translateX(4px); } 70% { transform: translateX(-2px); } }
.form-error:not(:empty) { animation: error-in 220ms var(--ease-out) both; }
@keyframes error-in { from { opacity: 0; transform: translateY(-4px); } }
.check input, .scenario input { transition: border-color 0.25s, background-color 0.25s, transform var(--dur-press) var(--ease-out); }
.check input:active, .scenario input:active { transform: scale(0.9); }
.check input:checked::after { animation: check-pop 200ms var(--ease-out); }
.scenario input:checked::after { animation: dot-pop 200ms var(--ease-out); }
@keyframes check-pop { from { opacity: 0; transform: translateY(-1px) rotate(-45deg) scale(0.4); } }
@keyframes dot-pop { from { opacity: 0; transform: scale(0.3); } }

/* ---- fixes: native buttons must not inherit the browser's grey ---- */
.btn { background: transparent; }
.btn--primary { background: var(--accent); }

/* ---- destructive actions: pale yellow, never the coral accent ---- */
.btn--danger { border-color: var(--danger); color: var(--danger); --sweep: var(--danger); }
.btn--danger:focus-visible { color: var(--wine-900); }
@media (hover: hover) and (pointer: fine) { .btn--danger:hover { color: var(--wine-900); } }
.link--danger { color: var(--danger); text-decoration-color: oklch(0.88 0.13 95 / 0.5); }

/* ---- busy button: label changes, a small ring turns ---- */
.btn.is-loading > span::after { content: ""; display: inline-block; width: 13px; height: 13px; margin-left: 10px; vertical-align: -2px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: btn-spin 0.7s linear infinite; }
@keyframes btn-spin { to { transform: rotate(360deg); } }
@keyframes btn-pulse { 50% { opacity: 0.35; } }

/* ---- modal window (public/js/dialog.js): centred on desktop, bottom sheet on phones ---- */
.modal { padding: 0; border: 1px solid var(--wine-600); border-radius: var(--radius); background: var(--wine-800); color: var(--bone); width: min(480px, calc(100vw - 32px)); max-height: calc(100dvh - 32px); overflow: auto; box-shadow: 0 30px 80px oklch(0 0 0 / 0.55); }
.modal::backdrop { background: oklch(0.1 0.04 18 / 0.74); backdrop-filter: blur(3px); }
.modal[open] { animation: modal-in 0.28s var(--ease-out) both; }
.modal[open]::backdrop { animation: modal-fade 0.28s ease both; }
.modal--danger { border-color: oklch(0.88 0.13 95 / 0.45); }
.modal-box { display: grid; gap: 18px; padding: clamp(22px, 4vw, 32px); }
.modal h2 { font: 400 var(--fs-h3)/1.15 var(--font-display); }
.modal-body { color: var(--bone-dim); }
.modal .field { margin-top: 2px; }
.modal-error:empty { display: none; }
.modal-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 12px; margin-top: 4px; }
@keyframes modal-in { from { opacity: 0; transform: translateY(14px) scale(0.98); } }
@keyframes modal-fade { from { opacity: 0; } }
.modal.is-closing { animation: modal-out 0.2s ease-in both; pointer-events: none; }
.modal.is-closing::backdrop { animation: modal-fade-out 0.2s ease both; }
@keyframes modal-out { to { opacity: 0; transform: translateY(10px) scale(0.98); } }
@keyframes modal-fade-out { to { opacity: 0; } }
@media (max-width: 560px) {
  .modal { width: 100%; max-width: none; margin: auto 0 0; border-width: 1px 0 0; border-radius: 18px 18px 0 0; padding-bottom: env(safe-area-inset-bottom); }
  .modal[open] { animation-name: sheet-in; }
  .modal-actions { flex-direction: column-reverse; }
  .modal-actions .btn { width: 100%; }
}
@keyframes sheet-in { from { transform: translateY(100%); } }
@keyframes sheet-out { to { transform: translateY(100%); } }
@media (max-width: 560px) { .modal.is-closing { animation-name: sheet-out; } }

/* ---- toasts (public/js/toast.js) ---- */
.toasts { position: fixed; z-index: calc(var(--z-tag) + 5); left: 50%; bottom: calc(16px + env(safe-area-inset-bottom)); transform: translateX(-50%); display: grid; gap: 8px; width: min(420px, calc(100vw - 32px)); pointer-events: none; }
.toast { margin: 0; padding: 12px 16px; border: 1px solid var(--wine-600); border-radius: var(--radius); background: var(--wine-700); color: var(--bone); font-size: 15px; line-height: 1.4; box-shadow: 0 12px 40px oklch(0 0 0 / 0.4); animation: toast-in 0.3s var(--ease-out) both; pointer-events: auto; }
.toast--error { border-color: var(--danger); }
.toast-link { margin-left: 8px; color: var(--accent); font-weight: 500; text-underline-offset: .25em; }
.toast--success { border-color: var(--accent); }
.toast.is-leaving { opacity: 0; transform: translateY(8px); transition: opacity 0.25s, transform 0.25s; }
@keyframes toast-in { from { opacity: 0; transform: translateY(10px); } }

/* ---- route loading: a thin line while a page fetches its data ---- */
html.is-loading::before { content: ""; position: fixed; top: 0; left: 0; z-index: calc(var(--z-header) + 1); height: 2px; width: 35%; background: var(--accent); animation: route-progress 1.1s linear infinite; }
html.is-loading main { opacity: 0.55; transition: opacity 0.2s; }
@keyframes route-progress { from { transform: translateX(-100%); } to { transform: translateX(300%); } }

@media (prefers-reduced-motion: reduce) {
  .modal[open], .modal[open]::backdrop, .toast, html.is-loading::before { animation: none; }
  .field input:user-invalid, .field select:user-invalid, .field textarea:user-invalid, textarea:user-invalid,
  .form-error:not(:empty), .check input:checked::after, .scenario input:checked::after { animation: none; }
  /* The waiting indicator stays visible without turning: it fades in and out. */
  .btn.is-loading > span::after { border-right-color: currentColor; animation: btn-pulse 1.6s ease-in-out infinite !important; }
}

/* The cookie notice: above the demo tag, below the toasts; one line on a wide screen, stacked on a phone. */
.cookie-notice { position: fixed; z-index: calc(var(--z-tag) + 2); left: 50%; bottom: calc(16px + env(safe-area-inset-bottom)); transform: translateX(-50%); width: min(720px, calc(100vw - 32px)); display: flex; gap: 12px 20px; align-items: center; justify-content: space-between; padding: 14px 18px; border: 1px solid var(--wine-600); border-radius: var(--radius); background: var(--wine-700); color: var(--bone); font-size: 14px; line-height: 1.45; box-shadow: 0 12px 40px oklch(0 0 0 / 0.4); }
.cookie-notice p { margin: 0; }
.cookie-notice .btn { flex: none; }
@media (max-width: 560px) { .cookie-notice { flex-direction: column; align-items: stretch; } }

/* ---- lists and pickers in the site's own style: no grey system arrow, no system calendar chrome ---- */
select, .field select {
  appearance: none; -webkit-appearance: none; width: 100%; min-height: 48px; padding: 0 44px 0 14px; border: 1px solid var(--wine-600); border-radius: var(--radius);
  background-color: var(--wine-950); color: var(--bone); font: inherit; font-size: 16px; color-scheme: dark; cursor: pointer; text-overflow: ellipsis;
  background-image: linear-gradient(45deg, transparent 50%, var(--bone-dim) 50%), linear-gradient(135deg, var(--bone-dim) 50%, transparent 50%);
  background-position: calc(100% - 22px) 50%, calc(100% - 16px) 50%; background-size: 6px 6px, 6px 6px; background-repeat: no-repeat;
  transition: border-color var(--dur-ui) var(--ease-out), background-color var(--dur-ui) var(--ease-out), box-shadow var(--dur-ui) var(--ease-out);
}
select:focus-visible { outline: 2px solid transparent; outline-offset: 2px; border-color: var(--accent); background-color: var(--wine-900); box-shadow: 0 0 0 3px color-mix(in oklch, var(--accent) 24%, transparent); }
select option { background: var(--wine-950); color: var(--bone); }
select:disabled { opacity: 0.55; cursor: not-allowed; }
.stats-table select { width: auto; min-height: 40px; font-size: 14px; }
@media (hover: hover) and (pointer: fine) { select:hover:not(:focus) { border-color: color-mix(in oklch, var(--wine-600), var(--bone) 30%); } }
.field input[type="date"], .field input[type="time"] { appearance: none; -webkit-appearance: none; display: block; min-height: 48px; text-align: left; }
.field input[type="date"]::-webkit-date-and-time-value, .field input[type="time"]::-webkit-date-and-time-value { text-align: left; }
.field input[type="date"]::-webkit-calendar-picker-indicator, .field input[type="time"]::-webkit-calendar-picker-indicator { cursor: pointer; opacity: 0.7; }
.field input[type="number"], .field input[inputmode="numeric"] { font-variant-numeric: tabular-nums; }

/* File picker: the real input stays for the keyboard and screen readers, the block below is what the person sees. */
.field .file-input, .file-input { position: absolute; width: 1px !important; height: 1px;  min-height: 0 !important; padding: 0 !important; border: 0 !important; opacity: 0; overflow: hidden; clip-path: inset(50%); }
.file-pick { position: relative; }
.file-box { display: flex; align-items: center; gap: 14px; min-height: 64px; padding: 10px 14px; border: 1px dashed var(--wine-600); border-radius: var(--radius); background: var(--wine-950); cursor: pointer; min-width: 0; transition: border-color var(--dur-ui) var(--ease-out), background-color var(--dur-ui) var(--ease-out); }
.file-btn { flex: none; padding: 10px 16px; border: 1px solid var(--accent); border-radius: var(--radius); color: var(--accent); font-weight: 500; font-size: 15px; }
.file-name { min-width: 0; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--bone-dim); font-size: 14px; }
.file-box.has-file { border-style: solid; }
.file-box.has-file .file-name { color: var(--bone); }
.file-input:focus-visible + .file-box { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in oklch, var(--accent) 24%, transparent); }
@media (hover: hover) and (pointer: fine) { .file-box:hover { border-color: var(--accent); background-color: var(--wine-900); } }
