:root {
    --background: #121213;
    --surface: #1a1a1b;
    --surface-elevated: #202022;
    --foreground: #f4f4f5;
    --muted: #9a9aa0;
    --border: #3a3a3c;
    --border-strong: #565758;
    --tile-empty-border: #3a3a3c;
    --tile-filled-border: #6b6b6e;
    --key: #3a3a3c;
    --key-hover: #48484b;
    --accent: #5b8def;
    --accent-strong: #4472d1;
    --correct: #4caf6e;
    --present: #d6b23c;
    --absent: #e35b5b;
    --danger: #9b5cff;
    --white: #f4f4f5;
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;
    --space-tight: clamp(4px, 1vh, 10px);
    --space-base: clamp(6px, 1.6vh, 16px);
    --space-emphasis: clamp(7px, 0.5vh, 14px);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    height: 100dvh;
    overflow-y: auto;
    background: var(--background);
    color: var(--foreground);
    font-family: "Segoe UI", Roboto, Arial, Helvetica, sans-serif;
    display: flex;
    justify-content: center;
}

button {
    font: inherit;
}

.hidden {
    display: none !important;
}

.mode-select {
    width: min(100%, 560px);
    min-height: 100vh;
    padding: 48px 20px;
    display: flex;
    flex-direction: column;
    gap: 40px;
}

.mode-select-header {
    text-align: center;
}

.mode-select-header h1 {
    margin: 0;
    font-size: 40px;
    font-weight: 800;
    letter-spacing: 6px;
    background: linear-gradient(120deg, var(--accent), var(--correct));
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}

.mode-select-subtitle {
    margin: 8px 0 0;
    color: var(--muted);
    font-size: 15px;
}

.mode-cards {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.mode-card {
    display: flex;
    flex-direction: column;
    gap: 6px;
    align-items: flex-start;
    text-align: left;
    padding: 20px 22px;
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    background: var(--surface);
    color: var(--foreground);
    cursor: pointer;
    transition: transform 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}

.mode-card:hover {
    transform: translateY(-2px);
    border-color: var(--accent);
    background: var(--surface-elevated);
}

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

.mode-card-title {
    font-size: 20px;
    font-weight: 800;
    letter-spacing: 1px;
}

.mode-card-description {
    color: var(--muted);
    font-size: 14px;
}

.mode-card-stat {
    margin-top: 8px;
    font-size: 12px;
    font-weight: 700;
    color: var(--accent);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.game {
    width: min(100%, 520px);
    height: 100%;
    padding: clamp(6px, 1vh, 10px) 16px clamp(6px, 1vh, 10px);
    display: flex;
    flex-direction: column;
    gap: var(--space-base);
}

.header {
    height: clamp(38px, 6vh, 52px);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: var(--space-emphasis);
    flex-shrink: 0;
}

.header h1 {
    margin: 0;
    flex: 1;
    text-align: center;
    font-size: 20px;
    font-weight: 800;
    letter-spacing: 2px;
}

.icon-button,
.close-button {
    border: 0;
    background: transparent;
    color: var(--foreground);
    cursor: pointer;
}

.icon-button {
    flex: 0 0 auto;
    width: 36px;
    height: 36px;
    border: 2px solid var(--border-strong);
    border-radius: 50%;
    font-size: 18px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: border-color 0.15s ease, background 0.15s ease;
}

.icon-button:hover {
    border-color: var(--accent);
    background: var(--surface-elevated);
}

.meta-bar {
    display: flex;
    justify-content: center;
    gap: var(--space-tight);
    flex-wrap: wrap;
    flex-shrink: 0;
}

.meta-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1px;
    padding: 5px 14px;
    border-radius: var(--radius-md);
    background: var(--surface);
    border: 1px solid var(--border);
    min-width: 78px;
}

.meta-label {
    font-size: 10px;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    color: var(--muted);
}

.meta-value {
    font-size: 18px;
    font-weight: 800;
    font-variant-numeric: tabular-nums;
}

.board {
    width: min(350px, 92vw, 62dvh);
    margin: var(--space-base) auto 0;
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 5px;
    flex-shrink: 0;
}

.tile {
    aspect-ratio: 1;
    border: 2px solid var(--tile-empty-border);
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: clamp(24px, 8vw, 34px);
    font-weight: 800;
    user-select: none;
    background: transparent;
    color: var(--foreground);
}

.tile.filled {
    border-color: var(--tile-filled-border);
}

.tile.correct,
.tile.present,
.tile.absent {
    color: var(--white);
    border-color: transparent;
}

.tile.correct {
    background: var(--correct);
}

.tile.present {
    background: var(--present);
}

.tile.absent {
    background: var(--absent);
}

.tile.revealed {
    animation: flip 0.45s ease forwards;
}

.tile.shake {
    animation: shake 0.4s ease;
}

@keyframes flip {
    0% {
        transform: rotateX(0deg);
    }
    50% {
        transform: rotateX(90deg);
    }
    100% {
        transform: rotateX(0deg);
    }
}

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

.message {
    min-height: 16px;
    text-align: center;
    font-size: 14px;
    font-weight: 700;
    color: var(--muted);
    flex-shrink: 0;
}

.keyboard {
    width: 100%;
    margin-top: calc(var(--space-base) * -1);
    display: flex;
    flex-direction: column;
    gap: var(--space-tight);
    flex-shrink: 0;
}

.keyboard-row {
    display: flex;
    justify-content: center;
    gap: var(--space-tight);
}

.key {
    height: clamp(34px, 6vh, 52px);
    min-width: 30px;
    padding: 0 8px;
    border: 0;
    border-radius: var(--radius-sm);
    background: var(--key);
    color: var(--foreground);
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
    flex: 1;
    max-width: 44px;
    transition: background 0.1s ease;
}

.key:hover {
    background: var(--key-hover);
}

.key.wide {
    max-width: 65px;
    font-size: 12px;
}

.key.correct,
.key.present,
.key.absent {
    color: var(--white);
}

.key.correct {
    background: var(--correct);
}

.key.present {
    background: var(--present);
}

.key.absent {
    background: var(--absent);
}

.result-modal-content {
    width: min(460px, 100%);
    display: flex;
    flex-direction: column;
    gap: 18px;
    text-align: center;
}

.stats-summary {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.stats-summary strong {
    font-size: 20px;
}

.stats-summary span {
    color: var(--muted);
    font-size: 13px;
}

.extra-line {
    color: var(--accent) !important;
    font-weight: 700;
}

.next-game {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    font-size: 13px;
    color: var(--muted);
}

.next-game strong {
    font-size: 16px;
    color: var(--foreground);
    font-variant-numeric: tabular-nums;
}

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

.reset-button,
.secondary-button {
    padding: 10px 18px;
    border-radius: var(--radius-md);
    cursor: pointer;
    font-weight: 700;
    font-size: 14px;
    border: 1px solid transparent;
}

.reset-button {
    background: var(--accent);
    color: var(--white);
}

.reset-button:hover {
    background: var(--accent-strong);
}

.secondary-button {
    background: transparent;
    border-color: var(--border-strong);
    color: var(--foreground);
}

.secondary-button:hover {
    border-color: var(--accent);
}

.daily-stats {
    display: flex;
    flex-direction: column;
    gap: 18px;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
}

.stat-box {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 10px 4px;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--surface);
}

.stat-box strong {
    font-size: 22px;
}

.stat-box span {
    color: var(--muted);
    font-size: 11px;
}

.distribution-chart h3,
.last-week-chart h3,
.podium-section h3 {
    margin: 0 0 10px;
    font-size: 13px;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.distribution-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin: 0;
    padding: 0;
    list-style: none;
}

.distribution-row {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
}

.distribution-row-label {
    width: 14px;
    flex: 0 0 14px;
    color: var(--muted);
}

.distribution-row-bar-track {
    flex: 1;
    height: 20px;
    border-radius: var(--radius-sm);
    background: var(--surface);
    border: 1px solid var(--border);
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    padding-right: 6px;
}

.distribution-row-bar {
    height: 100%;
    min-width: 20px;
    background: var(--key);
    display: flex;
    align-items: center;
    justify-content: flex-end;
    padding-right: 6px;
    border-radius: var(--radius-sm);
}

.distribution-row.has-wins .distribution-row-bar {
    background: var(--correct);
}

.distribution-row-count {
    color: var(--white);
    font-weight: 700;
    font-size: 11px;
}

.last-week-list {
    display: flex;
    gap: 6px;
    justify-content: center;
    margin: 0;
    padding: 0;
    list-style: none;
}

.last-week-day {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    width: 36px;
}

.last-week-day-box {
    width: 28px;
    height: 28px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-strong);
    background: var(--surface);
}

.last-week-day.won .last-week-day-box {
    background: var(--correct);
    border-color: var(--correct);
}

.last-week-day.lost .last-week-day-box {
    background: var(--absent);
    border-color: var(--absent);
}

.last-week-day-label {
    font-size: 10px;
    color: var(--muted);
}

.last-week-day.today .last-week-day-label {
    color: var(--accent);
    font-weight: 700;
}

.podium-section {
    display: flex;
    flex-direction: column;
}

.podium-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin: 0;
    padding: 0;
    list-style: none;
}

.podium-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--surface);
}

.podium-rank {
    font-size: 18px;
    width: 24px;
    flex: 0 0 24px;
}

.podium-value {
    font-weight: 700;
    flex: 1;
    text-align: left;
}

.podium-date {
    color: var(--muted);
    font-size: 12px;
}

.dev-reset-button {
    align-self: center;
    margin-top: 16px;
    padding: 8px 12px;
    border: 1px dashed var(--border-strong);
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--muted);
    cursor: pointer;
}

.modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.65);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    z-index: 10;
}

.modal-content {
    position: relative;
    width: min(420px, 100%);
    padding: 28px;
    border-radius: var(--radius-lg);
    background: var(--surface-elevated);
    border: 1px solid var(--border);
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.45);
    max-height: 85vh;
    overflow-y: auto;
}

.modal-content h2 {
    margin: 0 0 12px;
}

.modal-content p {
    line-height: 1.5;
}

.close-button {
    position: absolute;
    top: 8px;
    right: 10px;
    font-size: 28px;
    line-height: 1;
}

.example {
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 12px 0;
}

.example p {
    margin: 0;
    font-size: 14px;
}

.example-tile {
    width: 42px;
    height: 42px;
    flex: 0 0 42px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--white);
    font-weight: 800;
}

.example-tile.correct {
    background: var(--correct);
}

.example-tile.present {
    background: var(--present);
}

.example-tile.absent {
    background: var(--absent);
}

.maintenance-overlay {
    position: fixed;
    inset: 0;
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: rgba(10, 10, 11, 0.60);
}

.maintenance-message {
    width: min(520px, 100%);
    padding: 32px 28px;
    text-align: center;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: 0 24px 80px rgba(0, 0, 0, 0.45);
}

.maintenance-message h2 {
    margin: 0 0 16px;
    font-size: clamp(28px, 6vw, 42px);
    line-height: 1.05;
    font-weight: 800;
    letter-spacing: 3px;
    background: linear-gradient(120deg, var(--accent), var(--correct));
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}

.maintenance-message p {
    margin: 0;
    color: var(--foreground);
    font-size: clamp(14px, 2.5vw, 17px);
    line-height: 1.5;
}

.maintenance-return {
    position: fixed;
    bottom: 45px;
    left: 24px;
    right: 24px;
    text-align: center;
    color: var(--muted);
    font-size: 18px;
    letter-spacing: 0.5px;
}

@media (max-width: 420px) {
    .game {
        padding-left: 10px;
        padding-right: 10px;
    }

    .key {
        padding: 0 5px;
    }

    .meta-item {
        min-width: 68px;
        padding: 6px 10px;
    }

    .mode-select {
        padding: 32px 16px;
    }

    .mode-select-header h1 {
        font-size: 32px;
    }
}

.tamper-overlay {
    z-index: 10000;
}

.corner-links {
    position: fixed;
    top: 14px;
    right: 14px;
    z-index: 20;
    display: flex;
    gap: 8px;
}

.corner-link {
    width: 50px;
    height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm);
    color: var(--muted);
    background: transparent;
    opacity: 0.6;
    transition: opacity 0.2s ease, color 0.2s ease, background 0.2s ease;
}

.corner-link svg {
    width: 26px;
    height: 26px;
}

.corner-link:hover {
    opacity: 1;
    color: var(--foreground);
    background: var(--surface);
}

.tamper-title {
    background: none;
    -webkit-background-clip: unset;
    background-clip: unset;
    color: var(--danger);
}

.tamper-close-button {
    margin-top: 20px;
}

.tile.higher,
.tile.lower {
    background: var(--accent);
    border-color: var(--accent);
    color: #ffffff;
    position: relative;
}

.tile.higher::after,
.tile.lower::after {
    position: absolute;
    top: 2px;
    right: 4px;
    font-size: 0.6em;
    line-height: 1;
}

.tile.higher::after {
    content: "▲";
}

.tile.lower::after {
    content: "▼";
}

.hints-list {
    display: flex;
    flex-direction: column;
    gap: var(--space-tight);
    margin: 0;
    margin-top: calc(var(--space-base) * -1);
    padding: 0;
    list-style: none;
    flex-shrink: 0;
}

.hint-item {
    padding: 6px 10px;
    border-radius: 8px;
    border: 1px solid var(--border-strong);
    color: var(--muted);
    font-size: 0.8em;
    line-height: 1.25;
    display: flex;
    align-items: center;
    transition: background 0.2s ease, color 0.2s ease, border-color 0.2s ease;
}

.hint-item.satisfied {
    border-color: var(--correct);
    color: var(--correct);
    background: rgba(76, 175, 110, 0.12);
}

.hint-item.violated {
    border-color: var(--absent);
    color: var(--absent);
    background: rgba(227, 91, 91, 0.12);
}

.tile {
    cursor: pointer;
}

.tile.selected {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent);
}

.tile.active-row {
    border-color: rgba(91, 141, 239, 0.45);
}