:root {
    --primary: #4f46e5;
    --bg: #f8fafc;
    --surface: #ffffff;
    --text: #1e293b;
    --text-muted: #64748b;
    --border: #cbd5e1;

    --tile: #cbd5e1;
    --tile-light: #f8fafc;
    --tile-dark: #64748b;
    --tile-open: #e2e8f0;
    --tile-edge: #94a3b8;
    --panel-dark: #1e293b;
    --led: #ef4444;

    --cell: 32px;
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    line-height: 1.6;
    overflow-x: hidden;
}

.visually-hidden {
    position: absolute;
    width: 1px; height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
}

.skip-link {
    position: absolute;
    left: 8px; top: -48px;
    background: var(--primary);
    color: #fff;
    padding: 8px 12px;
    border-radius: 6px;
    z-index: 20;
}
.skip-link:focus { top: 8px; }

:focus-visible { outline: 3px solid var(--primary); outline-offset: 2px; }

.site-header { text-align: center; padding: 32px 16px 8px; }
.site-header h1 { margin: 0; font-size: clamp(1.6rem, 4vw, 2.2rem); letter-spacing: -0.01em; }
.tagline { margin: 4px 0 0; color: var(--text-muted); }

main {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 16px;
    gap: 32px;
}

.card {
    display: flex;
    flex-direction: column;
    align-items: center;
    background: var(--surface);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.08);
    border-radius: 16px;
    padding: 24px;
    max-width: 100%;
}

.difficulty {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 20px;
    width: 100%;
    justify-content: center;
    flex-wrap: wrap;
}
.difficulty label { font-weight: 600; color: var(--text-muted); }
.difficulty select {
    font: inherit;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 8px 12px;
    cursor: pointer;
}

.control-panel {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    margin-bottom: 24px;
    background: var(--tile-open);
    padding: 10px 16px;
    border-radius: 8px;
    border: 2px solid var(--border);
    border-bottom-color: var(--tile-light);
    border-right-color: var(--tile-light);
    border-top-color: var(--tile-edge);
    border-left-color: var(--tile-edge);
}

.counter {
    font-size: 24px;
    font-weight: bold;
    color: var(--led);
    background: var(--panel-dark);
    padding: 4px 8px;
    border-radius: 4px;
    font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
    line-height: 1;
    border: 2px solid var(--tile-edge);
    border-top-color: #0f172a;
    border-left-color: #0f172a;
    border-bottom-color: #f1f5f9;
    border-right-color: #f1f5f9;
    min-width: 62px;
    text-align: center;
}

.reset-btn {
    font-size: 28px;
    width: 48px; height: 48px;
    display: flex; align-items: center; justify-content: center;
    cursor: pointer;
    background: var(--tile);
    border: 4px solid var(--tile-edge);
    border-top-color: var(--tile-light);
    border-left-color: var(--tile-light);
    border-bottom-color: var(--tile-dark);
    border-right-color: var(--tile-dark);
    padding: 0;
    border-radius: 4px;
}
.reset-btn:active {
    border-top-color: var(--tile-dark);
    border-left-color: var(--tile-dark);
    border-bottom-color: var(--tile-light);
    border-right-color: var(--tile-light);
}

.board-scroll {
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 2px;
}

.grid {
    display: grid;
    gap: 0;
    width: max-content;
    border: 4px solid var(--tile-edge);
    border-top-color: var(--tile-dark);
    border-left-color: var(--tile-dark);
    border-bottom-color: #f1f5f9;
    border-right-color: #f1f5f9;
    background: var(--tile);
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
    touch-action: manipulation;
}

.cell {
    width: var(--cell);
    height: var(--cell);
    margin: 0;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font: bold 18px/1 system-ui, sans-serif;
    cursor: pointer;
    background: var(--tile);
    border: 3px solid var(--tile-edge);
    border-top-color: var(--tile-light);
    border-left-color: var(--tile-light);
    border-bottom-color: var(--tile-dark);
    border-right-color: var(--tile-dark);
    user-select: none;
    -webkit-user-select: none;
    border-radius: 0;
}
.cell:active:not(.revealed) {
    border-top-color: var(--tile-dark);
    border-left-color: var(--tile-dark);
    border-bottom-color: var(--tile-light);
    border-right-color: var(--tile-light);
}
.cell:focus-visible { outline-offset: -3px; z-index: 1; }

.cell.revealed {
    background: var(--tile-open);
    border: 1px solid var(--tile-edge);
    font-weight: 900;
    cursor: default;
}
.cell.death { background: var(--led); }

.n1 { color: #2563eb; } .n2 { color: #16a34a; } .n3 { color: #dc2626; }
.n4 { color: #9333ea; } .n5 { color: #ea580c; } .n6 { color: #0d9488; }
.n7 { color: #000; }    .n8 { color: #57534e; }

.hint { margin: 16px 0 0; font-size: 0.875rem; color: var(--text-muted); text-align: center; }
.noscript { color: var(--led); font-weight: 600; }

.content {
    width: 100%;
    max-width: 680px;
    background: var(--surface);
    border-radius: 16px;
    padding: 24px 28px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.05);
}
.content h2 { margin-top: 0; }
.content h3 { margin-top: 1.5em; }
.content ul { padding-left: 1.25em; }
.content details { border-top: 1px solid var(--border); padding: 10px 0; }
.content details:last-child { border-bottom: 1px solid var(--border); }
.content summary { cursor: pointer; font-weight: 600; }
.content details p { margin: 8px 0 0; color: var(--text-muted); }

.site-footer { text-align: center; color: var(--text-muted); padding: 24px 16px 40px; font-size: 0.875rem; }

/* Toast */
.toast {
    position: fixed;
    left: 50%;
    bottom: 24px;
    transform: translate(-50%, 24px);
    opacity: 0;
    pointer-events: none;
    padding: 12px 20px;
    border-radius: 10px;
    color: #fff;
    font-weight: 600;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
    transition: opacity 0.2s, transform 0.2s;
    z-index: 30;
    max-width: calc(100vw - 32px);
    text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.success { background: #16a34a; }
.toast.error { background: #dc2626; }

@media (max-width: 520px) {
    :root { --cell: 28px; }
    .card { padding: 16px; }
    .content { padding: 20px; }
    .cell { font-size: 16px; }
}

@media (prefers-reduced-motion: reduce) {
    .toast { transition: none; }
}
