/* =========================================================================
   Kojo Capture — styles
   Mobile-first. Cream/ink palette. Serif body for reading, sans for UI.
   Built to the cognitive design guide: big touch targets, high contrast,
   generous line-height, semantic colour, key info first.
   ========================================================================= */

:root {
    /* Palette (from design guide) */
    --cream: #F7F3EC;
    --cream-panel: #EFE9DC;
    --ink: #1C1A16;
    --deep: #0F1F2E;
    --muted: #6B6B6B;
    --hairline: #D8D2C6;
    --accent: #C8A96A;       /* amber — pending / highlight */
    --green: #3F7D58;        /* approved / go */
    --red: #A34242;          /* reject / stop */
    --blue: #2E5A87;         /* info / nav */

    /* Spacing scale */
    --s1: 4px;
    --s2: 8px;
    --s3: 12px;
    --s4: 16px;
    --s5: 24px;
    --s6: 32px;
    --s7: 48px;

    /* Fonts */
    --serif: 'Lora', 'Georgia', serif;
    --sans: 'DM Sans', -apple-system, BlinkMacSystemFont, system-ui, sans-serif;

    /* Radii */
    --r1: 6px;
    --r2: 10px;
    --r3: 16px;
}

/* Reset essentials */
* {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html, body {
    margin: 0;
    padding: 0;
    background: var(--cream);
    color: var(--ink);
    font-family: var(--serif);
    font-size: 17px;
    line-height: 1.7;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    padding-bottom: env(safe-area-inset-bottom);
}

/* ---- Layout ------------------------------------------------------------- */

#app {
    max-width: 680px;
    margin: 0 auto;
    padding: 0 var(--s4) var(--s7);
    min-height: 100vh;
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 10;
    background: var(--cream);
    padding: var(--s4) 0 var(--s3);
    border-bottom: 1px solid var(--hairline);
    margin-bottom: var(--s5);
}

.brand {
    font-family: var(--sans);
    font-weight: 700;
    font-size: 28px;
    letter-spacing: -0.02em;
    color: var(--deep);
    margin: 0 0 var(--s3);
}

.tabs {
    display: flex;
    gap: var(--s2);
}

.tab {
    flex: 1;
    background: transparent;
    border: 1px solid var(--hairline);
    color: var(--muted);
    padding: var(--s3) var(--s4);
    font-family: var(--sans);
    font-size: 15px;
    font-weight: 500;
    border-radius: var(--r2);
    cursor: pointer;
    transition: all 0.15s ease;
    min-height: 44px;
}

.tab.active {
    background: var(--deep);
    color: var(--cream);
    border-color: var(--deep);
}

/* ---- Screens ------------------------------------------------------------ */

.screen {
    display: none;
}

.screen.active {
    display: block;
}

/* ---- Cards -------------------------------------------------------------- */

.card {
    background: #FFFFFF;
    border: 1px solid var(--hairline);
    border-radius: var(--r3);
    padding: var(--s5);
    margin-bottom: var(--s4);
}

.card h2 {
    font-family: var(--sans);
    font-weight: 600;
    font-size: 18px;
    line-height: 1.4;
    margin: 0 0 var(--s2);
    color: var(--deep);
}

.helper {
    font-family: var(--serif);
    font-size: 15px;
    color: var(--muted);
    margin: 0 0 var(--s4);
    line-height: 1.6;
}

/* ---- Inner tabs (link vs upload) --------------------------------------- */

.tabs-inner {
    display: flex;
    gap: var(--s1);
    background: var(--cream-panel);
    padding: var(--s1);
    border-radius: var(--r2);
    margin-bottom: var(--s4);
}

.tab-inner {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--muted);
    padding: var(--s3);
    font-family: var(--sans);
    font-size: 14px;
    font-weight: 500;
    border-radius: var(--r1);
    cursor: pointer;
    min-height: 40px;
}

.tab-inner.active {
    background: #FFFFFF;
    color: var(--deep);
    box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}

.source-panel {
    display: none;
}

.source-panel.active {
    display: block;
}

/* ---- Inputs ------------------------------------------------------------- */

input[type="url"] {
    width: 100%;
    padding: var(--s4);
    font-family: var(--sans);
    font-size: 16px;      /* 16px prevents iOS zoom on focus */
    background: var(--cream);
    border: 1px solid var(--hairline);
    border-radius: var(--r2);
    color: var(--ink);
    min-height: 48px;
}

input[type="url"]:focus {
    outline: none;
    border-color: var(--deep);
    background: #FFFFFF;
}

.file-label {
    display: block;
    width: 100%;
    padding: var(--s5) var(--s4);
    text-align: center;
    background: var(--cream);
    border: 2px dashed var(--hairline);
    border-radius: var(--r2);
    font-family: var(--sans);
    font-size: 15px;
    color: var(--muted);
    cursor: pointer;
    transition: all 0.15s ease;
    min-height: 80px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.file-label:hover, .file-label.has-file {
    border-color: var(--deep);
    color: var(--deep);
    background: #FFFFFF;
}

/* ---- Recorder ----------------------------------------------------------- */

.recorder {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--s3);
    padding: var(--s4) 0;
}

.record-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 140px;
    height: 140px;
    border-radius: 50%;
    background: var(--deep);
    color: var(--cream);
    border: none;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: var(--sans);
    font-weight: 500;
    gap: var(--s2);
}

.record-btn:hover {
    transform: scale(1.02);
}

.record-btn.recording {
    background: var(--red);
    animation: pulse 1.4s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(163, 66, 66, 0.4); }
    50% { box-shadow: 0 0 0 14px rgba(163, 66, 66, 0); }
}

.record-icon {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--cream);
}

.record-btn.recording .record-icon {
    border-radius: 4px;
    width: 24px;
    height: 24px;
}

#record-label {
    font-size: 13px;
    letter-spacing: 0.02em;
}

.timer {
    font-family: var(--sans);
    font-weight: 600;
    font-size: 20px;
    color: var(--deep);
    font-variant-numeric: tabular-nums;
}

.timer.hidden, .voice-preview.hidden {
    display: none;
}

.voice-preview {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--s3);
    padding: var(--s4) 0 0;
    border-top: 1px solid var(--hairline);
    margin-top: var(--s4);
}

.voice-preview audio {
    width: 100%;
    max-width: 320px;
}

.link-btn {
    background: transparent;
    border: none;
    color: var(--blue);
    font-family: var(--sans);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    padding: var(--s2) var(--s3);
    text-decoration: underline;
    min-height: 36px;
}

/* ---- Primary action ---------------------------------------------------- */

.actions-card {
    text-align: center;
}

.primary-btn {
    width: 100%;
    padding: var(--s4) var(--s5);
    background: var(--deep);
    color: var(--cream);
    border: none;
    border-radius: var(--r2);
    font-family: var(--sans);
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s ease;
    min-height: 52px;
}

.primary-btn:hover:not(:disabled) {
    background: #1f3c5a;
}

.primary-btn:disabled {
    background: var(--hairline);
    color: var(--muted);
    cursor: not-allowed;
}

.status-text {
    font-family: var(--sans);
    font-size: 14px;
    color: var(--muted);
    margin: var(--s3) 0 0;
    min-height: 20px;
}

.status-text.success {
    color: var(--green);
}

.status-text.error {
    color: var(--red);
}

/* ---- Library ----------------------------------------------------------- */

.library-header h2 {
    margin-bottom: 0;
}

.library-list {
    display: flex;
    flex-direction: column;
    gap: var(--s3);
}

.entry {
    background: #FFFFFF;
    border: 1px solid var(--hairline);
    border-radius: var(--r2);
    padding: var(--s4);
    cursor: pointer;
    transition: all 0.15s ease;
}

.entry:hover {
    border-color: var(--deep);
}

.entry-head {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: var(--s3);
    margin-bottom: var(--s2);
}

.entry-time {
    font-family: var(--sans);
    font-size: 13px;
    color: var(--muted);
    font-weight: 500;
}

.entry-source {
    font-family: var(--sans);
    font-size: 11px;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    background: var(--cream-panel);
    color: var(--muted);
    padding: 3px 8px;
    border-radius: var(--r1);
    white-space: nowrap;
}

.entry-transcript {
    font-family: var(--serif);
    font-size: 15px;
    color: var(--ink);
    line-height: 1.6;
    margin: var(--s2) 0;
}

.entry-transcript.pending {
    color: var(--muted);
    font-style: italic;
}

.entry-meta {
    font-family: var(--sans);
    font-size: 12px;
    color: var(--muted);
    margin-top: var(--s2);
}

.entry-expanded {
    display: none;
    margin-top: var(--s4);
    padding-top: var(--s4);
    border-top: 1px solid var(--hairline);
}

.entry.open .entry-expanded {
    display: block;
}

.entry-audio {
    width: 100%;
    margin-bottom: var(--s3);
}

.entry-video {
    width: 100%;
    max-height: 400px;
    border-radius: var(--r2);
    margin-bottom: var(--s3);
    background: var(--cream-panel);
}

.entry-link {
    font-family: var(--sans);
    font-size: 13px;
    color: var(--blue);
    word-break: break-all;
    margin-bottom: var(--s3);
    display: block;
}

.entry-actions {
    display: flex;
    gap: var(--s2);
    margin-top: var(--s4);
}

.secondary-btn, .danger-btn {
    flex: 1;
    padding: var(--s3) var(--s4);
    border: 1px solid var(--hairline);
    border-radius: var(--r2);
    font-family: var(--sans);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    background: #FFFFFF;
    color: var(--ink);
    min-height: 44px;
    transition: all 0.15s ease;
}

.danger-btn {
    color: var(--red);
    border-color: var(--red);
}

.danger-btn:hover {
    background: var(--red);
    color: #FFFFFF;
}

.empty-state {
    text-align: center;
    padding: var(--s7) var(--s4);
    color: var(--muted);
    font-family: var(--serif);
    font-style: italic;
}

/* ---- Toast ------------------------------------------------------------- */

.toast {
    position: fixed;
    bottom: var(--s5);
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: var(--deep);
    color: var(--cream);
    padding: var(--s3) var(--s5);
    border-radius: var(--r2);
    font-family: var(--sans);
    font-size: 14px;
    font-weight: 500;
    box-shadow: 0 4px 20px rgba(0,0,0,0.15);
    transition: transform 0.3s ease;
    z-index: 100;
    max-width: 90%;
    text-align: center;
}

.toast.show {
    transform: translateX(-50%) translateY(0);
}

.toast.success {
    background: var(--green);
}

.toast.error {
    background: var(--red);
}

/* ---- Tablet and up ----------------------------------------------------- */

@media (min-width: 680px) {
    #app {
        padding: 0 var(--s5) var(--s7);
    }

    .card {
        padding: var(--s6);
    }

    .record-btn {
        width: 160px;
        height: 160px;
    }
}

/* ---- Transcript editing and read-aloud --------------------------------- */

.transcript-wrap .transcript-view { display: block; }
.transcript-wrap .transcript-edit { display: none; }

.transcript-wrap[data-state="edit"] .transcript-view { display: none; }
.transcript-wrap[data-state="edit"] .transcript-edit { display: block; }

.transcript-controls {
    display: flex;
    flex-wrap: wrap;
    gap: var(--s2);
    align-items: center;
    margin-top: var(--s3);
}

.transcript-icon-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    background: var(--cream);
    color: var(--deep);
    border: 1px solid var(--hairline);
    border-radius: 999px;
    font-family: var(--sans);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    min-height: 36px;
    transition: all 0.15s ease;
}

.transcript-icon-btn:hover {
    border-color: var(--deep);
    background: #FFFFFF;
}

.transcript-icon-btn.speaking {
    background: var(--green);
    color: #FFFFFF;
    border-color: var(--green);
    animation: speak-pulse 1.6s ease-in-out infinite;
}

@keyframes speak-pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(63, 125, 88, 0.3); }
    50% { box-shadow: 0 0 0 8px rgba(63, 125, 88, 0); }
}

.icon-speaker, .icon-pencil {
    width: 14px;
    height: 14px;
    display: inline-block;
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
}

.icon-speaker {
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%230F1F2E' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><polygon points='11 5 6 9 2 9 2 15 6 15 11 19 11 5'/><path d='M15.54 8.46a5 5 0 0 1 0 7.07'/><path d='M19.07 4.93a10 10 0 0 1 0 14.14'/></svg>");
}

.icon-pencil {
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%230F1F2E' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><path d='M17 3a2.85 2.83 0 1 1 4 4L7.5 20.5 2 22l1.5-5.5Z'/></svg>");
}

.transcript-icon-btn.speaking .icon-speaker {
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23FFFFFF' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><polygon points='11 5 6 9 2 9 2 15 6 15 11 19 11 5'/><path d='M15.54 8.46a5 5 0 0 1 0 7.07'/><path d='M19.07 4.93a10 10 0 0 1 0 14.14'/></svg>");
}

.entry-edited-badge {
    display: inline-block;
    padding: 3px 10px;
    font-family: var(--sans);
    font-size: 11px;
    font-weight: 500;
    letter-spacing: 0.03em;
    background: var(--accent);
    color: #FFFFFF;
    border-radius: 999px;
}

.transcript-editor {
    width: 100%;
    padding: var(--s4);
    font-family: var(--serif);
    font-size: 16px;
    line-height: 1.7;
    color: var(--ink);
    background: var(--cream);
    border: 1px solid var(--deep);
    border-radius: var(--r2);
    resize: vertical;
    min-height: 100px;
    box-sizing: border-box;
}

.transcript-editor:focus {
    outline: none;
    background: #FFFFFF;
}

.transcript-edit-actions {
    display: flex;
    gap: var(--s3);
    margin-top: var(--s3);
}

.edit-cancel-btn {
    flex: 1;
    padding: var(--s3) var(--s4);
    background: transparent;
    color: var(--muted);
    border: 1px solid var(--hairline);
    border-radius: var(--r2);
    font-family: var(--sans);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    min-height: 44px;
    transition: all 0.15s ease;
}

.edit-cancel-btn:hover {
    color: var(--deep);
    border-color: var(--deep);
}

.edit-save-btn {
    flex: 2;
    padding: var(--s3) var(--s4);
    background: var(--deep);
    color: var(--cream);
    border: none;
    border-radius: var(--r2);
    font-family: var(--sans);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    min-height: 44px;
    transition: all 0.15s ease;
}

.edit-save-btn:hover:not(:disabled) {
    background: #1f3c5a;
}

.edit-save-btn:disabled {
    background: var(--hairline);
    color: var(--muted);
    cursor: not-allowed;
}

/* =========================================================================
   Session 2 additions (iteration 3) — countdown, wider framing
   Replaces previous Session 2 additions block entirely.
   ========================================================================= */

.capture-card {
    padding-bottom: 1rem;
}

/* Camera frame — wider aspect ratio for comfortable framing --------------- */
.camera-frame {
    position: relative;
    margin: 0.75rem 0 1rem 0;
    background: #1C1A16;
    border-radius: 14px;
    overflow: hidden;
    aspect-ratio: 3 / 4;          /* wider than 9/16, fits more of your face */
    max-height: 70vh;
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.camera-frame.is-recording {
    box-shadow: 0 0 0 3px rgba(224, 122, 95, 0.6);
}

.camera-preview {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transform: scaleX(-1);        /* mirror like a selfie */
    background: #1C1A16;
    display: block;
    opacity: 0;
    transition: opacity 0.25s ease;
}

.camera-preview.ready {
    opacity: 1;
}

/* Placeholder shown before camera activation ------------------------------ */
.camera-placeholder {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    text-align: center;
    color: rgba(247, 243, 236, 0.85);
    font-family: 'DM Sans', sans-serif;
    gap: 1rem;
    pointer-events: none;
    transition: opacity 0.2s ease;
}

.camera-placeholder.hidden {
    opacity: 0;
    pointer-events: none;
}

.camera-placeholder-icon {
    font-size: 3rem;
    opacity: 0.6;
    line-height: 1;
}

.camera-placeholder-text {
    font-size: 0.95rem;
    opacity: 0.8;
    line-height: 1.4;
    max-width: 18ch;
}

/* Countdown overlay ------------------------------------------------------- */
.countdown-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(28, 26, 22, 0.35);
    z-index: 5;
    pointer-events: none;
    transition: opacity 0.15s ease;
}

.countdown-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

.countdown-number {
    font-family: 'DM Sans', sans-serif;
    font-size: 8rem;
    font-weight: 700;
    color: #F7F3EC;
    line-height: 1;
    text-shadow: 0 6px 24px rgba(0, 0, 0, 0.45);
    animation: countdown-tick 1s ease-out infinite;
}

@keyframes countdown-tick {
    0%   { transform: scale(1.25); opacity: 0.4; }
    20%  { transform: scale(1.0);  opacity: 1.0; }
    100% { transform: scale(1.0);  opacity: 1.0; }
}

/* Status overlay ---------------------------------------------------------- */
.camera-status {
    position: absolute;
    left: 0;
    right: 0;
    top: 50%;
    transform: translateY(-50%);
    padding: 1rem;
    text-align: center;
    color: #F7F3EC;
    font-family: 'DM Sans', sans-serif;
    font-size: 0.95rem;
    line-height: 1.4;
    background: rgba(28, 26, 22, 0.85);
    pointer-events: none;
    z-index: 4;
}

.camera-status.hidden {
    display: none;
}

.camera-status.info  { color: #F7F3EC; }
.camera-status.warn  { color: #F3B64B; }
.camera-status.error { color: #E07A5F; }

/* Overlays inside the camera frame ---------------------------------------- */
.camera-overlay-top {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    padding: 0.75rem;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    z-index: 3;
    pointer-events: none;
}

.camera-overlay-bottom {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 1.25rem;
    display: flex;
    justify-content: center;
    z-index: 3;
    pointer-events: none;
}

.camera-overlay-bottom .record-btn {
    pointer-events: auto;
    background: rgba(28, 26, 22, 0.85);
    color: #F7F3EC;
    border: 2px solid rgba(247, 243, 236, 0.9);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
}

.camera-overlay-bottom .record-btn:hover,
.camera-overlay-bottom .record-btn:focus {
    background: rgba(28, 26, 22, 0.95);
}

.camera-overlay-bottom .record-btn.recording {
    background: rgba(224, 122, 95, 0.95);
    border-color: rgba(247, 243, 236, 1);
}

.camera-overlay-bottom .record-btn.counting-down {
    background: rgba(243, 182, 75, 0.95);
    color: #1C1A16;
    border-color: rgba(28, 26, 22, 0.2);
}

/* Timer and progress bar (overlaid on frame) ------------------------------ */
.camera-overlay-top .timer {
    background: rgba(28, 26, 22, 0.7);
    color: #F7F3EC;
    padding: 0.3rem 0.7rem;
    border-radius: 999px;
    font-family: 'DM Sans', sans-serif;
    font-size: 0.85rem;
    align-self: center;
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
}

.camera-overlay-top .timer.hidden {
    display: none;
}

.record-progress {
    width: 100%;
    height: 4px;
    background: rgba(255, 255, 255, 0.25);
    border-radius: 2px;
    overflow: hidden;
}

.record-progress.hidden {
    display: none;
}

.record-progress-bar {
    height: 100%;
    width: 0%;
    background: #4A8B4E;
    border-radius: 2px;
    transition: width 0.1s linear, background 0.25s ease;
}

.record-progress-bar.warn {
    background: #E07A5F;
}

/* Reaction preview ------------------------------------------------------- */
.reaction-preview {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 0.75rem;
    margin-top: 1rem;
}

.reaction-preview.hidden {
    display: none;
}

.reaction-video {
    width: 100%;
    max-height: 55vh;
    background: #1C1A16;
    border-radius: 12px;
    display: block;
}

.reaction-video.hidden,
.reaction-audio.hidden {
    display: none;
}

.reaction-audio {
    width: 100%;
}

/* Library --- face badge and face video section --------------------------- */
.entry-source {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
}

.entry-face-badge {
    display: inline-block;
    padding: 0.1rem 0.5rem;
    font-family: 'DM Sans', sans-serif;
    font-size: 0.7rem;
    font-weight: 500;
    letter-spacing: 0.02em;
    background: rgba(74, 139, 78, 0.15);
    color: #4A8B4E;
    border-radius: 999px;
    text-transform: lowercase;
}

.entry-face {
    margin-top: 0.75rem;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.entry-label {
    font-family: 'DM Sans', sans-serif;
    font-size: 0.8rem;
    font-weight: 500;
    color: rgba(28, 26, 22, 0.65);
    text-transform: uppercase;
    letter-spacing: 0.06em;
}
