:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --panel: #ffffff;
  --text: #15181e;
  --muted: #667085;
  --line: #d9dee7;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --teal: #0f766e;
  --danger: #c2410c;
  --danger-dark: #9a3412;
  --shadow: 0 18px 45px rgba(15, 23, 42, 0.08);
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
}

html {
  overflow-y: scroll;
  scrollbar-gutter: stable;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body.timer-running {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100dvh;
  overflow: hidden;
  overscroll-behavior: none;
}

button,
input,
select {
  font: inherit;
}

button {
  min-height: 46px;
  border: 0;
  border-radius: 8px;
  padding: 0 16px;
  background: var(--primary);
  color: #ffffff;
  font-weight: 750;
  cursor: pointer;
}

button:hover {
  background: var(--primary-dark);
}

button.secondary {
  background: #e7ebf2;
  color: #1f2937;
}

button.secondary:hover {
  background: #d6dce8;
}

button.danger {
  background: var(--danger);
}

button.danger:hover {
  background: var(--danger-dark);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.6;
}

input,
select {
  width: 100%;
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  background: #ffffff;
  color: var(--text);
}

label span,
.label,
.eyebrow {
  display: block;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.app-shell {
  width: 100%;
  max-width: 1100px;
  margin: 0 auto;
  padding: 18px 14px 28px;
  overflow-x: clip;
}

.auth-view {
  display: grid;
  min-height: 92vh;
  align-content: center;
  gap: 22px;
}

.brand-block h1,
.topbar .eyebrow {
  margin: 2px 0 0;
  font-size: clamp(2rem, 9vw, 4.25rem);
  line-height: 1;
}

.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  min-width: 0;
}

.auth-panel {
  display: grid;
  gap: 16px;
  padding: 18px;
}

.auth-actions,
.result-actions,
.settings-actions {
  display: grid;
  gap: 10px;
}

.form-message {
  min-height: 1.25rem;
  margin: 0;
  color: var(--danger);
  font-weight: 700;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
  min-width: 0;
}

.topbar .eyebrow {
  color: var(--text);
  font-size: 2rem;
  font-weight: 900;
  text-transform: none;
}

.tabbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
  padding: 8px 0 14px;
  background: var(--bg);
  min-width: 0;
}

.tab {
  min-height: 42px;
  background: #e7ebf2;
  color: #1f2937;
}

.tab.active {
  background: var(--text);
  color: #ffffff;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.trainer-controls {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  margin: 14px 0 12px;
  min-width: 0;
}

.case-picker {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin: 0 0 12px;
  min-width: 0;
}

.case-chip input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.case-chip span {
  display: grid;
  min-height: 42px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  color: var(--text);
  font-size: 1rem;
  font-weight: 850;
  text-transform: none;
}

.case-chip input:checked + span {
  border-color: var(--primary);
  background: #dbeafe;
  color: #1e3a8a;
}

.timer-pad {
  display: flex;
  flex-direction: column;
  min-height: 72vh;
  gap: 22px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
  background: #ffffff;
  box-shadow: var(--shadow);
  user-select: none;
  touch-action: pan-y;
  min-width: 0;
  max-width: 100%;
}

.timer-topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.timer-pad-fullscreen {
  position: fixed;
  inset: 0;
  z-index: 9999;
  width: 100%;
  height: 100dvh;
  max-width: none;
  min-height: 100dvh;
  border: 0;
  border-radius: 0;
  padding: max(18px, env(safe-area-inset-top)) max(18px, env(safe-area-inset-right)) max(18px, env(safe-area-inset-bottom)) max(18px, env(safe-area-inset-left));
  overscroll-behavior: none;
  touch-action: none;
}

.timer-pad-fullscreen:fullscreen {
  width: 100vw;
  height: 100dvh;
}

.icon-button {
  min-width: 38px;
  min-height: 38px;
  padding: 0;
  display: inline-grid;
  place-items: center;
  border-radius: 999px;
  font-size: 1.2rem;
  font-weight: 900;
  line-height: 0;
  flex: 0 0 auto;
}

.icon-button svg {
  width: 18px;
  height: 18px;
  display: block;
}

.scramble-block {
  display: grid;
  gap: 8px;
  width: 100%;
  min-width: 0;
}

.scramble-header-row {
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr);
  align-items: center;
  width: 100%;
  min-width: 0;
}

.scramble-header-row .label {
  font-size: 1.5rem;
}

.scramble-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  width: max-content;
  justify-self: end;
  min-width: 0;
}

.scramble {
  margin: 0;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: clamp(1.35rem, 5.8vw, 2.25rem);
  font-weight: 800;
  line-height: 1.35;
  white-space: normal;
  word-spacing: 0.35em;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.timer-stack {
  flex: 1;
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0;
}

.phase {
  color: var(--teal);
  font-size: 1rem;
  font-weight: 850;
  line-height: 1;
  text-transform: uppercase;
  margin: 0;
}

.timer-display {
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  font-variant-numeric: tabular-nums;
  font-size: clamp(3.4rem, 21vw, 9rem);
  font-weight: 900;
  line-height: 0.95;
  max-width: 100%;
  overflow: hidden;
}

.reveal-block {
  display: grid;
  gap: 6px;
  border-left: 4px solid var(--teal);
  padding: 10px 12px;
  background: #ecfdf5;
}

.reveal-block strong {
  font-size: 1.4rem;
}

.reveal-block span {
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  line-height: 1.35;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.timer-help-button {
  align-self: flex-start;
}

.timer-help-button {
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  margin-left: auto;
}

.timer-pad .result-actions {
  margin-top: auto;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.timer-pad .result-actions > button {
  width: 100%;
}

.result-panel {
  margin-top: 12px;
  padding: 16px;
}

.result-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.result-panel-header h2 {
  margin: 0;
  font-size: 1.1rem;
}

.empty-solves {
  margin: 0;
  color: var(--muted);
  font-weight: 750;
}

.solve-list-wrap {
  width: 100%;
  overflow-x: hidden;
}

.show-all-solves-button {
  width: 100%;
  margin-top: 12px;
}

.solve-list-header,
.solve-time-row {
  display: grid;
  grid-template-columns: max-content max-content max-content minmax(56px, 1fr);
  align-items: center;
  width: 100%;
  border-bottom: 1px solid var(--line);
}

.solve-list-header {
  color: var(--muted);
  font-size: 0.72rem;
  text-transform: uppercase;
  font-weight: 900;
}

.solve-list-header > div,
.solve-time-row > div {
  min-width: 75px;
  padding: 10px 8px;
}

.solve-list-header > div {
  padding-top: 8px;
  padding-bottom: 8px;
}

.solve-number-cell,
.solve-case-cell,
.solve-time-cell,
.solve-delete-cell {
  font-weight: 850;
}

.solve-number-cell {
  color: var(--muted);
  white-space: nowrap;
  width: max-content;
}

.solve-case-stack {
  display: inline-flex;
  flex-direction: column;
  gap: 4px;
  width: fit-content;
  max-width: 100%;
  min-width: 0;
}

.solve-case-cell {
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  width: max-content;
}

.solve-case-button {
  display: block;
  width: 100%;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  text-align: left;
}

.solve-case-button:hover {
  background: transparent;
}

.solve-case-stack strong {
  max-width: 100%;
  overflow: hidden;
  font-size: 1rem;
  font-weight: 950;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.solve-time-cell {
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  text-align: right;
  white-space: nowrap;
  width: max-content;
}

.solve-time-cell.failed {
  font-family: inherit;
  font-size: 1.02rem;
  font-weight: 900;
}

.solve-delete-cell {
  text-align: right;
  width: 100%;
}

.solve-action-buttons {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

.solve-badges {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 4px;
  max-width: 100%;
}

.solve-badge {
  border-radius: 999px;
  padding: 2px 6px;
  background: #dbeafe;
  color: #1e3a8a;
  font-size: 0.68rem;
  font-weight: 850;
  text-transform: uppercase;
}

.solve-badge.failed {
  background: #ffedd5;
  color: #9a3412;
}

.solve-delete-button {
  display: inline-grid;
  place-items: center;
  width: 34px;
  height: 34px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  color: var(--danger);
}

.solve-delete-button:hover {
  background: #fff1eb;
}

.solve-fail-button {
  display: inline-grid;
  place-items: center;
  width: 34px;
  height: 34px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  color: var(--danger);
}

.solve-fail-button:hover {
  background: #fff1eb;
}

.solve-fail-button.active {
  background: var(--danger);
  border-color: var(--danger);
  color: #ffffff;
}

.solve-fail-button.active:hover {
  background: var(--danger-dark);
}

.solve-fail-button svg {
  width: 16px;
  height: 16px;
}

.solve-delete-button svg {
  width: 16px;
  height: 16px;
}

.solve-tooltip {
  position: fixed;
  z-index: 10000;
  max-width: min(340px, calc(100vw - 24px));
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  background: #ffffff;
  box-shadow: var(--shadow);
  display: grid;
  gap: 6px;
}

.solve-tooltip strong {
  font-size: 0.95rem;
}

.solve-tooltip span {
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  font-size: 0.8rem;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.metric {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #fbfcfe;
}

.metric span {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
}

.metric strong {
  display: block;
  margin: 4px 0 0;
  font-size: 1.15rem;
  font-weight: 900;
}

.total-bar {
  display: flex;
  width: 100%;
  min-height: 70px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #edf1f7;
}

.total-bar-fill {
  display: grid;
  min-width: 0;
  place-items: center;
  align-content: center;
  gap: 4px;
  padding: 10px 8px;
  color: #ffffff;
  text-align: center;
  background: var(--primary);
}

.total-bar-fill span {
  max-width: 100%;
  overflow: hidden;
  font-size: 0.72rem;
  font-weight: 850;
  text-overflow: ellipsis;
  text-transform: uppercase;
  white-space: nowrap;
}

.total-bar-fill strong {
  max-width: 100%;
  overflow: hidden;
  font-size: clamp(0.98rem, 4.8vw, 1.35rem);
  font-weight: 950;
  line-height: 1;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.stats-grid {
  display: grid;
  gap: 12px;
  min-width: 0;
}

.stats-grid .panel,
.table-panel,
#settingsView .panel {
  padding: 16px;
}

.panel h2 {
  margin: 0 0 14px;
  font-size: 1.2rem;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  min-width: 0;
}

.chart-header {
  display: grid;
  gap: 10px;
}

.chart-box {
  position: relative;
  width: 100%;
  height: min(360px, 55vh);
  max-height: calc(100vh - 220px);
  min-height: 220px;
}

.chart-box canvas {
  display: block;
  width: 100% !important;
  height: 100% !important;
}

.chart-case-filter {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 6px;
}

.chart-case-button {
  min-height: 34px;
  border: 1px solid var(--line);
  padding: 0 6px;
  background: #ffffff;
  color: var(--text);
  font-size: 0.86rem;
}

.chart-case-button:hover {
  background: #eef2f8;
}

.chart-case-button.active {
  border-color: var(--primary);
  background: var(--primary);
  color: #ffffff;
}

.table-panel {
  margin-top: 12px;
}

.stats-list-wrap {
  width: 100%;
  overflow-x: hidden;
}

.stats-list-header,
.stats-time-row {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) max-content max-content max-content max-content;
  align-items: center;
  width: 100%;
  border-bottom: 1px solid var(--line);
}

.stats-list-header {
  color: var(--muted);
  font-size: 0.72rem;
  text-transform: uppercase;
  font-weight: 900;
}

.stats-sort-button,
.stats-time-row > div {
  min-width: 75px;
  padding: 10px 8px;
}

.stats-sort-button {
  border: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  background: transparent;
  color: inherit;
  font-size: inherit;
  font-weight: inherit;
  justify-content: flex-start;
  min-height: 0;
  padding-top: 8px;
  padding-bottom: 8px;
  text-transform: inherit;
}

.stats-sort-button:hover {
  background: #eef2f8;
}

.stats-sort-button.active {
  color: var(--primary);
}

.stats-sort-button[data-direction="asc"]::after,
.stats-sort-button[data-direction="desc"]::after {
  margin-left: 6px;
  font-size: 0.68rem;
}

.stats-sort-button[data-direction="asc"]::after {
  content: "▲";
}

.stats-sort-button[data-direction="desc"]::after {
  content: "▼";
}

.stats-sort-button {
  padding-top: 8px;
  padding-bottom: 8px;
}

.stats-case-cell,
.stats-solves-cell,
.stats-time-cell {
  font-weight: 850;
}

.stats-case-cell {
  min-width: 0;
  text-align: left;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.stats-solves-cell,
.stats-time-cell {
  white-space: nowrap;
}

.stats-solves-cell {
  text-align: center;
}

.stats-time-cell {
  text-align: right;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
}

.settings-actions {
  grid-template-columns: 1fr;
}

@media (min-width: 720px) {
  .app-shell {
    padding: 28px 24px 42px;
  }

  .auth-view {
    grid-template-columns: minmax(0, 1fr) minmax(0, 380px);
    align-items: center;
  }

  .trainer-controls {
    grid-template-columns: minmax(0, 1fr);
    align-items: stretch;
  }

  .case-picker {
    grid-template-columns: repeat(7, minmax(0, 1fr));
  }

  .result-actions,
  .settings-actions {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .stats-grid {
    grid-template-columns: minmax(0, 0.85fr) minmax(0, 1.15fr);
  }

  .metric-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}
