:root {
    --primary: #6366f1;
    --secondary: #8b5cf6;
    --accent: #f0abfc;
    --bg-gradient-start: #0f172a;
    --bg-gradient-end: #1e1b4b;
    --card-bg: #01031f;
    --card-border: rgba(255, 255, 255, 0.1);
    --text-primary: #f8fafc;
    --text-secondary: #cbd5e1;
    --text-muted: #94a3b8;
    --accent-cyan: #22d3ee;
    --accent-purple: #a78bfa;
    --highlight-bg: rgba(99, 102, 241, 0.3);
    --bubble-bd: black;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    overflow-x: hidden;
    /* Fix for Edge mobile dynamic toolbar */
    height: -webkit-fill-available;
}

body {
    font-family: "Inter", sans-serif;
    background-color: var(--bg-gradient-start);
    min-height: 100vh;
    /* height: 100dvh; */
    color: var(--text-primary);
    line-height: 1.8;
    padding: 0;
    overflow-x: hidden;
    position: relative;
}

body::after {
    content: "";
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: -1;
    background: linear-gradient(
        135deg,
        var(--bg-gradient-start) 0%,
        var(--bg-gradient-end) 100%
    );
}

body::before {
    content: "";
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 0;
    background-image: url("../assets/sea-world.svg");
    background-position: center top;
    background-repeat: repeat;
    background-size: 375px auto;
    opacity: 0.05;
    pointer-events: none;
    /* Hardware acceleration to fix mobile jitter */
    transform: translateZ(0);
    will-change: transform;
}

.container {
    max-width: 900px;
    margin: 0 auto;
    position: relative;
    z-index: 1;
    padding: 0 20px;
    margin-top: 78px;
    /* padding-bottom: 120px; */
}

/* Conversation Title */
.conversation-title {
    font-family: "Cal Sans", sans-serif;
    font-size: 1.75rem;
    color: var(--text-primary);
    text-align: center;
    margin-bottom: 24px;
    padding: 16px 24px;
    background: rgba(99, 102, 241, 0.15);
    border: 1px solid rgba(99, 102, 241, 0.3);
    border-radius: 16px;
    letter-spacing: 0.5px;
}

/* Sticky Navbar */
.sticky-nav {
    position: fixed;
    /* Use dvh-aware top to account for Edge mobile dynamic toolbar */
    top: 0;
    left: 0;
    width: 100%;
    background: rgba(1, 3, 31, 0.95);
    -webkit-backdrop-filter: blur(10px);
    backdrop-filter: blur(10px);
    z-index: 100;
    border-bottom: 1px solid var(--card-border);
    padding: 12px 20px;
    padding-top: max(12px, env(safe-area-inset-top, 12px));
    margin-bottom: 20px;
    /* GPU acceleration */
    -webkit-transform: translate3d(0, 0, 0);
    transform: translate3d(0, 0, 0);
}

.sticky-nav .nav-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.sticky-nav .nav-home {
    flex-shrink: 0;
}

.hamburger-menu img {
    display: block;
    width: 24px;
    height: 24px;
    transition:
        width 0.2s ease,
        height 0.2s ease;
}

.sticky-nav .nav-center {
    display: flex;
    align-items: center;
    gap: 8px;
    overflow: hidden;
}

.nav-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* Desktop: align .nav-center with .dialogue-container */
@media (min-width: 514px) {
    .sticky-nav .nav-content {
        position: relative;
    }

    .sticky-nav .nav-center {
        position: absolute;
        left: 50%;
        justify-content: center;
        transform: translateX(-50%);
        width: 100%;
        max-width: 900px;
        padding: 0 20px;
        overflow: visible;
        pointer-events: none;
    }

    .sticky-nav .nav-center > * {
        pointer-events: auto;
    }
}

.sticky-nav .nav-title {
    font-family: "Cal Sans", sans-serif;
    /* font-weight: 700; */
    /* color: var(--text-primary); */
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: 1.5rem; /* Larger font for desktop */
    background: linear-gradient(358deg, #00e9fa 0%, #ffdd00 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

/* Icon Buttons in Nav */
.icon-btn {
    background: transparent;
    border: none;
    color: var(--text-primary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 8px;
    border-radius: 50%;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.icon-btn:hover {
    color: var(--accent);
    background: rgba(255, 255, 255, 0.1);
}

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

.info-btn {
    padding: 4px;
    /* color: var(--text-muted); */
    opacity: 0.5;
}

.info-btn img {
    width: 16px;
    height: 16px;
}

/* Specific adjustment if needed */
/* .hamburger-menu inherits .icon-btn styles */

.instruction {
    display: flex;
    flex-direction: column;
    gap: 40px;
    margin: 24px auto 0;
    padding: 20px;
    width: 100%;
    max-width: 500px;
    background: var(--highlight-bg);
    border-radius: 16px;
    font-size: 1.15rem;
    color: var(--text-primary);
    line-height: 1.6;
    text-align: left;
}

/* When inside the modal, remove top margin and maybe background if the modal has it */
.instruction-content .instruction {
    margin: 0;
    width: 100%;
    max-width: 100%;
    background: transparent; /* Or keep it if we want the card look inside modal */
    padding: 0; /* Let the modal padding handle it? Or keep padding but transparent bg?
                 Actually, the modal has padding. Let's keep the instruction as a block but reset margins. */
}

.instruction-item {
    display: flex;
    align-items: flex-start;
    gap: 16px;
}

.instruction-icon {
    font-size: 2rem;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
}

.instruction-icon img {
    width: 100%;
    height: 100%;
    object-fit: contain; /* keeps aspect ratio */
}

.instruction .expression {
    cursor: default;
}

/* Scene Divider */
.scene-divider {
    text-align: center;
    margin: 30px 0;
    color: var(--text-muted);
    font-style: italic;
    font-size: 1.05rem;
    position: relative;
}

.scene-divider::before,
.scene-divider::after {
    content: "";
    position: absolute;
    top: 50%;
    width: 30%;
    height: 1px;
    background: var(--card-border);
}

.scene-divider::before {
    left: 0;
}
.scene-divider::after {
    right: 0;
}

/* Dialogue */
.dialogue-container {
    background: transparent;
    border: none;
    border-radius: 0;
    padding: 20px 0;
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
    display: flex;
    flex-direction: column;
    gap: 24px;
}

.dialogue-line {
    display: flex;
    flex-direction: column;
    max-width: 80%; /* Space for emojis on the right */
}

/* Semantic-based speaker alignment */
.dialogue-line.other-speaker {
    align-self: flex-start;
}

.dialogue-line.main-speaker {
    align-self: flex-end;
}

/* Group Spacing */
.dialogue-line.group-start {
    margin-top: 24px;
}

.dialogue-line.group-inner,
.dialogue-line.group-last {
    margin-top: -18px; /* Tighter vertical spacing within groups */
}

/* Group Bubble Transitions & Shapes */
/* Other Speaker (Left) */
.other-speaker.group-start .speech-bubble {
    border-radius: 40px 40px 40px 6px;
}

.other-speaker.group-inner .speech-bubble {
    border-radius: 6px 40px 40px 6px;
}

.other-speaker.group-last .speech-bubble {
    border-radius: 6px 40px 40px 40px;
}

/* Main Speaker (Right) */
.main-speaker.group-start .speech-bubble {
    border-radius: 40px 40px 6px 40px;
}

.main-speaker.group-inner .speech-bubble {
    border-radius: 40px 6px 6px 40px;
}

.main-speaker.group-last .speech-bubble {
    border-radius: 40px 6px 40px 40px;
}

.speech-bubble {
    /* background: #020422; */
    /* border: 6px solid var(--bubble-bd); */
    padding: 20px 24px;
    color: var(--text-primary);
    font-size: 1.25rem;
    line-height: 1.8;
    position: relative;
    transition: background 0.2s ease;
    min-width: 300px;
}

/* Semantic speech bubble styles */
.other-speaker .speech-bubble {
    border-radius: 40px 40px 40px 0;
    border: 6px solid var(--bubble-bd);
    background: #020422;
}

.main-speaker .speech-bubble {
    border-radius: 40px 40px 0 40px;
    border: 6px solid #0000005c;
    background: #12122c;
}

.speaker-info {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 8px;
}

.chat-layout .main-speaker .speaker-info {
    flex-direction: row-reverse;
}

.main-speaker .speaker-info {
    justify-content: flex-start;
}

.speaker-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    overflow: hidden;
    background: var(--card-bg);
}

.speaker-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.speaker-name {
    font-weight: 500;
    font-size: 1.05rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-primary);
}

/* Remove old speech-content wrapper styles */
/* Restore speech-content wrapper for positioning controls */
.speech-content {
    position: relative;
    display: flex;
    flex-direction: column;
}

.script-layout .speech-content {
    display: grid;
    grid-template-columns: 120px 1fr auto;
    gap: 16px;
    align-items: flex-start;
    flex-direction: row; /* Override flex-column for script layout */
}

.dialogue-text {
    display: none;
}
.dialogue-text.active {
    display: block;
}
.dialogue-text.mm {
    font-family: "Padauk", sans-serif;
    line-height: 2;
}

/* Expression Highlight */
.expression {
    color: var(--accent);
    text-decoration: underline;
    text-decoration-color: var(--primary);
    text-decoration-thickness: 2px;
    text-underline-offset: 3px;
    cursor: pointer;
    transition: all 0.2s ease;
    padding: 2px 4px;
    border-radius: 4px;
}

.expression:hover {
    background: var(--highlight-bg);
    text-decoration-color: var(--accent);
}

/* Modal */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    -webkit-backdrop-filter: blur(8px);
    backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
    padding: 20px;
}

.modal-overlay.active {
    opacity: 1;
    visibility: visible;
}

.modal {
    background: linear-gradient(135deg, #1e1b4b 0%, #0f172a 100%);
    border: 1px solid var(--card-border);
    border-radius: 24px;
    max-width: 550px;
    width: 100%;
    max-height: 85vh;
    /* overflow-y: auto;  <-- Removed to let body scroll */
    display: flex;
    flex-direction: column;
    overflow: hidden; /* Ensures rounded corners clip content */
    transform: scale(0.9) translateY(20px);
    transition: transform 0.3s ease;
    will-change: transform;
}

/* Custom Scrollbar for Modal Body and Score Viewer */
.modal-body::-webkit-scrollbar,
.score-details-viewer::-webkit-scrollbar,
.cms-content-wrapper::-webkit-scrollbar,
.topic-list::-webkit-scrollbar,
.expressions-list::-webkit-scrollbar,
.dialogue-editor::-webkit-scrollbar,
.preview-content::-webkit-scrollbar,
.speakers-grid::-webkit-scrollbar,
.form-group textarea::-webkit-scrollbar,
.wizard-content::-webkit-scrollbar {
    width: 6px;
}

.modal-body::-webkit-scrollbar-track,
.score-details-viewer::-webkit-scrollbar-track,
.cms-content-wrapper::-webkit-scrollbar-track,
.topic-list::-webkit-scrollbar-track,
.expressions-list::-webkit-scrollbar-track,
.dialogue-editor::-webkit-scrollbar-track,
.preview-content::-webkit-scrollbar-track,
.speakers-grid::-webkit-scrollbar-track,
.form-group textarea::-webkit-scrollbar-track,
.wizard-content::-webkit-scrollbar-track {
    background: transparent;
}

.modal-body::-webkit-scrollbar-thumb,
.score-details-viewer::-webkit-scrollbar-thumb,
.cms-content-wrapper::-webkit-scrollbar-thumb,
.topic-list::-webkit-scrollbar-thumb,
.expressions-list::-webkit-scrollbar-thumb,
.dialogue-editor::-webkit-scrollbar-thumb,
.preview-content::-webkit-scrollbar-thumb,
.speakers-grid::-webkit-scrollbar-thumb,
.form-group textarea::-webkit-scrollbar-thumb,
.wizard-content::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 6px;
}

.modal-body::-webkit-scrollbar-thumb:hover,
.score-details-viewer::-webkit-scrollbar-thumb:hover,
.cms-content-wrapper::-webkit-scrollbar-thumb:hover,
.topic-list::-webkit-scrollbar-thumb:hover,
.expressions-list::-webkit-scrollbar-thumb:hover,
.dialogue-editor::-webkit-scrollbar-thumb:hover,
.preview-content::-webkit-scrollbar-thumb:hover,
.speakers-grid::-webkit-scrollbar-thumb:hover,
.form-group textarea::-webkit-scrollbar-thumb:hover,
.wizard-content::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* Standard scrollbar-width and scrollbar-color for Firefox and modern Chromium */
@supports (scrollbar-width: thin) {
    .modal-body,
    .score-details-viewer,
    .cms-content-wrapper,
    .topic-list,
    .expressions-list,
    .dialogue-editor,
    .preview-content,
    .speakers-grid,
    .form-group textarea,
    .wizard-content {
        scrollbar-width: thin;
        scrollbar-color: rgba(255, 255, 255, 0.2) transparent;
    }
}

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

.modal-header {
    padding: 24px 28px;
    border-bottom: 1px solid var(--card-border);
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    /* position: sticky; <-- Removed */
    /* top: 0; */
    background: linear-gradient(135deg, #1e1b4b 0%, #1e1b4b 100%);
    z-index: 10;
    flex-shrink: 0;
}

.modal-title-wrapper {
    flex: 1;
    min-width: 0;
}

.modal-title {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 8px;
    line-height: 1.3;
}

.modal-badge {
    display: inline-block;
    font-size: 0.85rem;
    padding: 4px 10px;
    background: linear-gradient(
        135deg,
        var(--primary) 0%,
        var(--secondary) 100%
    );
    border-radius: 20px;
    font-weight: 500;
}

.modal-close {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: none;
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-primary);
    font-size: 1.4rem;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.modal-close:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: rotate(90deg);
}

.modal-body {
    padding: 28px;
    overflow-y: auto;
    flex: 1; /* Takes remaining space */
}

.section-label {
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    color: var(--primary);
    margin-bottom: 12px;
    font-weight: 600;
}

.definition-text {
    font-family: "Padauk", sans-serif;
    color: var(--text-secondary);
    font-size: 1.2rem;
    line-height: 2;
    margin-bottom: 28px;
}

.english-term {
    color: var(--accent-cyan);
    font-family: "Inter", sans-serif;
    font-weight: 600;
    background: rgba(34, 211, 238, 0.1);
    padding: 2px 8px;
    border-radius: 6px;
}

/* Example Dialogue in Modal */
.example-dialogue {
    background: rgba(99, 102, 241, 0.1);
    border: 1px solid rgba(99, 102, 241, 0.2);
    border-radius: 16px;
    padding: 20px;
}

.example-line {
    display: flex;
    gap: 10px;
    margin-bottom: 14px;
    align-items: flex-start;
}

.example-line:last-child {
    margin-bottom: 0;
}

.example-speaker {
    min-width: 28px;
    height: 28px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
    font-weight: 700;
    flex-shrink: 0;
}

.example-speaker.a {
    background: linear-gradient(135deg, var(--accent-cyan) 0%, #06b6d4 100%);
    color: #0f172a;
}

.example-speaker.b {
    background: linear-gradient(
        135deg,
        var(--accent-purple) 0%,
        var(--secondary) 100%
    );
    color: #0f172a;
}

.example-bubble {
    flex: 1;
}

.example-english {
    color: var(--text-primary);
    font-size: 1.05rem;
    margin-bottom: 4px;
}

.example-myanmar {
    font-family: "Padauk", sans-serif;
    color: var(--text-muted);
    font-size: 1rem;
}

.highlight {
    color: var(--accent);
    font-weight: 600;
}

/* Mobile Responsive */
@media (max-width: 513px) {
    /* Body padding removed globally for edge-to-edge header */
    .container {
        padding: 0 8px;
        padding-bottom: calc(30px + env(safe-area-inset-bottom));
    }

    .conversation-title {
        text-align: left;
        font-size: 1.4rem;
        padding: 12px 16px;
        border-radius: 12px;
    }
    .dialogue-container {
        padding: 0;
        gap: 20px;
    }
    .dialogue-line {
        max-width: 80%;
    }
    .speaker-avatar {
        width: 32px;
        height: 32px;
    }
    .speech-bubble {
        padding: 16px 18px;
        font-size: 1.1rem;
        border-width: 5px;
    }
    /* Semantic mobile speech bubble styles */
    .other-speaker .speech-bubble {
        border-radius: 30px 30px 30px 0;
    }
    .main-speaker .speech-bubble {
        border-radius: 30px 30px 0 30px;
    }

    .speaker-name {
        font-size: 0.9rem;
    }
    .speaker-info {
        margin-bottom: 10px;
    }
    .modal-body {
        padding: 20px;
    }
    .instruction {
        align-items: flex-start;
        border-radius: 15px;
        gap: 6px;
        text-align: left;
        padding: 8px 12px;
        font-size: 0.95rem;
    }

    /* Remove expensive blur on mobile for performance */

    .modal-overlay {
        -webkit-backdrop-filter: none;
        backdrop-filter: none;
    }

    /* Sticky Nav Mobile Adjustments */
    .sticky-nav {
        padding: 2px 2px;
        -webkit-backdrop-filter: none;
        backdrop-filter: none;
    }
    .sticky-nav .nav-title {
        font-size: 1.2rem;
    }
}

/* Instruction Modal Specifics */
.instruction {
    gap: 25px;
}
.instruction-modal {
    position: relative;
    max-width: 500px;
    padding: 20px;
}

.instruction-close {
    position: absolute;
    top: 12px;
    right: 12px;
    width: 32px;
    height: 32px;
    background: rgba(255, 255, 255, 0.1);
    font-size: 1.2rem;
    z-index: 20;
}

.instruction-close:hover {
    transform: rotate(90deg);
    background: rgba(255, 255, 255, 0.2);
}

.instruction-content {
    margin-top: 20px;
}

/* Ensure images in instruction are sized correctly in popup */
.instruction-content .instruction-icon {
    width: 40px;
    height: 40px;
}

/* Responsive adjustment for icon button */
@media (min-width: 768px) {
    .icon-btn svg {
        width: 28px;
        height: 28px;
    }

    /* Keep info button smaller relative to the title */
    .info-btn img {
        width: 20px;
        height: 20px;
    }

    .hamburger-menu img {
        width: 28px;
        height: 28px;
    }
}

/* Topic Grid Styles */
.topic-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 20px;
    padding: 20px 0;
}

.topic-card {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: 16px;
    padding: 24px;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.topic-card:hover {
    border-color: var(--primary);
    background: rgba(99, 102, 241, 0.1);
    transform: translateY(-2px);
}

.topic-card:focus {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

.topic-card:active {
    transform: translateY(0);
}

.topic-card-title {
    font-family: "Cal Sans", sans-serif;
    font-weight: 400;
    font-size: 1.25rem;
    color: var(--text-primary);
    margin: 0;
    line-height: 1.3;
}

.topic-card-description {
    font-size: 0.95rem;
    color: var(--text-secondary);
    margin: 0;
    line-height: 1.5;
}

/* Mobile adjustments for topic grid */
@media (max-width: 513px) {
    .topic-grid {
        grid-template-columns: 1fr;
        gap: 16px;
        padding: 16px 0;
    }

    .topic-card {
        padding: 20px;
        border-radius: 12px;
    }

    .topic-card-title {
        font-size: 1.15rem;
    }

    .topic-card-description {
        font-size: 0.9rem;
    }
}

/* Home View Styles */
.home-view {
    padding: 20px 0;
}

.home-title {
    font-family: "Cal Sans", sans-serif;
    font-size: 1.75rem;
    color: var(--text-primary);
    text-align: center;
    margin-bottom: 8px;
}

.dialogue-view {
    /* Container for dialogue content - inherits container styles */
    display: block;
}

/* Hidden utility class */
.hidden {
    display: none !important;
}

/* Back Button Styles */
.nav-back {
    flex-shrink: 0;
}

.nav-back svg {
    width: 24px;
    height: 24px;
}

@media (min-width: 768px) {
    .nav-back svg {
        width: 28px;
        height: 28px;
    }
}

/* Mobile adjustments for home view */
@media (max-width: 513px) {
    .home-view {
        padding: 16px 0;
    }

    .home-title {
        font-size: 1.4rem;
        text-align: left;
        padding: 0 8px;
    }
}

/* Loading Indicator Styles */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(15, 23, 42, 0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    opacity: 0;
    visibility: hidden;
    transition:
        opacity 0.3s ease,
        visibility 0.3s ease;
}

.loading-overlay.active {
    opacity: 1;
    visibility: visible;
}

.loading-spinner {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
}

.spinner {
    width: 48px;
    height: 48px;
    border: 4px solid rgba(99, 102, 241, 0.2);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

.loading-text {
    color: var(--text-secondary);
    font-size: 1rem;
    font-weight: 500;
}

/* Error Message Styles */
.error-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(15, 23, 42, 0.95);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    opacity: 0;
    visibility: hidden;
    transition:
        opacity 0.3s ease,
        visibility 0.3s ease;
    padding: 20px;
}

.error-overlay.active {
    opacity: 1;
    visibility: visible;
}

.error-container {
    background: linear-gradient(135deg, #1e1b4b 0%, #0f172a 100%);
    border: 1px solid rgba(239, 68, 68, 0.3);
    border-radius: 16px;
    padding: 32px;
    max-width: 400px;
    width: 100%;
    text-align: center;
}

.error-icon {
    font-size: 3rem;
    margin-bottom: 16px;
}

.error-title {
    font-family: "Cal Sans", sans-serif;
    font-size: 1.5rem;
    color: var(--text-primary);
    margin-bottom: 12px;
}

.error-message {
    color: var(--text-secondary);
    font-size: 1rem;
    line-height: 1.6;
    margin-bottom: 24px;
}

.error-actions {
    display: flex;
    gap: 12px;
    justify-content: center;
    flex-wrap: wrap;
}

.error-retry-btn,
.error-dismiss-btn {
    padding: 12px 24px;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    border: none;
}

.error-retry-btn {
    background: linear-gradient(
        135deg,
        var(--primary) 0%,
        var(--secondary) 100%
    );
    color: var(--text-primary);
}

.error-retry-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.4);
}

.error-dismiss-btn {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-secondary);
    border: 1px solid var(--card-border);
}

.error-dismiss-btn:hover {
    background: rgba(255, 255, 255, 0.15);
    color: var(--text-primary);
}

/* Mobile adjustments for loading and error */
@media (max-width: 513px) {
    .spinner {
        width: 40px;
        height: 40px;
        border-width: 3px;
    }

    .loading-text {
        font-size: 0.9rem;
    }

    .error-container {
        padding: 24px;
        border-radius: 12px;
    }

    .error-icon {
        font-size: 2.5rem;
    }

    .error-title {
        font-size: 1.25rem;
    }

    .error-message {
        font-size: 0.9rem;
    }

    .error-retry-btn,
    .error-dismiss-btn {
        padding: 10px 20px;
        font-size: 0.9rem;
    }
}

/* Game Mode Toggle */
.game-mode-toggle-wrapper {
    display: flex;
    align-items: center;
    margin-right: 12px;
    gap: 6px;
}

.toggle-label {
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-secondary);
}

.switch {
    position: relative;
    display: inline-block;
    width: 44px;
    height: 24px;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #ccc;
    transition: 0.4s;
}

.slider:before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: 0.4s;
}

input:checked + .slider {
    background-color: #6b2590;
}

input:focus + .slider {
    box-shadow: 0 0 1px var(--primary-color);
}

input:checked + .slider:before {
    transform: translateX(20px);
}

/* Rounded sliders */
.slider.round {
    border-radius: 24px;
}

.slider.round:before {
    border-radius: 50%;
}

/* Game Setup Modal */
.game-setup-modal {
    width: 90%;
    max-width: 400px;
}

.mode-selector {
    display: flex;
    gap: 10px;
    margin-top: 8px;
    margin-bottom: 20px;
}

.mode-btn {
    flex: 1;
    padding: 10px;
    border: 1px solid var(--card-border);
    background: rgba(255, 255, 255, 0.05);
    border-radius: 12px;
    color: var(--text-secondary);
    cursor: pointer;
    font-weight: 500;
    transition: all 0.2s ease;
}

.mode-btn.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
}

.mode-btn:hover:not(.active) {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-primary);
}

.input-group {
    margin-bottom: 16px;
}

.input-group label {
    display: block;
    margin-bottom: 6px;
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-primary);
}

.input-group input {
    width: 100%;
    padding: 10px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 1rem;
}

.speaker-assignment-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-top: 10px;
}

.assignment-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px;
    background: var(--bg-secondary);
    border-radius: 8px;
}

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

.assignment-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    object-fit: cover;
}

.assignment-name {
    font-weight: 500;
    font-size: 0.95rem;
}

.assignment-toggle {
    display: flex;
    background: var(--divider-color);
    border-radius: 16px;
    padding: 2px;
}

.assignment-btn {
    padding: 6px 16px;
    border-radius: 10px;
    font-size: 0.85rem;
    font-weight: 600;
    border: 1px solid transparent;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s ease;
}

.assignment-btn.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
    box-shadow: 0 2px 6px rgba(99, 102, 241, 0.2);
}

.primary-btn {
    background: linear-gradient(
        135deg,
        var(--primary) 0%,
        var(--secondary) 100%
    );
    color: white;
    border: none;
    border-radius: 12px;
    padding: 12px 24px;
    font-family: inherit;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
}

.primary-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 15px rgba(99, 102, 241, 0.4);
    filter: brightness(1.1);
}

.primary-btn:active {
    transform: translateY(0);
}

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

.primary-btn.secondary-style:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: var(--text-muted);
    box-shadow: none;
}

.start-game-btn {
    width: 100%;
    margin-top: 20px;
    padding: 14px;
    font-size: 1.1rem;
}

.setup-error-msg {
    color: #ef4444;
    background: rgba(239, 68, 68, 0.1);
    padding: 10px;
    border-radius: 8px;
    font-size: 0.9rem;
    font-weight: 500;
    margin-top: 15px;
    text-align: center;
    border: 1px solid rgba(239, 68, 68, 0.2);
}

/* Game Mode Styles */
.game-mode .dialogue-text.pending {
    filter: blur(6px);
    -webkit-user-select: none;
    user-select: none;
    pointer-events: none;
    opacity: 0.8;
}

/* Ensure bubble container is visible even if text is transparent */
.game-mode .speech-bubble {
    min-height: 60px;
    min-width: 300px;
}

/* Emoji Controls */
.emoji-controls {
    position: absolute;
    /* Align outside the bubble */
    top: 50%;
    transform: translateY(-50%);
    display: flex;
    flex-direction: column;
    gap: 8px;
    z-index: 10;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
    right: -45px; /* Always on the right side of the bubble */
}

.emoji-controls.active {
    opacity: 1;
    pointer-events: auto;
}

.emoji-btn {
    background: white;
    border: 1px solid var(--border-color);
    border-radius: 50%;
    width: 36px;
    height: 36px;
    font-size: 1.2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    transition: transform 0.2s;
}

.emoji-btn:hover {
    transform: scale(1.1);
}

.emoji-btn:active {
    transform: scale(0.95);
}

/* Floating Game Scoreboards */
.game-scoreboards-container {
    position: fixed;
    top: 102px; /* Just below the nav bar */
    left: 0;
    right: 0;
    display: flex;
    justify-content: space-between; /* P1 left, P2 right */
    padding: 0 15px;
    z-index: 900;
    pointer-events: none;
}

.player-card {
    background: rgba(1, 3, 31, 0.9); /* Matching --card-bg with transparency */
    border: 2px solid var(--primary-color);
    border-radius: 12px;
    padding: 8px 12px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    min-width: 100px;
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    pointer-events: auto;
}

.player-card.active-turn {
    transform: scale(1.05);
    box-shadow: 0 0 12px var(--primary-color);
    border-color: var(--accent-color);
}

/* Speaker cards individual colors if needed */
.player-card.p1-card {
    border-color: var(--primary-color);
}
.player-card.p2-card {
    border-color: #ec4899; /* Pinkish for P2? */
}

.player-card .p-info {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.player-card .p-name {
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 1px;
}

.player-card .p-score {
    font-size: 1.4rem;
    font-weight: 900;
    color: var(--text-primary);
    line-height: 1;
}

/* Enhanced Score Pop for Flying */
.score-pop {
    position: fixed; /* Fixed for easier calculation of destination */
    z-index: 1000;
    font-weight: 800;
    font-size: 2rem;
    pointer-events: none;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
    white-space: nowrap;
    transition: all 0.8s cubic-bezier(0.6, -0.28, 0.735, 0.045);
}

.score-pop.perfect {
    color: #fbbf24;
    text-shadow: 0 0 10px #f59e0b;
}
.score-pop.nice {
    color: #3b82f6;
}
.score-pop.missed {
    color: #9ca3af;
    font-size: 1.5rem;
}

.speech-bubble {
    position: relative; /* Ensure badges can be positioned relative to bubble */
}

.player-score-label {
    position: absolute;
    top: 1px;
    padding: 4px 15px;
    border-radius: 0px 106px 0px 121px;
    font-size: 0.3rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: white;
    z-index: 15;
    /* box-shadow: 0 2px 8px rgba(0,0,0,0.2); */
    pointer-events: none;
    /* border: 1px solid rgba(255,255,255,0.2); */
    opacity: 0; /* Hidden initially */
    transition:
        opacity 0.3s ease,
        top 0.3s ease,
        transform 0.3s ease;
}

/* Player Label Positioning - All Top Right */
.player-score-label {
    right: 3px;
}

.player-score-label[data-player-id="1"] {
    background: #ec4899;
}
.player-score-label[data-player-id="2"] {
    background: #ec4899;
}

/* Show only when active */
.player-score-label.active {
    opacity: 1;
    /* animation: badgePulse 2s infinite ease-in-out; */
    /* box-shadow: 0 0 12px rgba(255, 255, 255, 0.4); */
    transform: scale(1.05); /* Slightly larger when active */
    /* top: -15px;  */
}

@keyframes badgePulse {
    0% {
        box-shadow: 0 0 8px rgba(255, 255, 255, 0.3);
    }
    50% {
        box-shadow: 0 0 15px rgba(255, 255, 255, 0.6);
        transform: scale(1.1) translateY(-2px);
    }
    100% {
        box-shadow: 0 0 8px rgba(255, 255, 255, 0.3);
    }
}

@keyframes scorePulse {
    0% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.3);
    }
    100% {
        transform: scale(1);
    }
}

.score-updated {
    animation: scorePulse 0.4s ease-out;
}

/* Scoreboard Modal */
.scoreboard-modal {
    position: relative; /* For absolute positioning of close button if needed */
}

.scoreboard-modal .modal-close {
    position: absolute;
    top: 15px;
    right: 15px;
    z-index: 100;
}

.scoreboard-content {
    margin: 20px 0;
    display: flex;
    flex-direction: column;
    gap: 15px;
}

/* Scoreboard Modal v2 */
.score-row-v2 {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--card-border);
    border-radius: 16px;
    padding: 20px;
    margin-bottom: 20px;
    display: flex;
    flex-direction: column;
    gap: 15px;
}

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

.score-name {
    font-family: "Cal Sans", sans-serif;
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-primary);
}

.score-stars-container {
    display: flex;
    gap: 8px;
    font-size: 1.8rem;
}

.star-placeholder {
    opacity: 0.2;
}

.star-icon {
    display: inline-block;
    transform: scale(0);
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.star-icon.empty {
    filter: grayscale(1) opacity(0.5);
}

.animate-pop {
    animation: starPop 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

@keyframes starPop {
    0% {
        transform: scale(0) rotate(-45deg);
        opacity: 0;
    }
    70% {
        transform: scale(1.4) rotate(10deg);
        opacity: 1;
    }
    100% {
        transform: scale(1) rotate(0deg);
        opacity: 1;
    }
}

.score-details-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    text-align: center;
}

.score-stat-item {
    background: rgba(0, 0, 0, 0.3);
    padding: 8px;
    border-radius: 10px;
    display: flex;
    flex-direction: column;
}

.stat-label {
    font-size: 0.7rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 1px;
}

.stat-value {
    font-size: 1.1rem;
    font-weight: 800;
    color: var(--primary);
}

.score-breakdown {
    display: flex;
    justify-content: center;
    gap: 15px;
    font-size: 0.85rem;
    color: var(--text-secondary);
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    padding-top: 10px;
}

.score-breakdown span.perfect {
    color: #facc15;
}
.score-breakdown span.good {
    color: #60a5fa;
}
.score-breakdown span.missed {
    color: #94a3b8;
}

.stat-clickable {
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 6px;
    transition: all 0.2s ease;
    border: 1px solid transparent;
}

.stat-clickable:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.2);
    transform: translateY(-2px);
}

.score-details-wrapper {
    margin-top: 15px;
    background: rgba(0, 0, 0, 0.4);
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    overflow: hidden; /* Clips the child's scrollbar */
    animation: slideDown 0.3s ease-out;
}

.score-details-viewer {
    padding: 15px;
    max-height: 300px;
    overflow-y: auto;
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.details-header {
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--text-muted);
    letter-spacing: 2px;
    margin-bottom: 15px;
    text-align: center;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    padding-bottom: 8px;
}

.compact-line-item {
    margin-bottom: 12px;
    padding-bottom: 12px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.compact-line-item:last-child {
    margin-bottom: 0;
    padding-bottom: 0;
    border-bottom: none;
}

.compact-mm {
    font-family: "Padauk", sans-serif;
    color: var(--text-primary);
    font-size: 0.95rem;
    line-height: 1.6;
    margin-bottom: 4px;
}

.compact-en {
    color: var(--text-secondary);
    font-size: 0.85rem;
    font-style: italic;
}

.scoreboard-actions {
    display: flex;
    gap: 10px;
    margin-top: 20px;
}

/* Script Layout Styles */
.script-layout .speech-content {
    display: grid;
    grid-template-columns: 120px 1fr auto;
    gap: 16px;
    align-items: flex-start;
}

.script-layout .speaker-info {
    grid-column: 1;
    display: flex !important;
    flex-direction: column !important;
    align-items: flex-start !important;
    gap: 4px;
    margin-bottom: 0;
    position: sticky;
    top: 100px;
}

.script-layout .speaker-avatar {
    width: 32px;
    height: 32px;
}

.script-layout .speaker-name {
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--primary);
    text-align: left;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    width: 100%;
}

.script-layout .speech-bubble {
    grid-column: 2;
    background: transparent !important;
    border: none !important;
    padding: 0 !important;
    border-radius: 0 !important;
    min-width: 0 !important;
    box-shadow: none !important;
}

.script-layout .dialogue-line {
    max-width: 100%;
    align-self: stretch;
}

.script-layout .dialogue-text {
    font-size: 1.15rem;
    line-height: 1.6;
    margin-bottom: 8px;
}

.script-layout .dialogue-text.mm {
    color: var(--text-secondary);
}

.script-layout .dialogue-text.en {
    color: var(--text-primary);
}

.script-layout .emoji-controls {
    grid-column: 3;
    position: static;
    transform: none;
    flex-direction: row;
    padding-left: 10px;
}

/* Mobile variations */
@media (max-width: 600px) {
    .script-layout .speech-content {
        grid-template-columns: 80px 1fr auto;
        gap: 8px;
    }

    .script-layout .speaker-name {
        font-size: 0.7rem;
    }

    .script-layout .dialogue-text {
        font-size: 1.05rem;
    }
}
