* {
    box-sizing: border-box;
}

body {
    min-height: 100vh;
    margin: 0;
    background: #f1f5f9;
    color: #0f172a;
    font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    -webkit-font-smoothing: antialiased;
}

button,
input {
    font: inherit;
}

.app-nav {
    border-bottom: 1px solid #e2e8f0;
    background: #fff;
    box-shadow: 0 1px 2px rgb(15 23 42 / 0.05);
}

.nav-links {
    display: flex;
    max-width: 64rem;
    margin: 0 auto;
    padding: 0.75rem 1.5rem;
    gap: 0.5rem;
}

.nav-link {
    padding: 0.5rem 0.75rem;
    border-radius: 0.5rem;
    color: #475569;
    text-decoration: none;
    transition: background 150ms, color 150ms;
}

.nav-link:hover {
    background: #f1f5f9;
    color: #0f172a;
}

.nav-link-home {
    color: #0f172a;
    font-weight: 600;
}

.app-content {
    max-width: 64rem;
    margin: 0 auto;
    padding: 3rem 1.5rem;
}

.app-content > h1 {
    font-size: 2.25rem;
    letter-spacing: -0.025em;
}

.button {
    padding: 0.5rem 0.75rem;
    border: 0;
    border-radius: 0.5rem;
    cursor: pointer;
    font-size: 0.875rem;
    font-weight: 600;
    transition: background 150ms, color 150ms, transform 150ms;
}

.button:active {
    transform: scale(0.95);
}

.button-primary {
    background: #4f46e5;
    color: #fff;
}

.button-primary:hover {
    background: #6366f1;
}

.button-secondary {
    background: #f1f5f9;
    color: #334155;
}

.button-secondary:hover,
.button-quiet:hover {
    background: #e2e8f0;
}

.button-quiet {
    background: transparent;
    color: #475569;
    font-weight: 500;
}

.button-danger {
    background: transparent;
    color: #e11d48;
    font-weight: 500;
}

.button-danger:hover {
    background: #fff1f2;
}

.counter-card {
    display: grid;
    width: 100%;
    max-width: 28rem;
    margin: 0 auto;
    padding: 1.5rem;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.75rem;
    border: 1px solid #e2e8f0;
    border-radius: 1rem;
    background: #fff;
    box-shadow: 0 20px 25px -5px rgb(148 163 184 / 0.35), 0 8px 10px -6px rgb(148 163 184 / 0.35);
}

.counter-card > .button {
    padding: 0.75rem 1rem;
    border-radius: 0.75rem;
    font-size: 1rem;
}

.counter-heading {
    grid-row: 1;
    grid-column: 1 / -1;
    margin: 0 0 0.75rem;
    color: #0f172a;
    font-size: 2.25rem;
    letter-spacing: -0.025em;
    text-align: center;
}

.counter-heading span {
    color: #4f46e5;
}

.todo-card {
    max-width: 42rem;
    margin: 0 auto;
    overflow: hidden;
    border: 1px solid #e2e8f0;
    border-radius: 1rem;
    background: #fff;
    box-shadow: 0 20px 25px -5px rgb(148 163 184 / 0.35), 0 8px 10px -6px rgb(148 163 184 / 0.35);
}

.todo-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid #e2e8f0;
}

.todo-header h1 {
    margin: 0;
    font-size: 1.5rem;
    letter-spacing: -0.025em;
}

.todo-header .button {
    padding: 0.625rem 1rem;
    border-radius: 0.75rem;
}

.signals {
    display: none;
}

.todo-list {
    margin: 0;
    padding: 0;
    list-style: none;
}

.todo-item {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    padding: 1rem 1.5rem;
    gap: 0.75rem;
    transition: background 150ms;
}

.todo-item + .todo-item {
    border-top: 1px solid #f1f5f9;
}

.todo-item:hover {
    background: #f8fafc;
}

.todo-checkbox {
    width: 1.25rem;
    height: 1.25rem;
    flex-shrink: 0;
    cursor: pointer;
    accent-color: #4f46e5;
}

.todo-title,
.todo-input {
    min-width: 0;
    flex: 1;
}

.todo-title {
    color: #334155;
}

.todo-checkbox:checked ~ .todo-title {
    color: #94a3b8;
    text-decoration: line-through;
}

.todo-input {
    padding: 0.5rem 0.75rem;
    border: 1px solid #cbd5e1;
    border-radius: 0.5rem;
    background: #fff;
    color: #0f172a;
    outline: none;
    transition: border-color 150ms, box-shadow 150ms;
}

.todo-input:focus {
    border-color: #6366f1;
    box-shadow: 0 0 0 4px #e0e7ff;
}

.tetris-card {
    max-width: 52rem;
    margin: 0 auto;
    overflow: hidden;
    border: 1px solid #e2e8f0;
    border-radius: 1rem;
    background: #fff;
    box-shadow: 0 20px 25px -5px rgb(148 163 184 / 0.35), 0 8px 10px -6px rgb(148 163 184 / 0.35);
}

.tetris-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid #e2e8f0;
}

.tetris-header h1,
.tetris-next h2,
.tetris-help h2,
.tetris-eyebrow {
    margin: 0;
}

.tetris-header h1 {
    font-size: 1.75rem;
    letter-spacing: -0.025em;
}

.tetris-eyebrow {
    margin-bottom: 0.2rem;
    color: #64748b;
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.tetris-header-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.tetris-sound-toggle {
    width: 2rem;
    height: 2rem;
    padding: 0;
    border-radius: 999px;
    color: #4338ca;
    font-size: 1rem;
}

.tetris-status {
    padding: 0.35rem 0.65rem;
    border-radius: 999px;
    background: #eef2ff;
    color: #4338ca;
    font-size: 0.8rem;
    font-weight: 700;
}

.tetris-game {
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 1.5rem;
    gap: 1.5rem;
}

.tetris-board-wrap {
    position: relative;
    width: min(100%, 22rem);
    flex: 0 1 22rem;
}

.tetris-board {
    display: grid;
    width: 100%;
    overflow: hidden;
    grid-template-columns: repeat(10, minmax(0, 1fr));
    grid-template-rows: repeat(20, minmax(0, 1fr));
    aspect-ratio: 1 / 2;
    border: 4px solid #0f172a;
    border-radius: 0.5rem;
    background: #334155;
    gap: 1px;
}

.tetris-cell {
    min-width: 0;
    background: #111827;
}

.tetris-board .tetris-cell[class*="piece-"] {
    border: 2px solid rgb(255 255 255 / 0.22);
    border-right-color: rgb(15 23 42 / 0.3);
    border-bottom-color: rgb(15 23 42 / 0.3);
    border-radius: 2px;
}

.piece-i { background: #22d3ee; }
.piece-j { background: #3b82f6; }
.piece-l { background: #fb923c; }
.piece-o { background: #facc15; }
.piece-s { background: #4ade80; }
.piece-t { background: #a855f7; }
.piece-z { background: #f43f5e; }

.tetris-overlay {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    border-radius: 0.5rem;
    background: rgb(15 23 42 / 0.68);
    color: #fff;
    font-size: 1.25rem;
    letter-spacing: 0.025em;
    text-align: center;
}

.tetris-sidebar {
    display: grid;
    width: 13rem;
    flex: 0 0 13rem;
    gap: 1rem;
}

.tetris-stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    border: 1px solid #e2e8f0;
    border-radius: 0.75rem;
}

.tetris-stats div {
    display: flex;
    min-width: 0;
    padding: 0.7rem 0.25rem;
    flex-direction: column;
    align-items: center;
}

.tetris-stats div + div {
    border-left: 1px solid #e2e8f0;
}

.tetris-stats span {
    color: #64748b;
    font-size: 0.7rem;
    text-transform: uppercase;
}

.tetris-stats strong {
    max-width: 100%;
    overflow: hidden;
    color: #0f172a;
    font-size: 1rem;
    text-overflow: ellipsis;
}

.tetris-next,
.tetris-help {
    padding: 1rem;
    border: 1px solid #e2e8f0;
    border-radius: 0.75rem;
    background: #f8fafc;
}

.tetris-next h2,
.tetris-help h2 {
    margin-bottom: 0.75rem;
    color: #475569;
    font-size: 0.8rem;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

.tetris-preview {
    display: grid;
    width: 7rem;
    margin: 0 auto;
    grid-template-columns: repeat(4, 1fr);
    aspect-ratio: 1;
    gap: 2px;
}

.tetris-preview .tetris-cell {
    border-radius: 3px;
    background: transparent;
}

.tetris-preview .piece-i {
    background: #22d3ee;
    transform: translateY(calc(-50% - 1px));
}
.tetris-preview .piece-j { background: #3b82f6; }
.tetris-preview .piece-l { background: #fb923c; }
.tetris-preview .piece-o { background: #facc15; }
.tetris-preview .piece-s { background: #4ade80; }
.tetris-preview .piece-t { background: #a855f7; }
.tetris-preview .piece-z { background: #f43f5e; }

.tetris-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.5rem;
}

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

.tetris-help p {
    margin: 0.45rem 0 0;
    color: #64748b;
    font-size: 0.8rem;
}

.tetris-help kbd {
    display: inline-block;
    min-width: 1.6rem;
    margin-right: 0.2rem;
    padding: 0.15rem 0.35rem;
    border: 1px solid #cbd5e1;
    border-bottom-width: 2px;
    border-radius: 0.3rem;
    background: #fff;
    color: #334155;
    font: 600 0.7rem ui-monospace, SFMono-Regular, Menlo, monospace;
    text-align: center;
}

.tetris-mobile-controls {
    display: none;
    touch-action: none;
}

.tetris-audio,
.tetris-audio-event {
    display: none;
}

@media (max-width: 48rem) {
    .tetris-game {
        align-items: stretch;
        flex-direction: column;
        gap: 0.5rem;
    }

    .tetris-board-wrap {
        width: min(100%, 19rem);
        margin: 0 auto;
        flex-basis: auto;
    }

    .tetris-sidebar {
        width: 100%;
        flex-basis: auto;
        grid-template-columns: minmax(0, 1fr) 6rem;
        gap: 0.5rem;
    }

    .tetris-stats {
        height: 2rem;
        align-self: center;
        grid-column: auto;
    }

    .tetris-next {
        height: 2.75rem;
    }

    .tetris-stats div {
        padding: 0.1rem 0;
    }

    .tetris-stats span {
        font-size: 0.5rem;
        line-height: 1;
    }

    .tetris-stats strong {
        font-size: 0.7rem;
        line-height: 1;
    }

    .tetris-next {
        display: flex;
        padding: 0.2rem 0.4rem;
        align-items: center;
        justify-content: space-between;
        gap: 0.4rem;
    }

    .tetris-next h2 {
        display: block;
        margin: 0;
        font-size: 0.55rem;
        letter-spacing: 0;
        line-height: 1;
    }

    .tetris-preview {
        width: 2.25rem;
        flex: 0 0 2.25rem;
        gap: 1px;
    }

    .tetris-preview .piece-i {
        transform: translateY(calc(-50% - 0.5px));
    }

    .tetris-actions {
        grid-column: 1 / -1;
    }

    .tetris-help {
        display: none;
    }

    .tetris-mobile-controls {
        display: grid;
        padding: 0 1.5rem 1.5rem;
        grid-template-columns: repeat(3, 1fr);
        gap: 0.5rem;
    }

    .tetris-mobile-controls button {
        min-height: 3rem;
        border: 0;
        border-radius: 0.75rem;
        background: #e2e8f0;
        color: #0f172a;
        cursor: pointer;
        font-size: 1.25rem;
        font-weight: 700;
        touch-action: manipulation;
    }

    .tetris-mobile-controls button:active {
        background: #cbd5e1;
    }

    .tetris-mobile-controls .tetris-drop-button {
        grid-column: span 2;
        background: #4f46e5;
        color: #fff;
        font-size: 0.9rem;
    }

    body:has(.tetris-card-playing) {
        overflow: hidden;
    }

    .tetris-card-playing {
        position: fixed;
        inset: 0;
        z-index: 100;
        width: 100%;
        height: 100dvh;
        max-width: none;
        margin: 0;
        overflow: auto;
        border: 0;
        border-radius: 0;
        background: #fff;
        box-shadow: none;
    }

    .tetris-card-playing .tetris-header {
        display: none;
    }

    .tetris-card-playing .tetris-game {
        padding: 0.5rem;
        gap: 0.5rem;
    }

    .tetris-card-playing .tetris-mobile-controls {
        padding: 0 0.5rem 0.5rem;
    }
}

@media (max-width: 40rem) {
    .nav-links,
    .app-content {
        padding-right: 1rem;
        padding-left: 1rem;
    }

    .todo-header,
    .todo-item,
    .tetris-header,
    .tetris-game {
        padding-right: 1rem;
        padding-left: 1rem;
    }

    .tetris-mobile-controls {
        padding-right: 1rem;
        padding-left: 1rem;
    }
}
