:root {
    --bg-1: #f8fafc;
    --bg-2: #e2e8f0;
    --ink: #0f172a;
    --muted: #475569;
    --panel: rgba(255, 255, 255, 0.78);
    --panel-border: rgba(15, 23, 42, 0.12);
    --line: #94a3b8;
    --alive: #22c55e;
    --dead: #ffffff;
    --accent: #fb923c;
    --danger: #dc2626;
    --shadow: 0 20px 45px rgba(15, 23, 42, 0.15);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    height: 100vh;
    overflow: hidden;
    font-family: "Sora", sans-serif;
    color: var(--ink);
    background:
        radial-gradient(circle at 10% 10%, rgba(251, 146, 60, 0.22), transparent 38%),
        radial-gradient(circle at 80% 15%, rgba(15, 118, 110, 0.18), transparent 36%),
        linear-gradient(140deg, var(--bg-1), var(--bg-2));
    padding: 1.5rem clamp(1rem, 2vw, 2rem);
    box-sizing: border-box;
}

.app-shell {
    max-width: 1800px;
    height: 100%;
    margin: 0 auto;
    display: grid;
    grid-template-columns: minmax(320px, 400px) 1fr;
    grid-template-rows: auto 1fr;
    grid-template-areas:
        "hero hero"
        "controls board";
    gap: 1.5rem;
    align-items: start;
}

.hero {
    grid-area: hero;
    animation: reveal 600ms ease forwards;
}

.eyebrow {
    margin: 0;
    font-family: "Space Mono", monospace;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: var(--muted);
}

h1 {
    margin: 0.35rem 0;
    font-size: clamp(1.7rem, 4vw, 2.8rem);
    line-height: 1.1;
}

.heading-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

.heading-row h1 {
    margin: 0.35rem 0;
}

.subtitle {
    margin: 0;
    color: var(--muted);
}

.panel {
    backdrop-filter: blur(12px);
    background: var(--panel);
    border: 1px solid var(--panel-border);
    box-shadow: var(--shadow);
    border-radius: 18px;
    animation: reveal 700ms ease forwards;
}

.controls {
    grid-area: controls;
    padding: 1rem;
    display: grid;
    gap: 1rem;
}

.slider-grid {
    display: grid;
    gap: 0.8rem;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
}

.control {
    display: grid;
    gap: 0.4rem;
    padding: 0.85rem;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.72);
}

.control span {
    font-size: 0.85rem;
    color: var(--muted);
}

.control strong {
    font-family: "Space Mono", monospace;
    font-size: 0.9rem;
}

input[type="range"] {
    width: 100%;
    accent-color: #0f766e;
}

.button-row {
    display: flex;
    gap: 0.6rem;
    flex-wrap: wrap;
}

.actions-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.btn {
    border: 1px solid rgba(15, 23, 42, 0.2);
    background: #ffffff;
    color: var(--ink);
    border-radius: 999px;
    padding: 0.55rem 1rem;
    font-family: "Sora", sans-serif;
    font-weight: 600;
    cursor: pointer;
    transition: transform 120ms ease, box-shadow 120ms ease, background-color 120ms ease;
}

.btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 8px 16px rgba(15, 23, 42, 0.1);
}

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

.btn-primary {
    background: #0f766e;
    border-color: #0f766e;
    color: #f0fdfa;
}

.btn-primary.is-running {
    background: #ea580c;
    border-color: #ea580c;
}

.btn-danger {
    border-color: #ef4444;
    color: #b91c1c;
}

.btn-active {
    background: #0ea5e9;
    border-color: #0ea5e9;
    color: #ffffff;
}

select.btn.pattern-select {
    appearance: none;
    -webkit-appearance: none;
    background-image: url('data:image/svg+xml;utf8,<svg fill="%230f172a" height="24" viewBox="0 0 24 24" width="24" xmlns="http://www.w3.org/2000/svg"><path d="M7 10l5 5 5-5z"/></svg>');
    background-repeat: no-repeat;
    background-position: right 0.6rem center;
    padding-right: 2.2rem;
    font-size: 0.88rem;
}

.btn-about {
    flex: 0 0 auto;
    border-color: rgba(15, 118, 110, 0.55);
    color: #0f766e;
    background: rgba(236, 254, 255, 0.78);
    min-width: 120px;
    padding: 0.75rem 1.5rem;
    margin-right: 2.5rem;
    font-family: "Space Mono", monospace;
    font-size: 0.95rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.status-row {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
    font-family: "Space Mono", monospace;
    font-size: 0.88rem;
    color: #0f172a;
}

.status-row p {
    margin: 0;
    padding: 0.3rem 0.6rem;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: #ffffff;
}

.hint {
    margin: 0;
    font-size: 0.88rem;
    color: #475569;
}

.modal {
    position: fixed;
    inset: 0;
    display: grid;
    place-items: center;
    padding: 1rem;
    background: rgba(15, 23, 42, 0.55);
    z-index: 1000;
}

.modal[hidden] {
    display: none;
}

.modal-card {
    width: min(92vw, 560px);
    max-height: 85vh;
    overflow: auto;
    background: #ffffff;
    border: 1px solid rgba(15, 23, 42, 0.16);
    border-radius: 16px;
    box-shadow: var(--shadow);
    padding: 1.1rem 1.1rem 1rem;
    display: grid;
    gap: 0.85rem;
}

.modal-card h2,
.modal-card p,
.modal-card ol {
    margin: 0;
}

.modal-card ol {
    padding-left: 1.2rem;
    display: grid;
    gap: 0.35rem;
    color: #1e293b;
}

.modal-close {
    justify-self: end;
    border: 1px solid rgba(15, 23, 42, 0.2);
    border-radius: 999px;
    width: 2rem;
    height: 2rem;
    font: inherit;
    font-weight: 700;
    background: #ffffff;
    cursor: pointer;
}

.modal-credit {
    font-weight: 700;
    color: #475569;
    font-size: 0.95rem;
    margin-top: 1rem;
    text-align: center;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

.author-name {
    font-family: "Space Mono", monospace;
    font-weight: 800;
    color: #0f766e;
    background: linear-gradient(135deg, #0f766e, #fb923c);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    display: inline-block;
    padding: 0 0.2rem;
    transform: scale(1.05);
}

.social-icon {
    display: inline-flex;
    align-items: center;
    color: #0f766e;
    transition: color 150ms ease, transform 150ms ease;
}

.social-icon:hover {
    color: #0d9488;
    transform: scale(1.1);
}

.board-wrap {
    grid-area: board;
    padding: clamp(0.5rem, 1vw, 1rem);
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100%;
    min-height: 0;
}

.grid {
    display: grid;
    max-width: 100%;
    max-height: 100%;
    width: 100%;
    height: 100%;
    aspect-ratio: 1 / 1;
    margin: 0 auto;
    border: 1px solid #64748b;
    border-radius: 12px;
    overflow: hidden;
    background: #ffffff;
    object-fit: contain;
}

.cell {
    border: 1px solid var(--line);
    background: var(--dead);
    transition: background-color 120ms linear;
}

.cell.alive {
    box-shadow: inset 0 0 0 1px rgba(15, 118, 110, 0.25);
}

.cell.preview {
    background: #86efac;
    box-shadow: inset 0 0 0 1px #4ade80;
    opacity: 0.8;
}

@keyframes reveal {
    from {
        opacity: 0;
        transform: translateY(8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@media (max-width: 900px) {
    body {
        height: auto;
        overflow: auto;
    }
    .app-shell {
        height: auto;
        grid-template-columns: 1fr;
        grid-template-rows: auto auto auto;
        grid-template-areas:
            "hero"
            "controls"
            "board";
    }
}

@media (max-width: 720px) {
    body {
        padding: 1rem 0.75rem 1.5rem;
    }

    .status-row {
        gap: 0.55rem;
    }

    .actions-row {
        display: block;
    }

    .heading-row {
        flex-wrap: wrap;
        align-items: flex-start;
        gap: 0.55rem;
    }

    .btn {
        flex: 1 1 calc(50% - 0.4rem);
        text-align: center;
    }

    .btn-about {
        margin-left: auto;
        margin-right: 0;
        flex: 0 0 auto;
    }
}