/* Graphics settings panel (drive/ui/graphicsPanel.js).
   Desktop: popover under the top bar, right side.
   Phones (≤ 720 px wide): bottom sheet.
   Landscape phones (short + touch): side drawer so the view stays visible. */

#sh-gfx.is-open { color: var(--sh-ink); border-color: var(--sh-accent); }
#sh-gfx.has-pending { color: var(--sh-accent); }
#sh-gfx.has-pending::after {
  content: "";
  position: absolute;
  top: 5px;
  right: 5px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--sh-accent);
}
#sh-gfx { position: relative; }

.gfx-pop {
  display: flex;
  flex-direction: column;
  gap: 0;
  padding: 0;
  overflow: hidden;
  width: min(400px, calc(100vw - 2 * var(--sh-gap)));
  /* top offset 8px + bottom bar + a gap above it */
  max-height: calc(100vh - var(--sh-top-h) - var(--sh-status-h) - 8px - var(--sh-gap));
  max-height: calc(100dvh - var(--sh-top-h) - var(--sh-status-h) - 8px - var(--sh-gap));
}

/* ---------- header ---------- */
.gfx-head {
  flex: none;
  padding: 12px 14px 10px;
  border-bottom: 1px solid var(--sh-line);
}
.gfx-title {
  display: flex;
  align-items: center;
  gap: 12px;
}
.gfx-title h3 {
  flex: 1 1 auto;
  margin: 0;
  font-size: 14px;
}
.gfx-hints {
  flex: 0 0 auto;
  gap: 8px;
  padding: 0;
  font-size: 11.5px;
  color: var(--sh-muted);
}
.gfx-running {
  margin: 6px 0 0;
  font: 11px/1.4 var(--sh-f-mono);
  color: var(--sh-faint);
}

/* ---------- body ---------- */
.gfx-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.gfx-presets-wrap { display: flex; flex-direction: column; gap: 7px; }
.gfx-preset-line .gfx-name { font-weight: 600; }
.gfx-preset-line .gfx-preset-sel { flex-basis: 62%; max-width: 240px; }
.gfx-preset-note { font-size: 11.5px; line-height: 1.35; color: var(--sh-muted); }
.gfx-preset-note[hidden] { display: none; }
.gfx-presets {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 4px;
}
.gfx-chip {
  min-width: 0;
  padding: 7px 4px;
  border: 1px solid var(--sh-line-2);
  border-radius: 8px;
  background: var(--sh-raise);
  color: var(--sh-muted);
  font: 500 12px var(--sh-f-ui);
  cursor: pointer;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.gfx-chip:hover { color: var(--sh-ink); }
.gfx-chip[aria-pressed="true"] {
  background: var(--sh-accent-soft);
  border-color: var(--sh-accent);
  color: var(--sh-accent);
}
.gfx-chip:focus-visible,
.gfx-link:focus-visible,
.gfx-reset:focus-visible,
.gfx-sel:focus-visible,
.gfx-group > summary:focus-visible {
  outline: 2px solid var(--sh-accent);
  outline-offset: 2px;
}
.gfx-legend {
  display: flex;
  gap: 14px;
  margin: 0;
  font-size: 11px;
  color: var(--sh-faint);
}
.gfx-legend > span { display: inline-flex; align-items: center; gap: 5px; }

/* GPU-cost meter: three rising bars, filled up to data-c (0–3). */
.gfx-cost {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: flex-end;
  gap: 2px;
  height: 11px;
  cursor: help;
}
.gfx-cost[hidden] { display: none; }
.gfx-cost i {
  width: 3px;
  border-radius: 1px;
  background: var(--sh-line-2);
}
.gfx-cost i:nth-child(1) { height: 5px; }
.gfx-cost i:nth-child(2) { height: 8px; }
.gfx-cost i:nth-child(3) { height: 11px; }
.gfx-cost[data-c="1"] i:nth-child(-n+1) { background: #7cc48a; }
.gfx-cost[data-c="2"] i:nth-child(-n+2) { background: #e2b456; }
.gfx-cost[data-c="3"] i:nth-child(-n+3) { background: #e57a5c; }
.gfx-legend .gfx-cost { cursor: default; }

/* An option the other choices make pointless. */
.gfx-row.gfx-na .gfx-line,
.gfx-row.gfx-na .sh-toggle,
.gfx-row.gfx-na input[type="range"] { opacity: 0.42; }
.gfx-row.gfx-na .gfx-hint { opacity: 0.6; }
.gfx-rl {
  font-style: normal;
  margin-left: 5px;
  font-size: 11px;
  color: var(--sh-accent);
  opacity: 0.85;
  cursor: help;
}
.gfx-legend .gfx-rl { margin-left: 0; cursor: default; }

/* groups */
.gfx-group {
  border: 1px solid var(--sh-line);
  border-radius: 10px;
  background: var(--sh-raise);
}
.gfx-group > summary {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  list-style: none;
  cursor: pointer;
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--sh-muted);
  user-select: none;
  -webkit-user-select: none;
}
.gfx-group > summary::-webkit-details-marker { display: none; }
.gfx-group > summary::after {
  content: "";
  margin-left: auto;
  width: 6px;
  height: 6px;
  border-right: 1.5px solid currentColor;
  border-bottom: 1.5px solid currentColor;
  transform: rotate(45deg) translate(-2px, -2px);
  transition: transform 0.15s ease;
}
.gfx-group[open] > summary::after { transform: rotate(225deg) translate(-2px, -2px); }
.gfx-badge {
  font: 600 10px/1 var(--sh-f-mono);
  letter-spacing: 0;
  padding: 3px 6px;
  border-radius: 8px;
  background: var(--sh-accent-soft);
  color: var(--sh-accent);
  font-style: normal;
}
.gfx-group-b {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 0 12px 10px;
}

/* rows */
.gfx-row {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 7px 0;
  border-top: 1px solid var(--sh-line);
}
.gfx-row:first-child { border-top: 0; }
.gfx-line {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  font-size: 12.5px;
  color: var(--sh-ink);
}
.gfx-name { flex: 1 1 auto; min-width: 0; }
.gfx-row-select .gfx-line { cursor: pointer; }
.gfx-sel {
  flex: 0 1 52%;
  min-width: 0;
  max-width: 190px;
  height: 32px;
  padding: 0 8px;
  border: 1px solid var(--sh-line-2);
  border-radius: 8px;
  background: var(--sh-well);
  color: var(--sh-ink);
  font: 12.5px var(--sh-f-ui);
  color-scheme: dark;
}
.gfx-val {
  flex: 0 0 auto;
  font: 12px var(--sh-f-mono);
  color: var(--sh-muted);
  min-width: 3.4em;
  text-align: right;
}
.gfx-reset {
  flex: 0 0 auto;
  width: 22px;
  height: 22px;
  padding: 0;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--sh-muted);
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
}
.gfx-reset:hover { color: var(--sh-ink); }
.gfx-reset.is-default { visibility: hidden; }
.gfx-row-range input[type="range"] { width: 100%; margin: 4px 0 2px; }
.gfx-range { position: relative; }
.gfx-range-guard { display: none; }
.gfx-row .sh-toggle { padding: 2px 0; }
.gfx-hint {
  font-size: 11px;
  line-height: 1.4;
  color: var(--sh-faint);
}
.gfx-nohints .gfx-hint { display: none; }

/* ---------- footer ---------- */
.gfx-foot {
  flex: none;
  display: flex;
  flex-direction: column;
  border-top: 1px solid var(--sh-line);
  background: var(--sh-bar);
}
.gfx-pending {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 14px;
  background: var(--sh-accent-soft);
  border-bottom: 1px solid var(--sh-line);
}
.gfx-pending-t { font-size: 12.5px; color: var(--sh-ink); }
.gfx-pending-b { display: flex; gap: 6px; flex: 0 0 auto; }
.gfx-pending .sh-btn { height: 32px; padding: 0 12px; }
.gfx-foot-r { padding: 8px 14px; display: flex; justify-content: flex-end; }
.gfx-link {
  padding: 4px 0;
  border: 0;
  background: none;
  color: var(--sh-muted);
  font: 12px var(--sh-f-ui);
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}
.gfx-link:hover { color: var(--sh-ink); }

/* ---------- touch ---------- */
@media (pointer: coarse) {
  .gfx-pop .sh-toggle input { width: 42px; height: 24px; border-radius: 12px; }
  .gfx-pop .sh-toggle input::after { width: 18px; height: 18px; left: 3px; top: 3px; }
  .gfx-pop .sh-toggle input:checked::after { left: 21px; }
  .gfx-row { padding: 10px 0; }
  .gfx-sel { height: 40px; font-size: 14px; }
  .gfx-line, .gfx-pop .sh-toggle { font-size: 14px; min-height: 36px; }
  .gfx-chip { padding: 11px 4px; font-size: 13px; }
  .gfx-reset { width: 34px; height: 34px; font-size: 18px; }
  .gfx-pending .sh-btn { height: 40px; }
  .gfx-link { padding: 10px 0; font-size: 13px; }
  .gfx-group > summary { padding: 14px 12px; }
  .gfx-row-range input[type="range"] { height: 32px; margin: 2px 0; }
  /* Sliders only move on a sideways drag (graphicsPanel.js guardRange). */
  .gfx-range-guard {
    display: block;
    position: absolute;
    inset: 0;
    touch-action: pan-y;
    -webkit-tap-highlight-color: transparent;
  }
  .gfx-row.gfx-na .gfx-range-guard { pointer-events: none; }
  .gfx-hint { font-size: 11.5px; }
}

/* ---------- phones: bottom sheet ---------- */
@media (max-width: 720px) {
  .gfx-pop {
    top: auto;
    left: 0;
    right: 0;
    bottom: 0;
    width: auto;
    max-height: 86vh;
    max-height: 86dvh;
    border-radius: 16px 16px 0 0;
    border-bottom: 0;
    box-shadow: 0 -12px 40px rgba(0, 0, 0, 0.55);
    z-index: 46;
  }
  /* grab handle */
  .gfx-head { padding-top: 18px; position: relative; }
  .gfx-head::before {
    content: "";
    position: absolute;
    top: 7px;
    left: 50%;
    width: 36px;
    height: 4px;
    margin-left: -18px;
    border-radius: 2px;
    background: var(--sh-line-2);
  }
  .gfx-foot { padding-bottom: env(safe-area-inset-bottom, 0px); }
  .gfx-body { padding-left: max(14px, env(safe-area-inset-left, 0px)); padding-right: max(14px, env(safe-area-inset-right, 0px)); }
  .gfx-chip { font-size: 12px; }
  .gfx-sel { flex-basis: 56%; max-width: none; }
}

/* very narrow phones: presets wrap to 3 + 2 */
@media (max-width: 380px) {
  .gfx-presets { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

/* ---------- landscape phones: side drawer ---------- */
@media (max-height: 520px) and (pointer: coarse) {
  .gfx-pop {
    top: var(--sh-top-h);
    bottom: 0;
    left: auto;
    right: 0;
    width: min(420px, 60vw);
    max-height: none;
    border-radius: 12px 0 0 12px;
    border-bottom: 1px solid var(--sh-line-2);
    box-shadow: -12px 0 40px rgba(0, 0, 0, 0.5);
    z-index: 46;
  }
  .gfx-head { padding-top: 10px; }
  .gfx-head::before { display: none; }
  .gfx-pop { padding-right: env(safe-area-inset-right, 0px); }
}

@media (prefers-reduced-motion: reduce) {
  .gfx-group > summary::after { transition: none; }
}

/* FPS readout lives inside the Graphics button, to the left of the icon, on
   every screen size (updated from drive/main.js into #sh-gfx-fps). Phones and
   touch show just the number; desktop adds the word FPS. */
body.page-drive #drive-fps { display: none; }
#sh-gfx {
  display: inline-flex; flex-direction: row; align-items: center; justify-content: center;
  width: auto; min-width: 32px; padding: 0 10px; gap: 6px;
}
#sh-gfx svg { flex: 0 0 auto; }
#sh-gfx .sh-gfx-fps {
  display: inline-block;
  order: -1;
  font: 500 11px/1 var(--sh-f-mono);
  font-variant-numeric: tabular-nums;
  color: var(--sh-ink);
  text-align: right;
  white-space: nowrap;
}
#sh-gfx .sh-gfx-fps:empty,
#sh-gfx.fps-hidden .sh-gfx-fps { display: none; }
@media (min-width: 721px) and (pointer: fine) {
  #sh-gfx .sh-gfx-fps:not(.is-idle)::after { content: " FPS"; color: var(--sh-muted); }
}
