.tracks-main { width: 100%; padding: 0 0 54px; }
.portrait-required { display: none; }
.tracks-page-header { padding: 20px 22px; color: #fff; background: var(--color-brand); border-bottom: 4px solid var(--color-accent); }
.tracks-header-inner { width: min(1200px, 100%); margin: 0 auto; }
.tracks-header-inner h1 { margin: 0; color: #fff; font-size: clamp(1.7rem, 4vw, 2.5rem); }
.tracks-header-inner p { margin: 7px 0 0; color: #f3dfce; }
.tracks-page-header .back-link { display: inline-block; margin-bottom: 9px; color: #fff; font-size: .88rem; font-weight: 700; text-underline-offset: 3px; }

.tracks-game { width: min(1040px, calc(100% - 32px)); margin: 22px auto 0; padding: 24px; background: var(--color-surface); border: 1px solid var(--color-border); border-radius: 14px; box-shadow: var(--shadow-card); }

.theme-picker select { min-height: 42px; padding: 8px 34px 8px 11px; color: var(--color-ink); background: #fff; border: 1px solid #bca58f; border-radius: 8px; font: inherit; font-weight: 750; }

.game-controls { display: flex; flex-wrap: wrap; justify-content: center; gap: 7px; }
.game-controls button, .completion-card button { min-height: 44px; padding: 9px 13px; color: var(--color-ink); background: #fff; border: 1px solid var(--color-border); border-radius: 9px; font: inherit; font-weight: 800; cursor: pointer; touch-action: manipulation; }
.game-controls button:hover, .piece-palette button:hover { background: #f7ead9; border-color: #b28c68; }
.game-controls button:disabled { cursor: default; opacity: .45; }
#check-puzzle { color: #fff; background: var(--color-brand); border-color: var(--color-brand); }
.testing-control { border-style: dashed !important; }
.testing-control[aria-pressed="true"] { color: #fff; background: #765000; border-color: #765000; border-style: solid !important; }
#status { min-height: 1.5em; margin: 12px auto 4px; text-align: center; color: var(--color-muted); font-size: .9rem; line-height: 1.45; }
#status[data-kind="error"] { color: #9c2f25; font-weight: 750; }
#status[data-kind="success"] { color: #23603b; font-weight: 800; }

.play-layout { margin-top: 8px; display: grid; grid-template-columns: 168px minmax(0, 630px); justify-content: center; align-items: start; gap: 18px; }
.tool-panel { padding: 12px; background: #fffaf2; border: 1px solid var(--color-border); border-radius: 10px; }
.tool-panel h3 { margin: 0 0 9px; font-size: .94rem; text-align: center; }
.tool-panel > p { margin: 9px 0 0; color: var(--color-muted); font-size: .75rem; line-height: 1.4; text-align: center; }
.piece-palette { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; }
.piece-palette button { min-width: 0; min-height: 66px; padding: 5px 3px; display: grid; justify-items: center; align-content: center; gap: 2px; color: var(--color-ink); background: #fff; border: 1px solid #c6af99; border-radius: 7px; cursor: pointer; touch-action: manipulation; }
.piece-palette button[aria-pressed="true"] { background: #fff0ce; border-color: #a96300; box-shadow: inset 0 0 0 2px #d99320; }
.piece-palette small { font-size: .64rem; font-weight: 750; }
.piece-icon { width: 36px; height: 36px; display: block; }
.piece-icon svg { width: 100%; height: 100%; display: block; overflow: visible; }
.piece-icon path { fill: none; stroke-linecap: butt; }
.piece-icon .path-shadow { stroke: #fff; stroke-width: 24; }
.piece-icon .path-main { stroke: #3b3b3b; stroke-width: 13; }
.piece-icon .rail-ties, .piece-icon .rail-outer, .piece-icon .rail-gap, .piece-icon .rail-tie-centers,
.piece-icon .pipe-shadow, .piece-icon .pipe-outer, .piece-icon .pipe-inner, .piece-icon .pipe-highlight,
.piece-icon .wire-shadow, .piece-icon .wire-casing, .piece-icon .wire-core { display: none; }
.piece-palette[data-theme="railroad"] .path-main { display: none; }
.piece-palette[data-theme="railroad"] .path-shadow { stroke-width: 36; }
.piece-palette[data-theme="railroad"] .rail-ties { display: block; stroke: #80572f; stroke-width: 31; stroke-dasharray: 3 9; }
.piece-palette[data-theme="railroad"] .rail-outer { display: block; stroke: #343638; stroke-width: 20; }
.piece-palette[data-theme="railroad"] .rail-gap { display: block; stroke: #f0ddba; stroke-width: 9; }
.piece-palette[data-theme="railroad"] .rail-tie-centers { display: block; stroke: #80572f; stroke-width: 9; stroke-dasharray: 3 9; }
.piece-palette[data-theme="plumbing"] .path-main,
.piece-palette[data-theme="electrical"] .path-main { display: none; }
.piece-palette[data-theme="plumbing"] .pipe-shadow { display: block; stroke: #fff; stroke-width: 34; }
.piece-palette[data-theme="plumbing"] .pipe-outer { display: block; stroke: #6c3923; stroke-width: 25; }
.piece-palette[data-theme="plumbing"] .pipe-inner { display: block; stroke: #b96f43; stroke-width: 19; }
.piece-palette[data-theme="plumbing"] .pipe-highlight { display: block; stroke: #f0b17b; stroke-width: 4; stroke-dasharray: 24 8; }
.piece-palette[data-theme="electrical"] .wire-shadow { display: block; stroke: #fff; stroke-width: 28; }
.piece-palette[data-theme="electrical"] .wire-casing { display: block; stroke: #26323a; stroke-width: 17; }
.piece-palette[data-theme="electrical"] .wire-core { display: block; stroke: #e3a424; stroke-width: 7; }
.erase-icon { width: 34px; height: 34px; display: grid; place-items: center; color: #5e544b; font-size: 1.45rem; font-weight: 500; line-height: 1; }

.board-wrap { width: min(100%, 630px); }
.tracks-board { --track-color: #353535; position: relative; width: 100%; display: grid; grid-template-columns: repeat(9, minmax(0, 1fr)); grid-template-rows: repeat(9, minmax(0, 1fr)); aspect-ratio: 1; -webkit-user-select: none; user-select: none; touch-action: manipulation; }
.clue-corner, .column-clue, .row-clue, .track-cell { min-width: 0; min-height: 0; }
.column-clue, .row-clue { position: relative; display: grid; place-items: center; color: #3c2e24; font: 850 clamp(.8rem, 2.5vw, 1.15rem)/1 Arial, sans-serif; }
.column-clue.complete, .row-clue.complete { color: #23603b; background: #e8f4e9; border-radius: 50%; }
.column-clue.exceeded, .row-clue.exceeded { color: #fff; background: #a84035; border-radius: 50%; }
.column-clue[data-count-mark]:not([data-count-mark=""])::after,
.row-clue[data-count-mark]:not([data-count-mark=""])::after {
    content: attr(data-count-mark) / "";
    position: absolute;
    inset: auto 9% 7% auto;
    font-size: .62em;
}
.track-cell { position: relative; width: auto; padding: 0; display: grid; place-items: center; overflow: visible; color: var(--color-ink); background: #fff; border: 0; border-right: 1px solid #aa9b8e; border-bottom: 1px solid #aa9b8e; border-radius: 0; cursor: crosshair; -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
.track-cell.first-row { border-top: 3px solid #563b28; }
.track-cell.first-column { border-left: 3px solid #563b28; }
.track-cell.last-row { border-bottom: 3px solid #563b28; }
.track-cell.last-column { border-right: 3px solid #563b28; }
.track-cell.fixed { background: #fff0cf; cursor: default; }
.track-cell.error { background-color: #ffe1dd; box-shadow: inset 0 0 0 3px #b23b30; z-index: 2; }
.track-cell:focus-visible { outline: 4px solid var(--color-accent); outline-offset: -5px; z-index: 4; }
.cell-piece { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; overflow: visible; }
.cell-piece svg { width: 100%; height: 100%; display: block; overflow: visible; }
.solution-piece { z-index: 5; opacity: .25; }
.cell-piece .path-shadow { fill: none; stroke: #fff; stroke-width: 24; stroke-linecap: butt; }
.cell-piece .path-main { fill: none; stroke: var(--track-color); stroke-width: 14; stroke-linecap: butt; }
.cell-piece .rail-ties, .cell-piece .rail-outer, .cell-piece .rail-gap, .cell-piece .rail-tie-centers,
.cell-piece .pipe-shadow, .cell-piece .pipe-outer, .cell-piece .pipe-inner, .cell-piece .pipe-highlight,
.cell-piece .wire-shadow, .cell-piece .wire-casing, .cell-piece .wire-core { display: none; fill: none; stroke-linecap: butt; }
.empty-mark { color: #9a625d; font: 500 clamp(1rem, 5vw, 2rem)/1 Arial, sans-serif; opacity: .72; }
.theme-device { position: absolute; left: 3px; bottom: 3px; z-index: 7; min-width: 16px; height: 16px; padding: 0 3px; display: grid; place-items: center; color: #fff; background: #456f76; border: 1px solid #fff; border-radius: 8px; box-shadow: 0 1px 3px rgba(0,0,0,.35); font: 800 8px/1 Arial, sans-serif; pointer-events: none; }
.battery-device { color: #27220e; background: #f5d34e; }
.bulb-device { color: #77610b; background: #fff4a8; font-size: 11px; }
.tracks-board.solved[data-theme="electrical"] .bulb-device { color: #fff; background: #ffd83d; box-shadow: 0 0 9px 4px rgba(255, 216, 61, .8); }
.fixed-mark { position: absolute; top: 3px; right: 4px; width: 8px; height: 8px; background: #8d5a20; border-radius: 50%; box-shadow: 0 0 0 2px #fff0cf; }
.grid-puzzle-id { min-height: 1.1em; margin-top: 14px; color: #76695e; font-size: .68rem; font-weight: 700; letter-spacing: .03em; text-align: right; }

.tracks-board[data-theme="railroad"] .path-main { display: none; }
.tracks-board[data-theme="railroad"] .path-shadow { stroke-width: 36; }
.tracks-board[data-theme="railroad"] .rail-ties,
.print-tracks .rail-ties { display: block; stroke: var(--rail-crossbeam, #80572f); stroke-width: 31; stroke-dasharray: 3 9; }
.tracks-board[data-theme="railroad"] .rail-outer,
.print-tracks .rail-outer { display: block; stroke: var(--rail-stroke, #343638); stroke-width: 20; }
.tracks-board[data-theme="railroad"] .rail-gap,
.print-tracks .rail-gap { display: block; stroke: var(--rail-gap, #f0ddba); stroke-width: 9; }
.tracks-board[data-theme="railroad"] .rail-tie-centers,
.print-tracks .rail-tie-centers { display: block; stroke: var(--rail-crossbeam, #80572f); stroke-width: 9; stroke-dasharray: 3 9; }
.tracks-board[data-theme="plumbing"] .path-main,
.tracks-board[data-theme="electrical"] .path-main { display: none; }
.tracks-board[data-theme="plumbing"] .pipe-shadow { display: block; stroke: #fff; stroke-width: 36; }
.tracks-board[data-theme="plumbing"] .pipe-outer { display: block; stroke: #6c3923; stroke-width: 27; }
.tracks-board[data-theme="plumbing"] .pipe-inner { display: block; stroke: #b96f43; stroke-width: 20; }
.tracks-board[data-theme="plumbing"] .pipe-highlight { display: block; stroke: #f4bd8d; stroke-width: 4; stroke-dasharray: 26 9; }
.tracks-board[data-theme="electrical"] .wire-shadow { display: block; stroke: #fff; stroke-width: 30; }
.tracks-board[data-theme="electrical"] .wire-casing { display: block; stroke: #26323a; stroke-width: 18; }
.tracks-board[data-theme="electrical"] .wire-core { display: block; stroke: #e3a424; stroke-width: 7; }
.tracks-board.solved { filter: drop-shadow(0 0 7px rgba(35, 96, 59, .45)); }

.theme-completion-animation { position: absolute; z-index: 8; left: 11.111%; top: 11.111%; width: 88.889%; height: 88.889%; overflow: visible; pointer-events: none; }
.theme-completion-animation[hidden] { display: none; }
.theme-completion-animation svg { width: 100%; height: 100%; overflow: visible; }
.completion-route { fill: none; stroke-linecap: round; stroke-linejoin: round; }
.train-guide { stroke: rgba(255,255,255,.55); stroke-width: 3; }
.completion-train rect { fill: #b51f24; stroke: #fff; stroke-width: 4; }
.completion-train circle { fill: #252525; stroke: #fff; stroke-width: 2; }
.pipe-flow-base { stroke: rgba(27,83,112,.25); stroke-width: 16; }
.water-flow { stroke: #39a8e0; stroke-width: 8; stroke-dasharray: 18 20; animation: water-flow 1s linear infinite; }
.circuit-glow { stroke: #ffd83d; stroke-width: 13; filter: drop-shadow(0 0 8px #ffd83d); animation: circuit-pulse .9s ease-in-out infinite alternate; }
.completion-bulb circle { fill: #ffdf42; stroke: #fff3a0; stroke-width: 8; filter: drop-shadow(0 0 12px #ffd83d); }
.completion-bulb path { fill: none; stroke: #765e00; stroke-width: 7; stroke-linecap: round; }
@keyframes water-flow { to { stroke-dashoffset: -38; } }
@keyframes circuit-pulse { to { opacity: .55; stroke-width: 8; } }

.rules-card { width: min(100%, 670px); margin: 20px auto 0; text-align: left; border: 1px solid var(--color-border); border-radius: 10px; background: #fff; }
.rules-card summary { padding: 13px 15px; font-weight: 800; cursor: pointer; }
.rules-content { padding: 0 16px 14px; line-height: 1.55; }
.rules-content p:first-child { margin-top: 0; }
.rules-content ul { padding-left: 22px; }
.rules-content li + li { margin-top: 7px; }

.completion { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 20px; background: rgba(43, 25, 14, .72); }
.completion[hidden] { display: none; }
.completion-card { width: min(430px, 100%); padding: 30px 26px; text-align: center; background: #fffaf2; border: 4px solid #4e8060; border-radius: 20px; box-shadow: 0 28px 80px rgba(20, 10, 4, .45); animation: completion-pop .42s ease-out both; }
.completion-art { min-height: 1.3em; margin: 0 auto 5px; font-size: 2.2rem; line-height: 1; }
.completion-mark { width: 64px; height: 64px; margin: -64px auto 12px; display: grid; place-items: center; color: #fff; background: #4e8060; border: 5px solid #fffaf2; border-radius: 50%; font-size: 2rem; }
.completion-card > p:first-of-type { margin: 0; color: #23603b; font-size: .76rem; font-weight: 850; letter-spacing: .12em; text-transform: uppercase; }
.completion-card h2 { margin: 4px 0 10px; color: var(--color-brand-strong); font-size: clamp(2rem, 8vw, 3.2rem); }
.completion-card button { min-width: 130px; color: #fff; background: var(--color-brand); border-color: var(--color-brand); }
@keyframes completion-pop { from { opacity: 0; transform: translateY(20px) scale(.88); } }

@media (max-width: 780px) {
    .tracks-page-header { padding: 14px; }
    .tracks-game { width: calc(100% - 20px); padding: 18px 10px; }
    .play-layout { grid-template-columns: 1fr; gap: 10px; }
    .board-wrap { margin: 0 auto; }
    .tool-panel { width: min(100%, 630px); margin: 0 auto; }
    .piece-palette { grid-template-columns: repeat(8, minmax(0, 1fr)); }
    .piece-palette button { min-height: 56px; }
    .piece-palette small { display: none; }
    .tool-panel > p { margin-top: 6px; }
}

@media (max-width: 600px) {
    .theme-picker select { width: 100%; }
    .game-controls { display: grid; grid-template-columns: repeat(3, 1fr); }
    .game-controls button { min-width: 0; padding-inline: 4px; }
    #check-puzzle { grid-column: span 2; }
    .piece-palette button { min-height: 48px; padding: 3px 1px; }
    .piece-icon { width: 30px; height: 30px; }
    .erase-icon { width: 29px; height: 29px; font-size: 1.5rem; }
    .tool-panel > p { font-size: .74rem; }
    .column-clue, .row-clue { font-size: clamp(.75rem, 4vw, 1rem); }
}

@media (max-width: 360px) {
    .tracks-game { width: calc(100% - 10px); padding-inline: 5px; }
    .piece-icon { width: 27px; height: 27px; }
    .game-controls button { font-size: .8rem; }
    .fixed-mark { width: 6px; height: 6px; }
}

@media (orientation: landscape) and (max-height: 600px) and (pointer: coarse) {
    .portrait-required { position: fixed; inset: 0; z-index: 1000; padding: 24px; display: grid; place-items: center; color: #3c2e24; background: #fffaf2; }
    .portrait-required-card { width: min(460px, 100%); padding: 24px; text-align: center; background: #fff; border: 3px solid var(--color-brand); border-radius: 18px; box-shadow: var(--shadow-card); }
    .portrait-required-card h1 { margin: 6px 0 8px; color: var(--color-brand-strong); font-size: clamp(1.65rem, 7vw, 2.4rem); }
    .portrait-required-card p { margin: 0 0 18px; }
    .portrait-required-card a { display: inline-block; padding: 10px 14px; color: #fff; background: var(--color-brand); border-radius: 8px; font-weight: 800; text-decoration: none; }
    .rotate-phone-icon { display: block; color: var(--color-accent); font-size: 3rem; font-weight: 900; line-height: 1; }
}

@media (prefers-contrast: more) {
    .track-cell { border-color: #302820; }
    .track-cell.fixed { box-shadow: inset 0 0 0 3px #6f4318; }
    .column-clue.complete, .row-clue.complete { outline: 2px solid #155b2e; }
}

@media (prefers-reduced-motion: reduce) {
    .completion-card, .water-flow, .circuit-glow { animation: none; }
    .completion-train animateMotion { display: none; }
}

#tracks-printout { display: none; }

@page { size: letter portrait; margin: .5in; }

@media print {
    html, body.site-frame { display: block !important; height: auto; overflow: visible; margin: 0; padding: 0; background: #fff; color: #000; }
    body.site-frame > :not(#tracks-printout) { display: none !important; }
    #tracks-printout { display: block; }
    .tracks-print-sheet {
        width: min(100%, 7.1in);
        margin: 0 auto;
        color: #000;
        font: 12pt/1.35 Arial, sans-serif;
        break-inside: avoid;
    }
    .tracks-print-sheet + .tracks-print-sheet { break-before: page; page-break-before: always; }
    .tracks-print-sheet h1 { margin: 0 0 .1in; font-size: 24pt; }
    .print-details { margin: 0 0 .2in; font-weight: bold; }
    .print-instructions { min-height: .6in; margin: 0 0 .12in; }
    .print-tracks { --rail-crossbeam: #333; --rail-stroke: #000; --rail-gap: #fff; }
    .print-grid > svg { display: block; width: 75%; height: auto; margin-inline: auto; }
    .print-credit { margin: .14in 0 0; text-align: center; }
}


.tracks-play-back { display: block; width: fit-content; margin: 14px auto 0; font-weight: 750; }
.tracks-play-back + .tracks-game { margin-top: 10px; }
.tracks-library { width: min(820px, calc(100% - 24px)); margin: 20px auto; }
.tracks-library table { width: 100%; border-collapse: collapse; color: var(--color-ink); background: #fff; }
.tracks-library th, .tracks-library td {
    padding: 9px clamp(4px, 1.5vw, 14px);
    border-bottom: 1px solid var(--color-border);
    text-align: left;
    font-size: clamp(.81rem, 3vw, 1rem);
}
.tracks-library thead { background: #f7ead9; }
.tracks-library tbody tr:hover, .tracks-library tbody tr:focus-within { background: #fff7e9; }
.tracks-library tbody a { display: inline-block; padding-block: 5px; font-weight: 750; }
.tracks-library td[data-solved] { color: #23603b; font-weight: 750; }

.tracks-library-header { display: flex; align-items: center; gap: clamp(12px, 4vw, 48px); }
.tracks-header-engine { display: block; width: clamp(92px, 24vw, 290px); height: auto; flex: none; }
.tracks-library .tracks-engine-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: clamp(42px, 8vw, 76px);
    min-height: 40px;
    padding: 3px;
    border: 1px solid #bca58f;
    border-radius: 6px;
    background: #f7ead9;
    vertical-align: middle;
}
.tracks-library .tracks-engine-link:hover { background: #f0dabc; }
.tracks-engine-link img { display: block; width: 100%; height: 33px; object-fit: contain; }

.game-heading {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: center;
    gap: 8px 16px;
    margin-bottom: 14px;
}
.game-heading h1 { margin: 0; font-size: clamp(1.65rem, 5vw, 2.15rem); }
.puzzle-meta:not([hidden]) { display: flex; flex-wrap: wrap; gap: 5px; }
.puzzle-meta span {
    padding: 4px 8px;
    color: #4c3828;
    background: #fff7e9;
    border: 1px solid #d9bea0;
    border-radius: 999px;
    font-size: .76rem;
    font-weight: 800;
}

.tracks-library time { white-space: nowrap; }
@media (max-width: 420px) {
    .tracks-library th, .tracks-library td { padding-inline: 4px; font-size: .76rem; }
    .tracks-library .tracks-engine-link { width: 38px; }
}
