:root {
    --paper: #f4f7f6;
    --grid-fine: rgba(14, 90, 96, 0.07);
    --grid-bold: rgba(14, 90, 96, 0.14);
    --ink: #15282e;
    --ink-soft: #4a6168;
    --teal: #0d5c63;
    --teal-deep: #093f44;
    --orange: #d9480f;
    --board: #20382e;
    --board-line: #3a564a;
    --chalk: #ecf3ee;
    --chalk-dim: #a8bfb2;
    --card: #fdfefe;
    --line: #cfdedd;
    --serif: 'Noto Serif SC', 'Source Han Serif SC', 'Songti SC', 'SimSun', serif;
    --sans: 'PingFang SC', 'Microsoft YaHei', 'Segoe UI', sans-serif;
    --mono: 'JetBrains Mono', 'Consolas', 'Menlo', monospace;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    padding: 18px 14px 48px;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    color: var(--ink);
    font-family: var(--sans);
    background-color: var(--paper);
    background-image:
        linear-gradient(var(--grid-fine) 1px, transparent 1px),
        linear-gradient(90deg, var(--grid-fine) 1px, transparent 1px),
        linear-gradient(var(--grid-bold) 1px, transparent 1px),
        linear-gradient(90deg, var(--grid-bold) 1px, transparent 1px);
    background-size: 14px 14px, 14px 14px, 70px 70px, 70px 70px;
}

.topbar {
    width: 100%;
    max-width: 980px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 14px;
}

.back {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    border: 1px solid var(--line);
    border-radius: 3px;
    color: var(--teal);
    background: var(--card);
    font-size: 13.5px;
    font-weight: 700;
    text-decoration: none;
    transition: .2s;
}

.back:hover { border-color: var(--teal); color: var(--teal-deep); }
.exp-no { color: var(--orange); font: 700 12px var(--mono); letter-spacing: .2em; }

.container {
    width: 100%;
    max-width: 980px;
    padding: 22px;
    border: 1px solid var(--line);
    border-radius: 4px;
    background: var(--card);
    box-shadow: 0 18px 40px -24px rgba(13, 92, 99, .3);
}

.page-head {
    position: relative;
    display: flex;
    align-items: baseline;
    flex-wrap: wrap;
    gap: 14px;
    padding-bottom: 12px;
    margin-bottom: 16px;
    border-bottom: 2.5px solid var(--ink);
}

.page-head::after {
    content: '';
    position: absolute;
    left: 0;
    right: 0;
    bottom: -6px;
    border-bottom: 1px solid var(--ink);
}

h1 { margin: 0; font: 900 24px var(--serif); letter-spacing: .04em; }
.subtitle { color: var(--ink-soft); font: 12px var(--mono); letter-spacing: .08em; }

.canvas-wrapper {
    position: relative;
    width: 100%;
    margin-top: 14px;
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: 3px;
    background-color: #fbfdfc;
    background-image:
        linear-gradient(rgba(14, 90, 96, .05) 1px, transparent 1px),
        linear-gradient(90deg, rgba(14, 90, 96, .05) 1px, transparent 1px);
    background-size: 14px 14px;
}

canvas { display: block; width: 100%; height: 500px; }

.stats {
    margin-top: 14px;
    padding: 16px 18px;
    border: 1px solid #122019;
    border-radius: 4px;
    color: var(--chalk);
    background: radial-gradient(ellipse at 30% 0%, #2a463a 0%, var(--board) 70%);
    box-shadow: inset 0 0 0 2px var(--board-line), inset 0 0 36px rgba(0, 0, 0, .35);
    font: 13px/1.85 var(--mono);
}

.stats strong { color: #fff; }
.stats .accent { color: #ffd166; }
.stats .ok { color: #8bd6ac; }
.stats .warn { color: #ff9d7e; }

.legend {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 16px;
    padding-top: 8px;
    margin-top: 8px;
    border-top: 1px dashed var(--board-line);
    color: var(--chalk-dim);
    font-size: 12px;
}

.legend-item { display: inline-flex; align-items: center; gap: 5px; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; }

.presets { margin-top: 18px; }
.section-label {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 10px;
    color: var(--ink);
    font: 900 14px var(--serif);
    letter-spacing: .08em;
}

.section-label::after { content: ''; flex: 1; border-top: 1px dashed var(--line); }
.preset-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 10px; }

.preset {
    padding: 10px 12px;
    border: 1px solid var(--line);
    border-radius: 3px;
    color: var(--ink);
    background: var(--paper);
    font-family: var(--sans);
    text-align: left;
    cursor: pointer;
    transition: .2s;
}

.preset:hover, .preset:focus-visible, .preset.active {
    border-color: var(--teal);
    background: #fff;
    outline: none;
    box-shadow: 0 0 0 3px rgba(13, 92, 99, .12);
}

.preset.active { border-left: 4px solid var(--teal); padding-left: 9px; }
.preset b { display: block; margin-bottom: 3px; color: var(--teal-deep); font-size: 13px; }
.preset span { color: var(--ink-soft); font: 11.5px var(--mono); }

.controls {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
    gap: 12px;
    margin-top: 18px;
}

.control-group {
    display: flex;
    flex-direction: column;
    min-width: 0;
    padding: 10px 12px;
    border: 1px solid var(--line);
    border-radius: 3px;
    background: var(--paper);
    transition: .2s;
}

.control-group:focus-within { border-color: var(--teal); box-shadow: 0 0 0 3px rgba(13, 92, 99, .12); }
label { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 6px; color: var(--ink-soft); font-size: 12px; font-weight: 700; }
label .val { color: var(--teal); font-family: var(--mono); }
input[type='range'] { width: 100%; margin-top: 8px; accent-color: var(--teal); cursor: pointer; }
select, input[type='number'] { width: 100%; padding: 7px 8px; border: 1px solid var(--line); border-radius: 3px; color: var(--ink); background: #fff; font: 13px var(--mono); }
select:focus, input[type='number']:focus { border-color: var(--teal); outline: none; }
.toggle-row { display: flex; align-items: center; justify-content: flex-start; gap: 8px; min-height: 28px; margin-bottom: 0; color: var(--ink); font-size: 13px; cursor: pointer; }
input[type='checkbox'], input[type='radio'] { width: 16px; height: 16px; margin: 0; accent-color: var(--teal); cursor: pointer; }

.btn-group { grid-column: 1 / -1; display: flex; gap: 14px; margin-top: 6px; }
button.action {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 13px;
    border: 0;
    border-radius: 3px;
    font: 700 15px var(--sans);
    cursor: pointer;
    transition: .2s;
}

button.primary { color: #fff; background: var(--teal); box-shadow: 0 4px 10px -3px rgba(13, 92, 99, .5); }
button.primary:hover { background: var(--teal-deep); transform: translateY(-1px); }
button.secondary { border: 1px solid var(--line); color: var(--ink); background: #fff; }
button.secondary:hover { border-color: var(--ink-soft); transform: translateY(-1px); }
button:focus-visible { outline: 3px solid rgba(13, 92, 99, .4); outline-offset: 1px; }

details.notes { margin-top: 18px; border: 1px solid var(--line); border-left: 4px solid var(--orange); border-radius: 3px; background: var(--paper); }
details.notes summary { padding: 12px 16px; font: 900 14px var(--serif); letter-spacing: .06em; list-style: none; cursor: pointer; user-select: none; }
details.notes summary::before { content: '▸ '; color: var(--orange); }
details.notes[open] summary::before { content: '▾ '; }
.notes-body { padding: 0 18px 16px; color: var(--ink-soft); font-size: 13.5px; line-height: 2; }
.notes-body b { color: var(--ink); }
.notes-body code { padding: 1px 6px; border: 1px solid var(--line); border-radius: 3px; color: var(--teal-deep); background: #fff; font: 12.5px var(--mono); }
.notes-body ol, .notes-body ul { margin: 6px 0; padding-left: 22px; }

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

@media (max-width: 600px) {
    body { padding: 12px 8px 36px; }
    .container { padding: 14px; }
    canvas { height: 390px; }
    .btn-group { flex-direction: column; gap: 8px; }
    .topbar { align-items: flex-start; }
    .exp-no { padding-top: 9px; font-size: 10px; }
}

@media (prefers-reduced-motion: reduce) {
    .preset, button.action, .back { transition: none; }
}
