:root {
    --bg: #f1f5f9;
    --panel: #ffffff;
    --shadow: rgba(15, 23, 42, 0.15);
    --text: #1f2937;
    --accent: #7c3aed;
    --muted: #64748b;
}

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

body {
    font-family: "Inter", "Segoe UI", Arial, sans-serif;
    background: radial-gradient(circle at top, #dfe7fd, #f8fafc);
    color: var(--text);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    padding: 32px 16px;
}

.app {
    width: min(1240px, 100%);
    background: var(--panel);
    border-radius: 18px;
    box-shadow: 0 28px 60px -40px var(--shadow);
    padding: 32px;
    display: flex;
    flex-direction: column;
    gap: 28px;
}

header {
    text-align: center;
}

header h1 {
    font-size: clamp(2rem, 2.5vw, 2.75rem);
    letter-spacing: -0.03em;
    margin-bottom: 8px;
}

header p {
    color: var(--muted);
    font-size: 1rem;
}

.layout {
    display: grid;
    grid-template-columns: minmax(220px, 260px) minmax(500px, 1fr) minmax(240px, 300px) minmax(220px, 260px);
    gap: 32px;
}

.board {
    border: 1px solid #e2e8f0;
    border-radius: 14px;
    padding: 18px;
    background-color: #f8fafc;
    display: flex;
    flex-direction: column;
    gap: 12px;
    max-height: 660px;
    overflow-y: auto;
    min-width: 520px;
}

.board-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    padding: 10px 14px;
    border-radius: 12px;
    transition: background 0.2s ease, transform 0.2s ease;
}

.board-row.active {
    background-color: #ede9fe;
    transform: translateX(4px);
}

.board-row.completed {
    opacity: 0.82;
}

.row-index {
    font-weight: 600;
    color: var(--muted);
    width: 24px;
}

.guess {
    display: flex;
    gap: 8px;
}

.peg {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    border: 2px dashed #cbd5f5;
    background: #fff;
    display: grid;
    place-items: center;
    cursor: pointer;
    transition: transform 0.2s ease, border-color 0.2s ease;
    font-weight: 700;
    font-size: 1rem;
    line-height: 1;
    text-transform: uppercase;
}

.peg.filled {
    border-style: solid;
    border-color: rgba(255, 255, 255, 0.65);
    box-shadow: inset 0 1px 3px rgba(15, 23, 42, 0.2);
}

.peg:hover {
    transform: scale(1.05);
    border-color: var(--accent);
}

.feedback {
    min-width: 150px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-size: 0.95rem;
    color: var(--muted);
    text-align: right;
}

.feedback strong {
    color: var(--text);
}

.sidebar {
    display: flex;
    flex-direction: column;
    gap: 24px;
}

.timer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 18px;
    border-radius: 16px;
    background: linear-gradient(135deg, #f8fafc, #e0e7ff);
    box-shadow: 0 16px 30px -28px rgba(79, 70, 229, 0.65);
}

.timer-label {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.timer-value {
    font-size: clamp(1.6rem, 2.4vw, 2.2rem);
    font-weight: 700;
    color: #312e81;
    font-variant-numeric: tabular-nums;
}

.palette {
    display: grid;
    grid-template-columns: repeat(3, minmax(70px, 1fr));
    gap: 12px;
}

.palette button {
    border: none;
    border-radius: 12px;
    padding: 14px 12px;
    color: #fff;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.18s ease, box-shadow 0.18s ease;
    box-shadow: 0 12px 20px -12px rgba(15, 23, 42, 0.4);
}

.palette button:hover,
.palette button:focus-visible {
    transform: translateY(-2px);
    outline: none;
    box-shadow: 0 16px 28px -15px rgba(15, 23, 42, 0.45);
}

.comments {
    background-color: #f8fafc;
    border-radius: 14px;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    box-shadow: inset 0 1px 0 rgba(15, 23, 42, 0.05);
}

.comments h2 {
    font-size: 1.1rem;
    font-weight: 600;
}

.comment-form {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.comment-input {
    resize: vertical;
    min-height: 72px;
    border-radius: 10px;
    border: 1px solid #cbd5f5;
    padding: 10px 12px;
    font-size: 0.95rem;
    font-family: inherit;
    color: var(--text);
    background-color: #fff;
    box-shadow: inset 0 1px 2px rgba(15, 23, 42, 0.08);
}

.comment-input:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.comment-submit {
    align-self: flex-end;
    border: none;
    border-radius: 10px;
    padding: 10px 16px;
    background-color: var(--accent);
    color: #fff;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.comment-submit:hover,
.comment-submit:focus-visible {
    transform: translateY(-1px);
    box-shadow: 0 10px 18px -12px rgba(124, 58, 237, 0.6);
}

.comment-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-height: 360px;
    overflow-y: auto;
    padding-right: 4px;
    padding-left: 0;
    margin: 0;
}

.comment-placeholder {
    border: 1px dashed #cbd5f5;
    border-radius: 12px;
    padding: 14px;
    background-color: #ffffff;
    color: var(--muted);
    font-size: 0.9rem;
    text-align: center;
}

.comment-item {
    display: flex;
    gap: 12px;
    align-items: flex-start;
    background-color: #fff;
    border-radius: 12px;
    padding: 12px;
    border: 1px solid #e2e8f0;
}

.comment-meta {
    font-size: 0.8rem;
    color: var(--muted);
    margin-bottom: 6px;
}

.comment-body {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.comment-text {
    flex: 1;
    white-space: pre-wrap;
    word-break: break-word;
    font-size: 0.95rem;
    color: var(--text);
}

.comment-remove {
    border: none;
    background: none;
    color: var(--muted);
    cursor: pointer;
    font-weight: 600;
    transition: color 0.2s ease;
}

.comment-remove:hover,
.comment-remove:focus-visible {
    color: #b91c1c;
}

.comment-moderate {
    align-self: flex-end;
    border: 1px solid #cbd5f5;
    border-radius: 10px;
    padding: 8px 12px;
    background: transparent;
    color: var(--muted);
    font-weight: 600;
    cursor: pointer;
    transition: background-color 0.2s ease, color 0.2s ease, border-color 0.2s ease;
}

.comment-moderate:hover,
.comment-moderate:focus-visible {
    background-color: #ede9fe;
    border-color: var(--accent);
}

.comment-moderate[aria-pressed="true"] {
    background-color: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

.comment-moderate[aria-pressed="true"]:hover,
.comment-moderate[aria-pressed="true"]:focus-visible {
    background-color: #6d28d9;
}

.leaderboard {
    background: linear-gradient(165deg, #eef2ff 0%, #f8fafc 65%);
    border-radius: 14px;
    padding: 18px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    box-shadow: inset 0 1px 0 rgba(148, 163, 184, 0.18);
}

.leaderboard h2 {
    font-size: 1.15rem;
    font-weight: 700;
    color: #312e81;
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.leaderboard-status {
    min-height: 24px;
    font-size: 0.9rem;
    color: var(--muted);
}

.leaderboard-groups {
    display: flex;
    flex-direction: column;
    gap: 18px;
}

.leaderboard-group {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding-top: 6px;
}

.leaderboard-group + .leaderboard-group {
    border-top: 1px solid rgba(148, 163, 184, 0.25);
    padding-top: 16px;
}

.leaderboard-group-title {
    font-size: 1rem;
    font-weight: 600;
    color: #1e293b;
}

.leaderboard-group-description {
    font-size: 0.85rem;
    color: var(--muted);
}

.leaderboard-empty {
    font-size: 0.9rem;
    color: var(--muted);
    font-style: italic;
}

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

.leaderboard-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 14px;
    background-color: rgba(255, 255, 255, 0.85);
    border-radius: 12px;
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.08);
    border: 1px solid rgba(148, 163, 184, 0.25);
}

.leaderboard-rank {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    font-weight: 700;
    color: #4338ca;
    background: rgba(99, 102, 241, 0.12);
    font-variant-numeric: tabular-nums;
}

.leaderboard-entry {
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex: 1;
}

.leaderboard-name {
    font-weight: 600;
    color: var(--text);
}

.leaderboard-time {
    font-size: 0.9rem;
    color: var(--muted);
    font-variant-numeric: tabular-nums;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    border: 0;
}

.options {
    background-color: #f1f5f9;
    border-radius: 12px;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.options .toggle {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    cursor: pointer;
    color: var(--muted);
    font-weight: 500;
}

.options input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: var(--accent);
    cursor: pointer;
}

.options span {
    color: var(--text);
}

.controls {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.controls button {
    border: none;
    border-radius: 10px;
    padding: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: background-color 0.2s ease, transform 0.2s ease;
    color: #fff;
    background-color: var(--muted);
}

.controls button.primary {
    background-color: var(--accent);
}

.controls button:disabled {
    cursor: not-allowed;
    opacity: 0.6;
}

.controls button:not(:disabled):hover {
    transform: translateY(-1px);
}

.status {
    min-height: 40px;
    background-color: #e2e8f0;
    border-radius: 10px;
    padding: 10px 12px;
    font-weight: 500;
    color: var(--text);
}

.status.success {
    background-color: #34d39933;
    color: #047857;
}

.status.fail {
    background-color: #fecaca33;
    color: #b91c1c;
}

.status.warning {
    background-color: #fde68a33;
    color: #b45309;
}

.secret {
    background-color: #f1f5f9;
    border-radius: 12px;
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.secret-label {
    font-weight: 600;
    color: var(--muted);
}

.secret-code {
    display: flex;
    gap: 10px;
    filter: blur(10px);
    opacity: 0.3;
    transition: filter 0.3s ease, opacity 0.3s ease;
}

.secret-code.revealed {
    filter: none;
    opacity: 1;
}

.secret-code .peg {
    cursor: default;
    border: none;
    width: 36px;
    height: 36px;
    box-shadow: inset 0 1px 4px rgba(15, 23, 42, 0.5);
}

.instructions {
    background-color: #f8fafc;
    border-radius: 12px;
    padding: 18px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.instructions h2 {
    font-size: 1.15rem;
}

.instructions ul {
    display: grid;
    gap: 10px;
    list-style: disc inside;
    color: var(--muted);
}

@media (max-width: 1100px) {
    .layout {
        grid-template-columns: 1fr;
    }

    .board {
        max-height: none;
        min-width: 100%;
    }

    .comments,
    .sidebar,
    .leaderboard {
        width: 100%;
    }

    .leaderboard {
        order: 4;
    }
}

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