:root {
    color-scheme: dark;
    --paper: #f6e8cc;
    --subtle: #d3b996;
    --gold: #e4b87b;
    --line: #ad815553;
    --panel: #30231a;
}

html:has(.hair-rescue) { overflow: hidden; }
.hair-rescue {
    margin: 0;
    color: var(--paper);
    font: 15px/1.45 system-ui, Tahoma, sans-serif;
    background: radial-gradient(ellipse at 50% 5%, #4b3021, #201812 58%, #15110e);
}
.hair-rescue:has(#game-hearts-hud:not([hidden])) { --rescue-hearts: var(--hp-height, 38px); }
.hair-rescue :is(button, summary, a, input, canvas):focus-visible { outline: 2px solid #ffdc9e; outline-offset: 2px; }
.hair-rescue *, .hair-rescue *::before, .hair-rescue *::after { box-sizing: border-box; }
.hair-rescue [hidden] { display: none !important; }
.rescue {
    height: calc(100dvh - var(--game-guest-height, 0px) - var(--rescue-hearts, 0px));
    max-width: 1080px;
    padding: 8px max(14px, env(safe-area-inset-left), env(safe-area-inset-right)) max(10px, env(safe-area-inset-bottom));
    margin-inline: auto;
    display: grid;
    grid-template-rows: auto minmax(0, 1fr);
    gap: 8px;
}
.rescue-header, .rescue-nav, .dialog-heading { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.rescue-header h1 { margin: 0; font-size: clamp(17px, 3vw, 29px); font-weight: 750; }
.rescue-header h1 span { color: var(--gold); margin-inline-end: .15em; }
.rescue :is(button, summary), .hair-rescue :is(#target, #client-list, #result, #shop) button {
    min-height: 38px;
    border: 1px solid var(--line);
    border-radius: 9px;
    padding: 6px 10px;
    color: var(--paper);
    background: linear-gradient(#453124, #2a2018);
    font-family: inherit;
    font-size: inherit;
    font-weight: 650;
    cursor: pointer;
}
.rescue button:disabled { opacity: .5; cursor: default; }
.rescue button[aria-pressed=true], #customer-list button[aria-current=true] {
    border-color: #edb871;
    background: linear-gradient(#60432a, #38291c);
    box-shadow: inset 0 0 0 1px #ffda9030;
}
.rescue button.gold, #result button.gold {
    color: #2a190e;
    border-color: #ffdb9d;
    background: linear-gradient(#f2d29d, #d6a263);
    box-shadow: 0 2px 8px #140d0a4d, inset 0 1px #fff4d688;
}
.rescue-menu { position: relative; z-index: 3; }
.rescue-menu summary { display: grid; place-items: center; width: 38px; list-style: none; font-size: 1.45rem; line-height: 1; }
.rescue-menu summary::-webkit-details-marker { display: none; }
.rescue-menu > div {
    position: absolute;
    inset-block-start: calc(100% + 6px);
    inset-inline-end: 0;
    width: max-content;
    min-width: 154px;
    display: grid;
    gap: 4px;
    padding: 6px;
    background: #251a13;
    border: 1px solid var(--line);
    border-radius: 11px;
    box-shadow: 0 6px 20px #0007;
}
.rescue-menu :is(a, button) { text-align: start; padding: 8px; color: var(--paper); }
.rescue-menu a { text-decoration: none; border-radius: 6px; }
.rescue-menu a:hover { background: #503a29; }
.workbench {
    min-height: 0;
    display: grid;
    grid-template-columns: minmax(0, 1.65fr) minmax(235px, 1fr);
    align-items: center;
    gap: 12px;
}
.chair {
    position: relative;
    inline-size: 100%;
    block-size: 100%;
    min-height: 0;
    max-inline-size: min(680px, calc(100dvh - var(--game-guest-height, 0px) - var(--rescue-hearts, 0px) - 60px));
    justify-self: center;
    overflow: hidden;
    isolation: isolate;
    border: 1px solid #bc9158a0;
    border-radius: 15px;
    background: #211913;
    box-shadow: 0 12px 36px #100b08a0, inset 0 0 0 2px #e4b87b16;
}
#hair { display: block; width: 100%; height: 100%; touch-action: none; cursor: crosshair; }
.chair:has(.aim:not([hidden])) #hair { cursor: none; }
.aim {
    --handle-side: 1;
    position: absolute;
    z-index: 1;
    pointer-events: none;
    transform: translate(-50%, -50%);
    border: 1px solid #ffe8b6;
    border-radius: 50%;
    box-shadow: 0 0 5px #402111, inset 0 0 4px #da9e6060;
    display: grid;
    place-items: center;
}
.aim-point { width: 3px; height: 3px; background: #ffecb9; border-radius: 50%; }
.aim.handle-left { --handle-side: -1; }
.tool-picture, .tool-cursor {
    background-image: var(--tool-sheet, url('./in-hand-tools.webp'));
    background-repeat: no-repeat;
    background-position: 0% var(--sprite-row, 0%);
    background-size: 200% 200%;
}
.tool-cursor {
    --tip-x: 7%;
    --tip-y: 50%;
    --angle: 18deg;
    position: absolute;
    top: 50%;
    left: 50%;
    width: clamp(90px, 30vw, 148px);
    aspect-ratio: 2;
    translate: calc(-1 * var(--tip-x)) calc(-1 * var(--tip-y));
    rotate: calc(var(--angle) * var(--handle-side));
    scale: var(--handle-side) 1;
    transform-origin: var(--tip-x) var(--tip-y);
    filter: var(--metal-finish, brightness(1)) drop-shadow(1px 3px 3px #160c08ac);
}
.chair[data-tool=scissors] .is-working .tool-cursor { animation: scissors-snip .19s steps(1) infinite; }
[data-tool=clipper] :is(.tool-cursor, .tool-picture) { --sprite-row: 100%; }
.chair[data-tool=clipper] .tool-cursor { --tip-y: 45%; --angle: 12deg; }
.chair[data-tool=clipper] .is-working .tool-cursor { animation: clipper-buzz .08s ease-in-out infinite alternate; }
.chair[data-tool=comb] .tool-cursor {
    --tip-x: 43%;
    --tip-y: 67%;
    --angle: -13deg;
    filter: drop-shadow(0 -1px 1px #ffe1ad70) drop-shadow(1px 3px 3px #160c08ac);
}
[data-tool=comb] :is(.tool-cursor, .tool-picture) { background-position: 100% 100%; }
[data-tool=comb] .tool-picture { filter: drop-shadow(0 -1px 0 #ffe1ad99); }
.chair[data-tool=comb] .is-working .tool-cursor { animation: comb-sweep .24s ease-out alternate infinite; }
[data-tool=razor] :is(.tool-cursor, .tool-picture) {
    background: url('./razor.webp') center / contain no-repeat;
}
.chair[data-tool=razor] .tool-cursor { --tip-x: 7%; --tip-y: 50%; --angle: 17deg; }
.chair[data-tool=razor] .is-working .tool-cursor { animation: razor-sweep .16s ease-in-out infinite alternate; }
[data-tool=foam] :is(.tool-cursor, .tool-picture) {
    --tool-sheet: url('./studio-tools.webp');
    background-position: 100% 100%;
}
.chair[data-tool=foam] .tool-cursor { --tip-x: 13%; --angle: 18deg; }
.chair[data-tool=foam] .is-working .tool-cursor { animation: brush-sweep .22s ease-in-out infinite alternate; }
.chair[data-tool=foam] .aim { border-color: #fff7dd; }
.rescue[data-scissors=scissors-rose] [data-tool=scissors],
.rescue[data-scissors=scissors-onyx] [data-tool=scissors],
.rescue[data-clipper=clipper-chrome] [data-tool=clipper],
.rescue[data-clipper=clipper-copper] [data-tool=clipper],
.shop-card:is([data-style=scissors-rose], [data-style=scissors-onyx], [data-style=clipper-chrome], [data-style=clipper-copper]) {
    --tool-sheet: url('./studio-tools.webp');
}
.rescue[data-scissors=scissors-onyx] [data-tool=scissors], .shop-card[data-style=scissors-onyx] { --metal-finish: grayscale(.88) brightness(.65) contrast(1.15); }
.rescue[data-clipper=clipper-copper] [data-tool=clipper], .shop-card[data-style=clipper-copper] { --metal-finish: sepia(.8) saturate(1.65) hue-rotate(-17deg); }
.rescue[data-chair=chair-wine] .chair { border-color: #b26c83; }
.rescue[data-chair=chair-emerald] .chair { border-color: #64aa86; }
.chair[data-tool=clipper] .aim { border-style: dashed; }
.chair[data-tool=comb] .aim { border-color: #c3ebc6; }
.chair[data-tool=razor] .aim { border-color: #d1f2ff; }
@keyframes scissors-snip {
    0%, 72% { background-position: 0% 0%; }
    32% { background-position: 100% 0%; }
}
@keyframes clipper-buzz {
    to { rotate: calc(10deg * var(--handle-side)); }
}
@keyframes comb-sweep {
    to { rotate: calc(-5deg * var(--handle-side)); }
}
@keyframes razor-sweep {
    to { rotate: calc(12deg * var(--handle-side)); }
}
@keyframes brush-sweep {
    to { rotate: calc(9deg * var(--handle-side)); }
}
.clipping {
    position: absolute;
    width: 2px;
    height: 13px;
    border-radius: 50%;
    background: linear-gradient(#e8bd87, #3e291c 42%, #1b1716);
    pointer-events: none;
    animation: hair-fall .55s ease-in forwards;
}
@keyframes hair-fall {
    from { opacity: .95; transform: rotate(5deg); }
    to { opacity: 0; transform: translate(var(--drift), 64px) rotate(var(--spin)); }
}
@media (prefers-reduced-motion: reduce) {
    .hair-rescue .chair .is-working .tool-cursor { animation: none; }
    .clipping { animation-duration: .01s; }
}
.clock {
    position: absolute;
    z-index: 2;
    top: 9px;
    left: 9px;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 3px 9px;
    border: 1px solid #e8b67fa0;
    border-radius: 9px;
    background: #22170fe8;
    color: #ffe1a7;
    direction: ltr;
    font-size: 17px;
    font-variant-numeric: tabular-nums;
}
.clock b.urgent { color: #ffa784; }
.rescue button.reference {
    position: absolute;
    z-index: 2;
    right: 9px;
    bottom: 9px;
    width: clamp(63px, 14%, 100px);
    display: grid;
    gap: 3px;
    padding: 4px;
    font-size: clamp(9px, 2vw, 12px);
    line-height: 1.2;
}
.reference canvas { display: block; width: 100%; border-radius: 5px; }
.rescue button.face-zoom {
    position: absolute;
    z-index: 2;
    left: 8px;
    bottom: 8px;
    min-width: 44px;
    min-height: 44px;
    padding: 1px;
    font-size: 23px;
    line-height: 1;
    border-color: #d4ae77b8;
    background: #271c16e8;
}
.rescue button.face-zoom[aria-pressed=true] { background: #64442c; }
.loading { position: absolute; inset: 40% 12px auto; text-align: center; text-shadow: 0 1px #000; }
.loading button { display: block; margin: 5px auto 0; }
.station {
    display: grid;
    gap: 13px;
    min-width: 0;
    padding: 17px;
    border: 1px solid var(--line);
    border-radius: 13px;
    background: linear-gradient(142deg, #3c2b20, #201813);
    box-shadow: 0 8px 25px #120d08a0, inset 0 1px #ffce9523;
}
.brief { min-width: 0; }
.brief :is(p, h2) { margin: 0; }
.brief h2 { font-size: clamp(16px, 2.4vw, 23px); }
.brief p:not(.case-counter), .hint { color: var(--subtle); }
.brief small, .case-counter { color: #e8b77e; font-size: 12px; }
.touch-tip { display: none; }
.tools { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
.full-service .tools { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.tools button { display: grid; place-items: center; gap: 3px; min-width: 0; padding: 4px 3px; font-size: 13px; }
.tool-picture { display: block; width: 65px; max-width: 100%; height: 34px; filter: var(--metal-finish, brightness(1)); }
.guards { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 4px; margin-top: 5px; font-size: 13px; }
.guards > span { grid-column: 1 / -1; font-size: 11px; }
.guards button { min-height: 34px; min-width: 0; padding: 0 4px; }
.hint { margin: 0; font-size: 12px; }
.salon-actions, .result-actions { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.5fr); gap: 6px; font-size: 13px; }
.hair-rescue :is(#target, #client-list, #result, #shop) {
    width: min(475px, calc(100% - 20px));
    max-height: calc(100dvh - 18px);
    padding: 12px;
    color: var(--paper);
    background: linear-gradient(145deg, #402d21, #211812);
    border: 1px solid #a97d52;
    border-radius: 16px;
    box-shadow: 0 15px 65px #0009, inset 0 1px #ffce953a;
    overflow: auto;
    overscroll-behavior: contain;
}
.hair-rescue :is(#target, #client-list, #result, #shop)::backdrop { background: #110c09c9; }
.dialog-heading h2 { margin: 0; font-size: 1.16rem; }
.dialog-heading button { font-size: 20px; min-width: 38px; line-height: 1; }
#target-photo { display: block; width: auto; max-width: 100%; max-height: 65dvh; margin: 8px auto; border-radius: 9px; }
#target-request { margin: 4px 0; color: var(--subtle); text-align: center; }
#customer-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; margin-top: 8px; }
#customer-list button { display: grid; text-align: start; gap: 2px; }
#customer-list :is(small, span) { color: var(--subtle); }
.shop-info { color: var(--subtle); font-size: 13px; }
.shop-info p { margin: 4px 0; }
.shop-info p:empty { display: none; }
.shop-info a { color: #f2ce93; }
#shop-items { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 7px; margin-top: 8px; }
.shop-card {
    display: grid;
    place-items: center;
    align-content: space-between;
    gap: 5px;
    min-width: 0;
    min-height: 106px;
    padding: 5px;
    border: 1px solid var(--line);
    border-radius: 9px;
    background: #1a130e87;
    text-align: center;
    font-size: 12px;
}
.shop-card button { width: 100%; padding-inline: 3px; }
.shop-card button:disabled { opacity: .69; cursor: default; }
.chair-swatch {
    width: 34px;
    height: 28px;
    border: 1px solid #ccaa8585;
    border-radius: 8px 8px 5px 5px;
    background: radial-gradient(ellipse at 25% 15%, #fff4d144, transparent 79%), var(--leather, #423827);
    box-shadow: inset 0 -5px 8px #0007, 0 3px 6px #0006;
}
.shop-card[data-style=chair-wine] { --leather: #93485e; }
.shop-card[data-style=chair-emerald] { --leather: #37795f; }
#score { display: block; text-align: center; font-size: clamp(32px, 6vw, 49px); font-weight: 800; color: #f2ce93; line-height: 1.12; }
#service-score { margin: 3px 0 0; color: #eac797; font-size: 12px; text-align: center; }
#result-note { margin: 4px 0 10px; color: var(--subtle); text-align: center; font-size: 13px; }
.comparison { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.comparison figure { margin: 0; border: 1px solid var(--line); border-radius: 9px; overflow: hidden; text-align: center; }
.comparison canvas { display: block; width: 100%; height: auto; max-height: 41dvh; object-fit: cover; object-position: center 22%; }
.comparison figcaption { padding: 4px; color: var(--subtle); font-size: 13px; }
.result-actions { grid-template-columns: 1.35fr 1fr 1fr; margin-top: 8px; }
.share-fallback { display: flex; gap: 6px; margin-top: 8px; }
.share-fallback input { flex: 1; min-width: 0; border: 1px solid var(--line); border-radius: 7px; padding-inline: 5px; direction: ltr; }
#share-feedback { margin: 5px 0 0; font-size: 13px; }
.no-script { position: fixed; z-index: 100; inset: 45% 8px auto; text-align: center; }

@media (max-width: 680px) {
    .rescue { padding: 4px max(7px, env(safe-area-inset-left), env(safe-area-inset-right)) max(5px, env(safe-area-inset-bottom)); gap: 5px; }
    .rescue-header { gap: 4px; }
    .rescue-nav { gap: 5px; }
    .rescue-nav > button { padding-inline: 6px; font-size: 12px; }
    .workbench { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr) auto; gap: 5px; align-items: stretch; }
    .chair { max-inline-size: 100%; border-radius: 10px; }
    .station { padding: 6px; gap: 5px; }
    .brief { display: flex; align-items: baseline; flex-wrap: wrap; gap: 0 6px; }
    .brief p:not(.case-counter) { flex-basis: 100%; font-size: 12px; }
    .brief small { font-size: 10px; }
    .brief .touch-tip { display: inline; }
    .hint { display: none; }
    .tools button { font-size: 12px; }
    .clock { left: 5px; top: 5px; font-size: 15px; }
    .rescue button.reference { right: 5px; bottom: 5px; }
}
@media (max-width: 680px) and (orientation: portrait) {
    .chair { max-block-size: 123vw; align-self: center; }
}
@media (max-width: 680px) and (max-height: 650px) {
    html body.hair-rescue:has(.game-guest-bar) { --game-guest-height: 42px; }
    .hair-rescue .game-guest-bar { padding-block: 3px; }
    .hair-rescue .game-guest-bar a { min-height: 34px; padding-block: 5px; }
    .tool-picture { height: 24px; width: 46px; }
    .reference canvas { display: none; }
    .guards > span { display: none; }
    .brief :is(h2, .case-counter) { line-height: 1.2; }
}
@media (orientation: landscape) and (max-height: 520px) {
    html body.hair-rescue:has(.game-guest-bar) { --game-guest-height: 40px; }
    .hair-rescue .game-guest-bar { padding-block: 2px; }
    .hair-rescue .game-guest-bar a { min-height: 34px; padding-block: 5px; }
    .rescue { padding-block: 3px; gap: 4px; }
    .rescue-header h1 { font-size: 18px; }
    .workbench { grid-template-columns: minmax(0, 1fr) minmax(200px, .8fr); grid-template-rows: minmax(0, 1fr); gap: 6px; }
    .chair { max-inline-size: calc(100dvh - 105px); }
    .station { padding: 6px; gap: 5px; align-self: center; }
    .tool-picture { height: 22px; width: 42px; }
    .guards { grid-template-columns: auto repeat(6, minmax(0, 1fr)); }
    .guards > span { grid-column: auto; align-self: center; }
    .reference canvas { display: none; }
    .hint { display: none; }
}
