/* ============================================================
SpeakUp — AI English Speaking Practice
style.css  |  Dark terminal-meets-studio aesthetic
   ============================================================ */

/* ── CSS Variables ────────────────────────────────────────── */
:root {
    --bg: #080c10;
    --bg-panel: #0d1117;
    --bg-card: #111820;
    --bg-card-2: #161e28;
    --border: rgba(255, 255, 255, 0.07);
    --border-bright: rgba(255, 255, 255, 0.13);

    --text-primary: #e8edf2;
    --text-secondary: #7a8fa6;
    --text-dim: #3d5066;

    --accent: #00e5ff;
    --accent-glow: rgba(0, 229, 255, 0.18);
    --accent-dim: rgba(0, 229, 255, 0.06);
    --green: #00ffa3;
    --green-glow: rgba(0, 255, 163, 0.15);
    --red: #ff4d6d;
    --red-glow: rgba(255, 77, 109, 0.15);
    --yellow: #ffd60a;

    --radius-sm: 6px;
    --radius-md: 12px;
    --radius-lg: 18px;
    --radius-xl: 24px;

    --font-display: 'Syne', sans-serif;
    --font-mono: 'Space Mono', monospace;

    --transition: 200ms cubic-bezier(.4, 0, .2, 1);
    --transition-slow: 400ms cubic-bezier(.4, 0, .2, 1);
}

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

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

body {
    font-family: var(--font-display);
    background: var(--bg);
    color: var(--text-primary);
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    overflow-x: hidden;
}

button {
    cursor: pointer;
    font-family: inherit;
    border: none;
    outline: none;
}

video {
    display: block;
}

/* ── Ambient Background ───────────────────────────────────── */
.bg-grid {
    position: fixed;
    inset: 0;
    z-index: 0;
    pointer-events: none;
    background-image:
        linear-gradient(rgba(0, 229, 255, 0.025) 1px, transparent 1px),
        linear-gradient(90deg, rgba(0, 229, 255, 0.025) 1px, transparent 1px);
    background-size: 40px 40px;
}

.bg-glow {
    position: fixed;
    inset: 0;
    z-index: 0;
    pointer-events: none;
    background:
        radial-gradient(ellipse 60% 40% at 20% 10%, rgba(0, 229, 255, 0.06) 0%, transparent 70%),
        radial-gradient(ellipse 50% 50% at 80% 80%, rgba(0, 255, 163, 0.04) 0%, transparent 70%);
}

/* ── Header ──────────────────────────────────────────────── */
.site-header {
    position: relative;
    z-index: 10;
    border-bottom: 1px solid var(--border);
    background: rgba(8, 12, 16, 0.85);
    backdrop-filter: blur(12px);
}

.header-inner {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 24px;
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.logo {
    display: flex;
    align-items: center;
    gap: 10px;
}

.logo-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--accent);
    box-shadow: 0 0 12px var(--accent);
    animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {

    0%,
    100% {
        opacity: 1;
        box-shadow: 0 0 10px var(--accent);
    }

    50% {
        opacity: .6;
        box-shadow: 0 0 20px var(--accent);
    }
}

.logo-text {
    font-size: 1.25rem;
    font-weight: 800;
    letter-spacing: -0.02em;
    color: var(--text-primary);
}

.logo-tag {
    font-family: var(--font-mono);
    font-size: 0.65rem;
    color: var(--text-dim);
    letter-spacing: 0.12em;
    text-transform: uppercase;
    border: 1px solid var(--border);
    padding: 2px 8px;
    border-radius: 99px;
}

.header-status {
    display: flex;
    align-items: center;
    gap: 12px;
}

.status-pill {
    font-family: var(--font-mono);
    font-size: 0.7rem;
    letter-spacing: 0.08em;
    color: var(--text-dim);
    padding: 4px 12px;
    border: 1px solid var(--border);
    border-radius: 99px;
    transition: var(--transition);
}

.status-pill.active {
    color: var(--green);
    border-color: var(--green);
    background: var(--green-glow);
}

.status-pill.recording {
    color: var(--red);
    border-color: var(--red);
    background: var(--red-glow);
    animation: blink 1s step-end infinite;
}

@keyframes blink {

    0%,
    100% {
        opacity: 1
    }

    50% {
        opacity: .4
    }
}

/* ── Main Layout ─────────────────────────────────────────── */
.main-layout {
    position: relative;
    z-index: 1;
    flex: 1;
    display: grid;
    grid-template-columns: 1fr 300px;
    gap: 0;
    max-width: 1400px;
    margin: 0 auto;
    width: 100%;
    padding: 20px 24px 0;
    min-height: 0;
}

/* ── Text Panel ──────────────────────────────────────────── */
.text-panel {
    display: flex;
    flex-direction: column;
    gap: 16px;
    padding-right: 20px;
    border-right: 1px solid var(--border);
}

.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.panel-label {
    font-family: var(--font-mono);
    font-size: 0.65rem;
    letter-spacing: 0.14em;
    color: var(--text-dim);
    text-transform: uppercase;
}

.text-meta {
    display: flex;
    gap: 8px;
}

.badge {
    font-family: var(--font-mono);
    font-size: 0.65rem;
    letter-spacing: 0.06em;
    color: var(--text-secondary);
    background: var(--bg-card);
    border: 1px solid var(--border);
    padding: 3px 10px;
    border-radius: 99px;
}

.badge-accent {
    color: var(--accent);
    border-color: rgba(0, 229, 255, 0.25);
    background: var(--accent-dim);
}

/* Text Display */
.text-display {
    flex: 1;
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 28px 32px;
    min-height: 200px;
    position: relative;
    overflow: hidden;
    transition: var(--transition-slow);
}

.text-display::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: linear-gradient(90deg, transparent, var(--accent), transparent);
    opacity: 0;
    transition: var(--transition-slow);
}

.text-display.has-text::before {
    opacity: 1;
}

.text-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    min-height: 160px;
    gap: 14px;
    text-align: center;
}

.placeholder-icon {
    font-size: 2.5rem;
    opacity: 0.15;
    animation: spin 8s linear infinite;
}

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

.text-placeholder p {
    font-size: 0.9rem;
    color: var(--text-dim);
    line-height: 1.6;
}

.text-placeholder strong {
    color: var(--text-secondary);
}

/* The actual practice text */
#practiceText {
    font-family: var(--font-display);
    font-size: 1.45rem;
    font-weight: 600;
    line-height: 1.75;
    color: var(--text-primary);
    letter-spacing: 0.01em;
    animation: fadeInUp 0.4s ease;
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(12px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Word highlighting */
.word {
    display: inline;
    cursor: default;
}

.word.correct {
    color: var(--green);
    text-shadow: 0 0 8px var(--green-glow);
    text-decoration: underline;
    text-decoration-color: rgba(0, 255, 163, 0.4);
}

.word.wrong {
    color: var(--red);
    text-shadow: 0 0 8px var(--red-glow);
    text-decoration: line-through;
    text-decoration-color: rgba(255, 77, 109, 0.5);
}

.word.current {
    color: var(--accent);
    text-shadow: 0 0 12px var(--accent-glow);
    background: var(--accent-dim);
    border-radius: 3px;
    padding: 0 2px;
}

/* Transcript */
.transcript-container {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 14px 18px;
    min-height: 80px;
    max-height: 110px;
    overflow-y: auto;
}

.transcript-container::-webkit-scrollbar {
    width: 4px;
}

.transcript-container::-webkit-scrollbar-track {
    background: transparent;
}

.transcript-container::-webkit-scrollbar-thumb {
    background: var(--border-bright);
    border-radius: 2px;
}

.transcript-label {
    font-family: var(--font-mono);
    font-size: 0.6rem;
    letter-spacing: 0.14em;
    color: var(--text-dim);
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.live-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--text-dim);
    transition: var(--transition);
}

.live-dot.active {
    background: var(--red);
    box-shadow: 0 0 8px var(--red);
    animation: blink 1s step-end infinite;
}

.transcript-text {
    font-family: var(--font-mono);
    font-size: 0.82rem;
    line-height: 1.7;
    color: var(--text-secondary);
    word-break: break-word;
}

/* ── Sidebar ─────────────────────────────────────────────── */
.sidebar {
    padding-left: 20px;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

/* Camera Widget */
.camera-widget {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
}

.camera-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    border-bottom: 1px solid var(--border);
}

.camera-label {
    font-family: var(--font-mono);
    font-size: 0.6rem;
    letter-spacing: 0.14em;
    color: var(--text-dim);
}

.camera-status {
    font-family: var(--font-mono);
    font-size: 0.62rem;
    letter-spacing: 0.1em;
    color: var(--text-dim);
    transition: var(--transition);
}

.camera-status.on {
    color: var(--green);
}

.camera-viewport {
    position: relative;
    width: 100%;
    aspect-ratio: 4/3;
    background: #050810;
    overflow: hidden;
}

#cameraVideo {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transform: scaleX(-1);
    /* mirror */
    opacity: 0;
    transition: opacity 0.4s ease;
}

#cameraVideo.visible {
    opacity: 1;
}

.camera-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    color: var(--text-dim);
    font-family: var(--font-mono);
    font-size: 0.7rem;
    transition: opacity 0.3s ease;
}

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

.camera-icon {
    font-size: 1.8rem;
    opacity: 0.25;
}

.camera-rec {
    position: absolute;
    top: 10px;
    right: 10px;
    font-family: var(--font-mono);
    font-size: 0.58rem;
    letter-spacing: 0.1em;
    color: var(--red);
    background: rgba(0, 0, 0, 0.6);
    padding: 3px 8px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    gap: 5px;
    opacity: 0;
    transition: var(--transition);
}

.camera-rec.visible {
    opacity: 1;
    animation: blink 1.5s step-end infinite;
}

.rec-dot {
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: var(--red);
    box-shadow: 0 0 6px var(--red);
}

/* Timer Widget */
.timer-widget {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 14px 16px;
}

.timer-label {
    font-family: var(--font-mono);
    font-size: 0.6rem;
    letter-spacing: 0.14em;
    color: var(--text-dim);
    margin-bottom: 8px;
}

.timer-display {
    font-family: var(--font-mono);
    font-size: 2rem;
    font-weight: 700;
    color: var(--accent);
    letter-spacing: 0.04em;
    text-shadow: 0 0 20px var(--accent-glow);
}

.timer-colon {
    animation: blink 1s step-end infinite;
}

.timer-bar-track {
    margin-top: 10px;
    height: 3px;
    border-radius: 2px;
    background: var(--bg-card-2);
    overflow: hidden;
}

.timer-bar {
    height: 100%;
    width: 0%;
    border-radius: 2px;
    background: linear-gradient(90deg, var(--accent), var(--green));
    transition: width 1s linear;
}

/* Score Preview */
.score-preview {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 14px 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.score-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border);
}

.score-row:last-child {
    border-bottom: none;
    padding-bottom: 0;
}

.score-label {
    font-family: var(--font-mono);
    font-size: 0.62rem;
    letter-spacing: 0.06em;
    color: var(--text-dim);
}

.score-val {
    font-family: var(--font-mono);
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--text-primary);
    transition: var(--transition);
}

/* ── Control Bar ─────────────────────────────────────────── */
.control-bar {
    position: relative;
    z-index: 10;
    border-top: 1px solid var(--border);
    background: rgba(8, 12, 16, 0.9);
    backdrop-filter: blur(12px);
    padding: 16px 24px;
    margin-top: 20px;
}

.control-inner {
    max-width: 1400px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    gap: 16px;
    flex-wrap: wrap;
}

.control-group {
    display: flex;
    gap: 8px;
    align-items: center;
}

.control-group+.control-group {
    padding-left: 16px;
    border-left: 1px solid var(--border);
}

/* ── Buttons ─────────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 9px 18px;
    font-family: var(--font-display);
    font-size: 0.8rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    border-radius: var(--radius-sm);
    transition: all var(--transition);
    white-space: nowrap;
    position: relative;
    overflow: hidden;
}

.btn::after {
    content: '';
    position: absolute;
    inset: 0;
    background: white;
    opacity: 0;
    transition: opacity 150ms;
}

.btn:active::after {
    opacity: 0.05;
}

.btn:disabled {
    opacity: 0.3;
    pointer-events: none;
}

.btn-primary {
    background: var(--accent);
    color: #000;
    box-shadow: 0 0 20px rgba(0, 229, 255, 0.25);
}

.btn-primary:hover {
    background: #33eaff;
    box-shadow: 0 0 28px rgba(0, 229, 255, 0.4);
    transform: translateY(-1px);
}

.btn-secondary {
    background: var(--bg-card-2);
    color: var(--text-secondary);
    border: 1px solid var(--border);
}

.btn-secondary:hover {
    border-color: var(--border-bright);
    color: var(--text-primary);
    transform: translateY(-1px);
}

.btn-success {
    background: var(--green);
    color: #000;
    box-shadow: 0 0 20px rgba(0, 255, 163, 0.2);
}

.btn-success:hover {
    background: #33ffb5;
    box-shadow: 0 0 28px rgba(0, 255, 163, 0.35);
    transform: translateY(-1px);
}

.btn-danger {
    background: var(--bg-card-2);
    color: var(--red);
    border: 1px solid rgba(255, 77, 109, 0.3);
}

.btn-danger:hover {
    background: var(--red-glow);
    transform: translateY(-1px);
}

.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--border);
}

.btn-ghost:hover {
    border-color: var(--border-bright);
    color: var(--text-primary);
}

/* ── Modal Overlay ───────────────────────────────────────── */
.modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 100;
    background: rgba(5, 8, 13, 0.85);
    backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--transition-slow);
}

.modal-overlay.visible {
    opacity: 1;
    pointer-events: all;
}

.score-modal {
    background: var(--bg-panel);
    border: 1px solid var(--border-bright);
    border-radius: var(--radius-xl);
    padding: 36px;
    width: 90%;
    max-width: 500px;
    box-shadow: 0 30px 80px rgba(0, 0, 0, 0.6), 0 0 60px var(--accent-glow);
    transform: scale(0.92) translateY(16px);
    transition: transform var(--transition-slow);
}

.modal-overlay.visible .score-modal {
    transform: scale(1) translateY(0);
}

.modal-header {
    text-align: center;
    margin-bottom: 24px;
}

.modal-title {
    font-size: 1.6rem;
    font-weight: 800;
    letter-spacing: -0.02em;
    color: var(--text-primary);
}

.modal-subtitle {
    font-family: var(--font-mono);
    font-size: 0.7rem;
    letter-spacing: 0.1em;
    color: var(--text-dim);
    margin-top: 4px;
}

/* Score Ring */
.modal-score-ring {
    position: relative;
    width: 130px;
    height: 130px;
    margin: 0 auto 24px;
}

.ring-svg {
    transform: rotate(-90deg);
}

.ring-bg {
    fill: none;
    stroke: var(--bg-card-2);
    stroke-width: 8;
}

.ring-fill {
    fill: none;
    stroke: var(--accent);
    stroke-width: 8;
    stroke-linecap: round;
    transition: stroke-dashoffset 1s cubic-bezier(.4, 0, .2, 1);
    filter: drop-shadow(0 0 6px var(--accent));
}

.ring-center {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.ring-pct {
    font-family: var(--font-mono);
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--accent);
}

.ring-label {
    font-family: var(--font-mono);
    font-size: 0.55rem;
    letter-spacing: 0.1em;
    color: var(--text-dim);
    margin-top: 2px;
}

/* Modal Stats */
.modal-stats {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-bottom: 18px;
}

.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 14px;
    text-align: center;
}

.stat-icon {
    font-size: 1.2rem;
    margin-bottom: 6px;
}

.stat-val {
    font-family: var(--font-mono);
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text-primary);
}

.stat-name {
    font-family: var(--font-mono);
    font-size: 0.58rem;
    letter-spacing: 0.08em;
    color: var(--text-dim);
    margin-top: 2px;
}

/* Modal Feedback */
.modal-feedback {
    text-align: center;
    font-size: 0.88rem;
    line-height: 1.6;
    color: var(--text-secondary);
    padding: 14px 18px;
    background: var(--bg-card);
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
    margin-bottom: 20px;
    min-height: 50px;
}

.modal-actions {
    display: flex;
    gap: 10px;
    justify-content: center;
}

/* ── Toast ───────────────────────────────────────────────── */
.toast {
    position: fixed;
    bottom: 100px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    z-index: 200;
    background: var(--bg-card-2);
    border: 1px solid rgba(255, 77, 109, 0.4);
    color: var(--red);
    padding: 10px 20px;
    border-radius: var(--radius-md);
    font-family: var(--font-mono);
    font-size: 0.75rem;
    display: flex;
    align-items: center;
    gap: 8px;
    opacity: 0;
    pointer-events: none;
    transition: all var(--transition-slow);
    white-space: nowrap;
}

.toast.visible {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

.toast-icon {
    font-size: 1rem;
}

/* ── Fullscreen Mode ─────────────────────────────────────── */
body.fullscreen-mode .site-header {
    display: none;
}

body.fullscreen-mode .control-bar {
    display: none;
}

body.fullscreen-mode .main-layout {
    padding: 0;
    max-width: 100%;
    grid-template-columns: 1fr;
    height: 100dvh;
}

body.fullscreen-mode .text-panel {
    padding: 40px 60px;
    border-right: none;
    justify-content: center;
}

body.fullscreen-mode #practiceText {
    font-size: 2.1rem;
    line-height: 1.85;
}

body.fullscreen-mode .sidebar {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 200px;
    padding: 0;
    z-index: 50;
}

body.fullscreen-mode .camera-widget {
    border-radius: var(--radius-md);
}

body.fullscreen-mode .timer-widget,
body.fullscreen-mode .score-preview {
    display: none;
}

/* Fullscreen exit button */
.fullscreen-exit {
    position: fixed;
    top: 16px;
    right: 16px;
    z-index: 60;
    display: none;
}

body.fullscreen-mode .fullscreen-exit {
    display: flex;
}

/* ── Scrollbar ───────────────────────────────────────────── */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--border-bright);
    border-radius: 3px;
}

/* ── Responsive ──────────────────────────────────────────── */
@media (max-width: 900px) {
    .main-layout {
        grid-template-columns: 1fr;
        padding: 16px;
    }

    .text-panel {
        padding-right: 0;
        border-right: none;
        border-bottom: 1px solid var(--border);
        padding-bottom: 20px;
    }

    .sidebar {
        padding-left: 0;
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 12px;
    }

    .camera-widget {
        grid-column: 1 / -1;
    }

    .control-inner {
        gap: 10px;
    }

    .control-group+.control-group {
        padding-left: 10px;
    }

    #practiceText {
        font-size: 1.15rem;
    }
}

@media (max-width: 600px) {
    .sidebar {
        grid-template-columns: 1fr;
    }

    .camera-widget {
        grid-column: auto;
    }

    .control-inner {
        flex-direction: column;
        align-items: stretch;
    }

    .control-group+.control-group {
        padding-left: 0;
        border-left: none;
        border-top: 1px solid var(--border);
        padding-top: 10px;
    }

    .control-group {
        justify-content: center;
        flex-wrap: wrap;
    }

    .btn {
        flex: 1;
        justify-content: center;
    }
}