/* ==========================================================================
   Cape Clash — Settings Screen
   Implements docs/specs/SETTINGS-SPEC.md as a *decorator skin* built by
   public/js/settingsui.js (global CapeSettingsUI).

   SAFETY VALVE: every rule below is scoped under `#capeSettings`, the container
   settingsui.js builds fresh inside `#settingsScr`. Delete this <link> (or let
   settingsui.js never run) and the original sliders/buttons — kept in the DOM,
   only hidden via `.legacySettingsUI` — reappear with zero other changes.

   Load order: in <head>, after index.html's own inline <style> block, so the
   var() fallbacks below only ever fire when this sheet is used standalone
   (see public/settingslab.html).
   ========================================================================== */

:root{
  /* the six game tokens (--ink --paper --pow --red --panel --panel2) are
     declared by index.html's own <style> and are NOT redefined here */
  --cs-body:#d8d2f0;    /* .pk / .card body text                 */
  --cs-body2:#cfc4ff;   /* .tag / .scrSub color                  */
  --cs-stroke:#4a3d85;  /* .tinyBtn / .card outline color        */
}

/* the original settings chrome: kept in the DOM (still `.click()`-able and
   still holding the engine's real listeners), only ever hidden with CSS */
.legacySettingsUI{display:none !important;}

/* #settingsScr is `.screen.center` (justify-content:center + overflow-y:auto).
   A centred flex child taller than the scroll box has its overflowing top
   CLIPPED and unreachable. flex-start + `margin:auto 0` centres exactly the
   same way while it fits, and scrolls from the real top when it does not. */
#settingsScr.center{justify-content:flex-start;}

#capeSettings{
  margin:auto 0;
  width:min(400px,100%);
  display:flex;
  flex-direction:column;
  align-items:center;
  gap:12px;
  padding-top:var(--sa-top,env(safe-area-inset-top,0px));
  padding-bottom:var(--sa-bottom,env(safe-area-inset-bottom,0px));
  box-sizing:border-box;
}
#capeSettings *{box-sizing:border-box;}
/* `hidden` must always win over the explicit displays set below */
#capeSettings [hidden]{display:none !important;}
/* NEITHER family nor colour may be normalised across `#capeSettings button` (1,0,1):
   that selector out-ranks every .cs-* class below (0,1,0), so .cs-danger / .cs-cancel /
   .cs-back declared `font-family:'Bangers'` and silently got Nunito instead — settings
   was the only screen whose buttons spoke a different typeface than its own labels.
   The switch is the only text-free button, so it is the only one normalised here. */
#capeSettings .cs-switch{font-family:'Nunito',sans-serif;color:inherit;}
#capeSettings button:focus-visible,
#capeSettings input:focus-visible{outline:3px solid var(--paper,#fff8e7);outline-offset:2px;}

/* ------------------------------------------------------------------ panel */
/* the existing .card chrome recipe (panel bg, ink border, stroke outline),
   resized into a full-width container so no dead space is left on screen */
.cs-panel{
  width:min(360px,100%);
  background:var(--panel,#241b44);
  border:3px solid var(--ink,#1b1430);
  outline:3px solid var(--cs-stroke);
  border-radius:16px;
  padding:14px 12px 12px;
  display:flex;
  flex-direction:column;
  gap:12px;
}
.cs-header{text-align:center;display:flex;flex-direction:column;gap:2px;}
.cs-title{
  font-family:'Bangers',cursive;font-size:32px;letter-spacing:2px;
  color:var(--pow,#ffd23f);text-shadow:3px 3px 0 var(--red,#e03131);line-height:1;
}
.cs-sub{font-size:12px;font-weight:700;color:var(--cs-body2);line-height:1.3;}

.cs-body{display:flex;flex-direction:column;gap:14px;}

/* --------------------------------------------------------------- section */
.cs-section{display:flex;flex-direction:column;gap:2px;}
.cs-sectionHead{
  display:flex;align-items:center;gap:7px;
  font-family:'Bangers',cursive;font-size:15px;letter-spacing:1.6px;font-weight:400;
  color:var(--cs-body2);
  border-bottom:2px solid var(--cs-stroke);
  padding-bottom:4px;margin-bottom:2px;
}
.cs-sectionIco{width:16px;height:16px;flex:0 0 16px;display:block;opacity:.9;}
.cs-sectionIco svg{display:block;}

/* ------------------------------------------------------------------- row */
.cs-row{
  display:flex;align-items:center;gap:10px;
  padding:9px 4px;min-height:48px;                 /* mobile tap target */
  border-bottom:1px solid rgba(255,255,255,.06);
}
.cs-row:last-child{border-bottom:0;}
.cs-ico{width:24px;height:24px;flex:0 0 24px;display:block;}
.cs-ico svg{display:block;}
.cs-labelwrap{display:flex;flex-direction:column;gap:1px;min-width:0;flex:1 1 auto;}
.cs-label{
  font-family:'Bangers',cursive;font-size:15px;letter-spacing:1px;
  color:var(--paper,#fff8e7);line-height:1.1;
}
.cs-hint{font-size:11.5px;font-weight:700;color:var(--cs-body);opacity:.78;line-height:1.3;}

/* ---------------------------------------------------------- slider row */
/* two lines: icon + label + value on top, a full-width track underneath.
   At 360px a single-line slider row leaves the track ~120px wide, which is a
   bad drag target on a phone (SETTINGS-SPEC.md 2). */
.cs-row-slider{flex-direction:column;align-items:stretch;gap:7px;}
.cs-rowtop{display:flex;align-items:center;gap:10px;}
.cs-val{
  font-family:'Bangers',cursive;font-size:15px;letter-spacing:1px;
  color:var(--pow,#ffd23f);flex:0 0 auto;min-width:44px;text-align:right;
}

.cs-range{
  -webkit-appearance:none;appearance:none;
  width:100%;height:44px;background:transparent;cursor:pointer;margin:0;
  --cs-fill:0%;
}
.cs-range::-webkit-slider-runnable-track{
  height:10px;border-radius:6px;border:2px solid var(--ink,#1b1430);
  background:linear-gradient(to right,
    var(--pow,#ffd23f) 0 var(--cs-fill), var(--panel2,#2e2358) var(--cs-fill) 100%);
}
.cs-range::-moz-range-track{
  height:10px;border-radius:6px;border:2px solid var(--ink,#1b1430);
  background:linear-gradient(to right,
    var(--pow,#ffd23f) 0 var(--cs-fill), var(--panel2,#2e2358) var(--cs-fill) 100%);
}
.cs-range::-webkit-slider-thumb{
  -webkit-appearance:none;appearance:none;
  width:22px;height:22px;border-radius:50%;margin-top:-8px;
  background:var(--paper,#fff8e7);border:3px solid var(--ink,#1b1430);
  box-shadow:0 2px 0 rgba(0,0,0,.35);
}
.cs-range::-moz-range-thumb{
  width:22px;height:22px;border-radius:50%;
  background:var(--paper,#fff8e7);border:3px solid var(--ink,#1b1430);
  box-shadow:0 2px 0 rgba(0,0,0,.35);
}

/* ---------------------------------------------------------- switch row */
.cs-valchip{
  font-size:9.5px;font-weight:800;letter-spacing:.4px;text-transform:uppercase;
  color:var(--ink,#1b1430);background:var(--cs-body2);
  border-radius:6px;padding:2px 7px;flex:0 0 auto;white-space:nowrap;
  max-width:38%;overflow:hidden;text-overflow:ellipsis;
}
.cs-switch{
  position:relative;flex:0 0 52px;width:52px;height:30px;border-radius:15px;
  background:var(--panel2,#2e2358);border:2px solid var(--cs-stroke);
  cursor:pointer;padding:0;
  transition:background .18s ease,border-color .18s ease;
}
/* 52x30 is a 30px tap target. This pad extends the hit area to 60x44 without
   moving a single pixel of the visual switch. */
.cs-switch::before{content:'';position:absolute;inset:-7px -4px;border-radius:19px;}
/* 52x30 switch, 2px border -> a 48x26 content box; a 22x22 border-box knob
   inset 2px leaves exactly 22px of travel. */
.cs-knob{
  position:absolute;top:2px;left:2px;width:22px;height:22px;border-radius:50%;
  background:var(--cs-body2);border:2px solid var(--ink,#1b1430);
  transition:transform .18s cubic-bezier(.2,1.4,.4,1),background .18s ease;
}
.cs-switch.on{background:var(--pow,#ffd23f);border-color:var(--ink,#1b1430);}
.cs-switch.on .cs-knob{transform:translateX(22px);background:var(--ink,#1b1430);}
.cs-switch:active .cs-knob{transform:translateX(0) scale(.92);}
.cs-switch.on:active .cs-knob{transform:translateX(22px) scale(.92);}

/* ---------------------------------------------------------- danger row */
.cs-row-danger{flex-direction:column;align-items:stretch;gap:9px;}
.cs-row-danger .cs-labelwrap{flex-direction:column;}
.cs-row-danger > .cs-ico{display:none;}   /* the button carries the trash glyph */
.cs-dangerWrap{display:flex;gap:8px;align-items:stretch;}
/* What RESET is about to throw away (SETTINGS-SPEC.md 3.3/3.4), filled from the
   engine's #setResetSummary text only while armed. Sits ABOVE the button so it reads
   before the player's thumb is anywhere near the danger zone. */
.cs-dangerSummary{
  font-family:system-ui,-apple-system,sans-serif;font-size:12px;font-weight:700;
  letter-spacing:.2px;line-height:1.35;text-align:center;color:var(--paper,#fff8e7);
  background:rgba(224,49,49,.14);border:1.5px solid rgba(224,49,49,.55);
  border-radius:8px;padding:6px 9px;
}
.cs-danger{
  flex:1 1 auto;display:flex;align-items:center;justify-content:center;gap:8px;
  min-height:46px;padding:10px 12px;cursor:pointer;position:relative;isolation:isolate;
  font-family:'Bangers',cursive;font-size:16px;letter-spacing:1.2px;
  color:#fff;background:var(--red,#e03131);
  border:3px solid var(--ink,#1b1430);border-radius:12px;
  box-shadow:0 4px 0 #7c1a1a;overflow:hidden;
}
.cs-danger:active{transform:translateY(3px);box-shadow:0 1px 0 #7c1a1a;}
.cs-dangerIco{width:20px;height:20px;flex:0 0 20px;display:block;}
.cs-dangerIco svg{display:block;}
/* Armed = the IRREVERSIBLE half, so it steps BACK to an outline and CANCEL takes
   the solid treatment. The glow is an opacity fade on a pseudo-element (see
   hud.css 6.6) instead of an infinite box-shadow repaint. */
.cs-danger.armed{
  background:transparent;color:var(--red,#e03131);
  border-color:var(--red,#e03131);box-shadow:0 4px 0 #7c1a1a;
}
.cs-danger.armed::after{
  content:'';position:absolute;inset:-3px;border-radius:12px;pointer-events:none;
  box-shadow:0 0 14px 2px rgba(224,49,49,.65);
  animation:csArmPulse 1.6s ease-in-out infinite;
  z-index:0;
}
/* HOLD TO CONFIRM (SETTINGS-SPEC.md 3.3): a fill sweeps left-to-right over exactly
   HOLD_MS (the JS timeout and this transition duration are the same 1500ms constant,
   so the bar finishing IS the confirm firing, never a race between the two). Base
   state (armed, not holding) is an empty bar with a quick .18s snap-back transition,
   so letting go early visibly retreats instead of just vanishing. `.holding` overrides
   both the scale and the transition to the slow linear fill - later in the cascade at
   equal specificity, so it wins on both properties while the class is present. */
.cs-danger.armed::before{
  content:'';position:absolute;inset:0;z-index:0;pointer-events:none;
  background:rgba(224,49,49,.5);transform-origin:left center;
  transform:scaleX(0);transition:transform .18s ease-out;
}
.cs-danger.holding::before{transform:scaleX(1);transition:transform 1.5s linear;}
.cs-dangerIco,.cs-dangerLabel{position:relative;z-index:1;}
.cs-cancel{
  flex:0 0 auto;min-height:46px;padding:8px 14px;cursor:pointer;
  font-family:'Bangers',cursive;font-size:14px;letter-spacing:1px;
  color:var(--ink,#1b1430);background:var(--paper,#fff8e7);
  border:3px solid var(--ink,#1b1430);border-radius:12px;
  box-shadow:0 4px 0 #8a6a12;
}
/* CANCEL is the escape hatch from the armed state: it matches .cs-danger's own height at
   EVERY size, not just under 700px, so the way out is never the smaller target. */
.cs-cancel{min-height:46px;}
.cs-cancel:active{transform:translateY(2px);}
@keyframes csArmPulse{0%,100%{opacity:.25}50%{opacity:1}}

/* ------------------------------------------------- export / import rows */
.cs-row-export,.cs-row-import{flex-direction:column;align-items:stretch;gap:7px;}
.cs-row-export > .cs-ico,.cs-row-import > .cs-ico{display:none;}
/* COPY SAVE / IMPORT SAVE are the player's ONLY backup path - safe, reversible actions
   that had a smaller target than the destructive HOLD TO CONFIRM beside them. 44px is
   the floor for every control in this panel now. */
.cs-tiny{
  align-self:flex-start;min-height:44px;padding:6px 16px;cursor:pointer;
  font-family:'Bangers',cursive;font-size:14px;letter-spacing:1px;
  color:var(--ink,#1b1430);background:var(--pow,#ffd23f);
  border:2.5px solid var(--ink,#1b1430);border-radius:10px;
  box-shadow:0 3px 0 #8a6a12;
}
.cs-tiny:active{transform:translateY(2px);box-shadow:0 1px 0 #8a6a12;}
.cs-dataArea{
  width:100%;min-height:64px;resize:vertical;font-family:monospace;font-size:9.5px;
  color:var(--paper,#fff8e7);background:var(--panel2,#2e2358);
  border:1.5px solid #5f5790;border-radius:8px;padding:7px;
}
.cs-dataMsg{
  font-family:system-ui,-apple-system,sans-serif;font-size:11px;font-weight:700;
  color:var(--paper,#fff8e7);opacity:.85;
}
.cs-dataMsg.cs-msgBad{color:#ff8a8a;opacity:1;}

/* ----------------------------------------------------------- cycle row */
/* A three-state control (DISPLAY > GRAPHICS: AUTO / HIGH / BATTERY SAVER). It reads
   like a value chip and behaves like a button: the label is whatever the original
   tinyBtn currently says, so the engine can widen it to 'AUTO . SAVER' without the
   skin knowing. 44px min-height, like every other control in this panel. */
.cs-cycle{
  flex:0 0 auto;max-width:46%;min-height:44px;padding:5px 12px;cursor:pointer;
  font-family:'Bangers',cursive;font-size:13px;letter-spacing:.8px;line-height:1.15;
  color:var(--paper,#fff8e7);background:var(--panel2,#2e2358);
  border:2.5px solid var(--cs-stroke);border-radius:10px;
  text-align:center;white-space:normal;overflow-wrap:anywhere;
  transition:background .18s ease,border-color .18s ease,color .18s ease;
}
.cs-cycle.on{
  color:var(--ink,#1b1430);background:var(--pow,#ffd23f);
  border-color:var(--ink,#1b1430);box-shadow:0 3px 0 #8a6a12;
}
.cs-cycle.on:active{transform:translateY(2px);box-shadow:0 1px 0 #8a6a12;}
.cs-cycle:active{transform:translateY(1px);}
.cs-row-na .cs-cycle{cursor:default;filter:grayscale(1);}

/* ------------------------------------------------------- unsupported row */
/* A control the hardware cannot provide (HAPTICS with no vibration motor: every
   desktop, every iPhone). The row stays readable and keeps its 'N/A' value chip -
   it is an explanation, not a hidden feature. */
.cs-row-na{opacity:.55;}
.cs-row-na .cs-switch{cursor:default;filter:grayscale(1);}
.cs-row-na .cs-valchip{letter-spacing:1px;}

/* ------------------------------------------------------------------ back */
.cs-back{
  display:flex;align-items:center;justify-content:center;gap:7px;
  min-height:44px;padding:6px 18px;cursor:pointer;
  font-family:'Bangers',cursive;font-size:18px;letter-spacing:1px;
  color:var(--paper,#fff8e7);background:var(--panel,#241b44);
  border:2px solid var(--pow,#ffd23f);border-radius:10px;
}
.cs-back:active{transform:translateY(2px);}
.cs-backIco{width:16px;height:16px;flex:0 0 16px;display:block;}
.cs-backIco svg{display:block;}

/* -------------------------------------------------------------- entrance */
.cs-enter{animation:csEnter .26s ease both;}
@keyframes csEnter{from{opacity:0;transform:translateY(8px);}to{opacity:1;transform:none;}}

/* --------------------------------- mid-height trim (390x844 and similar) */
/* GAMEPLAY > HAPTICS and DISPLAY > REDUCED MOTION added two rows, which pushed the
   panel ~120px past a 844px-tall phone. Rather than dropping the hints (that is the
   <=700px treatment below), this tier just takes the air out: shorter rows, tighter
   section gaps, a slightly smaller title. Every row stays >=44px tall. */
@media (min-height:701px) and (max-height:920px){
  .cs-panel{padding:11px 12px 10px;gap:9px;}
  .cs-title{font-size:28px;}
  .cs-body{gap:9px;}
  .cs-row{padding:6px 4px;min-height:44px;}
  .cs-row-slider{gap:5px;}
  .cs-sectionHead{padding-bottom:3px;margin-bottom:1px;}
  /* The consequence copy on the ONE irreversible control is the last line to cut, not
     the first: at 390x844 the loudest, reddest, full-width button on the screen was the
     only row with no hint, while every safe row above it kept one. The ~14px comes off
     .cs-sub instead (already display:none in the shorter tier below). */
  .cs-sub{display:none;}
  .cs-row-danger .cs-hint{display:block;}
}

/* ------------------------------------------- compact height (360x640 etc) */
/* same breakpoint value the battle HUD and home.css already use */
@media (max-height:700px){
  .cs-panel{padding:10px 10px 8px;gap:8px;}
  .cs-title{font-size:24px;}
  .cs-sub{display:none;}
  .cs-body{gap:8px;}
  .cs-row{padding:6px 4px;min-height:44px;}
  .cs-hint{display:none;}
  .cs-sectionHead{font-size:13px;padding-bottom:3px;}
  /* Same rule as the tier above: the DANGER row keeps its consequence line at every
     size. What goes instead is the duplicate LABEL - the button itself already reads
     RESET SAVED DATA, so the label above it was saying the words twice. */
  .cs-row-danger .cs-hint{display:block;font-size:11.5px;line-height:1.25;}
  .cs-row-import .cs-hint{display:block;font-size:11.5px;line-height:1.3;}
  .cs-row-danger .cs-label{display:none;}
  .cs-danger{min-height:44px;font-size:15px;}
  .cs-cancel{min-height:44px;}
  .cs-back{font-size:16px;min-height:44px;}
}

/* --------------------------------------------------------- reduced motion */
@media (prefers-reduced-motion:reduce){
  .cs-enter{animation:none;}
  .cs-knob{transition:none;}
  .cs-switch{transition:none;}
  /* the glow is declared on ::after — `animation:none` on the ELEMENT does not
     cascade into its pseudo-element, so the armed RESET button kept pulsing. */
  .cs-danger.armed::after{animation:none;opacity:.6;}
  /* The hold-to-confirm fill is still functional (HOLD_MS drives the real timer, not
     this transition) - it just stops sweeping and appears instantly instead. */
  .cs-danger.armed::before,.cs-danger.holding::before{transition:none;}
}
/* Paired class half - see public/css/hud.css. body.cc-rm is set by index.html's
   applyReducedMotion() for BOTH the OS preference and the in-game switch. */
body.cc-rm .cs-enter{animation:none;}
body.cc-rm .cs-knob{transition:none;}
body.cc-rm .cs-switch{transition:none;}
body.cc-rm .cs-danger.armed::after{animation:none;opacity:.6;}
body.cc-rm .cs-danger.armed::before,body.cc-rm .cs-danger.holding::before{transition:none;}
#settingsLamplight{box-sizing:border-box;width:100%;margin:.5rem auto;padding:.2rem .8rem;border-radius:.7rem;background:#1a2842;color:#ffe3ac;text-align:left}
#settingsLamplight summary{cursor:pointer;padding:.7rem .2rem;min-height:44px;box-sizing:border-box}
#settingsLamplight summary:focus-visible{outline:2px solid #ffdc84;outline-offset:1px}
#settingsLamplight img{display:block;width:100%;height:auto}
#settingsLamplight small{display:block;margin:.65rem 0}
