/* The Settings sheet (src/settings-sheet.js), shared by the table screen and
 * the lobby. Moved out of styles.css so the lobby can use it without pulling in
 * the match HUD. Every rule is scoped under .sheet: the lobby has its own .seg,
 * .btn and .iconbtn, and these must not leak into them (or they into this).
 * The table screen's help sheet uses the same classes and gets them from here.
 *
 * Written against the shared semantic roles in ui-theme.css. The visual family
 * is deliberately the match result card's: same scrim, same fill, same entrance.
 */

/* ---- scrim + sheet ------------------------------------------------ */

.sheet {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(4, 8, 12, 0.62);
  backdrop-filter: blur(7px);
  animation: sheetScrimIn 0.3s ease both;
  pointer-events: auto; /* the table is not interactive behind a sheet */
  z-index: 20;
}

.sheet[hidden] { display: none; }

.sheet .sheetcard {
  width: min(520px, 92vw);
  max-height: min(86vh, 720px);
  display: flex;
  flex-direction: column;
  border-radius: 22px;
  background: var(--panel-fill);
  box-shadow: var(--control-shadow);
  animation: sheetCardIn 0.4s cubic-bezier(0.2, 1.3, 0.3, 1) both;
  overflow: hidden;
}

.sheet .sheethead {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 18px 18px 14px 22px;
  border-bottom: 1px solid var(--line);
}

.sheet .sheettitle {
  flex: 1;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.24em;
  text-transform: uppercase;
  color: var(--accent-primary);
}

/* The scroll region. Sheets are taller than the viewport on a phone. */
.sheet .sheetbody {
  padding: 6px 22px 18px;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.sheet .sheetfoot {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  padding: 14px 22px 18px;
  border-top: 1px solid var(--line);
}


/* ---- option groups ------------------------------------------------ */

.sheet .optgroup { margin-top: 18px; }

.sheet .optgroup > h3 {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 8px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--muted);
}

.sheet .optrow {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 42px;
  padding: 4px 0;
  border-top: 1px solid var(--line);
}

/* `display: flex` above outranks the browser's [hidden] rule, so a hidden row
   (Resign, offline) would still show without this. */
.sheet .optrow[hidden] { display: none; }

.sheet .optgroup .optrow:first-of-type { border-top: none; }

.sheet .optlabel { flex: 1; font-size: 13px; }

/* A row whose control does not apply right now (bot difficulty in hot seat).
   Dimmed and inert, never removed: a control that vanishes is a control the
   player cannot find again. */
.sheet .optrow.off { opacity: 0.4; }
.sheet .optrow.off .seg, .sheet .optrow.off .stepper, .sheet .optrow.off .switch { pointer-events: none; }

/* A one-line explanation under a label, for anything not self-evident. */
.sheet .opthint {
  display: block; /* its own line under the label, never trailing it */
  margin-top: 3px;
  max-width: 34ch;
  font-size: 11px;
  line-height: 1.35;
  color: var(--muted);
}

/* ---- segmented control (2-3 mutually exclusive values) ------------- */

.sheet .seg {
  display: flex;
  flex: none;
  padding: 3px;
  border-radius: 10px;
  background: var(--track);
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.6);
}

.sheet .seg > button {
  min-width: 62px;
  padding: 7px 12px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  cursor: pointer;
}

.sheet .seg > button[aria-pressed="true"] {
  background: var(--accent-primary);
  color: var(--on-accent);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.45);
}

.sheet .seg > button:focus-visible { outline: 2px solid var(--accent-primary); outline-offset: 2px; }

/* ---- stepper (many values, or long labels) ------------------------ */

.sheet .stepper {
  display: flex;
  align-items: center;
  flex: none;
  gap: 2px;
  padding: 3px;
  border-radius: 10px;
  background: var(--track);
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.6);
}

.sheet .stepper > button {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  padding: 0;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  cursor: pointer;
}

@media (hover: hover) {
  .sheet .stepper > button:hover { background: var(--track); }
}
.sheet .stepper > button:focus-visible { outline: 2px solid var(--accent-primary); outline-offset: -2px; }
.sheet .stepper > button .icon { width: 16px; height: 16px; }

.sheet .stepper > .stepval {
  min-width: 108px;
  text-align: center;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent-primary);
}

/* ---- switch (booleans) -------------------------------------------- */

.sheet .switch {
  position: relative;
  flex: none;
  width: 52px;
  height: 30px;
  padding: 0;
  border: none;
  border-radius: 15px;
  background: var(--track);
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.6);
  cursor: pointer;
  transition: background 0.16s ease;
}

.sheet .switch::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--muted);
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.5);
  transition: transform 0.16s cubic-bezier(0.2, 1.1, 0.4, 1), background 0.16s ease;
}

.sheet .switch[aria-checked="true"] { background: color-mix(in srgb, var(--accent-primary) 34%, transparent); }
.sheet .switch[aria-checked="true"]::after { transform: translateX(22px); background: var(--accent-primary); }
.sheet .switch:focus-visible { outline: 2px solid var(--accent-primary); outline-offset: 2px; }

/* ---- slider (volume) ---------------------------------------------- */

.sheet .slider {
  flex: none;
  width: 148px;
  height: 30px;
  accent-color: var(--accent-primary);
  cursor: pointer;
}

.sheet .slider:focus-visible { outline: 2px solid var(--accent-primary); outline-offset: 2px; }


/* Icons inside the sheet: outline strokes that follow the text colour. */
.sheet .icon {
  width: 20px;
  height: 20px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.sheet .icon.lg { width: 22px; height: 22px; }
.sheet .sheeticon { color: var(--accent-primary); }
.sheet .ui-theme-select { font-size: 12px; }

@keyframes sheetScrimIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes sheetCardIn {
  from { opacity: 0; transform: translateY(18px) scale(0.96); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@media (max-width: 760px) {
  .sheet .icon { width: 22px; height: 22px; }
  .sheet .icon.lg { width: 24px; height: 24px; }
  .sheet .sheetcard { width: 100%; max-height: 92vh; border-radius: 18px; }
  .sheet .sheethead { padding: 14px 14px 12px 16px; }
  .sheet .sheetbody { padding: 4px 16px 14px; }
  .sheet .sheetfoot { padding: 12px 16px 14px; }

  /* Stack the control under its label so neither is squeezed. */
  .sheet .optrow { flex-wrap: wrap; gap: 6px 12px; }
  .sheet .optlabel { flex: 1 0 100%; }
  .sheet .seg > button { min-width: 0; flex: 1; }
  .sheet .seg, .sheet .stepper { flex: 1; }
  .sheet .slider { flex: 1; width: auto; }
}
