/* ─── SETTINGS V2: card sections, mobile-first + desktop grid ─── */

body.on-settings {
  height: auto;
  min-height: 100dvh;
  overflow-y: auto;
  align-items: flex-start;
  background: #eef4ef;
}

#settings-layout {
  width: min(1180px, 100%);
  height: auto;
  max-height: none;
}

#screen-settings.settings-page {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: auto;
  max-height: none;
  min-height: calc(100dvh - 44px);
  padding: 0;
  background: var(--v2-page);
  border: 1px solid #d7e3da;
  border-radius: 24px;
  box-shadow: 0 12px 32px rgba(24, 50, 33, .07);
  overflow: visible;
}

.settings-page {
  --v2-ink: #1e2b23;
  --v2-muted: #6c7e72;
  --v2-line: #e1eae4;
  --v2-line-soft: #edf3ee;
  --v2-accent: #2f9e53;
  --v2-accent-dark: #247f42;
  --v2-soft: #eaf7ee;
  --v2-page: #f7faf7;
}

/* ── top bar ── */
.settings-page .settings-header {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 10px;
  position: relative;
  margin: 0;
  padding: 15px 18px 10px;
}
.settings-page .settings-header-left {
  display: flex;
  align-items: center;
  justify-self: start;
  gap: 8px;
  min-width: 0;
}
.settings-page .settings-about {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 38px;
  padding: 0 12px;
  border: 1px solid #d5e1d8;
  border-radius: 13px;
  background: #fff;
  color: #31453a;
  font: 600 12.5px/1 inherit;
  white-space: nowrap;
  cursor: pointer;
  box-shadow: 0 1px 2px rgba(25, 50, 32, .04);
  transition: background .15s, border-color .15s;
}
.settings-page .settings-about:hover {
  background: #f6faf7;
  border-color: #b8d8c2;
}
.settings-page .settings-header h1 {
  font-size: 19px;
  line-height: 1.15;
  font-weight: 750;
  letter-spacing: -0.02em;
  text-align: center;
  color: var(--v2-ink);
  grid-area: auto;
}
.settings-page .settings-back,
.settings-page .lang-btn {
  position: static;
  justify-self: start;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 38px;
  min-width: 42px;
  padding: 0 10px;
  border: 1px solid #d5e1d8;
  border-radius: 13px;
  background: #fff;
  color: #31453a;
  font: 600 13px/1 inherit;
  box-shadow: 0 1px 2px rgba(25, 50, 32, .04);
}
.settings-page .settings-back {
  font-size: 18px;
  width: 42px;
  padding: 0;
}
.settings-page .lang-btn {
  justify-self: end;
  font-size: 12.5px;
  letter-spacing: .02em;
  min-width: 46px;
}

/* ── page content & cards ── */
.settings-page .settings-content {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  align-items: start;
  flex: 0 0 auto;
  gap: 12px;
  padding: 4px 18px 6px;
}
.settings-page .settings-card {
  min-width: 0;
  padding: 14px;
  background: #fff;
  border: 1px solid var(--v2-line);
  border-radius: 18px;
  box-shadow: 0 1px 2px rgba(24, 50, 33, .035);
}
.settings-page .settings-card--mode { grid-column: 1 / -1; padding-bottom: 12px; }
.settings-page .settings-card--table,
.settings-page .settings-card--style,
.settings-page .settings-card--extra {
  grid-column: auto;
  grid-row: auto;
}

.settings-page .settings-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
}
.settings-page .settings-card-head h2 {
  margin: 0;
  font-size: 14px;
  line-height: 1.2;
  font-weight: 750;
  letter-spacing: .005em;
  color: var(--v2-ink);
}
.settings-badge {
  max-width: 62%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding: 4px 8px;
  border-radius: 999px;
  background: #f1f6f2;
  color: #5c7264;
  font-size: 10.5px;
  font-weight: 650;
  line-height: 1.1;
}
.settings-page .field-label {
  margin: 10px 0 5px;
  color: var(--v2-muted);
  font-size: 11px;
  font-weight: 650;
  line-height: 1.2;
}

/* ── modes ── */
.settings-page .mode-switch-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 0;
  padding: 0;
}
.settings-page .mode-switch-row .mode-switch {
  position: relative;
  min-width: 0;
  min-height: 48px;
  margin: 0;
  padding: 9px 10px;
  border: 1px solid var(--v2-line);
  border-radius: 12px;
  background: #fff;
  display: flex;
  align-items: center;
}
.settings-page .mode-switch.on {
  background: #f5fbf7;
  border-color: #bfe3ca;
}
.settings-page .mode-switch .checkbox-label {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 0;
  font-size: 11.5px;
  font-weight: 650;
  line-height: 1.15;
  color: #34493b;
}
.settings-page .mode-switch.on .checkbox-label { color: #23723c; }
.settings-page .mode-switch input[type="checkbox"] {
  appearance: none;
  -webkit-appearance: none;
  position: relative;
  flex: 0 0 32px;
  width: 32px;
  height: 19px;
  min-width: 32px;
  margin: 0;
  border: 0;
  border-radius: 20px;
  background: #dce6df;
  cursor: pointer;
  transition: background .15s;
}
.settings-page .mode-switch input[type="checkbox"]::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 15px;
  height: 15px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(25, 50, 32, .25);
  transition: left .15s;
}
.settings-page .mode-switch input[type="checkbox"]:checked {
  background: var(--v2-accent);
}
.settings-page .mode-switch input[type="checkbox"]:checked::after { left: 15px; }
.settings-page #sprint-mode-row .checkbox-label { padding-right: 31px; }
.settings-page .sprint-direction {
  top: 50%;
  right: 6px;
  width: 24px;
  height: 24px;
  border-radius: 7px;
  background: #fff;
  border-color: #cfe0d4;
  color: #2f7c47;
  font-size: 15px;
}
.settings-page .mode-tooltip {
  z-index: 30;
}

/* ── size ── */
.settings-page #grp-size {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
  width: 100%;
}
.settings-page #grp-size button {
  height: 38px;
  min-height: 38px;
  padding: 0 3px;
  border: 1px solid #dfe9e2;
  border-radius: 11px;
  background: #fff;
  color: #415247;
  font-size: 12px;
  font-weight: 650;
}
.settings-page #grp-size button.active {
  border-color: var(--v2-accent);
  background: var(--v2-soft);
  color: #23723c;
  font-weight: 750;
}
.settings-page #grp-size button.sprint-picked {
  border-color: #8bc99a;
  background: #f4fbf6;
}
.settings-page .sprint-size-hint {
  margin-top: 7px;
  font-size: 10.5px;
  line-height: 1.35;
}

/* ── segmented controls: type, order ── */
.settings-page #grp-type,
.settings-page #grp-order {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 3px;
  padding: 3px;
  border-radius: 12px;
  background: #f0f5f1;
  width: 100%;
}
.settings-page #grp-type button,
.settings-page #grp-order button {
  height: 34px;
  min-height: 34px;
  padding: 0 2px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: #405347;
  font-size: 11.5px;
  font-weight: 650;
  box-shadow: none;
}
.settings-page #grp-type button.active,
.settings-page #grp-order button.active {
  background: #fff;
  color: #24763e;
  box-shadow: 0 1px 3px rgba(28, 58, 37, .13);
}

/* ── style tiles ── */
.settings-page #grp-style {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 7px;
  width: 100%;
}
.settings-page #grp-style .style-choice {
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 59px;
  padding: 8px 9px;
  border: 1px solid var(--v2-line);
  border-radius: 13px;
  background: #fff;
  text-align: left;
  color: var(--v2-ink);
  overflow: hidden;
}
.settings-page #grp-style .style-choice.active {
  border-color: var(--v2-accent);
  background: #f5fbf7;
  box-shadow: inset 0 0 0 1px var(--v2-accent);
}
.settings-page .style-swatch {
  flex: 0 0 30px;
  width: 30px;
  height: 30px;
  border: 1px solid #dfe7e1;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #fff;
  color: #263a2d;
  font-size: 11px;
  font-weight: 750;
  line-height: 1;
}
.settings-page .style-swatch--rounded { border-radius: 50%; }
.settings-page .style-swatch--colored {
  border: 0;
  background: conic-gradient(from -35deg, #4DB6AC 0 25%, #F9CF3E 0 50%, #F07150 0 75%, #64B5F6 0);
}
.settings-page .style-swatch--elements { color: #f07150; border-color: #f1d3c8; font-size: 15px; }
.settings-page .style-copy { min-width: 0; }
.settings-page #grp-style .style-copy b {
  display: block;
  font-size: 10.5px;
  line-height: 1.16;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.settings-page #grp-style .style-copy small {
  display: block;
  margin-top: 2px;
  font-size: 9.4px;
  line-height: 1.15;
  color: var(--v2-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.settings-page .style-check {
  display: none;
  position: absolute;
  top: 6px;
  right: 6px;
  width: 15px;
  height: 15px;
  border-radius: 50%;
  background: var(--v2-accent);
  color: #fff;
  font-size: 9px;
  font-weight: 750;
  line-height: 15px;
  text-align: center;
}
.settings-page #grp-style .style-choice.active .style-check { display: block; }

/* ── alphabetic options inside the table card ── */
.settings-page #alpha-options {
  display: none;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 10px;
  margin-top: 9px;
  padding-top: 10px;
  border-top: 1px solid var(--v2-line-soft);
}
.settings-page #alpha-options .setting-group { min-width: 0; margin: 0; }
.settings-page #alpha-options .setting-group label {
  display: block;
  margin: 0 0 5px;
  font-size: 10.5px;
  font-weight: 650;
  color: var(--v2-muted);
}
.settings-page #alpha-options .btn-group {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  justify-content: flex-start;
}
.settings-page #alpha-options .btn-group button {
  height: 32px;
  min-height: 32px;
  padding: 0 8px;
  border: 1px solid #dfe9e2;
  border-radius: 9px;
  background: #fff;
  color: #405347;
  font-size: 10.5px;
  font-weight: 650;
}
.settings-page #alpha-options .btn-group button.active {
  border-color: var(--v2-accent);
  background: var(--v2-soft);
  color: #23723c;
}

/* ── locked style/order for Gorbo ── */
.settings-page #sg-style.locked,
.settings-page #sg-order.locked {
  opacity: .42;
  pointer-events: none;
  user-select: none;
}

/* ── extra toggles ── */
.settings-page .extra-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7px;
}
.settings-page .toggle-card {
  min-width: 0;
  min-height: 52px;
  padding: 8px 9px;
  border: 1px solid var(--v2-line);
  border-radius: 12px;
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}
.settings-page .toggle-copy { min-width: 0; }
.settings-page .toggle-copy b {
  display: block;
  font-size: 11px;
  line-height: 1.15;
  font-weight: 700;
  color: #34493b;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.settings-page .toggle-copy small {
  display: block;
  margin-top: 1px;
  font-size: 9.4px;
  line-height: 1.15;
  color: var(--v2-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.settings-page .ui-switch {
  position: relative;
  flex: 0 0 34px;
  width: 34px;
  height: 20px;
  padding: 0;
  border: 0;
  border-radius: 20px;
  background: #dce6df;
  cursor: pointer;
  transition: background .15s;
}
.settings-page .ui-switch::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(25, 50, 32, .25);
  transition: left .15s;
}
.settings-page .ui-switch.on { background: var(--v2-accent); }
.settings-page .ui-switch.on::after { left: 16px; }
.settings-page .legacy-group { display: none !important; }

/* ── bottom rows ── */
.settings-page .settings-rows {
  margin-top: 9px;
  border-top: 1px solid var(--v2-line-soft);
}
.settings-page .settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
  min-height: 43px;
  padding: 0 1px;
  border: 0;
  border-bottom: 1px solid var(--v2-line-soft);
  background: transparent;
  color: #34493b;
  font: 650 12px/1.2 inherit;
  text-align: left;
}
.settings-page .settings-row:last-child { border-bottom: 0; }
.settings-page .row-chevron {
  color: #8b9c91;
  font-size: 18px;
  font-weight: 400;
  line-height: 1;
}
.settings-page #btn-appearance.settings-row {
  min-height: 43px;
  margin: 0;
  padding: 0 1px;
  border: 0;
  border-bottom: 1px solid var(--v2-line-soft);
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  font: 650 12px/1.2 inherit;
  color: #34493b;
}
.settings-page #btn-appearance.settings-row:hover { background: transparent; }
.settings-page .save-setting-group {
  margin: 0;
  padding: 0;
  display: flex;
  min-height: 43px;
}
.settings-page .switch-control {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  flex: 0 0 auto;
  cursor: pointer;
}
.settings-page .switch-control input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}
.settings-page .switch-track {
  position: relative;
  display: block;
  width: 34px;
  height: 20px;
  border-radius: 20px;
  background: #dce6df;
  transition: background .15s;
}
.settings-page .switch-track::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(25, 50, 32, .25);
  transition: left .15s;
}
.settings-page .switch-control input:checked + .switch-track { background: var(--v2-accent); }
.settings-page .switch-control input:checked + .switch-track::after { left: 16px; }
.settings-page .switch-control input:focus-visible + .switch-track {
  outline: 2px solid #7acb91;
  outline-offset: 2px;
}

/* ── sticky CTA ── */
/* The appearance preview modal must sit above the sticky Start footer. */
.settings-page #appearance-overlay {
  z-index: 200;
}

.settings-page .settings-actions {
  position: sticky;
  bottom: 0;
  z-index: 20;
  margin-top: auto;
  padding: 10px 18px calc(16px + env(safe-area-inset-bottom));
  border-radius: 0 0 24px 24px;
  background: linear-gradient(180deg, rgba(238, 244, 239, 0), var(--v2-page) 38%);
}
.settings-page #btn-start {
  display: block;
  width: 100%;
  max-width: 320px;
  height: 54px;
  min-height: 54px;
  margin: 0 auto;
  padding: 0 20px;
  border: 0;
  border-radius: 16px;
  background: var(--v2-accent);
  color: #fff;
  font-size: 17px;
  font-weight: 750;
  box-shadow: 0 8px 18px rgba(47, 158, 83, .22);
}
.settings-page #btn-start:hover { background: var(--v2-accent-dark); }

/* ── reset legacy setting group spacing inside the new page ── */
#screen-settings.settings-page .settings-card .setting-group,
#screen-settings.settings-page .settings-card .save-setting-group {
  margin-top: 0;
  margin-bottom: 0;
}

/* ── desktop / tablet breakpoints ── */
@media (min-width: 881px) {
  /* Footer is outside the flow of the cards and cannot cover them. */
  #screen-settings.settings-page { min-height: 0; }
  .settings-page .settings-actions {
    position: static;
    margin-top: 12px;
  }
}

@media (max-width: 1100px) {
  .settings-page .settings-content {
    grid-template-columns: minmax(0, 1fr);
    gap: 10px;
  }
  .settings-page .settings-card--mode,
  .settings-page .settings-card--table,
  .settings-page .settings-card--style,
  .settings-page .settings-card--extra {
    grid-column: 1;
    grid-row: auto;
  }
}

@media (max-width: 880px) {
  .settings-page .settings-content {
    grid-template-columns: minmax(0, 1fr);
    gap: 10px;
    padding: 4px 14px 6px;
  }
  .settings-page .settings-card--mode,
  .settings-page .settings-card--table,
  .settings-page .settings-card--style,
  .settings-page .settings-card--extra {
    grid-column: 1;
    grid-row: auto;
  }
  .settings-page .settings-header { padding: 13px 14px 9px; }
  .settings-page .settings-actions { padding-left: 14px; padding-right: 14px; }
}

@media (max-width: 600px) {
  #settings-layout { width: 100%; }
  .settings-page .settings-header {
    grid-template-columns: 1fr auto;
    grid-template-rows: auto auto;
    gap: 8px 10px;
    padding: 12px 14px 8px;
  }
  .settings-page .settings-header-left { grid-column: 1; grid-row: 1; gap: 6px; }
  .settings-page .settings-about { padding: 0 9px; font-size: 11.5px; }
  .settings-page .settings-header .lang-btn {
    grid-column: 2;
    grid-row: 1;
    justify-self: end;
  }
  .settings-page .settings-header h1 {
    grid-column: 1 / -1;
    grid-row: 2;
    font-size: 18px;
    text-align: center;
  }
  .settings-page .settings-card { padding: 12px; border-radius: 16px; }
  .settings-page .settings-content { padding: 2px 12px 4px; gap: 9px; }
  .settings-page .settings-card-head h2 { font-size: 13.5px; }
  .settings-page .mode-switch .checkbox-label { font-size: 11px; }
  .settings-page .settings-actions { padding-left: 12px; padding-right: 12px; }
  .settings-page #btn-start { max-width: none; }
}

@media (max-width: 360px) {
  .settings-page .settings-about { padding: 0 7px; font-size: 11px; }
  .settings-page .settings-header-left { gap: 5px; }
  .settings-page .mode-switch .checkbox-label { gap: 5px; font-size: 10.5px; }
  .settings-page .mode-switch input[type="checkbox"] { flex-basis: 30px; width: 30px; min-width: 30px; }
  .settings-page .mode-switch input[type="checkbox"]::after { width: 14px; height: 14px; }
  .settings-page .mode-switch input[type="checkbox"]:checked::after { left: 14px; }
  .settings-page #grp-style .style-copy b { font-size: 10px; }
  .settings-page #grp-style .style-copy small { font-size: 9px; }
  .settings-page .toggle-copy b { font-size: 10.5px; }
}
