/* ==========================================================================
   Part Restoration Workbench (restore branch) — ui/RestoreScreen.js.
   #app.restore-mode hides the shop HUD; #restore holds the input pad, the
   top bar, the panel (right side panel on desktop + phone landscape, bottom
   sheet in phone portrait — data-layout), bolt number tags, the polish
   gauge, gesture hints and the tutorial banner.
   ========================================================================== */
.rbtn.bench { --c: #C8742B; --cd: #7E4310; }
.rbtn.bench.ping .badge { animation: badgePulse 1.4s infinite; }

#restore { display: none; pointer-events: none; z-index: 55; font-family: var(--font-body); color: var(--ink); }
#app.restore-mode #restore { display: block; }
#app.restore-mode #hud, #app.restore-mode #notify, #app.restore-mode #coach, #app.restore-mode #world-labels,
#app.restore-mode #world-ui, #app.restore-mode #joystick { display: none !important; }
#restore .b3 { pointer-events: auto; }
:where(#restore) .i { width: 1em; height: 1em; fill: currentColor; flex: none; }
.rst-pad { position: absolute; inset: 0; pointer-events: auto; touch-action: none; -webkit-user-select: none; user-select: none; }

/* top bar */
.rst-top { position: absolute; left: 0; right: 0; top: 0; display: flex; align-items: center; gap: 10px;
  padding: calc(var(--sa-t) + 8px) calc(var(--sa-r) + 12px) 8px calc(var(--sa-l) + 12px);
  background: linear-gradient(180deg, rgba(33,22,14,.94), rgba(33,22,14,.75)); color: #fff; pointer-events: auto;
  border-bottom: 3px solid var(--outline); }
.rst-top::after { content: ''; position: absolute; left: 0; right: 0; bottom: -7px; height: 4px; background: var(--stripe); background-size: 34px 34px; opacity: .85; }
.rst-title { flex: 1; min-width: 0; display: flex; align-items: center; gap: 8px; font-family: var(--font-display); font-size: 24px; letter-spacing: .5px; color: var(--hz-yellow); white-space: nowrap; }
.rst-title .i { width: 28px; height: 28px; }
.rst-title small { font-family: var(--font-body); font-size: 14px; color: #e5d6c4; font-weight: 700; letter-spacing: 0; overflow: hidden; text-overflow: ellipsis; }
.rst-bin { display: flex; align-items: center; gap: 6px; height: 40px; padding: 0 14px 0 8px; border-radius: 999px; background: var(--steel-800);
  border: 2px solid var(--outline); font-family: var(--font-display); font-size: 19px; }
.rst-bin .i { width: 24px; height: 24px; fill: #f0b070; }
.rst-x { width: 46px; min-width: 46px; height: 44px; min-height: 44px; padding: 0; border-radius: 12px; }
.rst-x .i { width: 24px; height: 24px; }

/* panel */
.rst-panel { position: absolute; pointer-events: auto; background: var(--paper); border: var(--bw) solid var(--outline);
  box-shadow: -4px 0 0 rgba(0,0,0,.18), 0 10px 30px rgba(0,0,0,.35); overflow-y: auto; overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch; padding: 12px 14px 14px; display: flex; flex-direction: column; gap: 10px; }
#restore[data-layout="desktop"] .rst-panel { right: calc(var(--sa-r) + 14px); top: calc(var(--sa-t) + 74px); bottom: calc(var(--sa-b) + 14px);
  width: min(400px, 36vw); border-radius: var(--r-lg); }
#restore[data-layout="portrait"] .rst-panel { left: 0; right: 0; bottom: 0; max-height: 46vh; border-radius: 22px 22px 0 0;
  border-bottom: 0; padding-bottom: calc(var(--sa-b) + 12px); gap: 8px; }
#restore[data-layout="portrait"] .rst-panel.ph-bin, #restore[data-layout="portrait"] .rst-panel.ph-result { max-height: 58vh; }
#restore[data-layout="land"] .rst-panel { right: 0; top: calc(var(--sa-t) + 60px); bottom: 0; width: min(360px, 44vw);
  border-radius: 18px 0 0 0; border-right: 0; padding: 8px calc(var(--sa-r) + 12px) calc(var(--sa-b) + 10px) 12px; gap: 6px; }
.rst-h2 { font-family: var(--font-display); font-size: 22px; line-height: 1.1; }
.rst-h2 span { display: block; font-family: var(--font-body); font-size: 14px; font-weight: 700; color: var(--ink-2); margin-top: 2px; }
.rst-h2.c { text-align: center; }
.rst-h2 b { color: #1F8A2E; font-family: var(--font-display); font-weight: 400; font-size: 17px; }
.rst-actions { display: flex; gap: 10px; align-items: center; justify-content: flex-end; flex-wrap: wrap; margin-top: auto; }
.rst-actions .b3.big { flex: 1; min-width: 160px; white-space: nowrap; }
.rst-actions .b3.ghost .i { transform: rotate(180deg); }
.rst-panel .rst-actions { position: sticky; bottom: -14px; margin: auto -14px -14px; padding: 8px 14px 14px; background: linear-gradient(180deg, rgba(255,244,220,0), var(--paper) 10px); z-index: 1; }
#restore[data-layout="portrait"] .rst-panel .rst-actions { bottom: calc(-12px - var(--sa-b)); padding-bottom: calc(12px + var(--sa-b)); margin-bottom: calc(-12px - var(--sa-b)); }
#restore[data-layout="land"] .rst-panel .rst-actions { bottom: calc(-10px - var(--sa-b)); padding: 6px 12px calc(10px + var(--sa-b)); margin: auto -12px calc(-10px - var(--sa-b)); }

/* bin */
.rst-list { display: flex; flex-direction: column; gap: 8px; }
#restore[data-layout="portrait"] .rst-list { display: grid; grid-template-columns: 1fr 1fr; }
.rst-card { background: var(--card); border: 2px solid var(--outline); border-radius: 14px; padding: 8px; display: flex; flex-direction: column; gap: 6px; box-shadow: 0 3px 0 var(--paper-line); min-width: 0; }
.rst-card.rare { background: linear-gradient(180deg, #f6ecff, var(--card)); border-color: #7B2FBE; }
.rc-h { display: flex; align-items: center; gap: 8px; min-width: 0; }
.rc-ic { width: 34px; height: 34px; flex: none; border-radius: 10px; background: #5a3a22; display: grid; place-items: center; }
.rc-ic .i { width: 24px; height: 24px; fill: #f0b070; }
.rc-n { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.15; }
.rc-n b { font-family: var(--font-display); font-weight: 400; font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rc-n span { font-size: 13px; font-weight: 700; color: var(--ink-2); }
.rc-v { font-size: 13px; font-weight: 700; color: var(--ink-2); }
.rc-v b { color: #1F8A2E; font-family: var(--font-display); font-weight: 400; font-size: 15px; }
.rst-card .b3.sm { min-height: 42px; font-size: 17px; padding: 0 10px; border-radius: 12px; }
.rst-dots { display: inline-flex; gap: 4px; }
.rst-dots i { width: 24px; height: 24px; border-radius: 7px; display: grid; place-items: center; background: var(--paper-2); border: 1.5px solid var(--paper-line); }
.rst-dots i .i { width: 15px; height: 15px; fill: var(--ink-2); opacity: .7; }
.rst-dots i.done { background: var(--buy); border-color: var(--outline); }
.rst-dots i.done .i { fill: #fff; opacity: 1; }
.rst-wait, .rst-note, .rst-empty { display: flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 700; color: var(--ink-2); padding: 6px 8px; border-radius: 10px; background: #f3ead9; border: 2px solid #e0cfae; }
.rst-empty { font-size: 14px; }
.rst-empty .i, .rst-note .i { width: 20px; height: 20px; fill: var(--steel-700); }
.rst-stars { display: inline-flex; gap: 2px; }
.rst-stars i { display: grid; place-items: center; }
.rst-stars i .i { width: 18px; height: 18px; fill: #cbbfa8; }
.rst-stars i.on .i { fill: #F2A516; filter: drop-shadow(0 1px 0 var(--outline)); }
.rst-stars.sm i .i { width: 15px; height: 15px; }
.rst-stars.big { gap: 8px; }
.rst-stars.big i .i { width: 54px; height: 54px; filter: drop-shadow(0 3px 0 var(--outline)); }
.rst-stars.big i.on { animation: rstStar .5s var(--ease-out) both; }
.rst-stars.big i:nth-child(2).on { animation-delay: .25s; } .rst-stars.big i:nth-child(3).on { animation-delay: .5s; }
@keyframes rstStar { 0% { transform: scale(0) rotate(-40deg); } 70% { transform: scale(1.25); } 100% { transform: scale(1); } }

/* task */
.rst-step { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.rs-ic { width: 38px; height: 38px; flex: none; border-radius: 11px; background: var(--hz-yellow); border: 2px solid var(--outline); display: grid; place-items: center; }
.rs-ic .i { width: 24px; height: 24px; fill: var(--hz-black); }
.rs-n { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.1; }
.rs-n b { font-family: var(--font-display); font-weight: 400; font-size: 20px; }
.rs-n span { font-size: 13px; font-weight: 700; color: var(--ink-2); }
.rst-how { font-size: 16px; font-weight: 800; line-height: 1.25; padding: 7px 9px; border-radius: 10px; background: #fff4d6; border: 2px solid var(--hz-yellow); }
.rst-timer, .rst-meter { display: flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 800; color: var(--ink-2); }
.rst-meter span { flex: none; min-width: 92px; }
.rst-timer .bar, .rst-meter .bar { flex: 1; height: 14px; border-radius: 7px; background: var(--paper-2); border: 2px solid var(--outline); overflow: hidden; }
.rst-timer .bar i, .rst-meter .bar i { display: block; height: 100%; width: 100%; transform-origin: left center; transform: scaleX(0); transition: transform .08s linear; }
.rst-timer .bar i { background: linear-gradient(90deg, var(--hz-orange), var(--hz-yellow)); }
.rst-timer .bar i.low { background: var(--danger); }
.rst-meter .bar i { background: var(--buy); }
.rst-meter .bar i.warn { background: linear-gradient(90deg, var(--buy), var(--hz-orange)); }
.rst-timer b, .rst-meter b { flex: none; min-width: 44px; text-align: right; font-family: var(--font-display); font-weight: 400; font-size: 16px; color: var(--ink); }
.rst-timer b { min-width: 34px; }
.rst-fb { min-height: 26px; display: flex; align-items: center; justify-content: center; gap: 6px; font-family: var(--font-display); font-size: 18px; color: #1F8A2E; opacity: 0; transition: opacity .15s; }
.rst-fb.on { opacity: 1; }
.rst-fb.bad { color: var(--danger); font-family: var(--font-body); font-weight: 800; font-size: 15px; }

/* result */
.rst-res { display: flex; flex-direction: column; gap: 8px; align-items: stretch; }
.rr-stars { display: flex; justify-content: center; padding-top: 4px; }
.rr-list { display: flex; flex-direction: column; gap: 4px; }
.rr-t { display: flex; align-items: center; gap: 8px; font-size: 14px; font-weight: 700; padding: 3px 8px; border-radius: 8px; background: var(--card); border: 1.5px solid var(--paper-line); }
.rr-t .i { width: 18px; height: 18px; fill: var(--steel-700); }
.rr-t span { flex: 1; }
.rr-t b { font-family: var(--font-display); font-weight: 400; font-size: 16px; }
.rr-where { display: flex; gap: 8px; align-items: flex-start; font-size: 14px; font-weight: 700; line-height: 1.3; padding: 8px 9px; border-radius: 12px; background: #fdf1e0; border: 2px solid #e8c48f; }
.rr-where.ok { background: #e8fbe9; border-color: var(--buy); }
.rr-where .i { width: 24px; height: 24px; flex: none; fill: #7B2FBE; }
.rr-where b { font-family: var(--font-display); font-weight: 400; font-size: 16px; color: #1F8A2E; }

/* bolt tags */
.rst-tags { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.rst-tag { position: absolute; left: 0; top: 0; width: 32px; height: 32px; display: grid; place-items: center; border-radius: 50%;
  background: #fff; border: 2.5px solid var(--outline); font-family: var(--font-display); font-size: 18px; font-style: normal; color: var(--ink);
  box-shadow: 0 3px 0 var(--outline); }
/* Bolt numbers sit on the bolt heads themselves. */
.rst-tag.bolt { width: 26px; height: 26px; font-size: 15px; border-width: 2px; box-shadow: 0 2px 0 var(--outline); }
.rst-tag.next { background: var(--hz-yellow); transform-origin: center; animation: rstTag 0.8s ease-in-out infinite; }
@keyframes rstTag { 0%, 100% { box-shadow: 0 3px 0 var(--outline), 0 0 0 0 rgba(255,194,26,.8); } 50% { box-shadow: 0 3px 0 var(--outline), 0 0 0 9px rgba(255,194,26,0); } }

/* polish gauge (top-centre of the bench view) */
.rst-gauge { position: absolute; left: 50%; top: calc(var(--sa-t) + 74px); transform: translateX(-50%); width: 230px; pointer-events: none;
  display: flex; flex-direction: column; align-items: center; gap: 4px; }
#restore[data-layout="desktop"] .rst-gauge { left: calc((100% - min(400px, 36vw) - 28px) / 2); }
#restore[data-layout="land"] .rst-gauge { left: calc((100% - min(360px, 44vw)) / 2); top: calc(var(--sa-t) + 58px); transform: translateX(-50%) scale(.8); transform-origin: top center; }
.g-dial { position: relative; width: 220px; height: 120px; overflow: hidden; border-radius: 110px 110px 0 0; background: radial-gradient(circle at 50% 100%, #30363d 0 28%, #1d2228 29% 100%);
  border: 3px solid var(--outline); border-bottom: 0; box-shadow: 0 4px 0 var(--outline); }
.g-green { position: absolute; inset: 0; opacity: .9; }
.g-needle { position: absolute; left: 50%; bottom: 0; width: 6px; height: 100px; margin-left: -3px; border-radius: 3px; background: var(--hz-yellow);
  border: 1.5px solid var(--outline); transform-origin: 50% 100%; }
.g-stops { display: flex; gap: 6px; }
.g-stops i { width: 16px; height: 16px; border-radius: 50%; background: #e6dccb; border: 2px solid var(--outline); }
.g-stops i.cur { background: var(--hz-yellow); }
.g-stops i.ok { background: var(--buy); }
.g-stops i.miss { background: var(--danger); }
.g-cap, .rst-holdcap { font-family: var(--font-display); font-size: 17px; color: #fff; text-shadow: var(--txt-outline); letter-spacing: .5px; }
.rst-holdcap { position: absolute; left: 50%; top: calc(var(--sa-t) + 80px); transform: translateX(-50%); pointer-events: none; padding: 4px 14px; border-radius: 999px; background: rgba(20,14,8,.55); }
#restore[data-layout="desktop"] .rst-holdcap { left: calc((100% - min(400px, 36vw) - 28px) / 2); }
#restore[data-layout="land"] .rst-holdcap { left: calc((100% - min(360px, 44vw)) / 2); top: calc(var(--sa-t) + 64px); }
.rst-holdcap.on { background: var(--buy); }

/* gesture hint (first time each task) */
.rst-hint { position: absolute; left: 0; top: 0; width: 100%; height: 100%; pointer-events: none; }
.rst-hint i { position: absolute; left: 40%; top: 40%; width: 56px; height: 56px; display: grid; place-items: center; border-radius: 50%; background: rgba(255,255,255,.85); border: 3px solid var(--outline); }
.rst-hint i .i { width: 34px; height: 34px; fill: var(--hz-black); }
#restore[data-layout="desktop"] .rst-hint i { left: 30%; }
#restore[data-layout="portrait"] .rst-hint i { left: 45%; top: 28%; }
.hint-rust i { animation: hScrub 1.3s ease-in-out infinite; }
.hint-bolts i, .hint-polish i { animation: hTap 0.9s ease-in-out infinite; }
.hint-replace i { animation: hDrag 1.6s ease-in-out infinite; }
.hint-paint i { animation: hHold 1.6s ease-in-out infinite; }
@keyframes hScrub { 0%, 100% { transform: translate(-50px, 0); } 50% { transform: translate(50px, 14px); } }
@keyframes hTap { 0%, 100% { transform: scale(1); } 50% { transform: scale(.8); } }
@keyframes hDrag { 0% { transform: translate(80px, 30px); } 70%, 100% { transform: translate(-40px, 60px); } }
@keyframes hHold { 0%, 100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(46,204,113,.7); } 50% { transform: scale(.85); box-shadow: 0 0 0 16px rgba(46,204,113,0); } }
html.reduce-motion .rst-hint i, html.reduce-motion .rst-tag.next, html.reduce-motion .rst-stars.big i.on { animation: none; }

/* tutorial banner + arrow */
#restore .rst-tut { position: absolute; pointer-events: auto; left: calc(var(--sa-l) + 14px); top: calc(var(--sa-t) + 74px);
  width: min(420px, calc(100vw - 28px)); background: var(--paper); border: var(--bw) solid var(--outline); border-radius: var(--r-md);
  box-shadow: 0 5px 0 var(--outline), 0 10px 22px rgba(10,14,20,.3); overflow: hidden; z-index: 3; }
#restore[data-layout="portrait"] .rst-tut { left: 50%; transform: translateX(-50%); top: calc(var(--sa-t) + 66px); }
#restore[data-layout="land"] .rst-tut { top: calc(var(--sa-t) + 58px); width: min(380px, calc(56vw - 30px)); }
#restore .b3.tut-pulse { outline: 4px solid var(--hz-yellow); outline-offset: 3px; animation: tutPulse 1s ease-in-out infinite; }
html.reduce-motion #restore .b3.tut-pulse { animation: none; }

/* phone tweaks */
#restore[data-layout="portrait"] .rst-title { font-size: 20px; }
#restore[data-layout="portrait"] .rst-title small { display: none; }
#restore[data-layout="portrait"] .rst-h2 { font-size: 19px; }
#restore[data-layout="portrait"] .rst-h2 span { font-size: 13px; }
#restore[data-layout="portrait"] .rst-how { font-size: 14px; padding: 5px 8px; }
#restore[data-layout="portrait"] .rst-stars.big i .i { width: 42px; height: 42px; }
#restore[data-layout="portrait"] .rr-list { display: grid; grid-template-columns: 1fr 1fr; }
#restore[data-layout="land"] .rst-top { padding-top: calc(var(--sa-t) + 5px); padding-bottom: 5px; }
#restore[data-layout="land"] .rst-title small { display: none; }
#restore[data-layout="land"] .rst-h2 { font-size: 18px; }
#restore[data-layout="land"] .rst-h2 span { font-size: 12px; }
#restore[data-layout="land"] .rst-how { font-size: 13px; padding: 4px 7px; }
#restore[data-layout="land"] .rs-n b { font-size: 17px; }
#restore[data-layout="land"] .rs-ic { width: 32px; height: 32px; }
#restore[data-layout="land"] .rst-fb { min-height: 18px; font-size: 15px; }
#restore[data-layout="land"] .rst-stars.big i .i { width: 36px; height: 36px; }
#restore[data-layout="land"] .rr-t { padding: 1px 7px; font-size: 13px; }
#restore[data-layout="land"] .rr-where { padding: 5px 8px; font-size: 13px; }
#restore[data-layout="land"] .rst-card { padding: 6px; gap: 4px; }
