/* ==========================================================================
   Design tokens — matches the Turant product design system (turant.us)
   ========================================================================== */
:root {
    --ink: #0a0a0a;
    --ink-soft: rgba(10, 10, 10, 0.6);
    --muted: #78716c;
    --background: #FDFBF7;
    --surface: #ffffff;
    --border: #e7e5e0;
    --border-strong: #d6d3cc;

    --pill-bg: rgba(118, 118, 128, 0.12);
    --passphrase-bg: #FFFCED;

    --success: #0ABF53;
    --success-bg: #E9FAF0;
    --danger: #FF4C4C;
    --danger-bg: #FEEEEE;
    --warning: #b45309;
    --warning-bg: #FEF3C7;

    --shadow-sm: 0 1px 2px rgba(10, 10, 10, 0.05);
    --shadow: 0 4px 14px rgba(10, 10, 10, 0.06);
    --shadow-lg: 0 20px 40px rgba(10, 10, 10, 0.12);

    --radius-full: 999px;
    --radius-lg: 24px;
    --radius: 16px;
    --radius-sm: 12px;

    --font-sans: 'Poppins', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --font-serif: 'Radley', 'Georgia', serif;
    --font-mono: 'SF Mono', 'Monaco', 'Menlo', monospace;
}

/* Reset */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

/* Base */
html {
    font-size: 16px;
    scroll-behavior: smooth;
}

body {
    font-family: var(--font-sans);
    background: var(--background);
    color: var(--ink);
    min-height: 100vh;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}

/* Container */
.container {
    max-width: 640px;
    margin: 0 auto;
    padding: 1rem;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Landing screen (mode picker) is a fixed, non-scrolling viewport-height screen.
   Flow pages (enroll/verify) scroll normally and are unaffected. */
body.is-landing {
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
}

body.is-landing .container {
    height: 100vh;
    height: 100dvh;
    min-height: 0;
    padding-top: clamp(0.25rem, 1.5vh, 0.5rem);
    padding-bottom: clamp(0.25rem, 1.5vh, 0.5rem);
}

body.is-landing .header {
    padding: clamp(0.5rem, 2vh, 1rem) 0 0;
    flex-shrink: 0;
}

body.is-landing .logo {
    margin-bottom: 0;
}

body.is-landing .logo-img {
    max-width: clamp(110px, 20vh, 180px);
}

/* main-content centers the title+card as one group in the middle of the
   page — same as the landing card centered on its own before, just with the
   title now sitting directly above it instead of being pinned under the logo. */
body.is-landing .main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 0;
    overflow: hidden;
}

body.is-landing .title-block {
    width: 100%;
    padding: 0;
    margin-bottom: clamp(1rem, 4vh, 2rem);
}

body.is-landing .landing-section {
    width: 100%;
    flex-shrink: 0;
}

body.is-landing .footer {
    flex-shrink: 0;
    padding: 0.75rem;
}

/* The title/subtitle are shared with the flow pages, so scope their
   compacting to the landing screen only. clamp() upper bounds match the
   original fixed values, so taller viewports render identically to before. */
body.is-landing .title-block h1 {
    font-size: clamp(1.25rem, 5vh, 1.75rem);
    margin-bottom: clamp(0.25rem, 1vh, 0.5rem);
}

body.is-landing .subtitle {
    font-size: clamp(0.7rem, 3vh, 0.95rem);
}

/* Header */
.header {
    text-align: center;
    padding: 2.25rem 0 0;
}

.logo {
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 1.75rem;
}

.logo-img {
    max-width: 180px;
    height: auto;
    object-fit: contain;
}

/* Title block (h1 + subtitle) — sits right under the logo on flow pages;
   becomes a flex-centered zone on the landing screen (see body.is-landing
   override above). */
.title-block {
    text-align: center;
    padding: 0 0 1.75rem;
}

.title-block h1 {
    font-family: var(--font-serif);
    font-weight: 400;
    font-size: 1.75rem;
    letter-spacing: -0.01em;
    margin-bottom: 0.5rem;
    color: var(--ink);
}

.subtitle {
    color: var(--ink-soft);
    font-size: 0.95rem;
    font-weight: 400;
}

/* Main Content */
.main-content {
    flex: 1;
    position: relative;
}

/* ==========================================================================
   Landing / Mode Selector
   ========================================================================== */
.landing-section {
    text-align: center;
    background: transparent;
    box-shadow: none;
    padding: clamp(1rem, 4vh, 1.75rem);
    margin-bottom: 0;
}

.landing-section h2 {
    font-family: var(--font-serif);
    font-weight: 400;
    font-size: clamp(1.15rem, 4vh, 1.5rem);
    color: var(--ink);
    margin-bottom: clamp(0.75rem, 3vh, 1.5rem);
}

.mode-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: clamp(0.75rem, 3vh, 1.25rem);
}

.mode-card {
    --mc-pad-x: clamp(1rem, 4vw, 1.5rem);
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: clamp(0.3rem, 1.2vh, 0.6rem);
    padding: clamp(1rem, 3vh, 1.75rem) var(--mc-pad-x) 0;
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    background: var(--surface);
    color: var(--ink);
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
    font-family: inherit;
    text-align: left;
    overflow: hidden;
}

.mode-card:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-lg);
    border-color: var(--border-strong);
}

.mode-icon {
    width: clamp(38px, 8vh, 52px);
    height: clamp(38px, 8vh, 52px);
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-full);
    background: var(--ink);
    color: #fff;
    margin-bottom: 0.25rem;
}

.mode-icon svg {
    width: clamp(18px, 4vh, 24px);
    height: clamp(18px, 4vh, 24px);
}

.mode-title {
    font-family: var(--font-serif);
    font-size: clamp(1.05rem, 4vh, 1.35rem);
    font-weight: 400;
    color: var(--ink);
}

.mode-desc {
    font-size: clamp(0.75rem, 3vh, 0.85rem);
    color: var(--ink-soft);
    line-height: 1.45;
}

.mode-cta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: calc(100% + 2 * var(--mc-pad-x));
    margin: clamp(0.4rem, 2vh, 0.75rem) calc(-1 * var(--mc-pad-x)) 0;
    margin-top: auto;
    padding: clamp(0.5rem, 2vh, 0.85rem) var(--mc-pad-x);
    background: rgba(10, 10, 10, 0.04);
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--ink);
    transition: background 0.2s ease;
}

.mode-card:hover .mode-cta {
    background: var(--ink);
    color: #fff;
}

.mode-cta-arrow {
    transition: transform 0.2s ease;
}

.mode-card:hover .mode-cta-arrow {
    transform: translateX(3px);
}

/* Back-to-home header */
.mode-header {
    margin-bottom: 0.5rem;
}

.btn-back {
    background: transparent;
    border: none;
    color: var(--ink-soft);
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    padding: 0.5rem 0.25rem;
    font-family: inherit;
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    transition: color 0.2s ease;
}

.btn-back svg {
    flex-shrink: 0;
}

.btn-back:hover {
    color: var(--ink);
}

.verify-result-details {
    background: rgba(10, 10, 10, 0.03);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 0.9rem 1.1rem;
    margin: 1.1rem 0 0.5rem;
    text-align: left;
    font-size: 0.85rem;
}

.verify-result-details .result-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.3rem 0;
    color: var(--ink-soft);
    gap: 0.75rem;
}

.verify-result-details .result-row strong {
    color: var(--ink);
    font-weight: 500;
}

.verify-result-details .result-pass {
    color: var(--success);
    font-weight: 600;
}

.verify-result-details .result-fail {
    color: var(--danger);
    font-weight: 600;
}

.verify-result-details .result-retry {
    color: var(--warning);
    font-weight: 600;
}

/* Raw JSON block showing the AI engine response */
.verify-json-block {
    margin: 0.85rem 0 0.25rem;
    text-align: left;
}

.verify-json-header {
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--ink-soft);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    margin-bottom: 0.4rem;
}

.verify-json {
    background: #16140f;
    color: #f2efe6;
    border-radius: var(--radius-sm);
    padding: 0.9rem;
    font-family: var(--font-mono);
    font-size: 0.75rem;
    line-height: 1.55;
    max-height: 240px;
    overflow: auto;
    white-space: pre;
    margin: 0;
}

/* ==========================================================================
   Sections / Cards
   ========================================================================== */
.section {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.75rem;
    margin-bottom: 1.25rem;
    box-shadow: var(--shadow-sm);
    transition: opacity 0.3s, transform 0.3s;
}

.section.disabled {
    opacity: 0.45;
    pointer-events: none;
}

.section h2 {
    font-family: var(--font-serif);
    font-size: 1.2rem;
    font-weight: 400;
    margin-bottom: 1.1rem;
    color: var(--ink);
}

/* Input Group */
.input-group {
    display: flex;
    gap: 0.75rem;
}

.input-group input {
    flex: 1;
    padding: 0.8rem 1.1rem;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-full);
    font-size: 1rem;
    font-family: inherit;
    background: var(--background);
    color: var(--ink);
    transition: border-color 0.2s, box-shadow 0.2s;
}

.input-group input::placeholder {
    color: var(--muted);
}

.input-group input:focus {
    outline: none;
    border-color: var(--ink);
    box-shadow: 0 0 0 3px rgba(10, 10, 10, 0.06);
}

/* ==========================================================================
   Buttons
   ========================================================================== */
.btn {
    padding: 0.8rem 1.6rem;
    border: none;
    border-radius: var(--radius-full);
    font-size: 1rem;
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;
    transition: background 0.2s ease, color 0.2s ease, transform 0.15s ease, box-shadow 0.2s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

.btn-primary {
    background: var(--ink);
    color: #fff;
}

.btn-primary:hover:not(:disabled) {
    background: #2a2a2a;
}

.btn-secondary {
    background: transparent;
    color: var(--ink);
    border: 1.5px solid var(--ink);
}

.btn-secondary:hover {
    background: var(--ink);
    color: #fff;
}

.btn-record {
    background: var(--ink);
    color: #fff;
    width: 100%;
    padding: 1.05rem;
    font-size: 1.05rem;
}

.btn-record:hover {
    background: #2a2a2a;
}

.btn-record .btn-icon {
    display: inline-flex;
    color: #fff;
}

.btn-record .btn-icon svg {
    width: 18px;
    height: 18px;
}

.btn-submit {
    background: var(--ink);
    color: #fff;
    width: 100%;
    padding: 1.05rem;
    font-size: 1.05rem;
}

.btn-submit:hover:not(:disabled) {
    background: #2a2a2a;
    box-shadow: var(--shadow);
}

.btn-submit:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* Messages */
.error-message {
    color: var(--danger);
    font-size: 0.875rem;
    margin-top: 0.6rem;
}

.status-message {
    color: var(--ink-soft);
    font-size: 0.875rem;
    margin-top: 0.6rem;
}

.hidden {
    display: none !important;
}

/* Progress Container */
.progress-container {
    margin-bottom: 1.5rem;
}

.progress-text {
    display: flex;
    justify-content: space-between;
    font-size: 0.85rem;
    color: var(--ink-soft);
    margin-bottom: 0.5rem;
}

.progress-text span:last-child {
    font-weight: 600;
    color: var(--ink);
}

.progress-bar {
    height: 6px;
    background: var(--pill-bg);
    border-radius: 4px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: var(--ink);
    border-radius: 4px;
    transition: width 0.3s ease;
}

/* Recording Card */
.recording-card {
    background: var(--background);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
}

/* Sequence Box (big digit + word display) */
.sequence-box {
    background: var(--passphrase-bg);
    border: none;
    border-radius: var(--radius-sm);
    padding: 1.5rem 1.25rem;
    margin-bottom: 1.5rem;
    text-align: center;
}

.sequence-prompt {
    font-size: 0.85rem;
    color: var(--muted);
    margin-bottom: 0.75rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.sequence-digits {
    font-family: var(--font-mono);
    font-size: clamp(1.4rem, 6vw, 2.1rem);
    font-weight: 700;
    color: var(--ink);
    letter-spacing: 0.2em;
    padding-left: 0.2em; /* compensate for trailing letter-spacing */
    margin-bottom: 0.5rem;
    line-height: 1.3;
    word-break: break-all;
}

.sequence-words {
    font-size: 1rem;
    color: var(--ink-soft);
    margin-bottom: 0.75rem;
    letter-spacing: 0.05em;
}

.sequence-position {
    font-size: 0.85rem;
    color: var(--muted);
}

/* Pre-roll prep indicator */
.prep-container {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 1.5rem;
}

.prep-text {
    font-size: 1.2rem;
    font-weight: 500;
    color: var(--warning);
    animation: pulse 0.8s ease-in-out infinite;
}

/* Countdown Container */
.countdown-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 1.5rem;
}

.countdown-circle {
    position: relative;
    width: 120px;
    height: 120px;
    margin-bottom: 1rem;
}

.countdown-svg {
    width: 100%;
    height: 100%;
    transform: rotate(-90deg);
}

.countdown-bg {
    fill: none;
    stroke: var(--pill-bg);
    stroke-width: 6;
}

.countdown-progress {
    fill: none;
    stroke: var(--danger);
    stroke-width: 6;
    stroke-linecap: round;
    transition: stroke-dashoffset 0.05s linear;
}

.countdown-text {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-family: var(--font-mono);
    font-size: 1.85rem;
    font-weight: 700;
    color: var(--ink);
}

.recording-status {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 500;
    color: var(--danger);
    font-size: 0.95rem;
}

/* Recording Controls */
.recording-controls {
    margin-top: 1rem;
}

/* Preview Section */
.preview-section {
    margin-top: 1.5rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--border);
}

.preview-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.preview-badge {
    background: var(--success-bg);
    color: var(--success);
    padding: 0.3rem 0.85rem;
    border-radius: var(--radius-full);
    font-size: 0.8rem;
    font-weight: 500;
}

.preview-duration {
    font-family: var(--font-mono);
    font-size: 0.85rem;
    color: var(--muted);
}

.preview-section audio {
    width: 100%;
    margin-bottom: 1rem;
    border-radius: var(--radius-full);
}

.preview-actions {
    display: flex;
    gap: 0.75rem;
}

.preview-actions .btn {
    flex: 1;
}

/* Sequence Progress Grid (6 sequences) */
.sequence-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.75rem;
}

.sequence-item {
    background: var(--surface);
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 0.85rem 0.5rem;
    text-align: center;
    transition: all 0.2s;
}

.sequence-item.current {
    border-color: var(--ink);
    background: var(--surface);
    box-shadow: 0 0 0 3px rgba(10, 10, 10, 0.06);
}

.sequence-item.complete {
    border-color: var(--success);
    background: var(--success-bg);
}

.sequence-item-label {
    display: block;
    font-size: 0.7rem;
    color: var(--muted);
    margin-bottom: 0.35rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.sequence-item-text {
    display: block;
    font-family: var(--font-mono);
    font-size: 1rem;
    font-weight: 700;
    color: var(--ink);
    letter-spacing: 0.15em;
    margin-bottom: 0.4rem;
}

.sequence-item.current .sequence-item-text {
    color: var(--ink);
}

.sequence-item.complete .sequence-item-text {
    color: var(--success);
}

.sequence-status {
    display: flex;
    justify-content: center;
}

.sample-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--border-strong);
    transition: background 0.2s;
}

.sample-dot.recorded {
    background: var(--success);
}

/* Submit Info */
.submit-info {
    text-align: center;
    color: var(--ink-soft);
    font-weight: 500;
    margin-bottom: 1rem;
    font-size: 0.95rem;
}

/* Auto-playback Indicator (compulsory listen after recording) */
.autoplay-indicator {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    padding: 0.9rem 1rem;
    margin: 1rem 0;
    background: var(--warning-bg);
    border: none;
    border-radius: var(--radius-sm);
    font-weight: 500;
    color: var(--warning);
    font-size: 0.9rem;
}

.autoplay-pulse {
    width: 12px;
    height: 12px;
    background: var(--warning);
    border-radius: 50%;
    animation: pulse 1s ease-in-out infinite;
    flex-shrink: 0;
}

/* Pulse Animation */
.pulse {
    width: 10px;
    height: 10px;
    background: var(--danger);
    border-radius: 50%;
    animation: pulse 1s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.5; transform: scale(1.2); }
}

/* Loader */
.loader {
    width: 18px;
    height: 18px;
    border: 2px solid transparent;
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ==========================================================================
   Result cards (inline — replace enroll/verify completion popups)
   ========================================================================== */
.result-wrap {
    margin-top: 1.25rem;
}

.result-card {
    background: var(--surface);
    border: 1.5px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 2.25rem 2rem;
    text-align: center;
    box-shadow: var(--shadow-sm);
    transition: background 0.25s ease, border-color 0.25s ease;
}

.result-card.is-success {
    background: var(--success-bg);
    border-color: var(--success);
}

.result-card.is-fail {
    background: var(--danger-bg);
    border-color: var(--danger);
}

.result-card.is-retry {
    background: var(--warning-bg);
    border-color: var(--warning);
}

.result-icon {
    width: 60px;
    height: 60px;
    background: #fff;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow-sm);
    margin: 0 auto 1.1rem;
}

.result-card.is-success .result-icon {
    color: var(--success);
}

.result-card.is-fail .result-icon {
    color: var(--danger);
}

.result-card.is-retry .result-icon {
    color: var(--warning);
}

.result-card h2 {
    font-family: var(--font-serif);
    font-weight: 400;
    font-size: 1.5rem;
    color: var(--ink);
    margin-bottom: 0.5rem;
}

.result-card.is-success h2 {
    color: var(--success);
}

.result-card.is-fail h2 {
    color: var(--danger);
}

.result-card.is-retry h2 {
    color: var(--warning);
}

.result-card p {
    color: var(--ink-soft);
    margin-bottom: 0.5rem;
    font-size: 0.95rem;
}

.result-username {
    font-weight: 600;
    color: var(--ink);
}

.result-card .btn {
    margin-top: 1.5rem;
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(10, 10, 10, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    padding: 1rem;
}

.modal-content {
    background: var(--surface);
    border-radius: var(--radius-lg);
    padding: 2.25rem 2rem;
    text-align: center;
    max-width: 400px;
    width: 100%;
    box-shadow: var(--shadow-lg);
}

.modal-content h3 {
    font-family: var(--font-serif);
    font-weight: 400;
    font-size: 1.3rem;
    margin-bottom: 1rem;
    color: var(--warning);
}

.modal-content p {
    margin-bottom: 0.5rem;
    color: var(--ink-soft);
    font-size: 0.95rem;
}

.error-detail {
    font-size: 0.85rem;
    color: var(--danger);
    margin: 1rem 0;
}

.modal-content .btn {
    margin-top: 1rem;
}

/* Footer */
.footer {
    text-align: center;
    padding: 1.75rem;
    color: var(--muted);
    font-size: 0.9rem;
}

.footer strong {
    color: var(--ink);
    font-weight: 600;
}

/* ==========================================================================
   Responsive
   ========================================================================== */
@media (max-width: 480px) {
    .container {
        padding: 0.5rem;
    }

    .header {
        padding: 1.5rem 0 0;
    }

    .logo-img {
        max-width: 140px;
    }

    .title-block {
        padding: 0 0 1.25rem;
    }

    .title-block h1 {
        font-size: 1.4rem;
    }

    .section {
        padding: 1.25rem;
        border-radius: var(--radius);
    }

    .input-group {
        flex-direction: column;
    }

    .input-group input {
        width: 100%;
    }

    .sequence-box {
        padding: 1rem 0.75rem;
    }


    .sequence-words {
        font-size: 0.85rem;
    }

    .sequence-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 0.5rem;
    }

    .sequence-item {
        padding: 0.6rem 0.35rem;
    }

    .sequence-item-text {
        font-size: 0.85rem;
        letter-spacing: 0.1em;
    }

    .preview-actions {
        flex-direction: column;
    }

    .countdown-circle {
        width: 100px;
        height: 100px;
    }

    .countdown-text {
        font-size: 1.5rem;
    }
}
