:root {
    --bg: #f3f5f9;
    --surface: #ffffff;
    --surface-muted: #f8fafc;
    --border: #e2e8f0;
    --text: #0f172a;
    --text-muted: #475569;
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --secondary: #0f172a;
    --secondary-hover: #1e293b;
    --success-bg: #ecfdf5;
    --success-border: #a7f3d0;
    --success-text: #065f46;
    --error-bg: #fef2f2;
    --error-border: #fecaca;
    --error-text: #991b1b;
    --warning-bg: #fffbeb;
    --warning-border: #fde68a;
    --warning-text: #92400e;
    --info-bg: #eff6ff;
    --info-border: #bfdbfe;
    --info-text: #1e40af;
    --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.05);
    --shadow-md: 0 10px 25px -5px rgba(15, 23, 42, 0.08), 0 8px 10px -6px rgba(15, 23, 42, 0.04);
    --radius-lg: 18px;
    --radius-md: 12px;
    --radius-sm: 8px;
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background-color: var(--bg);
    color: var(--text);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

.hidden {
    display: none !important;
}

.app-shell {
    max-width: 1180px;
    margin: 0 auto;
    padding: 24px 16px 48px;
}

.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 24px;
}

.brand {
    display: flex;
    align-items: center;
    gap: 14px;
}

.brand-mark {
    width: 48px;
    height: 48px;
    border-radius: 14px;
    background: linear-gradient(135deg, #2563eb, #0ea5e9);
    color: #ffffff;
    display: grid;
    place-items: center;
    font-weight: 800;
    font-size: 18px;
    letter-spacing: 0.03em;
    flex-shrink: 0;
    box-shadow: var(--shadow-sm);
}

.app-header h1 {
    margin: 0;
    font-size: 26px;
    line-height: 1.2;
    font-weight: 800;
}

.subtitle {
    margin: 4px 0 0;
    color: var(--text-muted);
    font-size: 14px;
}

.main-content {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 24px;
    box-shadow: var(--shadow-md);
}

/* Кнопки и поля ввода */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    border: 1px solid transparent;
    border-radius: var(--radius-md);
    padding: 10px 18px;
    font-size: 15px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: background-color 0.15s ease, transform 0.1s ease, opacity 0.15s ease, border-color 0.15s ease;
}

.btn:active:not(:disabled) {
    transform: translateY(1px);
}

.btn:disabled {
    opacity: 0.52;
    cursor: not-allowed;
}

.btn-lg {
    padding: 13px 24px;
    font-size: 16px;
}

.btn-block {
    width: 100%;
}

.btn-primary {
    background: var(--primary);
    color: #ffffff;
}

.btn-primary:hover:not(:disabled) {
    background: var(--primary-hover);
}

.btn-secondary {
    background: var(--secondary);
    color: #ffffff;
}

.btn-secondary:hover:not(:disabled) {
    background: var(--secondary-hover);
}

.btn-ghost {
    background: var(--surface);
    color: var(--text);
    border-color: var(--border);
}

.btn-ghost:hover:not(:disabled) {
    background: var(--surface-muted);
}

.field-label {
    display: block;
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--text);
}

.text-input {
    width: 100%;
    padding: 12px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    font-size: 15px;
    font-family: inherit;
    color: var(--text);
    background: var(--surface);
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.text-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.16);
}

.field-hint {
    margin: 6px 0 0;
    font-size: 13px;
    color: var(--text-muted);
}

.inline-error {
    margin-top: 12px;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    background: var(--error-bg);
    border: 1px solid var(--error-border);
    color: var(--error-text);
    font-size: 14px;
    font-weight: 500;
}

/* Стартовый экран */
.start-layout {
    display: grid;
    grid-template-columns: 1.25fr 1fr;
    gap: 28px;
    align-items: start;
}

.start-intro h2 {
    margin: 0 0 10px;
    font-size: 22px;
}

.start-intro p {
    margin: 0 0 14px;
    color: var(--text-muted);
}

.rules-list {
    margin: 0;
    padding-left: 18px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    font-size: 14px;
    color: var(--text-muted);
}

.rules-list strong {
    color: var(--text);
}

.start-form {
    background: var(--surface-muted);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 20px;
    display: flex;
    flex-direction: column;
}

.start-form .btn {
    margin-top: 16px;
}

/* HUD */
.game-layout {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.hud-bar {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 16px;
    padding: 16px 20px;
}

.hud-item {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 0;
}

.hud-label {
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
}

.hud-value {
    font-size: 18px;
    font-weight: 700;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.category-pill {
    color: var(--primary);
}

.score-value {
    color: #059669;
    font-variant-numeric: tabular-nums;
}

.mistakes-wrap {
    display: flex;
    align-items: center;
    gap: 10px;
}

.mistakes-dots {
    display: flex;
    gap: 5px;
}

.mistake-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #e2e8f0;
    transition: background-color 0.2s ease;
}

.mistake-dot.active {
    background: #dc2626;
}

/* Игровая сетка */
.play-grid {
    display: grid;
    grid-template-columns: 400px 1fr;
    gap: 20px;
    align-items: start;
}

/* Колесо */
.wheel-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 18px;
}

.wheel-stage {
    position: relative;
    width: min(340px, 78vw);
    height: min(340px, 78vw);
    display: grid;
    place-items: center;
    padding-top: 10px;
}

.wheel-pointer {
    position: absolute;
    top: -4px;
    left: 50%;
    transform: translateX(-50%);
    width: 0;
    height: 0;
    border-left: 14px solid transparent;
    border-right: 14px solid transparent;
    border-top: 24px solid #0f172a;
    z-index: 5;
    filter: drop-shadow(0 2px 3px rgba(15, 23, 42, 0.35));
}

.wheel-disc {
    position: relative;
    width: 100%;
    height: 100%;
    border-radius: 50%;
    border: 8px solid #0f172a;
    box-shadow: 0 12px 28px rgba(15, 23, 42, 0.22), inset 0 0 0 2px rgba(255, 255, 255, 0.25);
    transition: transform 3.8s cubic-bezier(0.12, 0.85, 0.2, 1);
    overflow: hidden;
    will-change: transform;
}

.wheel-divider {
    position: absolute;
    top: 0;
    left: 50%;
    width: 2px;
    height: 50%;
    margin-left: -1px;
    background: rgba(255, 255, 255, 0.45);
    transform-origin: 50% 100%;
    pointer-events: none;
}

.wheel-label {
    position: absolute;
    inset: 0;
    pointer-events: none;
}

.wheel-label span {
    position: absolute;
    top: 16px;
    left: 50%;
    transform: translateX(-50%);
    writing-mode: vertical-rl;
    text-orientation: mixed;
    color: #ffffff;
    font-size: 13px;
    font-weight: 800;
    letter-spacing: 0.03em;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.45);
    user-select: none;
    white-space: nowrap;
}

.wheel-hub {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 54px;
    height: 54px;
    transform: translate(-50%, -50%);
    border-radius: 50%;
    background: #ffffff;
    border: 6px solid #0f172a;
    box-shadow: 0 4px 10px rgba(15, 23, 42, 0.3);
    z-index: 3;
}

.sector-readout {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 10px 14px;
    border-radius: var(--radius-md);
    background: var(--surface-muted);
    border: 1px solid var(--border);
    font-size: 14px;
}

.sector-readout-label {
    color: var(--text-muted);
}

.sector-badge {
    color: var(--text);
}

/* Правая колонка */
.board-column {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.status-banner {
    padding: 12px 16px;
    border-radius: var(--radius-md);
    border: 1px solid transparent;
    font-weight: 600;
    font-size: 15px;
    margin-bottom: 20px;
}

.status-info {
    background: var(--info-bg);
    border-color: var(--info-border);
    color: var(--info-text);
}

.status-success {
    background: var(--success-bg);
    border-color: var(--success-border);
    color: var(--success-text);
}

.status-warning {
    background: var(--warning-bg);
    border-color: var(--warning-border);
    color: var(--warning-text);
}

.status-error {
    background: var(--error-bg);
    border-color: var(--error-border);
    color: var(--error-text);
}

.word-tiles {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px;
    padding: 10px 0;
}

.letter-tile {
    width: 44px;
    height: 52px;
    border-radius: var(--radius-md);
    border: 2px solid #cbd5e1;
    background: var(--surface-muted);
    display: grid;
    place-items: center;
    font-size: 24px;
    font-weight: 800;
    color: var(--text);
    transition: transform 0.2s ease, background-color 0.2s ease, border-color 0.2s ease;
}

.letter-tile.revealed {
    background: #eff6ff;
    border-color: #2563eb;
    color: #1e3a8a;
}

.letter-tile.missed {
    background: #fef2f2;
    border-color: #ef4444;
    color: #991b1b;
}

.gameover-box {
    margin-top: 20px;
    padding: 20px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
    background: var(--surface-muted);
    text-align: center;
}

.gameover-box h3 {
    margin: 0 0 8px;
    font-size: 20px;
}

.gameover-box p {
    margin: 0 0 16px;
    color: var(--text-muted);
}

/* Клавиатура и ввод слова */
.controls-header {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 14px;
}

.controls-header h2 {
    margin: 0;
    font-size: 18px;
}

.controls-hint {
    font-size: 13px;
    font-weight: 600;
    color: var(--primary);
}

.keyboard {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(42px, 1fr));
    gap: 8px;
    margin-bottom: 20px;
}

.key-btn {
    height: 42px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text);
    font-family: inherit;
    font-size: 16px;
    font-weight: 700;
    cursor: pointer;
    transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease, transform 0.1s ease;
}

.key-btn:hover:not(:disabled) {
    border-color: var(--primary);
    background: #eff6ff;
    color: var(--primary);
}

.key-btn:active:not(:disabled) {
    transform: translateY(1px);
}

.key-btn:disabled {
    cursor: not-allowed;
    opacity: 0.45;
}

.key-btn.used-hit {
    background: var(--success-bg);
    border-color: var(--success-border);
    color: var(--success-text);
    opacity: 1;
}

.key-btn.used-miss {
    background: #f1f5f9;
    border-color: #cbd5e1;
    color: #94a3b8;
    text-decoration: line-through;
    opacity: 0.75;
}

.guess-word-form {
    border-top: 1px solid var(--border);
    padding-top: 16px;
}

.guess-word-row {
    display: flex;
    gap: 10px;
}

.guess-word-row .text-input {
    flex: 1;
}

/* Таблица рекордов */
.leaderboard-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 16px;
}

.leaderboard-header h2 {
    margin: 0;
    font-size: 20px;
}

.table-wrap {
    overflow-x: auto;
}

.leaderboard-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

.leaderboard-table th,
.leaderboard-table td {
    text-align: left;
    padding: 11px 12px;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

.leaderboard-table th {
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
    background: var(--surface-muted);
}

.leaderboard-table tbody tr:last-child td {
    border-bottom: none;
}

.empty-cell {
    text-align: center !important;
    color: var(--text-muted);
    padding: 20px 12px !important;
}

/* Адаптивность */
@media (max-width: 960px) {
    .start-layout {
        grid-template-columns: 1fr;
    }

    .play-grid {
        grid-template-columns: 1fr;
    }

    .hud-bar {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 560px) {
    .app-shell {
        padding: 16px 12px 32px;
    }

    .card {
        padding: 16px;
        border-radius: 14px;
    }

    .app-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .letter-tile {
        width: 34px;
        height: 42px;
        font-size: 19px;
    }

    .guess-word-row {
        flex-direction: column;
    }

    .wheel-label span {
        font-size: 11px;
        top: 12px;
    }
}