:root {
    color-scheme: light;
    --bg: #f4f7fb;
    --panel: #ffffff;
    --ink: #132033;
    --muted: #5e6b7e;
    --accent: #0f766e;
    --accent-soft: #d9f0ed;
    --border: #d7e0ea;
    --shadow: 0 18px 40px rgba(19, 32, 51, 0.08);
}
* { box-sizing: border-box; }
body {
    margin: 0;
    font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    background: radial-gradient(circle at top left, #e8f4ff 0, transparent 35%),
                linear-gradient(180deg, #f8fbff 0%, var(--bg) 100%);
    color: var(--ink);
}
.shell {
    max-width: 1120px;
    margin: 0 auto;
    padding: 32px 24px 48px;
}
.hero {
    display: grid;
    gap: 16px;
    margin-bottom: 28px;
}
.eyebrow {
    text-transform: uppercase;
    letter-spacing: 0.14em;
    font-size: 0.78rem;
    color: var(--accent);
    font-weight: 700;
}
h1 {
    margin: 0;
    font-size: clamp(2.2rem, 4vw, 3.6rem);
    line-height: 1.02;
}
h2 { margin: 0 0 8px; font-size: 1.3rem; }
.intro {
    max-width: 68ch;
    margin: 0;
    font-size: 1.05rem;
    color: var(--muted);
}
.layout {
    display: grid;
    grid-template-columns: 1.2fr 0.8fr;
    gap: 24px;
    align-items: start;
}
.panel {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 24px;
    box-shadow: var(--shadow);
    overflow: hidden;
}
.panel__body { padding: 24px; }
.model-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 16px;
}
.model-card {
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 18px;
    background: linear-gradient(180deg, #fff 0%, #fafdff 100%);
    transition: transform 140ms ease, border-color 140ms ease, box-shadow 140ms ease;
}
.model-card.selected {
    border-color: var(--accent);
    box-shadow: 0 14px 28px rgba(15, 118, 110, 0.12);
    transform: translateY(-2px);
}
.model-card__eyebrow {
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--accent);
    font-weight: 700;
    margin-bottom: 10px;
}
.model-card p { margin: 0 0 8px; color: var(--muted); }
.selection {
    display: grid;
    gap: 12px;
}
.selection label {
    font-weight: 700;
    color: var(--ink);
}
.selection select {
    width: 100%;
    border-radius: 14px;
    border: 1px solid var(--border);
    padding: 14px 16px;
    font: inherit;
    background: #fff;
}
.selection__link {
    display: inline-flex;
    justify-content: center;
    align-items: center;
    border-radius: 14px;
    padding: 14px 18px;
    background: var(--accent);
    color: white;
    text-decoration: none;
    font-weight: 700;
}
.summary {
    margin-top: 18px;
    margin-bottom: 12px;
    padding: 16px;
    border-radius: 18px;
    background: var(--accent-soft);
    color: #0f3d3a;
}
.summary strong { display: block; margin-bottom: 6px; }
.summary p { margin: 0; }
.links {
    display: grid;
    gap: 10px;
    margin-top: 18px;
}
.links a { color: var(--accent); text-decoration: none; font-weight: 700; }
.action-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 12px;
    margin-bottom: 22px;
}
.workflow {
    margin-top: 18px;
    padding: 20px;
    border: 1px solid var(--border);
    border-radius: 20px;
    background: linear-gradient(180deg, #fff 0%, #fafdff 100%);
}
.workflow p { margin: 0 0 14px; color: var(--muted); }
.form-grid {
    display: grid;
    gap: 12px;
}
.form-grid label {
    font-weight: 700;
    color: var(--ink);
}
.form-grid input[type="file"] {
    width: 100%;
    border-radius: 14px;
    border: 1px solid var(--border);
    padding: 12px;
    background: #fff;
    font: inherit;
}
.button-row {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
}
button,
.button-row button,
.button-row a {
    border: 0;
    border-radius: 14px;
    padding: 14px 18px;
    font: inherit;
    font-weight: 700;
    background: var(--accent);
    color: white;
    cursor: pointer;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
button.primary {
    background: var(--accent);
    color: white;
}
button.secondary {
    background: #e7edf3;
    color: var(--ink);
}
.button-row button.secondary,
.button-row a.secondary {
    background: #e7edf3;
    color: var(--ink);
}
button:hover,
.button-row button:hover,
.button-row a:hover { filter: brightness(1.03); }
button:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}
.helper-links {
    display: grid;
    gap: 10px;
    margin-top: 18px;
}
.helper-links a { color: var(--accent); text-decoration: none; font-weight: 700; }
.meta-links {
    display: grid;
    gap: 10px;
    margin-top: 18px;
}
.meta-links a { color: var(--accent); text-decoration: none; font-weight: 700; }
.recording-state { display: none; }
.recording-state.active { display: block; }
.recording-state.hidden { display: none; }
.progress-container {
    margin: 20px 0;
    background: #f0f0f0;
    border-radius: 14px;
    height: 8px;
    overflow: hidden;
}
.progress-bar {
    height: 100%;
    background: var(--accent);
    transition: width 0.1s linear;
    width: 0%;
}
.classification-result {
    text-align: center;
    padding: 24px;
}
.result-icon {
    font-size: 3rem;
    margin-bottom: 16px;
}
.classification-result h2 {
    color: var(--accent);
    margin: 16px 0;
}
.classification-result p {
    margin: 8px 0;
    color: var(--muted);
}
.error-icon {
    font-size: 3rem;
    margin-bottom: 16px;
}
.error-message {
    color: #dc2626;
    margin: 16px 0;
}
/* Mobile-first responsive design */
@media (max-width: 860px) {
    .layout { grid-template-columns: 1fr; }
}

@media (max-width: 640px) {
    .shell {
        padding: 24px 16px 40px;
    }
    h1 {
        font-size: clamp(1.8rem, 3vw, 2.4rem);
    }
    button,
    .button-row button {
        padding: 12px 16px;
        min-height: 48px;
        min-width: 48px;
    }
    .primary.large {
        padding: 14px 32px;
        font-size: 1rem;
    }
}

/* Full-screen result states */
#state-result {
    animation: fadeIn 0.3s ease-in-out;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

#result-background {
    animation: bgSlideIn 0.4s ease-out;
}

@keyframes bgSlideIn {
    from { opacity: 0; }
    to { opacity: 0.95; }
}

/* Gyroscope visualization canvas */
#gyro-viz {
    display: block;
    width: 100%;
    height: 200px;
    margin: 0 auto;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: #fafafa;
}

#gyro-viz-enroll {
    width: 100%;
    height: 180px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: #fafafa;
}

/* Button accessibility */
button:focus-visible,
input:focus-visible,
select:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* Ensure pocket countdown ring is visible */
#pocket-countdown-ring {
    animation: pulse 1s ease-in-out infinite;
}

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

/* Haptic trigger (hidden element for iOS feedback) */
#haptic-trigger {
    position: absolute;
    opacity: 0;
    pointer-events: none;
    width: 0;
    height: 0;
}

/* Model page layout */
.model-page-container {
    max-width: 560px;
    margin: 0 auto;
}

/* State visibility */
#state-unenrolled,
#state-enrolled,
#state-pocket-countdown,
#state-recording,
#state-result,
#state-fallback,
#enroll-status,
#enroll-error,
#dev-menu,
#embedding-plot-modal {
    display: none;
}

#state-unenrolled.show,
#state-enrolled.show,
#state-pocket-countdown.show,
#state-recording.show,
#state-fallback.show,
#enroll-status.show,
#enroll-error.show,
#dev-menu.show,
#embedding-plot-modal.show {
    display: block;
}

#state-result.show {
    display: flex;
}

/* Pocket countdown styles */
.pocket-countdown-wrapper {
    text-align: center;
    padding: 40px 20px;
}

.pocket-countdown-intro {
    font-size: 1.2rem;
    color: var(--muted);
    margin-bottom: 30px;
}

.pocket-countdown-center {
    display: flex;
    justify-content: center;
    align-items: center;
    margin: 30px 0;
}

.pocket-countdown-timer {
    text-align: center;
}

.pocket-countdown-label {
    font-size: 0.85rem;
    color: var(--muted);
    margin-bottom: 8px;
}

#pocket-countdown-num {
    font-size: 3.2rem;
    font-weight: 700;
    color: var(--accent);
    font-family: monospace;
}

.pocket-countdown-info {
    font-size: 0.9rem;
    color: var(--muted);
}

.pocket-countdown-cues {
    font-size: 0.78rem;
    color: var(--muted);
    margin-top: 18px;
    line-height: 2;
}

/* Recording state styles */
.recording-wrapper {
    text-align: center;
    padding: 20px;
}

.recording-header {
    margin-bottom: 25px;
}

.recording-header-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}

.recording-label {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--ink);
}

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

.recording-progress-bar {
    background: #e8e8e8;
    border-radius: 8px;
    height: 6px;
    overflow: hidden;
}

#recording-progress {
    height: 100%;
    background: var(--accent);
    width: 0%;
    transition: width 0.1s linear;
}

.recording-prompt {
    font-size: 1.1rem;
    margin-bottom: 20px;
}

.recording-timer-wrapper {
    margin-top: 20px;
}

.recording-timer-label {
    font-size: 0.9rem;
    color: var(--muted);
    margin-bottom: 8px;
}

#recording-timer {
    font-size: 2rem;
    font-weight: 700;
    color: var(--accent);
    font-family: monospace;
    margin: 0;
}

/* Enrollment progress bar */
.enroll-progress-wrapper {
    margin-top: 10px;
    background: #c8e6e3;
    border-radius: 14px;
    height: 8px;
    overflow: hidden;
}

#enroll-progress {
    height: 100%;
    background: var(--accent);
    width: 0%;
    transition: width 1s linear;
}

.enroll-sample-count {
    margin-top: 6px;
    font-size: 0.85rem;
}

#gyro-viz-enroll {
    display: none;
    margin-top: 20px;
    width: 100%;
    height: 180px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: #fafafa;
}

#gyro-viz-enroll.show {
    display: block;
}

/* Error display */
#enroll-error {
    margin-top: 20px;
    color: #d32f2f;
}

#enroll-error-msg {
    margin-bottom: 0;
}

#enroll-error button {
    margin-top: 10px;
}

/* Dev menu */
#dev-menu {
    margin-top: 20px;
    padding: 16px;
    background: #f5f5f5;
    border-radius: 12px;
}

#dev-menu button {
    width: 100%;
    margin-bottom: 8px;
}

#dev-menu button:last-child {
    margin-bottom: 0;
    background: #e7edf3;
    color: var(--ink);
}

/* Result overlay */
#state-result {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1000;
    align-items: center;
    justify-content: center;
}

#state-result.show {
    display: flex;
}

#result-background {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    opacity: 0.95;
    transition: opacity 0.4s ease;
}

.result-content {
    position: relative;
    z-index: 1001;
    text-align: center;
    color: white;
}

#result-icon {
    font-size: 4rem;
    margin-bottom: 16px;
}

#result-confidence {
    font-size: 2.4rem;
    font-weight: 700;
    margin-bottom: 4px;
}

#result-match-label {
    font-size: 1rem;
    margin: 0 0 20px;
    opacity: 0.9;
}

/* Result distance/threshold bar */
.result-bar-wrapper {
    width: 240px;
    margin: 0 auto 20px;
}

.result-bar-container {
    position: relative;
    height: 6px;
    background: rgba(255, 255, 255, 0.25);
    border-radius: 3px;
}

#result-bar-fill {
    position: absolute;
    top: 0;
    left: 0;
    height: 100%;
    border-radius: 3px;
    background: rgba(255, 255, 255, 0.85);
    transition: width 0.5s ease;
    width: 0%;
}

.result-bar-tick {
    position: absolute;
    top: -5px;
    left: 50%;
    width: 2px;
    height: 16px;
    background: white;
    border-radius: 1px;
    transform: translateX(-50%);
}

.result-bar-labels {
    display: flex;
    justify-content: space-between;
    margin-top: 4px;
    font-size: 0.68rem;
    opacity: 0.65;
}

#result-margin-label {
    margin: 8px 0 0;
    font-size: 0.82rem;
    font-family: monospace;
    opacity: 0.9;
}

.result-tap-prompt {
    font-size: 0.85rem;
    opacity: 0.7;
    margin: 0;
}

/* Embedding plot modal */
#embedding-plot-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 999;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

#embedding-plot-modal.show {
    display: flex;
}

.embedding-modal-content {
    background: white;
    border-radius: 16px;
    max-width: 600px;
    width: 100%;
    padding: 24px;
    max-height: 80vh;
    overflow: auto;
}

.embedding-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

.embedding-modal-header h2 {
    margin: 0;
}

.embedding-modal-close {
    background: none;
    border: none;
    font-size: 1.4rem;
    cursor: pointer;
    padding: 0;
    color: var(--ink);
}

#embedding-plot {
    text-align: center;
}

#embedding-image {
    max-width: 100%;
    border: 1px solid var(--border);
    border-radius: 8px;
}
