/* Appearance tokens are shared by catalogs, sheets, SVG charts and native controls.
   Puzzle sticker colors stay unchanged; diagrams use their original dark artwork. */
:root {
  --sticker-border: #000;
  --glass: rgba(255, 255, 255, 0.3);
  --on-accent: #fff;
}
:root[data-mode='dark'] {
  color-scheme: dark;
  color: var(--text);
  --primary: #000;
  --theme-end: #008080;
  --accent: #80ffff;
  --text: #fff;
  --muted: rgba(224, 241, 243, 0.55);
  --bg: #071719;
  --panel: color-mix(in srgb, var(--theme-end) 30%, transparent);
  --line: color-mix(in srgb, var(--theme-end) 60%, #000 40%);
  --sidebar: rgba(27, 38, 43, 0.8);
  --tint: rgba(194, 236, 242, 0.1);
  --control: rgba(184, 220, 232, 0.16);
  --selected: rgba(188, 218, 230, 0.32);
  --glass: rgba(139, 244, 250, 0.16);
  --on-accent: #001a1a;
  --sticker-border: #b7c5c5;
  --gradient: linear-gradient(
    var(--native-gradient-angle, 135deg),
    var(--primary),
    var(--theme-end)
  );
  --red: #ff6868;
  --green: #32d65c;
  background: #000;
}
:root[data-mode='dark'] body,
:root[data-mode='dark'] body::before,
:root[data-mode='dark'] dialog,
:root[data-mode='dark'] dialog.notation-sheet,
:root[data-mode='dark'] dialog.playback-sheet {
  background: var(--gradient) fixed;
}
:root[data-mode='dark'] .sidebar {
  background: var(--sidebar);
}
:root[data-mode='dark'] .sidebar-group > summary {
  color: var(--muted);
}
:root[data-mode='dark'] .mobile-tabs,
:root[data-mode='dark'] .toolbar-pill,
:root[data-mode='dark'] .mobile-practice-actions,
:root[data-mode='dark'] .native-tabs {
  background: var(--glass);
  border-color: rgba(169, 245, 245, 0.25);
  box-shadow: inset 0 1px 2px #ffffff18;
}
:root[data-mode='dark'] .mobile-tabs a {
  color: var(--text);
}
:root[data-mode='dark'] .mobile-tabs a.active {
  color: var(--accent);
  background: color-mix(in srgb, var(--theme-end) 45%, #000 55%);
}
:root[data-mode='dark'] .icon-button,
:root[data-mode='dark'] .timer-penalties .button,
:root[data-mode='dark'] .native-stat-pills > div {
  background: var(--glass);
  border-color: rgba(190, 236, 240, 0.22);
  box-shadow: inset 0 1px 2px #ffffff18;
}
:root[data-mode='dark'] .toolbar-pill .icon-button,
:root[data-mode='dark'] .mobile-practice-actions .icon-button {
  background: transparent;
  box-shadow: none;
}
:root[data-mode='dark'] .button.primary,
:root[data-mode='dark'] .native-pro-banner .button.primary {
  color: var(--on-accent);
}
:root[data-mode='dark'] .set-card,
:root[data-mode='dark'] .video-card,
:root[data-mode='dark'] .algorithm-row,
:root[data-mode='dark'] .native-history-item,
:root[data-mode='dark'] .panel,
:root[data-mode='dark'] .puzzle-menu-button,
:root[data-mode='dark'] .notation-card,
:root[data-mode='dark'] .solution-row .solution,
:root[data-mode='dark'] .solutions-panel > [data-action='add-notation'] {
  background: var(--panel);
  border-color: var(--line);
}
:root[data-mode='dark'] .segmented,
:root[data-mode='dark'] .preview-mode-tabs,
:root[data-mode='dark'] .practice-menu-options {
  background: var(--control);
}
:root[data-mode='dark'] .segmented button {
  color: var(--muted);
}
:root[data-mode='dark'] .segmented button.selected {
  color: var(--text);
}
:root[data-mode='dark'] .learning-control button.selected {
  color: #fff;
}
:root[data-mode='dark'] .chip,
:root[data-mode='dark'] .notation-keyboard .button {
  background: var(--control);
  border-color: var(--line);
}
:root[data-mode='dark'] .chip.selected {
  color: var(--text);
  background: var(--selected);
}
:root[data-mode='dark'] .editor-input textarea {
  border-color: rgba(194, 228, 232, 0.3);
}
:root[data-mode='dark'] .native-video-placeholder {
  color: var(--text);
}
:root[data-mode='dark'] .list-toolbar input {
  background: var(--control);
}
:root[data-mode='dark'] .puzzle-wheel-window::before {
  background: var(--control);
}
:root[data-mode='dark'] .play-badge {
  background: #ffffffb3;
}
:root[data-mode='dark'] #timer-digits {
  color: #cad7d7;
}
:root[data-mode='dark'] #toast {
  background: #193b3d;
  color: #fff;
  border-color: #ffffff30;
}
:root[data-mode='dark'] dialog::backdrop {
  background: #0008;
}

/* The iPad Settings screen is a centered stack of panels. Phone previews show
   the same controls inline, with no page-specific palette overrides. */
.settings-grid {
  display: flex;
  flex-direction: column;
  max-width: 720px;
  margin: 20px auto;
  gap: 24px;
}
.settings-grid > .panel {
  padding: 18px;
  border-radius: 20px;
}
.settings-grid .panel-heading h2 {
  font-size: 17px;
}
.settings-grid .field-label {
  display: block;
  margin: 20px 0 9px;
  font-size: 15px;
}
.settings-grid .segmented {
  min-height: 34px;
}
.settings-grid .segmented button {
  font-size: 14px;
}
.settings-grid .theme-swatches {
  display: flex;
  justify-content: center;
  gap: 12px;
  flex-wrap: wrap;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--panel);
}
.settings-grid .swatch {
  width: 32px;
  height: 32px;
  border: 0;
  box-shadow: none;
}
.settings-grid .swatch.selected {
  outline: 3px solid var(--text);
  outline-offset: 1px;
}
.settings-grid .help-text {
  color: var(--muted);
  line-height: 1.4;
  font-size: 14px;
}
.settings-offer .native-pro-banner {
  margin: 0;
}
.settings-case-preview {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px;
  border-radius: 16px;
  margin-top: 12px;
  min-height: 78px;
}
.settings-case-preview .row-diagram {
  display: block;
  width: 56px;
  height: 56px;
  flex-shrink: 0;
}
.settings-case-preview img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}
.settings-case-preview strong {
  display: block;
  margin-top: 4px;
  font-size: 17px;
}
.settings-case-preview .status-dot {
  background: var(--green);
  width: 12px;
  height: 12px;
  flex-shrink: 0;
}
:root[data-row-style='glow'] .settings-case-preview .status-dot {
  display: none;
}
:root[data-row-style='glow'] .settings-case-preview picture {
  filter: drop-shadow(0 0 9px var(--green));
}
.settings-info-preview {
  padding: 12px;
  background: var(--tint);
  border-radius: 16px;
  margin-top: 12px;
}
.settings-info-preview h3 {
  display: flex;
  justify-content: space-between;
  margin: 0;
  font-size: 18px;
}
.settings-info-preview h3 .icon {
  color: var(--accent);
}

/* Native practice: scramble above the stopwatch, diagram below, history beside it. */
.practice-options {
  display: none;
}
.practice-screen > .page-head {
  display: none;
}
.practice-screen {
  height: 100%;
  min-height: 0;
}
.practice-stage {
  grid-template-rows: auto minmax(140px, 1fr) auto auto;
  gap: 16px;
}
.practice-stage > .scramble {
  font-size: clamp(21px, 2.1vw, 28px);
  font-weight: 700;
  padding: 4px 10px;
  line-height: 1.35;
  max-height: none;
}
.practice-clock #timer-digits {
  font-family: ui-monospace, 'SFMono-Regular', Menlo, monospace;
  font-weight: 500;
  font-variant-numeric: tabular-nums slashed-zero;
  font-feature-settings: 'zero' 1;
  font-size: clamp(70px, 7vw, 92px);
}
.timer-fraction {
  font-size: 0.7em;
}
.practice-clock #timer-hint {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
}
.practice-clock .practice-summary {
  color: var(--muted);
  margin-top: 18px;
  font-size: 16px;
}
.practice-preview-bottom {
  min-height: 130px;
  text-align: center;
}
.practice-preview-bottom .cube-net {
  width: 260px;
  max-width: 90%;
  height: min(180px, 23dvh);
}
.practice-preview-bottom picture {
  width: 110px;
  height: 110px;
}
.practice-preview-bottom p.native-case-notation {
  color: var(--text);
  font-size: 17px;
  font-weight: 600;
}
.preview-hidden {
  visibility: hidden;
}
.native-practice-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 54px;
}
.practice-stage > .native-practice-controls .icon-button {
  width: 64px;
  height: 54px;
  padding: 12px;
  border-radius: 28px;
  color: var(--accent);
}
.practice-stage > .native-practice-controls .icon {
  width: 32px;
  height: 32px;
}
.scramble-navigation {
  display: flex;
  gap: 8px;
}
.previous-scramble .icon {
  transform: rotate(180deg);
}
.timer-penalties .button {
  border-radius: 28px;
  min-width: 88px;
  min-height: 46px;
  font-size: 18px;
}
.practice-pane-tabs {
  margin: 0 0 12px;
}
.practice-history-card[hidden],
.practice-cases-pane[hidden] {
  display: none;
}
.practice-case-choice {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 12px;
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 16px;
  margin: 8px 0;
  text-align: left;
}
.practice-case-choice picture {
  width: 52px;
  height: 52px;
  display: block;
}
.practice-case-choice img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}
.native-history-item .penalty-select {
  display: none;
}
.history-day > h3 {
  font-size: 15px;
  font-weight: 600;
  color: var(--muted);
  margin: 28px 10px 9px;
}
.practice-history-card .history-day > h3 {
  color: var(--text);
  margin: 20px 0 6px;
}
.native-history-item small {
  color: var(--muted);
}

/* Expanded trend sheets keep the full chronological chart next to grouped solves. */
.trend-statistics {
  display: flex;
  flex-wrap: nowrap;
  overflow-x: auto;
  justify-content: center;
  gap: 8px;
}
.trend-statistics > div {
  flex: 0 0 auto;
  min-width: 60px;
  padding: 8px;
  border-radius: 16px;
  text-align: center;
}
.trend-statistics span {
  font-size: 12px;
}
.trend-statistics strong {
  font-size: 17px;
}
.trend-workspace {
  display: grid;
  grid-template-columns: 52fr 48fr;
  gap: 24px;
  height: 100%;
  min-height: 0;
}
.trend-chart-pane,
.trend-history-pane {
  min-width: 0;
  overflow-y: auto;
}
.trend-chart-pane .trend {
  width: 100%;
  height: 58dvh;
  max-height: none;
  margin-top: 35px;
}
.trend-history-pane {
  padding: 0 8px;
  display: flex;
  flex-direction: column;
}
.trend-history-pane > .native-history-list {
  margin-bottom: 16px;
}
button.text-link {
  border: 0;
  background: transparent;
  padding: 0;
  text-align: left;
}
.clear-times {
  position: sticky;
  bottom: 0;
  width: 100%;
  min-height: 50px;
  font-size: 18px;
  font-weight: 600;
  border-radius: 26px;
  background: var(--glass);
  backdrop-filter: blur(20px);
  margin-top: auto;
  flex-shrink: 0;
}
.all-history-link {
  display: block;
  margin: 16px 0;
}

@media (min-width: 701px) and (min-height: 501px), (min-width: 701px) and (pointer: fine) {
  .practice-layout {
    grid-template-columns: minmax(0, 1fr) minmax(270px, 34%);
    gap: 24px;
    height: 100%;
  }
  .workspace[data-screen='practice'] main {
    padding-top: 12px;
  }
  dialog.history-sheet {
    position: fixed;
    inset: 0;
    margin: 0;
    width: 100%;
    max-width: none;
    height: 100dvh;
    max-height: none;
    padding: 16px 24px;
    border: 0;
    border-radius: 0;
  }
  .history-sheet .modal-head {
    justify-content: center;
    position: relative;
    min-height: 44px;
    margin-bottom: 28px;
  }
  .history-sheet .modal-head h2 {
    font-size: 17px;
  }
  .history-sheet .modal-head .icon-button {
    position: absolute;
    right: 0;
  }
  .practice-history-sheet {
    height: calc(100% - 90px);
  }
  .practice-history-sheet .all-history-link {
    position: absolute;
    bottom: 8px;
    left: 24px;
    font-size: 13px;
  }
  .settings-grid .setting-row {
    padding: 15px 0;
  }
}
@media (max-width: 700px), (max-height: 500px) and (pointer: coarse) {
  :root[data-mode='dark'] .settings-grid > .panel {
    background: transparent;
    border: 0;
  }
  .workspace[data-screen='settings'] .page-head {
    justify-content: center;
    text-align: center;
  }
  .workspace[data-screen='settings'] .page-head h1 {
    font-size: 20px;
  }
  .settings-grid {
    margin: 0;
    gap: 26px;
  }
  .settings-grid > .panel {
    padding: 0;
    background: transparent;
    border: 0;
  }
  .settings-grid > .settings-offer {
    padding: 16px 0;
  }
  .settings-grid .theme-swatches {
    gap: 10px;
    flex-wrap: nowrap;
  }
  .settings-grid .swatch {
    width: 31px;
    height: 31px;
    flex-shrink: 0;
  }
  .settings-grid .segmented button {
    font-size: 14px;
    padding: 8px;
  }
  .settings-grid .field-label {
    color: var(--muted);
    font-weight: 600;
  }
  .settings-grid .panel-heading {
    margin-bottom: 16px;
  }
  .workspace[data-screen='practice'] .topbar-left {
    flex: 1;
  }
  .mobile-session-title {
    white-space: normal;
    overflow: visible;
    text-align: center;
    font-size: 17px;
  }
  .mobile-practice-actions {
    border: 1px solid var(--line);
    border-radius: 28px;
    padding: 2px 4px;
  }
  .mobile-practice-actions .icon-button {
    border: 0;
    width: 38px;
  }
  .practice-stage {
    gap: 12px;
    grid-template-rows: auto minmax(140px, 1fr) auto auto;
  }
  .practice-stage > .scramble {
    font-size: clamp(20px, 5.8vw, 27px);
    line-height: 1.3;
  }
  .practice-clock #timer-digits {
    font-size: 70px;
  }
  .practice-preview-bottom picture {
    width: 110px;
    height: 110px;
  }
  .practice-stage > .native-practice-controls .icon-button {
    width: 64px;
    height: 54px;
  }
  .trend-workspace {
    display: block;
    height: auto;
  }
  .trend-chart-pane .trend {
    height: 35dvh;
    margin-top: 20px;
  }
  .trend-statistics {
    justify-content: flex-start;
    padding: 0 0 8px;
  }
  .trend-history-pane {
    display: block;
    overflow: visible;
    padding: 0;
  }
  dialog.history-sheet {
    inset: auto 0 0;
    margin: 0;
    width: 100%;
    max-width: none;
    max-height: calc(100dvh - 24px);
    height: calc(100dvh - 24px);
    border-radius: 36px 36px 0 0;
  }
  .history-sheet .modal-head {
    position: relative;
    justify-content: center;
    min-height: 44px;
  }
  .history-sheet .modal-head .icon-button {
    position: absolute;
    right: 0;
  }
  .history-sheet .modal-head h2 {
    text-align: center;
    font-size: 18px;
  }
}
/* Phone landscape gives the clock and preview separate columns and a compact tab bar. */
@media (max-height: 500px) and (pointer: coarse), (max-width: 700px) and (max-height: 500px) {
  .mobile-tabs {
    width: min(440px, calc(100% - 48px));
    left: 50%;
    right: auto;
    transform: translateX(-50%);
    min-height: 44px;
    bottom: 18px;
  }
  .mobile-tabs a {
    min-height: 34px;
    flex-direction: row;
    gap: 8px;
    padding: 8px;
    font-size: 13px;
  }
  .mobile-tabs .icon {
    width: 23px;
    height: 23px;
  }
  .workspace[data-screen='practice'] main {
    padding-bottom: 65px;
  }
  .practice-stage > .native-practice-controls {
    justify-content: space-between;
    padding: 0 7%;
    min-height: 42px;
  }
  .practice-stage {
    grid-template-rows: auto minmax(0, 1fr) auto;
    grid-template-areas: 'scramble preview' 'clock preview' 'controls controls';
    grid-template-columns: minmax(0, 7fr) minmax(0, 3fr);
    gap: 4px 14px;
  }
  .practice-stage > .scramble {
    font-size: 25px;
  }
  .practice-clock #timer-digits {
    font-size: 54px;
  }
  .practice-clock .practice-summary {
    font-size: 13px;
    margin: 8px 0;
  }
  .practice-preview-bottom .cube-net {
    height: 120px;
  }
  .practice-preview-bottom picture {
    width: 70px;
    height: 70px;
  }
  .practice-stage > .native-practice-controls .icon-button {
    width: 50px;
    height: 42px;
    padding: 8px;
  }
  .trend-workspace {
    display: grid;
  }
  .trend-chart-pane .trend {
    height: 50dvh;
    margin-top: 8px;
  }
}
/* Keep the stopwatch visible when a solve starts; surrounding panes remain intact. */
.workspace[data-timer-active='true'] .practice-preview-bottom,
.workspace[data-timer-active='true'] .native-practice-controls,
.workspace[data-timer-active='true'] .practice-stage > .scramble {
  visibility: hidden;
}
.workspace[data-timer-active='true'] #timer-digits {
  color: var(--text);
}
.settings-grid {
  align-items: stretch;
  width: min(720px, 100%);
}
.settings-style-link {
  display: none;
}
.settings-style-dialog .settings-style-link {
  display: none;
}
.settings-style-dialog .settings-style-controls {
  display: block;
}
@media (min-width: 701px) and (min-height: 501px), (min-width: 701px) and (pointer: fine) {
  .settings-grid .settings-style-controls.rowStyle,
  .settings-grid .settings-style-controls.infoStyle,
  .settings-grid .settings-row-preview,
  .settings-grid .settings-row-preview + .help-text,
  .settings-grid .settings-info-preview,
  .settings-grid .settings-info-preview + .help-text {
    display: none;
  }
  .settings-grid .settings-style-link {
    display: flex;
    width: 100%;
    align-items: center;
    justify-content: space-between;
    padding: 20px 0;
    border: 0;
    border-top: 1px solid var(--line);
    background: transparent;
    font-size: 17px;
    text-align: left;
  }
  .settings-style-link span {
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--muted);
  }
  .settings-style-link .icon {
    width: 16px;
    height: 16px;
  }
}
