:root{font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Arial,sans-serif;color:#373229;background:#e5dac8;color-scheme:light}
*{box-sizing:border-box}html,body{margin:0;width:100%;height:100%;overflow:hidden;overscroll-behavior:none;-webkit-text-size-adjust:100%}
button{font:inherit;cursor:pointer;-webkit-tap-highlight-color:transparent}
button:focus-visible,[role=button]:focus-visible,[role=slider]:focus-visible{outline:3px solid #245f56;outline-offset:4px}
.app{display:flex;flex-direction:column;width:100%;height:100vh;height:100dvh;overflow:hidden;background:linear-gradient(145deg,#ebe0cf,#d8c7ad)}
.head{display:flex;align-items:center;justify-content:space-between;gap:12px;min-height:59px;padding:calc(9px + env(safe-area-inset-top)) max(13px,env(safe-area-inset-right)) 9px max(13px,env(safe-area-inset-left));background:#f6f1e7;border-bottom:1px solid #cfc2af;z-index:2}
.identity{display:flex;flex-direction:column;min-width:0;gap:3px}
.identity strong{font:700 clamp(16px,2.3vw,24px) Georgia,"Times New Roman",serif;white-space:nowrap;letter-spacing:-.3px}
.identity strong span{color:#706356}
.identity small{font:700 9px/1.1 Arial,sans-serif;letter-spacing:1.4px;color:#8b7c68;white-space:nowrap}
.header-buttons{display:flex;align-items:center;gap:7px}
.header-buttons button{border:1px solid #b7ab98;border-radius:7px;background:#ebe4d6;min-width:37px;min-height:35px;padding:7px 11px;color:#504436;font-weight:800;font-size:10px}
.header-buttons #open-guide{font-size:18px;padding:3px 13px}
.stage{display:flex;align-items:center;justify-content:center;min-width:0;min-height:0;flex:1 1 auto;overflow:hidden}
#machine{display:block;width:100%;height:100%;object-fit:contain;touch-action:none;user-select:none;-webkit-user-select:none}
#machine [data-action],#machine [data-lever],#machine [data-carriage-drag]{-webkit-tap-highlight-color:transparent}
#machine [data-action]:active{filter:brightness(.85)}
#machine #carriage{transition:transform 280ms cubic-bezier(.22,.75,.22,1);transform-box:view-box}
#machine .engaged{filter:drop-shadow(0 0 8px #bb873f)}
#machine .turn-cw{animation:windClockwise 710ms ease-in-out}
#machine .turn-ccw{animation:windAnticlockwise 710ms ease-in-out}
#machine #operating-crank{transform-origin:1205px 298px;transform-box:view-box}
@keyframes windClockwise{from{rotate:0deg}to{rotate:360deg}}
@keyframes windAnticlockwise{from{rotate:0deg}to{rotate:-360deg}}
.foot{display:flex;flex:0 0 auto;gap:min(3vw,30px);align-items:center;justify-content:center;flex-wrap:nowrap;padding:8px 15px 5px;background:#f6f1e7;border-top:1px solid #c2b5a3}
.readout{display:flex;min-width:0;align-items:center;flex-direction:column;gap:2px}
.readout small{font-size:9px;font-weight:800;letter-spacing:1.1px;color:#847566}
.readout output{font:700 clamp(12px,2.3vw,24px)/1.25 ui-monospace,Consolas,monospace;white-space:nowrap;font-variant-numeric:tabular-nums;color:#3b332e}
.status{padding:5px 12px calc(8px + env(safe-area-inset-bottom));font-size:12px;font-weight:600;color:#605242;text-align:center;background:#f6f1e7;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;min-height:26px}
.status.error{color:#942c25;background:#fbe9e2}
dialog{width:min(640px,94vw);max-height:85dvh;padding:0;border:1px solid #b8a995;border-radius:12px;background:#fffaf1;color:#332c26;box-shadow:0 20px 70px #26221f7a}
dialog::backdrop{background:#18171088}
dialog header{position:sticky;top:0;background:#f3eadc;display:flex;align-items:center;justify-content:space-between;padding:12px 18px;border-bottom:1px solid #d5c4ae;z-index:1}
dialog h2{font-size:18px;margin:0}
dialog header button{border:0;border-radius:6px;background:#e2d5c2;padding:4px 12px;font-size:24px}
.guide-body{overflow:auto;touch-action:pan-y;overscroll-behavior:contain;max-height:calc(85dvh - 62px);padding:14px 20px 28px;font-size:14px;line-height:1.5}
.guide-body p{margin:4px 0 13px}.guide-body h3{margin:16px 0 5px;font-size:15px}.guide-body label{display:block;margin:9px 0}
@media(max-width:680px){.head{min-height:48px;padding:calc(6px + env(safe-area-inset-top)) 9px 5px}.identity strong{font-size:15px}.identity small{font-size:6.5px;letter-spacing:.65px}.header-buttons button{padding:6px 8px;min-height:29px}.foot{gap:7px;padding:5px 6px}.readout small{font-size:7px;letter-spacing:0}.readout output{font-size:clamp(10px,3.3vw,16px)}.status{font-size:10px;padding:4px 8px calc(5px + env(safe-area-inset-bottom))}}
@media(orientation:landscape) and (max-height:600px){.head{min-height:33px;padding:3px 9px}.identity small{display:none}.identity strong{font-size:16px}.header-buttons button{min-height:28px;padding:3px 9px}.foot{padding:3px 8px}.readout small{font-size:7px}.readout output{font-size:14px}.status{padding:2px 8px;font-size:10px;min-height:15px}}
@media(prefers-reduced-motion:reduce){#machine #carriage{transition:none}#machine .turn-cw,#machine .turn-ccw{animation:none}}

/* Portrait keeps the live machine in the upper part, with LARGE mechanical
   controls in the BOTTOM half, as established in the original design. */
.portrait-panel{display:none}
@media(orientation:portrait){
 .app{background:#efe6d6}
 .stage{flex:0 0 39%;background:#e9dac6}
 .portrait-panel{display:flex;flex:1 1 auto;flex-direction:column;gap:5px;min-height:0;overflow:hidden;padding:7px 10px;background:#f2eddf;border-top:1px solid #c9bda8}
 .selector-heading,.portrait-position{display:flex;align-items:center;justify-content:space-between;flex:none;color:#746452;font-size:10px;letter-spacing:.7px;font-weight:800}
 .selector-heading span{font:700 13px/1.2 ui-monospace,Consolas,monospace;letter-spacing:1px;color:#362f28}
 .portrait-selectors{display:grid;grid-template-columns:repeat(10,minmax(0,1fr));gap:4px;flex:1 1 auto;min-height:74px;max-height:200px}
 .portrait-selector{display:flex;flex-direction:column;position:relative;align-items:center;min-width:0;border:1px solid #b9aa95;border-radius:5px;background:linear-gradient(90deg,#ddd0bb 0%,#fbf7ed 45%,#e0d3be 100%);touch-action:none;user-select:none;-webkit-user-select:none;cursor:ns-resize}
 .portrait-selector .place{flex:0 0 auto;font:700 10px/1.1 ui-monospace,monospace;color:#6e604d;padding-top:3px}
 .portrait-selector .track{position:relative;flex:1 1 auto;min-height:28px;width:100%;margin:5px 0 3px;touch-action:none}
 .portrait-selector .track::before{content:'';position:absolute;top:0;bottom:0;left:calc(50% - 2px);width:4px;background:#464640;border-radius:3px;box-shadow:inset 1px 0 2px #161915}
 .portrait-selector .knob{position:absolute;left:11%;width:78%;height:15px;top:0;transform:translateY(-50%);border-radius:4px;background:linear-gradient(145deg,#777d7f,#202328 68%);border:1px solid #9fa6a3;box-shadow:0 2px 3px #0006;pointer-events:none;transition:top 100ms ease-out}
 .portrait-selector .value{flex:0 0 auto;font:800 14px/1.2 ui-monospace,monospace;color:#41382e;padding-bottom:3px}
 .portrait-selector .bubble{display:none;position:absolute;z-index:5;top:-27px;left:50%;transform:translateX(-50%);color:white;background:#2a3633;border-radius:5px;padding:3px 7px;font:700 14px ui-monospace,monospace;pointer-events:none}
 .portrait-selector.active .bubble{display:block}.portrait-selector.active .knob{transition:none}
 .portrait-position{border-top:1px solid #d8c9b6;padding-top:4px}
 .portrait-position output{font:800 12px ui-monospace,monospace}
 .portrait-buttons{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));grid-template-rows:repeat(4,minmax(32px,1fr));gap:5px;flex:0 0 clamp(145px,24dvh,196px)}
 .portrait-buttons button{min-width:0;min-height:0;padding:4px;border:1px solid #b9aa95;border-radius:6px;background:#fffaf0;color:#4c4031;font-size:clamp(9px,2.6vw,12px);font-weight:800;letter-spacing:.25px;touch-action:manipulation}
 .portrait-buttons .turn-add,.portrait-buttons .turn-sub{background:#475c53;color:#fff;font-size:15px;border-color:#344a41}
 .portrait-buttons .turn-add strong,.portrait-buttons .turn-sub strong{font-size:11px}
 .portrait-buttons .transfer-control{background:#e8ddbd;color:#4a3822}
 .portrait-buttons button:active{filter:brightness(.86)}
 .foot{flex:0 0 auto}.status{flex:0 0 auto}
}
@media(orientation:portrait) and (max-height:760px){
 .stage{flex-basis:35%}.portrait-panel{padding:5px 8px;gap:3px}.portrait-buttons{flex-basis:clamp(120px,21dvh,158px);gap:4px;grid-template-rows:repeat(4,minmax(27px,1fr))}
 .portrait-selectors{min-height:58px}.portrait-position{padding-top:1px}.portrait-selector .track{margin:3px 0 2px}
}

/* Physical controls: each large hit target contains a miniature representation
   of the matching part on the photographed Model 239. */
@media(orientation:portrait){
 .portrait-buttons button.mechanical-button{
   display:flex;align-items:center;justify-content:flex-start;gap:clamp(4px,1.5vw,9px);
   padding:2px 7px;background:linear-gradient(165deg,#fcf8ed 0%,#e7dcc9 100%);
   border:1px solid #b3a48f;border-bottom:2px solid #a59783;
   box-shadow:inset 0 1px 0 #fffdf6,0 1px 2px #75695731;
   color:#42382e;letter-spacing:.12px;position:relative;overflow:hidden;
 }
 .portrait-buttons .mechanical-button .mechanic-icon{width:clamp(33px,10.1vw,45px);height:clamp(27px,7.5vw,35px);flex:0 0 auto;overflow:visible}
 .portrait-buttons .mechanical-button .mechanic-label{font-size:clamp(9px,2.55vw,11px);font-weight:800;line-height:1.12;text-align:center;flex:1 1 auto;white-space:normal}
 .portrait-buttons .mechanical-button .direction{font-size:14px;font-weight:900;color:#4e5a50}
 .portrait-buttons .mechanical-button.turn-add,.portrait-buttons .mechanical-button.turn-sub{
   background:linear-gradient(160deg,#f9f6ec,#dcd2bd);color:#41362a
 }
 .portrait-buttons .mechanical-button.turn-add .mechanic-label,.portrait-buttons .mechanical-button.turn-sub .mechanic-label{font-size:clamp(10px,2.65vw,12px)}
 .portrait-buttons .mechanical-button.transfer-control.engaged{
   background:linear-gradient(160deg,#f4e7cb,#d9c59e);box-shadow:inset 0 2px 6px #927c5166
 }
 .portrait-buttons .mechanical-button.is-moving{filter:brightness(.93);box-shadow:inset 0 3px 6px #554a393b}
 .portrait-buttons .mechanical-button .crank-motion,
 .portrait-buttons .mechanical-button .clear-turn,
 .portrait-buttons .mechanical-button .shift-key,
 .portrait-buttons .mechanical-button .quick-tab,
 .portrait-buttons .mechanical-button .transfer-pull{
   transform-box:view-box
 }
 .portrait-buttons [data-panel-action="cw"].is-moving .crank-motion{
   transform-origin:19px 21px;animation:portrait-crank-cw 720ms cubic-bezier(.2,.4,.4,1)
 }
 .portrait-buttons [data-panel-action="ccw"].is-moving .crank-motion{
   transform-origin:19px 21px;animation:portrait-crank-ccw 720ms cubic-bezier(.2,.4,.4,1)
 }
 .portrait-buttons .clear-control.is-moving .clear-turn{
   transform-origin:13px 13px;animation:portrait-crank-cw 680ms ease-in-out
 }
 .portrait-buttons .shift-control.is-moving .shift-key{animation:portrait-key-depress 220ms ease-out}
 .portrait-buttons .quick-control.is-moving .quick-tab{animation:portrait-quick-clear 600ms ease-in-out}
 .portrait-buttons .transfer-control.is-moving .transfer-pull{animation:portrait-pull 350ms ease-out}
 .portrait-buttons .transfer-control.engaged .transfer-pull{transform:translateX(6px)}
 .portrait-selector .knob{transition:top 200ms cubic-bezier(.18,.9,.25,1)}
}
@keyframes portrait-crank-cw{0%{transform:rotate(0)}100%{transform:rotate(360deg)}}
@keyframes portrait-crank-ccw{0%{transform:rotate(0)}100%{transform:rotate(-360deg)}}
@keyframes portrait-key-depress{0%,100%{transform:translateY(0)}35%{transform:translateY(5px) scale(.94)}}
@keyframes portrait-quick-clear{0%,100%{transform:translate(0,0) rotate(0)}28%{transform:translate(-5px,1px) rotate(-12deg)}58%{transform:translate(-7px,2px) rotate(-18deg)}}
@keyframes portrait-pull{0%{transform:translateX(0)}55%{transform:translateX(10px)}100%{transform:translateX(6px)}}
#machine [data-lever] rect:nth-child(-n+2){transition:transform 180ms ease-out}
#machine .wheel-rolling{animation:wheel-turn-visual 390ms ease-out both;animation-delay:var(--wheel-delay,0ms)}
@keyframes wheel-turn-visual{
 0%{opacity:.35;transform:translateY(-7px)}
 45%{opacity:.75;transform:translateY(3px)}
 100%{opacity:1;transform:translateY(0)}
}
#machine [data-action="input-clear"].operating {animation:portrait-quick-clear 550ms ease-in-out;transform-origin:1185px 391px}
#machine [data-action="counter-clear"].operating,#machine [data-action="acc-clear"].operating{animation:portrait-crank-cw 630ms ease-in-out;transform-box:fill-box;transform-origin:center}
#machine [data-action="left"].operating,#machine [data-action="right"].operating{animation:portrait-key-depress 220ms}
#machine [data-action="transfer"].engaged{transform:translateX(7px)}
@media(orientation:portrait) and (max-width:380px){
 .portrait-buttons .mechanical-button .mechanic-icon{width:32px}
 .portrait-buttons .mechanical-button{gap:3px;padding:1px 4px}
 .portrait-buttons .mechanical-button .mechanic-label{font-size:9px}
}
@media(prefers-reduced-motion:reduce){
 .portrait-buttons .mechanical-button.is-moving svg *,
 #machine .wheel-rolling,
 #machine [data-action].operating{animation:none!important}
}
/* Photograph-matched input checking drums, one per slider in portrait. */
.portrait-selector .dial-window{display:flex;align-items:center;justify-content:center;flex:0 0 auto;width:76%;min-height:17px;margin-top:2px;border:1px solid #8c806e;border-radius:3px;background:linear-gradient(180deg,#655649,#29231f);box-shadow:inset 0 1px 0 #c8b6a044;overflow:hidden}
.portrait-selector .dial-value{font:700 13px/1.1 Georgia,serif;color:#eee8dc;min-width:1ch;text-align:center;display:block}
.portrait-selector .dial-value.roll{animation:odhn-dial-rotate 340ms ease-out}
#machine .setting-wheel-animate{animation:odhn-dial-rotate 340ms ease-out}
#machine .wheel-rolling{animation:odhn-wheel-rotate 440ms ease-out both;animation-delay:var(--wheel-delay,0ms)}
@keyframes odhn-dial-rotate{0%{opacity:.18;transform:translateY(-12px)}55%{opacity:1;transform:translateY(3px)}100%{opacity:1;transform:translateY(0)}}
@keyframes odhn-wheel-rotate{0%{opacity:.22;transform:translateY(-8px)}50%{opacity:.8;transform:translateY(3px)}100%{opacity:1;transform:translateY(0)}}
@media(prefers-reduced-motion:reduce){#machine .setting-wheel-animate,#machine .wheel-rolling,.portrait-selector .dial-value.roll{animation:none!important}}

/* Authoritative 239 mechanics: selector pins are smooth, UNCAPPED steel shafts.
   They sink below the case line during a turn; no black Bakelite mushroom heads
   are possible on the rotor's travelling pins. Keep the full touch target. */
.portrait-selector .track{overflow:hidden}
.portrait-selector .knob{
 left:calc(50% - 4.5px);width:9px;height:24px;border-radius:6px;
 background:linear-gradient(90deg,#787f7e 0%,#e9ede8 25%,#fdfef8 45%,#9aa19e 72%,#606967 100%);
 border:1px solid #818782;box-shadow:inset 1px 0 2px #fff8,1px 1px 2px #0006;
}
.portrait-selector .knob::after{content:'';position:absolute;top:2px;bottom:3px;left:3px;width:1px;background:#fff9;border-radius:1px}
#machine .selector-pin{pointer-events:none}
@media(prefers-reduced-motion:reduce){#machine .selector-pin,.portrait-selector .knob{animation:none!important}}


/* Portrait register prominence: the real machine has three mechanically
   significant registers. They belong among the OPERATING CONTROLS and must
   never be reduced to a tiny footer or a secondary afterthought. */
@media(orientation:portrait){
 .stage{flex:0 0 34%}
 .foot{display:none}
 .portrait-panel{gap:5px;padding:6px 9px}
 .portrait-register-bank{flex:0 0 auto;display:flex;flex-direction:column;gap:4px;padding:5px 6px;background:#e1d5c3;border:1px solid #b4a58f;border-radius:8px;box-shadow:inset 0 1px 0 #fff9}
 .minor-registers{display:grid;grid-template-columns:1fr 1fr;gap:5px;min-width:0}
 .mechanical-register{display:flex;flex-direction:column;align-items:center;justify-content:center;gap:3px;min-width:0;background:#f9f4e8;border:1px solid #c9b9a1;border-radius:5px;padding:4px 3px 5px}
 .register-title{font:800 10px/1 ui-sans-serif,Arial,sans-serif;letter-spacing:.75px;color:#504336;display:flex;gap:6px;align-items:baseline;white-space:nowrap}
 .register-title small{font:700 8px/1.1 ui-sans-serif,Arial,sans-serif;letter-spacing:.25px;color:#887661}
 .register-digits{display:flex;align-items:center;justify-content:center;gap:1px;min-width:0;max-width:100%;height:26px;padding:2px 5px;background:linear-gradient(#887460 0%,#39312a 13%,#40362f 85%,#7b6a59 100%);border:2px solid #70614f;border-radius:3px;box-shadow:inset 0 2px 4px #08070699,0 1px 1px #fffbef;font-variant-numeric:tabular-nums}
 .register-digits .wheel-digit{display:flex;align-items:center;justify-content:center;flex:0 0 auto;width:clamp(15px,4.35vw,20px);height:21px;border-right:1px solid #877865;background:linear-gradient(180deg,#50443a,#282522 43%,#453a30);font:700 clamp(17px,4.9vw,22px)/1 Georgia,'Times New Roman',serif;color:#f5ede0;text-shadow:0 1px 1px #000}
 .register-digits .wheel-digit:last-child{border-right:0}
 .minor-registers .register-digits{height:23px;padding:2px 3px}
 .minor-registers .wheel-digit{width:clamp(12px,3.6vw,15px);height:18px;font-size:clamp(13px,3.9vw,16px)}
 .register-digits .wheel-digit.wheel-flip{animation:portrait-register-wheel-roll 390ms cubic-bezier(.22,.75,.35,1)}
 .portrait-selectors{min-height:72px;max-height:154px}
 .portrait-buttons{flex-basis:clamp(132px,19dvh,159px);grid-template-rows:repeat(4,minmax(30px,1fr))}
}
@keyframes portrait-register-wheel-roll{0%{opacity:.3;transform:translateY(-5px)}55%{opacity:.82;transform:translateY(3px)}100%{opacity:1;transform:translateY(0)}}
@media(orientation:portrait) and (max-height:760px){
 .stage{flex-basis:30%}
 .portrait-register-bank{gap:3px;padding:3px 4px}
 .mechanical-register{gap:2px;padding:2px}
 .portrait-buttons{flex-basis:clamp(120px,19dvh,146px)}
 .portrait-selectors{min-height:52px}
}
@media(prefers-reduced-motion:reduce){.register-digits .wheel-digit.wheel-flip{animation:none!important}}
