/* ==========================================================================
   Liquid Glass Sheet Modals
   ========================================================================== */

dialog.glass-sheet-modal {
  position: fixed;
  inset: 0;
  margin: auto;
  border: none;
  background: transparent;
  padding: 0;
  max-width: 540px;
  width: min(540px, calc(100vw - 32px));
  height: fit-content;
  max-height: 90dvh;
  border-radius: var(--r-xl);
  box-shadow: 0 40px 100px -10px rgba(0, 0, 0, 0.95);
  overflow: hidden;
  z-index: 1000;
}

dialog.glass-sheet-modal[open] {
  animation: modalPopIn 0.24s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

@keyframes modalPopIn {
  from {
    opacity: 0;
    transform: scale(0.95) translateY(12px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

dialog.glass-sheet-modal:not([open]) {
  display: none;
}

dialog.glass-sheet-modal::backdrop {
  background: rgba(0, 0, 0, 0.82);
  backdrop-filter: blur(28px) saturate(190%);
  -webkit-backdrop-filter: blur(28px) saturate(190%);
  animation: backdropFadeIn 0.22s ease forwards;
}

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

/* Unified Sizing Architecture: All core utility modals share identical 540px width */
#cross-modal,
#avg-modal,
#settings-modal,
#solve-modal,
#session-modal,
#alg-player-modal {
  max-width: 540px;
  width: min(540px, calc(100vw - 32px));
}

#confirm-dialog {
  max-width: 400px;
  width: min(400px, calc(100vw - 32px));
}

.modal-card {
  background: var(--glass-sheet-fill);
  backdrop-filter: var(--glass-blur-lg);
  -webkit-backdrop-filter: var(--glass-blur-lg);
  box-shadow: var(--liquid-shadow-lg);
  border-radius: var(--r-xl);
  padding: 20px;
  color: var(--text-primary);
  display: flex;
  flex-direction: column;
  gap: 14px;
  position: relative;
  max-height: 92dvh;
  overflow-y: auto;
  overflow-x: hidden;
}

.modal-card::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: var(--r-xl);
  padding: 1px;
  background: var(--liquid-rim-refraction);
  -webkit-mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
  -webkit-mask-composite: xor;
  mask-composite: exclude;
  pointer-events: none;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-eyebrow {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--text-tertiary);
}

.modal-close-circle {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.07);
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: transform 0.18s var(--ease-apple), background 0.18s var(--ease-apple), color 0.18s var(--ease-apple), border-color 0.18s var(--ease-apple);
}

.modal-close-circle:hover {
  background: rgba(255, 255, 255, 0.16);
  border-color: rgba(255, 255, 255, 0.28);
  color: #FFFFFF;
  transform: scale(1.06);
}

.modal-close-circle:active {
  transform: scale(0.92);
}

.modal-time-stage {
  text-align: center;
  padding: 2px 0;
}

#modal-solve-time {
  font-family: var(--font-display);
  font-feature-settings: "tnum" 1, "cv11" 1;
  font-size: clamp(2.4rem, 10vw, 3.4rem);
  font-weight: 650;
  letter-spacing: -0.045em;
  color: #F5F5F7;
  word-break: break-word;
}

.modal-date-tag {
  font-size: 0.75rem;
  color: var(--text-tertiary);
  margin-top: 3px;
}

.modal-scramble-box {
  background: rgba(255, 255, 255, 0.045);
  border: 1px solid rgba(255, 255, 255, 0.09);
  border-radius: var(--r-md);
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
  box-sizing: border-box;
}

.modal-scramble-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-width: 0;
}

.modal-scramble-box label {
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-tertiary);
  white-space: nowrap;
  flex-shrink: 0;
}

#modal-solve-scramble {
  font-size: 0.88rem;
  color: #F5F5F7;
  line-height: 1.48;
}

#modal-cube-preview {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  padding: 4px 0;
  width: 100%;
}

#modal-cube-preview .cube-preview-wrapper {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 105px;
  width: 100%;
}

#modal-cube-preview svg {
  max-height: 120px;
  width: auto;
}

.modal-actions-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: 2px;
}

.penalty-switch-group {
  display: flex;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.11);
  border-radius: var(--r-pill);
  padding: 3px;
  gap: 4px;
}

.btn-pill {
  border: none;
  background: none;
  color: var(--text-secondary);
  font-family: var(--font-sans);
  font-size: 0.8rem;
  font-weight: 600;
  padding: 6px 14px;
  border-radius: var(--r-pill);
  cursor: pointer;
  transition: background 0.16s var(--ease-apple), color 0.16s var(--ease-apple);
}

.btn-pill:hover {
  background: rgba(255, 255, 255, 0.10);
  color: #FFFFFF;
}

.btn-pill.active {
  background: rgba(255, 255, 255, 0.22);
  color: #FFFFFF;
}

.btn {
  padding: 10px 18px;
  border: none;
  border-radius: var(--r-pill);
  font-family: var(--font-sans);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  flex-shrink: 0;
  transition: transform 0.15s var(--ease-apple), background 0.18s var(--ease-apple), color 0.18s var(--ease-apple), box-shadow 0.18s var(--ease-apple);
}

.btn:active {
  transform: scale(0.96);
}

.btn-sm {
  padding: 8px 16px;
  font-size: 0.82rem;
}

.btn-primary {
  background: #F5F5F7;
  color: #000000;
}

.btn-primary:hover {
  background: #FFFFFF;
  box-shadow: 0 4px 18px rgba(255, 255, 255, 0.25);
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.08);
  color: #F5F5F7;
  border: 1px solid rgba(255, 255, 255, 0.14);
}

.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.14);
  border-color: rgba(255, 255, 255, 0.24);
  color: #FFFFFF;
}

.btn-danger {
  background: rgba(255, 69, 58, 0.18);
  color: #FF6961;
  border: 1px solid rgba(255, 69, 58, 0.34);
}

.btn-danger:hover {
  background: rgba(255, 69, 58, 0.28);
  border-color: rgba(255, 69, 58, 0.50);
  color: #FF453A;
}

/* Large scramble preview sheet (phones, opened from the compact stats row) */
.cube-preview-large {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 10px;
}

#cube-preview-large .bento-card-head {
  justify-content: center;
}

#cube-preview-large .bento-card-title {
  display: none;
}

#cube-preview-large .cube-view-seg-btn {
  min-width: 52px;
  height: 30px;
  font-size: 0.8rem;
}

#cube-preview-large .cube-reset-pill {
  width: 30px;
  height: 30px;
  font-size: 0.9rem;
}

#cube-preview-large .cube-preview-wrapper {
  height: min(280px, 40dvh);
}

#cube-preview-large .cube-net-svg,
#cube-preview-large .cube-3d-svg {
  width: 100%;
  height: 100%;
}

.cube-preview-caption {
  margin: 0;
  text-align: center;
  font-size: 0.78rem;
  line-height: 1.45;
  color: var(--text-tertiary);
}

/* Session Manager */
/* Puzzle / scramble type pickers and the "Practice" title: portrait phones only (mobile.css) */
.session-context-block,
.ctx-title-phone {
  display: none;
}

.ctx-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.ctx-group-label {
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-tertiary);
}

.ctx-event-seg {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 3px;
  padding: 3px;
  border-radius: var(--r-pill);
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.ctx-chip {
  font-family: var(--font-sans);
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.18s var(--ease-apple), color 0.18s var(--ease-apple), border-color 0.18s var(--ease-apple), transform 0.14s var(--ease-apple);
}

.ctx-chip:active {
  transform: scale(0.95);
}

.ctx-event-seg .ctx-chip {
  height: 34px;
  padding: 0 2px;
  border: none;
  border-radius: var(--r-pill);
  background: transparent;
  color: rgba(255, 255, 255, 0.58);
  font-size: 0.84rem;
}

.ctx-event-seg .ctx-chip.active {
  background: rgba(255, 255, 255, 0.14);
  color: #FFFFFF;
  font-weight: 700;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35), inset 0 1px 0.5px rgba(255, 255, 255, 0.28);
}

.ctx-subset-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.ctx-subset-chips .ctx-chip {
  height: 32px;
  padding: 0 13px;
  border-radius: var(--r-pill);
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.09);
  color: var(--text-secondary);
  font-size: 0.8rem;
}

.ctx-subset-chips .ctx-chip.active {
  background: rgba(var(--accent-rgb), 0.18);
  border-color: rgba(var(--accent-light-rgb), 0.45);
  color: var(--accent-light);
}

.new-session-row {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
}

.new-session-row input {
  flex: 1;
  min-width: 0;
  width: 100%;
  background: rgba(255, 255, 255, 0.055);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: var(--r-pill);
  padding: 10px 14px;
  color: #FFFFFF;
  font-family: var(--font-sans);
  font-size: 0.88rem;
  outline: none;
}

.sessions-list-container {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: min(360px, 50dvh);
  overflow-y: auto;
}

.sessions-list-container label {
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-tertiary);
}

#sessions-list-ul {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.session-row-item {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 52px;
  padding: 8px 8px 8px 12px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.07);
  border-radius: var(--r-md);
  cursor: pointer;
  transition: background 0.16s var(--ease-apple), border-color 0.16s var(--ease-apple);
}

.session-row-item:hover {
  background: rgba(255, 255, 255, 0.07);
}

.session-row-item.active {
  border-color: rgba(var(--accent-rgb), 0.45);
  background: rgba(var(--accent-rgb), 0.12);
}

.session-row-mark {
  width: 22px;
  height: 22px;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  color: #fff;
}

.session-row-item.active .session-row-mark {
  background: var(--accent);
  box-shadow: 0 2px 10px rgba(var(--accent-rgb), 0.45);
}

.session-row-item:not(.active) .session-row-mark {
  border: 1.5px solid rgba(255, 255, 255, 0.18);
}

.session-row-info {
  display: flex;
  flex-direction: column;
  gap: 1px;
  flex: 1;
  min-width: 0;
}

.session-row-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.session-row-name {
  font-weight: 600;
  font-size: 0.92rem;
}

.session-row-count {
  font-size: 0.76rem;
  font-family: var(--font-mono);
  color: var(--text-tertiary);
}

.session-row-item .del-session-btn {
  background: none;
  border: none;
  color: var(--text-tertiary);
  cursor: pointer;
  padding: 6px;
  border-radius: 8px;
}

.confirm-card {
  max-width: 370px;
  text-align: center;
}

.confirm-card h3 {
  font-size: 1.15rem;
  font-weight: 600;
}

.confirm-card p {
  font-size: 0.88rem;
  color: var(--text-secondary);
  line-height: 1.5;
  margin: 4px 0 12px;
}

.dialog-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
}


/* ── Modal Scramble Actions, Notes & WCA Average Breakdown ── */
.modal-scramble-btns {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.modal-scramble-btns .text-pill-btn {
  height: 24px;
  padding: 0 10px;
  font-size: 0.68rem;
  letter-spacing: 0.02em;
  flex-shrink: 0;
}

.modal-note-row input {
  width: 100%;
  background: rgba(255, 255, 255, 0.045);
  border: 1px solid rgba(255, 255, 255, 0.09);
  border-radius: var(--r-sm);
  padding: 8px 12px;
  color: #F5F5F7;
  font-family: var(--font-sans);
  font-size: 0.80rem;
  outline: none;
}

.modal-note-row input:focus {
  border-color: rgba(var(--accent-light-rgb), 0.45);
}

.avg-summary-pills {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.avg-summary-box {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 10px 14px;
  background: var(--glass-card-fill);
  border: 1px solid rgba(255, 255, 255, 0.09);
  border-radius: var(--r-md);
}

.avg-summary-val {
  font-size: 1.35rem;
  font-weight: 700;
  color: #F5F5F7;
}

.avg-summary-box.highlight-card .avg-summary-val {
  color: var(--green);
}

.avg-breakdown-list {
  display: flex;
  flex-direction: column;
  gap: 5px;
  max-height: 240px;
  overflow-y: auto;
  padding-right: 2px;
}

.avg-breakdown-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 10px;
  border-radius: var(--r-xs);
  background: rgba(255, 255, 255, 0.035);
  border: 1px solid rgba(255, 255, 255, 0.06);
  font-size: 0.78rem;
}

.avg-breakdown-row.trimmed-best {
  border-color: rgba(48, 209, 88, 0.28);
  color: var(--green);
}

.avg-breakdown-row.trimmed-worst {
  border-color: rgba(255, 159, 10, 0.25);
  color: var(--text-tertiary);
}

.avg-row-idx {
  font-family: var(--font-mono);
  font-size: 0.70rem;
  color: var(--text-tertiary);
  min-width: 24px;
}

.avg-row-time {
  font-family: var(--font-mono);
  font-weight: 700;
  min-width: 64px;
}

.avg-row-scr {
  flex: 1;
  font-family: var(--font-mono);
  font-size: 0.68rem;
  color: var(--text-tertiary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Optimal Cross Planner Modal */
.cross-solutions-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.cross-sol-card {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 10px 12px;
  border-radius: var(--r-md);
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.09);
  cursor: pointer;
  transition: border-color 0.18s var(--ease-apple), background 0.18s var(--ease-apple), transform 0.14s var(--ease-apple);
}

.cross-sol-card:hover {
  background: rgba(255, 255, 255, 0.07);
  border-color: rgba(255, 255, 255, 0.18);
}

.cross-sol-card:active {
  transform: scale(0.98);
}

.cross-sol-card.active {
  background: rgba(var(--accent-rgb), 0.14);
  border-color: rgba(var(--accent-light-rgb), 0.48);
}

.cross-sol-head {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
}

.cross-color-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  flex-shrink: 0;
}

.dot-white {
  background: #F5F5F7;
  box-shadow: 0 0 6px rgba(255, 255, 255, 0.6);
}

.dot-yellow {
  background: #FFD60A;
  box-shadow: 0 0 6px rgba(255, 214, 10, 0.6);
}

.cross-sol-title {
  font-size: 0.74rem;
  font-weight: 700;
  color: var(--text-primary);
  flex: 1;
  min-width: 0;
}

.cross-sol-code {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--accent-light);
  word-break: break-word;
}

/* ── Panel modals (Settings & Profile) share one fixed frame so switching
   tabs or sections never makes the window jump in size. ── */
#settings-modal,
#account-modal.acct-station-modal {
  width: min(580px, calc(100vw - 32px));
  max-width: 580px;
}

#settings-modal .modal-card,
#account-modal .modal-card.acct-modal-card {
  height: min(780px, calc(100dvh - 56px)) !important;
  max-height: none !important;
}

/* Pro Timer Settings Modal: fixed header, scrolling body */
#settings-modal .modal-card {
  padding: 18px 20px 0;
  gap: 12px;
  overflow: hidden;
}

.settings-rows {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  margin: 0 -20px;
  padding: 0 20px 22px;
}

/* Inside the fixed-height scroller the groups must keep their natural height
   (default flex-shrink would squash them and clip rows) */
.settings-rows > * {
  flex-shrink: 0;
}

/* iOS-style grouped list: section caption + one rounded group of rows */
.settings-section-title {
  margin: 14px 4px 6px;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-tertiary);
}

.settings-section-title:first-child {
  margin-top: 2px;
}

.settings-group {
  display: flex;
  flex-direction: column;
  border-radius: var(--r-md);
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
  overflow: hidden;
}

.setting-row {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px 14px;
}

.setting-row + .setting-row {
  border-top: 1px solid rgba(255, 255, 255, 0.06);
}

.setting-row-inline {
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.setting-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.setting-label {
  font-size: 0.86rem;
  font-weight: 600;
  color: #F5F5F7;
}

.setting-desc {
  font-size: 0.74rem;
  line-height: 1.35;
  color: var(--text-tertiary);
}

.setting-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.setting-pills .btn-pill {
  height: 32px;
  padding: 0 13px;
  font-size: 0.78rem;
  background: rgba(255, 255, 255, 0.055);
  border: 1px solid rgba(255, 255, 255, 0.09);
}

.setting-pills .btn-pill.active {
  background: rgba(var(--accent-rgb), 0.24);
  border-color: rgba(var(--accent-light-rgb), 0.52);
  color: var(--accent-light);
}

.setting-row-inline .setting-pills {
  flex-wrap: nowrap;
  flex-shrink: 0;
}

/* Accent colour swatches in Settings → Appearance */
.setting-swatches {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.setting-swatches .glow-swatch-dot {
  width: 32px;
  height: 32px;
  padding: 3px;
}

.setting-swatches .glow-swatch-dot.active {
  transform: none;
}

/* On/off switch */
.setting-switch {
  position: relative;
  flex-shrink: 0;
  width: 46px;
  height: 28px;
  border-radius: var(--r-pill);
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.12);
  cursor: pointer;
  transition: background 0.2s var(--ease-apple), border-color 0.2s var(--ease-apple);
}

.setting-switch::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #FFFFFF;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.4);
  transition: transform 0.22s var(--spring-apple);
}

.setting-switch.active {
  background: var(--green);
  border-color: transparent;
}

.setting-switch.active::after {
  transform: translateX(18px);
}

.settings-export-bar {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  flex-shrink: 0;
}

.settings-export-bar .btn {
  text-align: center;
  padding: 10px 12px;
  font-size: 0.8rem;
  white-space: nowrap;
}

/* Full backup on its own row, the two exports below it. All three are secondary: settings apply
   at once, so a bright button here would read as a "Save" that has to be pressed */
#btn-export-json-modal {
  grid-column: 1 / -1;
}

/* 2D / 3D centred over the cube, as in the large scramble sheet */
#modal-cube-preview .bento-card-head {
  justify-content: center;
  margin-bottom: 4px;
}

/* The scramble box right above already carries the "Scramble" caption */
#modal-cube-preview .bento-card-title {
  display: none;
}

/* Solve sheet: the scramble state deserves a proper-size cube */
#modal-cube-preview .cube-3d-svg {
  width: 168px !important;
  height: 136px !important;
}

#modal-cube-preview .cube-net-svg {
  width: 210px !important;
  height: auto !important;
}

/* Phones: confirm actions as two equal, thumb-sized buttons */
@media (max-width: 920px), (max-width: 1100px) and (max-height: 520px) {
  #confirm-dialog .dialog-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    width: 100%;
  }
  #confirm-dialog .dialog-actions .btn {
    height: 46px;
  }
}
