:root {
    --bg: #0a0a0a;
    --bg-gradient: linear-gradient(135deg, #0a0a0a 0%, #141414 50%, #1e1e1e 100%);

    --surface: rgba(20, 20, 20, 0.95);
    --surface-light: rgba(35, 35, 35, 0.8);
    --surface-card: rgba(25, 25, 25, 0.9);

    --text: #f0f0f0;
    --text-muted: #b0b0b0;
    --text-light: #d0d0d0;

    /* Very subtle muted accent (off-white with a slight tint) */
    --accent: #888888;
    --accent-gradient: linear-gradient(135deg, #888888 0%, #aaaaaa 100%);

    --success: #22c55e; /* Kept slightly green for clarity */
    --success-gradient: linear-gradient(135deg, #22c55e 0%, #15803d 100%);

    --error: #ef4444;
    --error-gradient: linear-gradient(135deg, #ef4444 0%, #b91c1c 100%);

    --warning: #eab308;
    --info: #a1a1aa; /* neutral gray instead of blue */

    --border: rgba(120, 120, 120, 0.25);
    --border-light: rgba(160, 160, 160, 0.15);

    --shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.5);

    --glow: 0 0 12px rgba(136, 136, 136, 0.25);
}


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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Inter', sans-serif;
    line-height: 1.6;
    background: var(--bg);
    background-image: var(--bg-gradient);
    color: var(--text);
    min-height: 100vh;
    padding: 0.5rem;
    overflow-x: hidden;
}

.wrap {
    max-width: 100%;
    width: 100%;
    background: var(--surface);
    border-radius: 1rem;
    padding: 1rem;
    box-shadow: var(--shadow-lg);
    backdrop-filter: blur(20px);
    border: 1px solid var(--border);
    margin: 0 auto;
}

/* Header styles */
header {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border);
    margin-bottom: 1rem;
    gap: 0.5rem;
}

h1 {
    font-size: 1.5rem;
    font-weight: 700;
    text-align: center;
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 0.25rem;
    letter-spacing: -0.02em;
}

h2 {
    font-size: 0.9rem;
    font-weight: 600;
    text-align: center;
    color: var(--text-light);
    margin: 0.25rem 0;
}

.meta {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    align-items: center;
    justify-content: center;
    width: 100%;
}

/* Button styles */
button {
    background: var(--surface-light);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 0.75rem 1rem;
    border-radius: 0.75rem;
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 500;
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
    min-height: 44px; /* iOS touch target */
    display: flex;
    align-items: center;
    justify-content: center;
    white-space: nowrap;
}

button:hover, button:focus {
    transform: translateY(-1px);
    box-shadow: var(--shadow);
    border-color: var(--accent);
    outline: none;
}

button:active {
    transform: translateY(0);
}

button.primary {
    background: var(--accent-gradient);
    border: none;
    color: white;
    box-shadow: var(--glow);
}

button.primary:hover, button.primary:focus {
    box-shadow: var(--shadow-lg), var(--glow);
}

button.check-btn {
    background: var(--success-gradient);
    color: white;
    border: none;
}

button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

/* Card styles */
.card {
    background: var(--surface-card);
    padding: 1rem;
    border-radius: 1rem;
    margin-top: 1rem;
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
}

/* Question styles */
.qnum {
    font-size: 1rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--accent);
    margin-bottom: 1rem;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.qtext {
    font-size: 1.1rem;
    font-weight: 600;
    margin: 1rem 0;
    text-align: center;
    color: var(--text);
    line-height: 1.5;
}

.opts {
    margin: 1rem 0;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.opt {
    display: flex;
    align-items: center;
    padding: 1rem;
    border-radius: 0.75rem;
    margin: 0;
    transition: all 0.3s ease;
    cursor: pointer;
    border: 1px solid var(--border);
    background: var(--surface-light);
    min-height: 44px;
    text-align: left;
}

.opt:hover, .opt:focus-within {
    background: var(--accent);
    color: white;
    transform: translateX(4px);
    box-shadow: var(--shadow);
}

.opt input[type="radio"],
.opt input[type="checkbox"] {
    margin-right: 0.75rem;
    transform: scale(1.2);
    accent-color: var(--accent);
    flex-shrink: 0;
}

/* Form styles */
input[type="text"] {
    width: 100%;
    padding: 1rem;
    border-radius: 0.75rem;
    border: 1px solid var(--border);
    font-size: 1rem;
    text-align: center;
    transition: all 0.3s ease;
    background: var(--surface-light);
    color: var(--text);
    min-height: 44px;
}

input[type="text"]:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.2);
    transform: translateY(-1px);
}

input[type="text"]::placeholder {
    color: var(--text-muted);
}

/* Navigation styles */
.nav {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 0.75rem;
    margin: 1.5rem 0;
    flex-wrap: wrap;
}

/* Progress bar */
.progress {
    height: 0.75rem;
    background: var(--surface-light);
    border-radius: 0.375rem;
    overflow: hidden;
    position: relative;
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.2);
    margin: 1rem 0;
}

.progress > i {
    display: block;
    height: 100%;
    background: var(--accent-gradient);
    transition: width 0.5s ease;
    border-radius: 0.375rem;
    position: relative;
}

.progress > i::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.3), transparent);
    animation: shimmer 2s infinite;
}

@keyframes shimmer {
    0% { transform: translateX(-100%); }
    100% { transform: translateX(100%); }
}

/* Utility classes */
.small {
    font-size: 0.8rem;
    color: var(--text-muted);
    text-align: center;
}

/* Match question styles */
.match-grid {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.match-row {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    padding: 1rem;
    background: var(--surface-light);
    border-radius: 0.75rem;
    border: 1px solid var(--border);
}

.match-label {
    font-weight: 600;
    color: var(--text);
    margin-bottom: 0.5rem;
}

select {
    width: 100%;
    padding: 0.75rem;
    border-radius: 0.5rem;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    font-size: 0.9rem;
    min-height: 44px;
}

select:focus {
    outline: none;
    border-color: var(--accent);
}

/* Footer styles */
.footer {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
    margin-top: 1.5rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--border);
}

.controls {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    justify-content: center;
}

/* Score display */
.score-display {
    text-align: center;
    margin: 1.5rem 0;
    padding: 1.5rem;
    background: var(--surface-light);
    border-radius: 1rem;
    border: 1px solid var(--border);
    font-size: 1.2rem;
    font-weight: 700;
}

.score-display .score {
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    font-size: 1.5rem;
}

/* Graded question styles */
.graded-question {
    margin-bottom: 1rem;
    padding: 1rem;
    border-radius: 0.75rem;
    background: var(--surface-light);
    border: 1px solid var(--border);
    transition: all 0.3s ease;
}

.graded-question-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.75rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid var(--border-light);
    flex-wrap: wrap;
    gap: 0.5rem;
}

.graded-question-status {
    font-size: 1rem;
    font-weight: 700;
    padding: 0.5rem 0.75rem;
    border-radius: 0.5rem;
    min-width: 50px;
    text-align: center;
}

.status-correct {
    background: var(--success);
    color: white;
}

.status-incorrect {
    background: var(--error);
    color: white;
}

.graded-question-text,
.graded-answer {
    margin-bottom: 0.75rem;
}

.user-answer,
.correct-answer {
    padding: 0.75rem;
    border-radius: 0.5rem;
    margin-top: 0.5rem;
}

.user-answer {
    background: var(--info);
    color: white;
}

.correct-answer {
    background: var(--success);
    color: white;
}

.back-button {
    margin: 1.5rem auto;
    display: block;
    width: 100%;
    max-width: 200px;
}

/* Tree container */
.tree-container {
    margin: 1rem 0;
    background: var(--surface-light);
    padding: 1rem;
    border-radius: 0.75rem;
    border: 1px solid var(--border);
}

.tree-node {
    margin: 0.25rem 0;
}

.tree-node-header {
    display: flex;
    align-items: center;
    padding: 0.75rem;
    border-radius: 0.5rem;
    cursor: pointer;
    transition: all 0.3s ease;
    background: var(--surface);
    border: 1px solid var(--border-light);
    min-height: 44px;
}

.tree-node-header:hover, .tree-node-header:focus {
    background: var(--accent);
    color: white;
    transform: translateX(2px);
}

.tree-expander {
    width: 1.25rem;
    height: 1.25rem;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
    border-radius: 50%;
    background: var(--accent);
    color: white;
    margin-right: 0.75rem;
    flex-shrink: 0;
}

.tree-node-icon {
    margin-right: 0.5rem;
    font-size: 1rem;
    flex-shrink: 0;
}

.tree-node-children {
    margin-left: 1.5rem;
    display: none;
    border-left: 1px solid var(--border-light);
    padding-left: 0.75rem;
}

.tree-node.expanded > .tree-node-children {
    display: block;
}

.tree-node.expanded > .tree-node-header > .tree-expander::before {
    content: "▼";
}

.tree-node.collapsed > .tree-node-header > .tree-expander::before {
    content: "▶";
}

.tree-node.leaf > .tree-node-header > .tree-expander {
    visibility: hidden;
}

.tree-node-link {
    color: inherit;
    text-decoration: none;
    font-weight: 500;
    flex: 1;
    word-break: break-word;
}

@media (max-width: 600px) {
    .tree-container {
        padding: 0.75rem;
        border-radius: 0.5rem;
    }

    .tree-node-header {
        padding: 0.5rem;
        font-size: 0.9rem;
    }

    .tree-expander {
        width: 1rem;
        height: 1rem;
        font-size: 0.7rem;
        margin-right: 0.5rem;
    }

    .tree-node-icon {
        font-size: 0.9rem;
        margin-right: 0.4rem;
    }

    .tree-node-children {
        margin-left: 1rem;
        padding-left: 0.5rem;
    }

    .tree-node-link {
        font-size: 0.9rem;
        word-break: break-word;
    }
}


/* Navigation input */
.goto-input {
    width: 3rem;
    padding: 0.5rem;
    border-radius: 0.5rem;
    border: 1px solid var(--border);
    text-align: center;
    font-size: 0.85rem;
    font-weight: 600;
    background: var(--surface-light);
    color: var(--text);
    min-height: 36px;
}

.goto-btn {
    padding: 0.5rem 0.75rem;
    border-radius: 0.5rem;
    border: 1px solid var(--accent);
    background: var(--accent-gradient);
    color: white;
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 600;
    min-width: 50px;
    min-height: 36px;
}

/* Feedback styles */
.feedback-container {
    margin-top: 1rem;
    padding: 1rem;
    border-radius: 0.75rem;
    display: none;
    text-align: center;
    font-weight: 600;
}

.feedback-correct {
    background: var(--success-gradient);
    color: white;
    border: none;
}

.feedback-incorrect {
    background: var(--error-gradient);
    color: white;
    border: none;
}

.feedback-icon {
    font-size: 1.2rem;
    margin-right: 0.5rem;
}

.feedback-answer {
    margin-top: 0.75rem;
    font-weight: 500;
    opacity: 0.95;
}

/* Match result styles */
.match-correct {
    color: var(--success);
    font-weight: 600;
}

.match-incorrect {
    color: var(--error);
    font-weight: 600;
}

.match-score {
    font-size: 0.85rem;
    margin-top: 0.25rem;
}

/* Label styles */
label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 500;
    color: var(--text);
    cursor: pointer;
    padding: 0.5rem 0.75rem;
    border-radius: 0.5rem;
    transition: all 0.3s ease;
}

label:hover {
    background: var(--surface-light);
}

input[type="checkbox"] {
    transform: scale(1.1);
    accent-color: var(--accent);
}

.speaker-btn {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1em;
    margin-left: 5px;
    color: #4a6fa5;
    display: inline-block;
}

.speaker-btn:hover {
    opacity: 0.7;
}

.no-speech .speaker-btn {
    display: none;
}

/* Desktop styles */
@media (min-width: 768px) {
    body {
        padding: 2rem;
        display: flex;
        align-items: center;
        justify-content: center;
    }
    
    .wrap {
        max-width: 56rem;
        padding: 2.5rem;
    }
    
    h1 {
        font-size: 2.5rem;
    }
    
    h2 {
        font-size: 1.1rem;
    }
    
    .meta {
        flex-direction: row;
        gap: 1rem;
    }
    
    .footer {
        flex-direction: row;
        justify-content: space-between;
        align-items: center;
    }
    
    .nav {
        gap: 2rem;
    }
    
    .qtext {
        font-size: 1.4rem;
    }
    
    .match-row {
        flex-direction: row;
        align-items: center;
        justify-content: space-between;
        align-items: center;
        gap: 1rem;
    }

    select {
        width: auto;
        min-width: 150px;
    }
    
    .controls {
        gap: 1rem;
    }
    
    button {
        min-width: 120px;
    }
    
    .tree-node-children {
        margin-left: 2rem;
        padding-left: 1rem;
    }
}

/* Large desktop styles */
@media (min-width: 1024px) {
    .wrap {
        max-width: 64rem;
        padding: 3rem;
    }
    
    .card {
        padding: 2rem;
    }
    
    .opts {
        gap: 1rem;
    }
    
    .opt {
        padding: 1.25rem;
    }
}