*, *::before, *::after {
    box-sizing: border-box;
}

.is-hidden {
    display: none !important;
}

:root {
    /* Theme: Magical Modern */
    --color-bg-start: #fffbf0;
    --color-bg-end: #efe6d5;

    --color-card: #ffffff;
    --color-text: #2c3e50;
    --color-text-muted: #7f8c8d;
    --color-border: #eaddcf;

    --color-primary: #2c3e50;
    --color-primary-hover: #34495e;
    --color-accent: #d89a2f; /* Desaturated golden orange */

    --color-good: #42a868; /* Softer green */
    --color-bad: #d45f54; /* Softer red */

    /* Desaturated Color Extensions */
    --color-accent-light: #f5e6d3;
    --color-speed-freeze: #8fb4d4;
    --color-speed-slow: #95a5a6;
    --color-speed-normal: #d4ad60;
    --color-speed-fast: #d47566;
    --color-star-gold: #d4a960;
    --color-star-bg-start: #faf5e8;
    --color-star-bg-end: #f5ead0;
    --color-star-border: #e6d5a8;
    --color-mastery-start: #d4ad60;
    --color-mastery-end: #d89a2f;

    --color-name-bg: #f0f4f8;
    --color-name-text: #54708b;
    --color-name-border: #d1dbe5;
    --color-name-hover-bg: #54708b;

    --color-timer-text: rgba(44, 62, 80, 0.4);

    --shadow-card: 0 12px 32px -4px rgba(44, 62, 80, 0.08);
    --shadow-button: 0 8px 16px -4px rgba(44, 62, 80, 0.12);
    --shadow-inner: inset 0 2px 4px rgba(0,0,0,0.03);
    --shadow-sm: 0 2px 4px rgba(44, 62, 80, 0.04);
    --shadow-md: 0 4px 12px rgba(44, 62, 80, 0.08);
    --shadow-lg: 0 8px 24px rgba(44, 62, 80, 0.12);
    --shadow-xl: 0 12px 32px rgba(44, 62, 80, 0.16);
    --shadow-glow-accent: 0 0 12px rgba(216, 154, 47, 0.2);
    --shadow-glow-star: 0 0 8px rgba(212, 169, 96, 0.25);

    --font-heading: 'Georgia', 'Times New Roman', serif;
    --font-body: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji';
    --font-regular: 400;
    --font-semibold: 600;
    --font-bold: 700;

    /* Typography Scale */
    --text-xs: 0.75rem;
    --text-sm: 0.875rem;
    --text-base: 1rem;
    --text-lg: 1.25rem;
    --text-xl: 1.5rem;
    --text-2xl: 2rem;

    /* Spacing Scale (4px base) */
    --space-1: 0.25rem;
    --space-2: 0.5rem;
    --space-3: 0.75rem;
    --space-4: 1rem;
    --space-5: 1.25rem;
    --space-6: 1.5rem;
    --space-8: 2rem;
    --space-10: 2.5rem;
    --space-12: 3rem;
    --space-16: 4rem;

    /* Border System */
    --border-width-thin: 1px;
    --border-width-thick: 2px;
    --border-solid: var(--border-width-thin) solid var(--color-border);
    --border-thick: var(--border-width-thick) solid var(--color-border);
    --border-dashed: var(--border-width-thin) dashed var(--color-border);
    --border-accent: var(--border-width-thick) solid var(--color-accent);
    --border-primary: var(--border-width-thin) solid var(--color-primary);

    /* Animation Timing */
    --duration-instant: 0.1s;
    --duration-fast: 0.2s;
    --duration-normal: 0.3s;
    --duration-slow: 0.5s;
    --ease-default: cubic-bezier(0.4, 0.0, 0.2, 1);
    --ease-in: cubic-bezier(0.4, 0.0, 1, 1);
    --ease-out: cubic-bezier(0.0, 0.0, 0.2, 1);
    --ease-bounce: cubic-bezier(0.175, 0.885, 0.32, 1.275);

    /* Icon Sizes */
    --icon-sm: 1rem;
    --icon-md: 1.25rem;
    --icon-lg: 1.5rem;
    --icon-xl: 2rem;

    --radius-lg: 20px;
    --radius-md: 12px;
    --radius-sm: 8px;
    --radius-pill: 999px;
}

html { font-size: 16px; }

body {
    margin: 0;
    padding: 0;
    font-family: var(--font-body);
    background: radial-gradient(circle at 50% 10%, var(--color-bg-start) 0%, var(--color-bg-end) 100%);
    color: var(--color-text);
    min-height: 100vh;
    line-height: 1.5;
}

.container {
    max-width: 680px;
    margin: 0 auto;
    padding: 2rem 1.25rem 4rem;
}

/* Header */
.app-header {
    text-align: center;
    margin-bottom: 3.5rem;
    position: relative;
}

.btn-help {
    position: absolute;
    top: 0;
    right: 0;
    background: var(--color-card);
    border: 1px solid var(--color-border);
    border-radius: 50%;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
    cursor: pointer;
    box-shadow: var(--shadow-sm);
    transition: all 0.2s ease;
    padding: 0;
}

.btn-help:hover {
    transform: translateY(-2px);
    border-color: var(--color-accent);
    box-shadow: var(--shadow-md);
    background-color: var(--color-accent-light);
}

.btn-help:focus {
    outline: none;
    box-shadow: 0 0 0 3px rgba(243, 156, 18, 0.4);
}

.header-icon {
    font-size: 2.5rem;
    margin-bottom: -0.25rem;
    animation: magic-float 4s ease-in-out infinite;
    display: inline-block;
    filter: drop-shadow(0 0 10px rgba(216, 154, 47, 0.3));
}

h1 {
    margin: 0 0 0.5rem;
    font-family: var(--font-heading);
    font-size: clamp(2.5rem, 10vw, 3.75rem);
    font-weight: 800;
    letter-spacing: -0.04em;
    background: linear-gradient(135deg, var(--color-primary) 25%, var(--color-accent) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    filter: drop-shadow(0 2px 4px rgba(44, 62, 80, 0.05));
    line-height: 1.1;
}

.subtitle {
    margin: 0;
    font-size: 0.8rem;
    color: var(--color-text-muted);
    font-weight: 700;
    letter-spacing: 0.25em;
    text-transform: uppercase;
    opacity: 0.8;
}

/* Panels */
.panel {
    background: var(--color-card);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    box-shadow: var(--shadow-card);
    margin-bottom: 1.5rem;
    position: relative;
    overflow: hidden;
}

.panel::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0; height: 4px;
    background: linear-gradient(90deg, var(--color-primary), var(--color-accent));
    opacity: 0.1;
}

.panel-title {
    margin: 0 0 1.25rem;
    font-family: var(--font-heading);
    font-size: 1.25rem;
    color: var(--color-primary);
    font-weight: 700;
    letter-spacing: 0.02em;
}

.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1.25rem;
}

.panel-header .panel-title { margin: 0; }

/* Player Name */
.player-name {
    background: transparent;
    border: none;
    padding: 0;
    font-size: 0.9rem;
    font-weight: 600;
    font-family: var(--font-body);
    color: var(--color-text-muted);
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 0.3rem;
    box-shadow: none;
}

.player-name:hover {
    color: var(--color-accent);
    transform: none;
    box-shadow: none;
}

.player-name::after {
    content: '✎';
    font-size: 0.7rem;
    opacity: 0.5;
}

/* Fields & Segmented Controls */
.field {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.75rem 0;
    border-top: 1px solid rgba(0,0,0,0.04);
}
.field:first-of-type { border-top: none; padding-top: 0; }

.field-label {
    font-weight: 700;
    font-size: 0.85rem;
    text-transform: uppercase;
    color: var(--color-text-muted);
    letter-spacing: 0.05em;
}

.field-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.5rem;
}

/* Toggle Switch Styling */
.timer-toggle, .hard-mode-toggle {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--color-text-muted);
    user-select: none;
    transition: opacity 0.2s ease;
}

.timer-toggle input, .hard-mode-toggle input {
    display: none;
}

.toggle-track {
    position: relative;
    width: 32px;
    height: 18px;
    background: var(--color-border);
    border-radius: 9px;
    transition: background 0.2s;
}

.toggle-thumb {
    position: absolute;
    top: 2px;
    left: 2px;
    width: 14px;
    height: 14px;
    background: #fff;
    border-radius: 50%;
    transition: transform 0.2s;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.timer-toggle input:checked + .toggle-track,
.hard-mode-toggle input:checked + .toggle-track {
    background: var(--color-accent);
}

.timer-toggle input:checked + .toggle-track .toggle-thumb,
.hard-mode-toggle input:checked + .toggle-track .toggle-thumb {
    transform: translateX(14px);
}

.hard-mode-toggle.is-disabled {
    cursor: not-allowed;
    opacity: 0.4;
    pointer-events: none;
}

.hard-mode-toggle.is-disabled .toggle-track {
    background: var(--color-border);
}

.session-row {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}
@media (min-width: 480px) {
    .session-row {
        flex-direction: row;
        gap: 2rem;
    }
    .session-row .field {
        flex: 1;
        border-top: none;
        padding: 0;
        display: block;
    }
    .session-row .field-label {
        display: block;
        margin-bottom: 0.5rem;
    }
}

.segmented, .stats-segmented {
    display: flex;
    border: 1px solid var(--color-border);
    border-radius: 8px;
    overflow: hidden;
    background: #ffffff;
}

.segmented-btn, .stats-segmented-btn {
    flex: 1;
    min-width: 36px;
    min-height: 36px;
    padding: 0.4rem 0.6rem;
    border: none;
    border-right: 1px solid var(--color-border);
    background: transparent;
    font-size: 1rem;
    cursor: pointer;
    font-family: inherit;
    color: var(--color-text);
    transition: background-color 0.1s;
}

.segmented-btn:last-child, .stats-segmented-btn:last-child {
    border-right: none;
}

.segmented-btn.is-active,
.stats-segmented-btn.is-active {
    background: var(--color-primary) !important;
    color: #ffffff !important;
}

.segmented-btn:hover:not(.is-active),
.stats-segmented-btn:hover:not(.is-active) {
    background: rgba(0, 0, 0, 0.04);
}

.segmented-btn:focus, .stats-segmented-btn:focus,
.btn-primary:focus, .btn-secondary:focus {
    outline: none;
    box-shadow: 0 0 0 3px rgba(243, 156, 18, 0.4);
}

.choice-btn:focus {
    outline: none;
}

/* Buttons */
.controls {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1.25rem;
    margin-top: 0.75rem;
}
@media (min-width: 520px) {
    .controls { grid-template-columns: 1fr 1fr; }
}

.btn-primary {
    background: var(--color-primary);
    color: #fff;
    border: none;
    padding: 1rem 2rem;
    border-radius: var(--radius-pill);
    font-size: 1.1rem;
    font-weight: 700;
    cursor: pointer;
    box-shadow: var(--shadow-button);
    transition: all 0.2s ease;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-family: var(--font-body);
}

.btn-primary:hover {
    background: var(--color-primary-hover);
    transform: translateY(-2px);
    box-shadow: 0 12px 24px -6px rgba(44, 62, 80, 0.2);
}

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

.btn-secondary {
    background: transparent;
    color: var(--color-text);
    border: 2px solid var(--color-border);
    padding: 0.9rem 2rem;
    border-radius: var(--radius-pill);
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-secondary:hover {
    border-color: var(--color-text);
    background: rgba(255,255,255,0.5);
}

.btn-link {
    background: none;
    border: none;
    color: var(--color-text-muted);
    text-decoration: underline;
    text-decoration-thickness: 1px;
    text-underline-offset: 4px;
    cursor: pointer;
    font-weight: 600;
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}
.btn-link:hover { color: var(--color-primary); }

/* Game Screen */
.game-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.pill {
    background: #fff;
    border: 1px solid var(--color-border);
    padding: 0.4rem 0.8rem;
    border-radius: var(--radius-pill);
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--color-text-muted);
    box-shadow: 0 2px 4px rgba(0,0,0,0.03);
}

.pill-pass {
    background: rgba(39, 174, 96, 0.1);
    color: var(--color-good);
    border-color: rgba(39, 174, 96, 0.3);
}

.running-timer {
    font-family: monospace;
    font-size: 0.9rem;
    color: var(--color-timer-text);
    font-weight: 500;
    margin-left: auto;
    margin-right: 1rem;
}

.play-area {
    position: relative;
    height: 62vh;
    max-height: 520px;
    background: rgba(255,255,255,0.65);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    overflow: hidden;
}

.selection-zone {
    position: absolute;
    bottom: 0; left: 0; right: 0;
    height: 22%;
    border-top: 2px dashed var(--color-border);
    pointer-events: none;
}

.falling-layer {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
}

.choice-cluster {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    width: min(500px, 94%);
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

.choice-cluster.is-falling {
    animation: sd-fall linear forwards;
}

@keyframes sd-fall {
    from { top: -150px; }
    to { top: 85%; }
}

.choice-cluster.is-static {
    top: 50%;
    transform: translate(-50%, -50%);
}

.choice-btn {
    background: #fff;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: 1rem;
    font-size: 1.25rem;
    font-weight: 500;
    letter-spacing: 0.05em;
    color: var(--color-text);
    cursor: pointer;
    box-shadow: 0 2px 6px rgba(0,0,0,0.04);
    transition: transform 0.15s, border-color 0.15s;
    min-height: 70px;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1.3;
}

.choice-btn:hover {
    transform: translateY(-2px);
    border-color: var(--color-primary);
    box-shadow: 0 8px 15px rgba(0,0,0,0.08);
}

.choice-btn:active { transform: scale(0.98); }

.choice-btn.is-correct {
    background: var(--color-good);
    color: #fff;
    border-color: var(--color-good);
    box-shadow: 0 0 15px rgba(39, 174, 96, 0.4);
}

.choice-btn.is-wrong {
    background: var(--color-bad);
    color: #fff;
    border-color: var(--color-bad);
    animation: shake 0.4s cubic-bezier(.36,.07,.19,.97) both;
}

@keyframes shake {
    10%, 90% { transform: translate3d(-1px, 0, 0); }
    20%, 80% { transform: translate3d(2px, 0, 0); }
    30%, 50%, 70% { transform: translate3d(-4px, 0, 0); }
    40%, 60% { transform: translate3d(4px, 0, 0); }
}

.hint {
    margin-top: 1rem;
    text-align: center;
    color: var(--color-text-muted);
    font-style: italic;
    min-height: 1.5rem;
}

/* Results */
.results-line {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--color-primary);
    margin: 0.5rem 0;
}

/* Errors Summary */
.errors-title {
    margin: 0.5rem 0 1.5rem;
    font-size: 1.1rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--color-text-muted);
    text-align: center;
}

.errors-list {
    list-style: none;
    padding: 0;
    margin: 0;
    display: grid;
    gap: 1rem;
}

.errors-item {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
}

.errors-correct, .errors-wrong {
    padding: 0.6rem 1.25rem;
    border-radius: var(--radius-md);
    font-weight: 700;
    font-size: 1.1rem;
    box-shadow: var(--shadow-sm);
    flex: 1;
    text-align: center;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
}

.errors-correct {
    background-color: var(--color-good);
    color: white;
}

.errors-wrong {
    background-color: var(--color-bad);
    color: white;
    opacity: 0.9;
}

.errors-wrong.is-timeout {
    font-size: 1.5rem;
    padding: 0.4rem 1.25rem;
}

.errors-arrow {
    color: var(--color-text-muted);
    font-weight: 700;
    font-size: 1.2rem;
    flex-shrink: 0;
}

.errors-empty {
    text-align: center;
    color: var(--color-good);
    font-weight: 600;
    margin: 1rem 0;
}

@media (max-width: 480px) {
    .errors-correct, .errors-wrong {
        font-size: 0.9rem;
        padding: 0.5rem 0.75rem;
    }
    .errors-item {
        gap: 0.5rem;
    }
}

.stars {
    display: flex;
    gap: 0.4rem;
    margin: 1rem 0;
    justify-content: center;
}

.star {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    border: 1px solid var(--color-border);
    background: rgba(0,0,0,0.03);
    font-size: 1.2rem;
    transition: all 0.3s ease;
}

.star::before {
    content: "☆";
    color: var(--color-border);
}

.star.is-on {
    border-color: var(--color-star-border);
    background: linear-gradient(135deg, var(--color-star-bg-start), var(--color-star-bg-end));
    box-shadow: var(--shadow-glow-star);
    transform: translateY(-2px);
    animation: popIn 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275) backwards;
}

.star.is-on::before {
    content: "★";
    color: var(--color-star-gold);
    filter: drop-shadow(0 0 2px rgba(212, 169, 96, 0.5));
}

@keyframes popIn {
    from { opacity: 0; transform: scale(0); }
    to { opacity: 1; transform: scale(1); }
}

.achievement-summary-card {
    margin-bottom: 1.5rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid rgba(0,0,0,0.06);
}

.achievement-summary-header {
    display: flex;
    align-items: flex-start;
    gap: 1rem;
    margin-bottom: 1rem;
}

.achievement-summary-icon {
    font-size: 2.5rem;
    line-height: 1;
    flex-shrink: 0;
}

.achievement-summary-title {
    font-family: var(--font-heading);
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--color-accent);
    line-height: 1.2;
}

.achievement-summary-count {
    font-size: 0.9rem;
    color: var(--color-text-muted);
    font-weight: 600;
    margin-top: 0.2rem;
}

.achievement-summary-progress {
    height: 12px;
    background: rgba(0,0,0,0.05);
    border-radius: 6px;
    overflow: hidden;
    margin-top: 0.5rem;
}

.achievement-summary-progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--color-mastery-start), var(--color-mastery-end));
    transition: width var(--duration-slow) var(--ease-out);
    border-radius: 4px;
}

.achievement-grid {
    display: grid;
    gap: 0.5rem;
    overflow-x: auto;
    padding-bottom: 1rem;
    margin-bottom: 1.5rem;
}

.achievement-summary {
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--color-text-muted);
    margin: 1.5rem 0 1rem 0;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    border-top: 1px solid rgba(0,0,0,0.06);
    padding-top: 1.5rem;
}

.achievement-row {
    display: grid;
    grid-template-columns: 120px repeat(5, 1fr);
    gap: 6px;
    align-items: center;
    min-width: 500px;
}

.achievement-header-cell {
    font-size: 0.7rem;
    font-weight: 700;
    color: var(--color-text-muted);
    text-align: center;
    text-transform: uppercase;
}

.achievement-label {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--color-text);
}

.achievement-cell {
    height: 44px;
    border-radius: 8px;
    background: rgba(0,0,0,0.03);
    border: 1px dashed var(--color-border);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    transition: all 0.2s;
}

.achievement-cell.is-unlocked {
    background: #fff;
    border-style: solid;
    box-shadow: 0 2px 6px rgba(0,0,0,0.05);
}

.achievement-cell.speed-freeze.is-unlocked { border-color: var(--color-speed-freeze); color: var(--color-speed-freeze); }
.achievement-cell.speed-slow.is-unlocked { border-color: var(--color-speed-slow); color: #7f8c8d; }
.achievement-cell.speed-normal.is-unlocked { border-color: var(--color-speed-normal); color: var(--color-speed-normal); }
.achievement-cell.speed-fast.is-unlocked { border-color: var(--color-speed-fast); color: var(--color-speed-fast); }

.achievement-item {
    padding: 1rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    background: #fff;
    margin-bottom: 0.75rem;
    transition: all 0.2s;
}

.achievement-item:hover {
    border-color: var(--color-accent);
    box-shadow: var(--shadow-card);
}

.achievement-name {
    font-weight: 700;
    color: var(--color-primary);
    margin-bottom: 0.25rem;
}

.achievement-tag {
    font-size: 0.7rem;
    background: var(--color-bad);
    color: #fff;
    padding: 0.1rem 0.4rem;
    border-radius: 4px;
    margin-left: 0.5rem;
    vertical-align: middle;
    text-transform: uppercase;
}

.broomstick-tag {
    display: inline-block;
    font-family: var(--font-body);
    font-size: 0.75rem;
    font-weight: 700;
    color: #54708b;
    background: #f0f4f8;
    padding: 0.2rem 0.6rem;
    border-radius: 6px;
    margin-left: 0.5rem;
    vertical-align: middle;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    border: 1px solid #d1dbe5;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}

.broomstick-item .achievement-desc {
    margin-top: 0.4rem;
}

.achievement-desc {
    font-size: 0.9rem;
    color: var(--color-text-muted);
    line-height: 1.4;
}

/* Cards (v2 styling) */
.mastery-card, .setup-card, .achievements-card {
    background: #fff;
    border: 2px solid var(--color-accent);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    box-shadow: 0 8px 20px rgba(216, 154, 47, 0.1);
    text-align: left;
    margin-bottom: 1.5rem;
}

/* Streak badge */
.streak-badge {
    background: linear-gradient(135deg, #ff6b35, #f7931e);
    color: #fff;
    padding: 0.35rem 0.8rem;
    border-radius: var(--radius-pill);
    font-size: 0.8rem;
    font-weight: 700;
    margin-left: auto;
    margin-right: 0.5rem;
    box-shadow: 0 2px 8px rgba(255, 107, 53, 0.3);
    display: flex;
    align-items: center;
    gap: 0.3rem;
    line-height: 1;
}

/* Persistence achievement gradient colours */
.achievement-item.persistence-50 { border-left: 6px solid #ffcc80; }
.achievement-item.persistence-100 { border-left: 6px solid #ffb74d; }
.achievement-item.persistence-250 { border-left: 6px solid #ffa726; }
.achievement-item.persistence-500 { border-left: 6px solid #ff9800; }
.achievement-item.persistence-750 { border-left: 6px solid #fb8c00; }
.achievement-item.persistence-1000 { border-left: 6px solid #f57c00; }
.achievement-item.persistence-1500 { border-left: 6px solid #ef6c00; }
.achievement-item.persistence-2000 { border-left: 6px solid #e65100; }
.achievement-item.persistence-3000 { border-left: 6px solid #d84315; }
.achievement-item.persistence-4000 { border-left: 6px solid #bf360c; }
.achievement-item.persistence-5000 { border-left: 6px solid #b71c1c; }

.setup-card .controls {
    margin-top: 1.5rem;
    padding-top: 1.5rem;
    border-top: 1px solid rgba(0,0,0,0.06);
}

.mastery-header {
    display: flex;
    align-items: flex-start;
    gap: 1rem;
    margin-bottom: 1rem;
}

.mastery-icon {
    font-size: 2.5rem;
    line-height: 1;
}

.mastery-title-info {
    flex-grow: 1;
}

.mastery-label-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.2rem;
}

.mastery-label {
    line-height: 1;
}

.player-name {
    background: var(--color-name-bg);
    border: 1px solid var(--color-name-border);
    border-radius: var(--radius-sm);
    padding: 0.35rem 0.8rem;
    font-size: 0.8rem;
    font-weight: 700;
    font-family: var(--font-body);
    color: var(--color-name-text);
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 0.4rem;
    box-shadow: var(--shadow-sm);
    line-height: 1;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.player-name:hover {
    background: var(--color-name-hover-bg);
    border-color: var(--color-name-hover-bg);
    color: #fff;
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.player-name::after {
    content: '✎';
    font-size: 0.75rem;
    opacity: 0.7;
}

.player-name:hover::after {
    color: #fff;
    opacity: 1;
}

.mastery-title-info {
    flex-grow: 1;
}

.mastery-label-row {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
}

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

.mastery-title {
    font-family: var(--font-heading);
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--color-accent);
}

.mastery-progress-bar {
    height: 12px;
    background: rgba(0,0,0,0.05);
    border-radius: 6px;
    overflow: hidden;
    margin-bottom: 0.75rem;
}

.mastery-progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--color-mastery-start), var(--color-mastery-end));
    width: 0%;
    transition: width 0.5s ease-out;
}

.mastery-stats-row {
    display: flex;
    justify-content: space-between;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--color-text-muted);
}

.mastery-next { color: var(--color-accent); }

/* Stats Header */
.stats-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.75rem;
    gap: 0.5rem;
}

.stats-header-buttons {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

/* Stats Table */
.stats-table { display: grid; gap: 0.5rem; }

.stats-row {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 1rem;
    align-items: center;
    padding: 0.75rem;
    border: 1px solid var(--color-border);
    border-radius: 12px;
    background: rgba(255,255,255,0.8);
}

.stats-word {
    font-weight: 700;
    font-size: 1rem;
}

.stats-history { display: flex; gap: 3px; }

.stats-history-segment {
    width: 20px;
    height: 20px;
    border-radius: 4px;
    border: 1px solid var(--color-border);
    background: rgba(0, 0, 0, 0.03);
}

.stats-history-segment.is-correct {
    background: rgba(28, 124, 58, 0.25);
    border-color: rgba(28, 124, 58, 0.55);
}

.stats-history-segment.is-wrong {
    background: rgba(180, 35, 24, 0.25);
    border-color: rgba(180, 35, 24, 0.55);
}

/* Modal */
.modal-overlay {
    background: rgba(44, 62, 80, 0.6);
    backdrop-filter: blur(2px);
    position: fixed; inset: 0;
    display: flex; align-items: center; justify-content: center;
    z-index: 1000;
}

.modal {
    background: #fff;
    border-radius: var(--radius-lg);
    padding: 2rem;
    max-width: 400px;
    width: 90%;
    box-shadow: 0 20px 40px rgba(0,0,0,0.2);
}

.modal-actions {
    margin-top: 1.5rem;
    display: flex;
    justify-content: flex-end;
    gap: 1rem;
}

/* Help Modal Specifics */
.help-modal {
    max-width: 480px;
    padding: 1.5rem;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
    border-bottom: 1px solid rgba(0,0,0,0.06);
    padding-bottom: 1rem;
}

.modal-header .modal-title {
    margin: 0;
}

.btn-close {
    background: transparent;
    border: none;
    font-size: 1.25rem;
    color: var(--color-text-muted);
    cursor: pointer;
    padding: 0.5rem;
    line-height: 1;
    border-radius: 4px;
}

.btn-close:hover {
    background: rgba(0,0,0,0.04);
    color: var(--color-primary);
}

.help-content {
    max-height: 60vh;
    overflow-y: auto;
    padding-right: 0.5rem;
}

/* Custom scrollbar for help content */
.help-content::-webkit-scrollbar {
    width: 6px;
}

.help-content::-webkit-scrollbar-track {
    background: rgba(0,0,0,0.02);
    border-radius: 3px;
}

.help-content::-webkit-scrollbar-thumb {
    background: var(--color-border);
    border-radius: 3px;
}

.help-section {
    display: flex;
    gap: 1.25rem;
    margin-bottom: 1.5rem;
}

.help-section:last-child {
    margin-bottom: 0.5rem;
}

.help-icon {
    font-size: 1.75rem;
    flex-shrink: 0;
    line-height: 1.2;
}

.help-title {
    margin: 0 0 0.25rem;
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--color-primary);
}

.help-text {
    margin: 0;
    font-size: 0.95rem;
    color: var(--color-text-muted);
    line-height: 1.45;
}

.btn-danger {
    background: var(--color-bad);
    color: #fff;
    border: none;
    padding: 0.75rem 1.5rem;
    border-radius: var(--radius-pill);
    font-weight: 700;
    cursor: pointer;
}

.btn-danger:hover { background: #a93226; }

.btn-clear-history {
    display: block;
    width: 100%;
    margin-top: 1.25rem;
    padding: 0.75rem;
    font-size: 0.9rem;
    font-weight: 700;
    font-family: inherit;
    color: var(--color-bad);
    background: transparent;
    border: 1px dashed var(--color-bad);
    border-radius: 12px;
    cursor: pointer;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    transition: background-color 0.2s;
}

.btn-clear-history:hover {
    background: rgba(180, 35, 24, 0.06);
}

.btn-clear-history:focus {
    outline: 3px solid var(--color-bad);
    outline-offset: 3px;
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01s !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01s !important;
        scroll-behavior: auto !important;
    }
}

/* Restored Animations */
@keyframes magic-float {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-4px); }
}

.mastery-icon {
    display: inline-block;
    animation: magic-float 4s ease-in-out infinite;
}

.achievement-icon {
    font-size: 1.4rem;
    line-height: 1;
    display: inline-block;
}

.achievement-cell.is-unlocked .achievement-icon {
    animation: magic-float 3s ease-in-out infinite;
    filter: drop-shadow(0 2px 4px rgba(0,0,0,0.1));
}
