* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --bg: #0a0a0f;
  --surface: #16161f;
  --border: #2a2a3a;
  --text: #e8e8f0;
  --text-strong: #e8e8f0;
  --text-medium: #e8e8f0;
  --text-dim: #888898;
  --accent: #6366f1;
  --accent-hover: #818cf8;
  --correct: #22c55e;
  --wrong: #ef4444;
  --skipped: #666;
  --correct-bg: rgba(34, 197, 94, 0.15);
  --wrong-bg: rgba(239, 68, 68, 0.15);
  --skipped-bg: rgba(100, 100, 100, 0.1);
}

:root[data-theme="light"] {
  --bg: #fdf6e3;
  --surface: #eee8d5;
  --border: #d3cbb7;
  --text: #657b83;
  --text-dim: #93a1a1;
  --accent: #268bd2;
  --accent-hover: #1a6fa0;
  --correct: #859900;
  --wrong: #dc322f;
  --skipped: #93a1a1;
  --correct-bg: rgba(133, 153, 0, 0.15);
  --wrong-bg: rgba(220, 50, 47, 0.15);
  --skipped-bg: rgba(147, 161, 161, 0.1);
  --text-strong: #2a2a2a;
  --text-medium: #455a64;
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme="light"]):not([data-theme="dark"]) {
    --bg: #fdf6e3;
    --surface: #eee8d5;
    --border: #d3cbb7;
    --text: #657b83;
    --text-dim: #93a1a1;
    --accent: #268bd2;
    --accent-hover: #1a6fa0;
    --correct: #859900;
    --wrong: #dc322f;
    --skipped: #93a1a1;
    --correct-bg: rgba(133, 153, 0, 0.15);
    --wrong-bg: rgba(220, 50, 47, 0.15);
    --skipped-bg: rgba(147, 161, 161, 0.1);
    --text-strong: #2a2a2a;
    --text-medium: #455a64;
  }
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

#app {
  max-width: 480px;
  margin: 0 auto;
  padding: 20px;
  min-height: 100%;
  display: flex;
  flex-direction: column;
}

.screen {
  display: none;
  flex-direction: column;
  gap: 24px;
  flex: 1;
  position: relative;
}

.screen.active {
  display: flex;
}

.screen-back-btn {
  position: absolute;
  top: 4px;
  left: 0;
  z-index: 5;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 8px 12px 8px 8px;
  background: transparent;
  border: 0;
  border-radius: 10px;
  color: var(--text-medium);
  font: inherit;
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.screen-back-btn:hover,
.screen-back-btn:focus-visible {
  background: color-mix(in srgb, var(--surface) 80%, #000 20%);
  color: var(--text-strong);
  outline: none;
}

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

h1 {
  font-size: 28px;
  font-weight: 700;
  text-align: center;
  margin-top: 40px;
  color: var(--text-strong);
}

h2 {
  font-size: 22px;
  font-weight: 600;
  text-align: center;
}

.subtitle {
  text-align: center;
  color: var(--text-dim);
  margin-top: -12px;
}

#screen-speed-setup h1 {
  margin-top: 20px;
}

.version-label {
  text-align: center;
  color: var(--text-dim);
  font-size: 0.7rem;
  margin-top: 16px;
  opacity: 0.5;
}

.home-actions .btn-secondary {
  width: 100%;
}

.home-theme-control {
  align-self: center;
}

.segmented-control {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px;
  background: color-mix(in srgb, var(--surface) 92%, #fff 8%);
  border: 1px solid var(--border);
  border-radius: 999px;
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.08);
}

.segment-btn {
  min-width: 46px;
  height: 42px;
  padding: 0 16px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--text-dim);
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, color 0.15s, transform 0.1s, box-shadow 0.15s;
}

.segment-btn:active {
  transform: scale(0.97);
}

.segment-btn.active {
  background: var(--bg);
  color: var(--text-strong);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
}

.segment-icon {
  width: 24px;
  height: 24px;
  display: block;
}

.theme-segmented-control {
  gap: 2px;
  padding: 5px;
}

.theme-segmented-control .segment-btn {
  min-width: 50px;
  height: 44px;
  padding: 0;
}

/* Home — Discipline Cards */
.discipline-list {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.discipline-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  aspect-ratio: 1;
  padding: 16px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  cursor: pointer;
  text-align: center;
  transition: background 0.15s, transform 0.1s;
}

.discipline-card:active {
  transform: scale(0.96);
  background: var(--border);
}

.discipline-icon {
  font-size: 36px;
}

.discipline-name {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-strong);
  display: block;
}

.discipline-desc {
  font-size: 12px;
  color: var(--text-dim);
  display: block;
}

/* Settings */
.setting {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.setting label {
  font-size: 14px;
  color: var(--text-dim);
  font-weight: 500;
}

.display-settings {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

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

.stepper {
  display: flex;
  align-items: center;
  gap: 4px;
}

.stepper input {
  width: 80px;
  text-align: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-strong);
  font-size: 18px;
  font-weight: 600;
  padding: 10px 4px;
  -moz-appearance: textfield;
}

.stepper input::-webkit-inner-spin-button,
.stepper input::-webkit-outer-spin-button {
  -webkit-appearance: none;
}

.stepper-btn {
  flex: 1;
  padding: 10px 2px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}

.stepper-btn:active {
  background: var(--border);
}

/* Checkbox */
.setting input[type="checkbox"] {
  width: 18px;
  height: 18px;
  margin-right: 8px;
  vertical-align: middle;
  accent-color: var(--accent);
}

.status-note {
  min-height: 1.2em;
  text-align: center;
  color: var(--text-dim);
  font-size: 13px;
}

.status-note.ready {
  color: var(--correct);
}

.status-note.error {
  color: var(--wrong);
}

/* Buttons */
.btn-primary, .btn-secondary {
  padding: 14px 24px;
  border: none;
  border-radius: 12px;
  font-size: 17px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}

.btn-primary:active, .btn-secondary:active {
  transform: scale(0.97);
}

.btn-primary {
  background: var(--accent);
  color: white;
}

.btn-primary:hover {
  background: var(--accent-hover);
}

.btn-primary:disabled,
.btn-secondary:disabled {
  opacity: 0.55;
  cursor: default;
}

.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
}

/* Playback */
#screen-playback {
  align-items: center;
  justify-content: center;
}

#playback-status {
  text-align: center;
}

#digit-display {
  font-size: 120px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 1;
  min-height: 140px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-medium);
}

#digit-display.countdown {
  color: var(--accent);
  font-size: 80px;
}

#elephant-display {
  min-height: 140px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 100px;
  line-height: 1;
}

#elephant-display.hidden {
  display: none;
}

#progress-text {
  font-size: 16px;
  color: var(--text-dim);
  margin-top: 12px;
  font-variant-numeric: tabular-nums;
}

/* Numbers Countdown */
#screen-numbers-countdown {
  align-items: center;
  justify-content: center;
  gap: 24px;
}

.numbers-countdown-display {
  font-size: 120px;
  font-weight: 700;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

#btn-countdown-skip {
  min-width: 140px;
}

/* Numbers Memorization */
#screen-numbers-memo {
  position: relative;
  min-height: calc(100vh - 40px);
}

.memo-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  position: absolute;
  top: calc(env(safe-area-inset-top) + 7.5rem);
  left: 0;
  right: 0;
}

.memo-timer {
  font-size: 28px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--text-strong);
  cursor: pointer;
}

.memo-timer.warning {
  color: var(--wrong);
}

.memo-timer.hidden-timer {
  font-size: 36px;
}

.memo-finished-btn {
  padding: 10px 24px;
  font-size: 15px;
}

.memo-row-display {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(50% - 6rem);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  font-size: 32px;
  font-weight: 700;
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro', system-ui, sans-serif;
  font-variant-numeric: tabular-nums;
  letter-spacing: var(--memo-letter-spacing, 8px);
  gap: var(--memo-row-gap, 1rem);
  color: var(--text-strong);
  text-align: center;
  transform: translateY(-50%);
}

.memo-row-line {
  white-space: nowrap;
  font-size: var(--memo-font-size, 32px);
  line-height: 1.15;
}

.memo-row-indicator {
  position: absolute;
  right: 0;
  bottom: calc(env(safe-area-inset-bottom) + 1rem);
  font-size: 14px;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.memo-nav {
  position: absolute;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom) + 11.25rem);
  display: flex;
  gap: 12px;
  justify-content: center;
  transform: translateX(-50%);
}

.memo-nav-btn {
  padding: 14px 28px;
  font-size: 20px;
  min-width: 70px;
}

.numbers-learning-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin: 24px 0;
}

.numbers-learning-btn {
  min-height: 72px;
  font-size: 1.05rem;
  font-weight: 700;
}

/* Speed Cards */
.speed-countdown-screen {
  align-items: center;
  justify-content: center;
  gap: 24px;
}

.speed-surface {
  position: relative;
  min-height: calc(100vh - 40px);
  margin: -20px;
  padding: calc(env(safe-area-inset-top) + 10px) 14px calc(env(safe-area-inset-bottom) + 16px);
  background: #b2b2b2;
  color: #333;
  overflow: hidden;
}

.speed-status-bar,
.speed-recall-header,
.speed-focus-header {
  display: flex;
  align-items: center;
  gap: 10px;
}

.speed-status-bar,
.speed-recall-header {
  justify-content: space-between;
}

.speed-status-bar {
  position: absolute;
  top: calc(env(safe-area-inset-top) + 10px);
  left: 14px;
  right: 14px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
}

.speed-pill {
  padding: 8px 12px;
  background: rgba(255, 255, 255, 0.78);
  border: 1px solid rgba(0, 0, 0, 0.08);
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  color: #4a4a4a;
}

.speed-pill.warning {
  color: #b42318;
}

.speed-finished-btn {
  padding: 6px 18px;
  font-size: 12px;
  border-radius: 4px;
}

.speed-clear-btn {
  padding: 10px 16px;
  font-size: 15px;
  border-radius: 12px;
}

#screen-speed-memo .speed-pill {
  padding: 0;
  background: none;
  border: none;
  border-radius: 0;
  font-size: 11px;
  color: rgba(0, 0, 0, 0.58);
}

#speed-memo-progress {
  grid-column: 1;
  justify-self: start;
}

#speed-memo-timer {
  grid-column: 3;
  justify-self: end;
}

#btn-speed-finished {
  grid-column: 2;
  justify-self: center;
  background: #29a944;
  box-shadow: none;
}

#screen-speed-memo {
  --speed-memo-card-width: min(72vw, 357px);
  --speed-memo-card-height: calc(var(--speed-memo-card-width) * 1.55);
  --speed-memo-cards-top: calc(env(safe-area-inset-top) + 78px);
  --speed-memo-side-inset: calc(env(safe-area-inset-right) - 60px);
  --speed-memo-cards-width: var(--speed-memo-card-width);
  margin: -20px;
  min-height: calc(100vh - 40px);
  padding: calc(env(safe-area-inset-top) + 18px) 16px calc(env(safe-area-inset-bottom) + 20px);
  background:
    radial-gradient(ellipse at 50% 32%, rgba(255, 255, 255, 0.06), rgba(255, 255, 255, 0) 55%),
    radial-gradient(ellipse at 50% 110%, rgba(0, 0, 0, 0.55), rgba(0, 0, 0, 0) 70%),
    repeating-linear-gradient(45deg, rgba(255, 255, 255, 0.022) 0 1px, rgba(0, 0, 0, 0) 1px 3px),
    repeating-linear-gradient(-45deg, rgba(0, 0, 0, 0.05) 0 1px, rgba(0, 0, 0, 0) 1px 3px),
    #0e3d28;
}

#screen-speed-memo .speed-memo-title {
  position: absolute;
  top: calc(env(safe-area-inset-top) + 26px);
  left: 18px;
  font-size: 20px;
  font-style: italic;
  color: rgba(255, 255, 255, 0.34);
  pointer-events: none;
}

#screen-speed-memo #btn-speed-finished {
  position: absolute;
  top: calc(env(safe-area-inset-top) + 22px);
  left: 50%;
  transform: translateX(-50%);
  grid-column: auto;
  justify-self: auto;
  min-width: 96px;
  padding: 8px 22px;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.5px;
  border-radius: 999px;
  background: rgba(8, 28, 18, 0.55);
  color: rgba(255, 255, 255, 0.95);
  border: 1px solid rgba(255, 255, 255, 0.22);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.18);
  text-shadow: none;
  transition: background 0.15s ease, transform 0.1s ease;
}

#screen-speed-memo #btn-speed-finished:hover {
  background: rgba(20, 60, 38, 0.7);
}

#screen-speed-memo #btn-speed-finished:active {
  transform: translateX(-50%) scale(0.97);
}

#screen-speed-memo .speed-main-preview {
  position: absolute;
  top: var(--speed-memo-cards-top);
  right: var(--speed-memo-side-inset);
  left: auto;
  width: auto;
  min-width: var(--speed-memo-card-width);
  min-height: var(--speed-memo-card-height);
  transform: none;
  display: flex;
  justify-content: flex-end;
  align-items: flex-start;
}

#screen-speed-memo .speed-main-fan {
  position: relative;
  height: calc(var(--speed-memo-card-width) * 1.42);
}

#screen-speed-memo .speed-main-layer {
  position: absolute;
  left: 0;
  bottom: 0;
}

#screen-speed-memo .speed-card.memo {
  width: var(--speed-memo-card-width);
}

#screen-speed-memo .speed-memo-fan {
  position: absolute;
  left: 50%;
  right: 0;
  bottom: calc(env(safe-area-inset-bottom) + 8px);
  width: calc(100% - 10px);
  height: 150px;
  transform: translateX(-50%);
}

#screen-speed-memo .speed-card.fan {
  position: absolute;
  left: 50%;
  bottom: 0;
  width: 48px;
  margin-left: -24px;
  transform-origin: center 320px;
}

#screen-speed-memo .speed-card.fan.memo-hidden {
  visibility: hidden;
}

#screen-speed-memo #speed-memo-timer {
  position: absolute;
  left: 18px;
  top: calc(var(--speed-memo-cards-top) + var(--speed-memo-card-height) + 14px);
  bottom: auto;
  height: 52px;
  display: flex;
  align-items: center;
  font-size: 28px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  font-family: 'SF Mono', 'Menlo', monospace;
  letter-spacing: 1px;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.18);
  color: rgba(255, 255, 255, 0.7);
  cursor: pointer;
}

#screen-speed-memo #speed-memo-timer.hidden-timer {
  font-size: 32px;
}

#screen-speed-memo #speed-memo-timer.learning-hidden {
  display: none;
}

#screen-speed-memo #speed-memo-progress {
  position: absolute;
  right: 18px;
  bottom: calc(env(safe-area-inset-bottom) + 18px);
  font-size: 15px;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.65);
}

#screen-speed-memo .speed-memo-nav {
  position: absolute;
  top: calc(var(--speed-memo-cards-top) + var(--speed-memo-card-height) + 14px);
  right: var(--speed-memo-side-inset);
  left: auto;
  bottom: auto;
  width: var(--speed-memo-card-width);
  transform: none;
  display: flex;
  justify-content: center;
  gap: 16px;
  margin-top: 0;
}

#screen-speed-memo .speed-memo-nav .speed-nav-btn {
  width: 52px;
  height: 52px;
  min-width: 52px;
  min-height: 52px;
  padding: 0;
  border-radius: 50%;
  background: rgba(8, 28, 18, 0.55);
  color: rgba(255, 255, 255, 0.95);
  border: 1px solid rgba(255, 255, 255, 0.22);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  font-size: 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.18);
  transition: background 0.15s ease, transform 0.1s ease;
}

#screen-speed-memo .speed-memo-nav .speed-nav-btn:hover {
  background: rgba(20, 60, 38, 0.7);
}

#screen-speed-memo .speed-memo-nav .speed-nav-btn:active {
  transform: scale(0.92);
}

.speed-memo-stage {
  display: grid;
  grid-template-columns: 1fr 138px 1fr;
  grid-template-rows: auto auto;
  align-items: end;
  gap: 18px 10px;
  margin-top: 72px;
  padding-top: 34px;
}

.speed-side-preview {
  display: flex;
  align-items: flex-end;
  min-height: 76px;
}

#speed-left-preview {
  grid-column: 1;
  grid-row: 2;
  justify-content: flex-start;
}

#speed-right-preview {
  grid-column: 3;
  grid-row: 2;
  justify-content: flex-end;
}

.speed-main-preview {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 184px;
  grid-column: 2;
  grid-row: 1;
}

.speed-main-fan {
  position: relative;
  width: 138px;
  height: 154px;
}

.speed-main-layer {
  position: absolute;
  left: 0;
  bottom: 0;
}

.speed-memo-nav {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin-top: 18px;
}

.speed-nav-btn {
  min-width: 42px;
  min-height: 38px;
  padding: 8px 12px;
  border-radius: 3px;
}

.speed-memo-nav .speed-nav-btn {
  background: #2d8ddc;
  color: #fff;
  border: none;
  box-shadow: none;
}

.speed-card {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100px;
  aspect-ratio: 0.72;
  border-radius: 5px;
  background: #fff;
  border: 1px solid rgba(0, 0, 0, 0.2);
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.18);
  color: #1f1f1f;
  user-select: none;
  overflow: visible;
}

.speed-card:not(.empty) {
  background: none;
  border: none;
  box-shadow: none;
}

.speed-card-img {
  display: block;
  width: 100%;
  height: auto;
  border-radius: inherit;
}

#screen-speed-memo .speed-card.memo .speed-card-img {
  filter: drop-shadow(0.6px 0.75px 1.75px rgba(0, 0, 0, 0.45));
}

#screen-speed-memo .speed-card.fan .speed-card-img {
  filter: drop-shadow(0 0.6px 0.75px rgba(0, 0, 0, 0.25));
}

.speed-card.red {
  color: #d64545;
}

.speed-card.empty {
  background: rgba(255, 255, 255, 0.35);
  border-style: dashed;
  box-shadow: none;
}

.speed-card.large {
  width: 150px;
}

.speed-card.memo {
  width: 96px;
}

.speed-card.setup-preview {
  width: 114px;
}

.speed-card.small {
  width: 82px;
}

.speed-card.strip {
  width: 16px;
  border-radius: 3px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.15);
}

.speed-card.strip.focus {
  width: 36px;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);
}

.speed-card.tiny {
  width: 46px;
  border-radius: 6px;
}

.speed-card.overview {
  width: 100%;
  max-width: 26px;
  border-radius: 4px;
  box-shadow: none;
}

.speed-card.slot {
  width: 100%;
  box-shadow: none;
  cursor: pointer;
}

.speed-card.active-slot {
  outline: 3px solid #f1dd34;
  outline-offset: 1px;
}

.speed-card.correct-slot {
  outline: 2px solid rgba(34, 197, 94, 0.6);
}

.speed-card.wrong-slot {
  outline: 2px solid rgba(220, 50, 47, 0.6);
}

.speed-card-corner {
  position: absolute;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
  font-weight: 700;
  line-height: 1;
  z-index: 2;
}

.speed-card-corner.top {
  top: 4px;
  left: 4px;
}

.speed-card-corner.bottom {
  right: 4px;
  bottom: 4px;
  transform: rotate(180deg);
}

.speed-card-rank {
  font-size: 14px;
}

.speed-card.large .speed-card-rank {
  font-size: 24px;
}

.speed-card.memo .speed-card-rank {
  font-size: 13px;
}

.speed-card.strip .speed-card-rank {
  font-size: 0;
}

.speed-card.tiny .speed-card-rank,
.speed-card.overview .speed-card-rank {
  font-size: 10px;
}

.speed-card-suit {
  font-size: 10px;
}

.speed-card.large .speed-card-suit {
  font-size: 18px;
}

.speed-card.memo .speed-card-suit {
  font-size: 9px;
}

.speed-card.strip .speed-card-suit {
  font-size: 0;
}

.speed-card-layout {
  position: absolute;
  inset: 16% 16% 16% 16%;
}

.speed-card-layout.face {
  display: flex;
  align-items: center;
  justify-content: center;
}

.speed-pip {
  position: absolute;
  transform: translate(-50%, -50%);
  font-size: 18px;
  line-height: 1;
}

.speed-card.memo .speed-pip {
  font-size: 15px;
}

.speed-card.strip .speed-pip,
.speed-card.overview .speed-pip {
  font-size: 8px;
}

.speed-card.tiny .speed-pip {
  font-size: 12px;
}

.speed-face-badge {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 6px 8px;
  border: 1px solid rgba(0, 0, 0, 0.1);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.8);
}

.speed-face-rank {
  font-size: 28px;
  font-weight: 700;
  line-height: 1;
}

.speed-face-suit {
  font-size: 18px;
  line-height: 1;
}

.speed-card.memo .speed-face-rank {
  font-size: 24px;
}

.speed-card.memo .speed-face-suit {
  font-size: 15px;
}

.speed-card.strip .speed-card-layout,
.speed-card.overview .speed-card-layout {
  inset: 20% 14% 20% 14%;
}

.speed-card.strip .speed-face-badge,
.speed-card.overview .speed-face-badge {
  padding: 2px 3px;
  border-radius: 3px;
}

.speed-card.strip .speed-face-rank,
.speed-card.overview .speed-face-rank {
  font-size: 9px;
}

.speed-card.strip .speed-face-suit,
.speed-card.overview .speed-face-suit {
  font-size: 7px;
}

.speed-card-back {
  background:
    linear-gradient(135deg, rgba(38, 139, 210, 0.92), rgba(82, 82, 255, 0.95)),
    repeating-linear-gradient(45deg, rgba(255, 255, 255, 0.14), rgba(255, 255, 255, 0.14) 6px, rgba(255, 255, 255, 0.02) 6px, rgba(255, 255, 255, 0.02) 12px);
  border-color: rgba(0, 0, 0, 0.12);
}

.speed-card-back::before {
  content: '';
  position: absolute;
  inset: 8px;
  border: 1px solid rgba(255, 255, 255, 0.45);
  border-radius: 6px;
}

.speed-ribbon {
  display: flex;
  align-items: flex-end;
  max-width: 108px;
}

.speed-ribbon .speed-card {
  margin-right: -12px;
}

.speed-ribbon .speed-card:last-child {
  margin-right: 0;
}

.speed-ribbon.right {
  justify-content: flex-end;
}

.speed-recall-board {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 12px;
}

.speed-recall-direction {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 12px;
}

.speed-recall-direction label {
  font-size: 13px;
  font-weight: 700;
  color: #515151;
}

.recall-direction-control {
  flex-shrink: 0;
}

.recall-direction-control .segment-btn {
  min-width: 64px;
}

.speed-board-row {
  display: grid;
  grid-template-columns: repeat(13, 1fr);
  gap: 4px;
}

.speed-slot-wrap {
  display: flex;
  flex-direction: column;
  gap: 3px;
  align-items: center;
  min-width: 0;
}

.speed-slot-label {
  font-size: 9px;
  color: #6f6f6f;
  font-variant-numeric: tabular-nums;
}

.speed-focus-header {
  justify-content: space-between;
  margin-top: 6px;
}

.speed-focus-label {
  font-size: 13px;
  font-weight: 700;
  color: #515151;
}

.speed-focus-nav {
  display: flex;
  gap: 8px;
}

.speed-focus-row {
  display: grid;
  grid-template-columns: repeat(13, 1fr);
  gap: 6px;
  align-items: start;
}

.speed-card-palette {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding: 8px 0 4px;
  -webkit-overflow-scrolling: touch;
}

.speed-card-palette .speed-card {
  flex-shrink: 0;
  cursor: pointer;
}

.speed-card-palette .speed-card.used {
  opacity: 0.35;
  cursor: default;
}

.speed-grouping-wrap {
  width: 100%;
}

.speed-primary-row,
.speed-secondary-row,
.speed-retap-row {
  display: grid;
  gap: 12px;
}

.speed-learning-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin: 24px 0;
}

.speed-learning-btn {
  min-height: 72px;
  font-size: 1.05rem;
  font-weight: 700;
}

.speed-primary-row {
  grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr);
  align-items: stretch;
}

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

.speed-retap-row {
  grid-template-columns: 1fr;
}

.speed-row-card {
  min-width: 0;
}

.setting.speed-row-card {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
}

.setting.speed-row-card > label {
  color: var(--text-strong);
  font-size: 15px;
  font-weight: 600;
  line-height: 1.35;
}

.setting.speed-row-card .select-wrap,
.setting.speed-row-card .stepper {
  width: 100%;
}

.setting.speed-row-card .stepper {
  gap: 6px;
}

.setting.speed-row-card .stepper input {
  min-width: 0;
}

.speed-option-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
}

.speed-option-row label {
  color: var(--text-strong);
  font-size: 15px;
  font-weight: 600;
  line-height: 1.35;
}

.speed-option-control {
  flex-shrink: 0;
  box-shadow: none;
}

.speed-option-control .segment-btn {
  min-width: 58px;
  height: 38px;
  padding: 0 12px;
  font-size: 12px;
}

.speed-secondary-row .speed-option-row {
  flex-direction: column;
  align-items: stretch;
  justify-content: flex-start;
}

.speed-secondary-row .speed-option-control {
  width: 100%;
  min-width: 0;
}

.speed-secondary-row .speed-option-control .segment-btn {
  flex: 1 1 0;
  min-width: 0;
  padding: 0 10px;
}

.speed-timer-card {
  align-items: flex-start;
}

.speed-timer-controls {
  display: flex;
  gap: 10px;
  width: 100%;
  flex-wrap: wrap;
}

.speed-timer-controls .speed-option-control {
  min-width: 0;
}

.speed-timer-controls .segment-btn {
  min-width: 64px;
}

.speed-retap-card .speed-option-control .segment-btn {
  min-width: 64px;
}

@media (max-width: 390px) {
  .speed-primary-row,
  .speed-secondary-row {
    grid-template-columns: 1fr 1fr;
  }

  .speed-primary-row > :first-child,
  .speed-retap-row > * {
    grid-column: 1 / -1;
  }

  .speed-timer-controls {
    flex-direction: column;
  }
}

@media (max-width: 430px) {
  .speed-setup-preview-layout {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .speed-setup-preview-hint,
  .speed-setup-preview-hint-left,
  .speed-setup-preview-hint-right {
    text-align: center;
    align-items: center;
  }

  .speed-setup-preview-hint-left .speed-hint-line {
    justify-content: center;
  }
}

.speed-setup-preview-card {
  display: flex;
  flex-direction: column;
  gap: 14px;
  align-items: center;
  padding: 18px 16px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
}

.speed-setup-preview-title {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text-dim);
}

.speed-setup-preview-layout {
  width: 100%;
  display: grid;
  grid-template-columns: minmax(72px, 1fr) minmax(0, 320px) minmax(72px, 1fr);
  gap: 10px;
  align-items: center;
}

.speed-setup-preview {
  width: 100%;
  min-height: 120px;
  display: flex;
  justify-content: center;
  align-items: flex-start;
}

.speed-setup-preview-hint {
  display: flex;
  flex-direction: column;
  gap: 8px;
  color: var(--text-dim);
  font-size: 12px;
  line-height: 1.55;
}

.speed-setup-preview-hint-left {
  text-align: right;
  align-items: flex-end;
}

.speed-setup-preview-hint-right {
  text-align: left;
  align-items: flex-start;
}

.speed-hint-line {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  align-items: center;
}

.speed-setup-preview-hint-left .speed-hint-line {
  justify-content: flex-end;
}

.speed-setup-preview-frame {
  position: relative;
  width: 100%;
  max-width: 320px;
}

.speed-setup-preview-stack {
  position: relative;
  height: 160px;
  margin: 0 auto;
  transform-origin: top left;
}

.speed-setup-preview-card-img {
  position: absolute;
  left: 0;
  bottom: 0;
}

.speed-card.setup-preview .speed-card-img {
  filter: drop-shadow(0 6px 16px rgba(0, 0, 0, 0.22));
}

.speed-setup-attribution {
  font-size: 12px;
  line-height: 1.45;
  color: var(--text-dim);
  text-align: center;
}

.speed-setup-attribution a {
  color: var(--accent);
}

.speed-card.slot .speed-card-corner {
  gap: 0;
}

.speed-card.slot .speed-card-rank {
  font-size: clamp(9px, 2.4vw, 12px);
}

.speed-card.slot .speed-card-suit {
  font-size: clamp(8px, 2vw, 10px);
}

.speed-card.slot .speed-pip {
  font-size: clamp(9px, 2.4vw, 12px);
}

.speed-card.slot .speed-card-corner.top {
  top: 4px;
  left: 5px;
}

.speed-card.slot .speed-card-corner.bottom {
  right: 5px;
  bottom: 4px;
}

.select-wrap {
  position: relative;
  display: inline-block;
  width: 8rem;
  max-width: 100%;
}

.select-field {
  width: 100%;
  padding: 12px 42px 12px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  appearance: none;
}

.select-wrap::after {
  content: '';
  position: absolute;
  right: 16px;
  top: 50%;
  width: 10px;
  height: 10px;
  border-right: 2px solid var(--text-dim);
  border-bottom: 2px solid var(--text-dim);
  pointer-events: none;
  transform: translateY(-70%) rotate(45deg);
}

.select-field:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.12);
}

.text-field {
  width: 100%;
  padding: 12px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 15px;
  font-weight: 500;
}

.text-field:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.12);
}

kbd {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.7em;
  padding: 0.1em 0.42em;
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: 6px;
  background: var(--surface);
  color: var(--text-strong);
  font-size: 0.92em;
  font-weight: 600;
  line-height: 1.1;
}

/* Recall Grid */
#recall-grid {
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow-y: auto;
  max-height: 55vh;
  -webkit-overflow-scrolling: touch;
}

.recall-row {
  display: flex;
  align-items: center;
  gap: 2px;
}

.recall-row-num {
  width: 28px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-dim);
  text-align: right;
  padding-right: 6px;
  flex-shrink: 0;
}

.recall-cell {
  width: calc((100% - 28px - 22px) / 12);
  flex-shrink: 0;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: 4px;
  font-size: 17px;
  font-weight: 600;
  font-family: 'SF Mono', 'Menlo', monospace;
  color: var(--text-strong);
  cursor: pointer;
  transition: border-color 0.1s;
}

.recall-cell.active {
  border-color: var(--accent);
  background: rgba(99, 102, 241, 0.12);
}

.recall-cell.highlight-block {
  background: rgba(99, 102, 241, 0.12);
  border-color: rgba(99, 102, 241, 0.4);
}

.recall-cell.highlight-focus {
  background: rgba(190, 242, 100, 0.55);
  border-color: var(--accent);
}

.recall-cell.filled {
  background: var(--surface);
}

.recall-cell.filled.highlight-block,
.recall-cell.filled.highlight-focus {
  background: rgba(99, 102, 241, 0.12);
}

.recall-cell.filled.highlight-focus {
  background: rgba(190, 242, 100, 0.55);
}

.recall-cell.unsure {
  background: rgba(234, 179, 8, 0.25);
  border-color: rgba(234, 179, 8, 0.5);
}

.recall-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-dim);
  transform: translateY(-2px);
}

.recall-toggle input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

.recall-options {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.recall-block-size {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-dim);
  font-size: 13px;
}

.recall-stepper {
  gap: 6px;
}

.recall-stepper input {
  width: 52px;
  font-size: 16px;
  padding: 8px 4px;
}

.recall-stepper .stepper-btn {
  min-width: 36px;
  padding: 8px 2px;
}

.recall-toolbar {
  display: flex;
  gap: 12px;
  justify-content: center;
}

.recall-toolbar button {
  padding: 8px 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}

.recall-toolbar button:active {
  background: var(--border);
}

.recall-hint {
  font-size: 13px;
  color: var(--text-dim);
}

.recall-actions, .results-actions {
  display: flex;
  gap: 12px;
}

.recall-actions .btn-primary,
.recall-actions .btn-secondary,
.results-actions .btn-primary,
.results-actions .btn-secondary {
  flex: 1;
}

/* Results */
#score-summary {
  text-align: center;
  font-size: 18px;
  padding: 16px;
  background: var(--surface);
  border-radius: 12px;
}

#score-summary .score-big {
  font-size: 48px;
  font-weight: 700;
  display: block;
  margin-bottom: 4px;
}

#score-summary .score-detail {
  color: var(--text-dim);
  font-size: 14px;
}

#score-summary .score-subdetail {
  display: block;
  margin-top: 8px;
  color: var(--text-dim);
  font-size: 13px;
}

#results-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 2px;
  justify-content: flex-start;
  padding: 8px;
  background: var(--surface);
  border-radius: 12px;
  max-height: 300px;
  overflow-y: auto;
}

#results-grid.speed-results-grid {
  display: flex;
  flex-direction: column;
  flex-wrap: nowrap;
  gap: 8px;
  background: #ececec;
  max-height: none;
}

#results-grid.speed-results-grid .speed-results-row {
  margin-top: 0;
}

.results-meta-grid {
  display: grid;
  gap: 12px;
}

.results-meta-grid.hidden {
  display: none;
}

.results-meta-card {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
}

.results-meta-label {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-strong);
}

.results-note-field {
  min-height: 88px;
  resize: vertical;
}

.result-cell {
  width: 28px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 600;
  font-family: 'SF Mono', 'Menlo', monospace;
  border-radius: 4px;
}

.result-cell.correct {
  background: var(--correct-bg);
  color: var(--correct);
}

.result-cell.wrong {
  background: var(--wrong-bg);
  color: var(--wrong);
  cursor: pointer;
}

.result-cell.revealed {
  background: #d0e0f0;
  color: #2a6496;
}

.result-cell.skipped {
  background: var(--skipped-bg);
  color: var(--skipped);
}

/* Row separator in results */
.result-row-break {
  width: 100%;
  height: 1px;
  background: var(--border);
  margin: 4px 0;
}

/* History */
.history-card,
.history-sync-card {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: 0 14px 34px rgba(0, 0, 0, 0.08);
}

.history-card-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
}

.history-card-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-strong);
}

.history-overview-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.history-overview-tile {
  display: flex;
  flex-direction: column;
  padding: 14px 12px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.03), transparent), var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: 0 14px 34px rgba(0, 0, 0, 0.08);
}

.history-overview-label {
  color: var(--text-dim);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.history-overview-value {
  margin-top: 8px;
  color: var(--text-strong);
  font-size: 20px;
  font-weight: 700;
  line-height: 1.2;
  font-variant-numeric: tabular-nums;
}

.history-overview-tile.is-text .history-overview-value {
  font-size: 15px;
  line-height: 1.25;
}

.history-overview-meta {
  margin-top: auto;
  padding-top: 6px;
  color: var(--text-dim);
  font-size: 12px;
  line-height: 1.35;
}

.history-backup-card .history-note {
  margin-top: 6px;
}

.history-sync-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
}

.history-sync-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-strong);
}

.history-sync-summary {
  margin-top: 6px;
  color: var(--text-dim);
  font-size: 13px;
  line-height: 1.45;
}

.history-sync-summary-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.history-sync-summary-row + .history-sync-summary-row {
  margin-top: 4px;
}

.history-sync-summary-label {
  color: var(--text-dim);
}

.history-sync-summary-value {
  text-align: right;
  color: var(--text-medium);
}

.sync-state-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 6px 10px;
  border-radius: 999px;
  background: var(--border);
  color: var(--text-medium);
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.sync-state-pill.ready {
  background: var(--correct-bg);
  color: var(--correct);
}

.sync-state-pill.pending {
  background: rgba(245, 158, 11, 0.14);
  color: #f59e0b;
}

.sync-state-pill.error {
  background: var(--wrong-bg);
  color: var(--wrong);
}

.history-sync-mode-wrap {
  width: 100%;
}

.sync-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}

.sync-head-info {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.sync-title-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.sync-helper {
  color: var(--text-dim);
  font-size: 13px;
  line-height: 1.4;
}

.sync-details-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  background: transparent;
  border: 0;
  color: var(--text-dim);
  font: inherit;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  border-radius: 10px;
  flex: 0 0 auto;
}

.sync-details-toggle:hover {
  background: color-mix(in srgb, var(--surface) 85%, #fff 15%);
  color: var(--text-strong);
}

.sync-details-toggle .sync-chevron {
  transition: transform 0.2s ease;
}

.sync-details-toggle.expanded .sync-chevron {
  transform: rotate(180deg);
}

.sync-body {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.sync-body.hidden {
  display: none;
}

.sync-separator {
  height: 1px;
  background: var(--border);
}

.sync-connect-row {
  display: flex;
  gap: 10px;
  align-items: center;
}

.sync-code-field {
  flex: 1;
  min-width: 0;
  position: relative;
  display: flex;
  align-items: center;
}

.sync-code-field .text-field {
  width: 100%;
  padding-right: 40px;
}

.sync-code-visibility-btn {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  background: transparent;
  border: 0;
  padding: 6px;
  cursor: pointer;
  color: var(--text-dim);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
}

.sync-code-visibility-btn:hover,
.sync-code-visibility-btn.active {
  color: var(--text-strong);
}

.sync-connect-btn {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  background: color-mix(in srgb, var(--surface) 80%, #fff 20%);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text-strong);
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

.sync-connect-btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.sync-stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.sync-stat {
  min-width: 0;
}

.sync-stat-label {
  color: var(--text-strong);
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 2px;
}

.sync-stat-value {
  color: var(--text-dim);
  font-size: 13px;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.sync-diagnostics-label {
  color: var(--text-medium);
  font-size: 14px;
  font-weight: 500;
}

.sync-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
}

.sync-icon-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  background: color-mix(in srgb, var(--surface) 82%, #000 18%);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text-strong);
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

.sync-icon-btn:hover {
  background: color-mix(in srgb, var(--surface) 75%, #000 25%);
}

.sync-text-btn {
  background: transparent;
  border: 0;
  color: var(--text-medium);
  font: inherit;
  font-size: 14px;
  cursor: pointer;
  padding: 8px 4px;
}

.sync-text-btn:hover {
  color: var(--text-strong);
}

.sync-advanced {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 14px;
  background: rgba(127, 127, 127, 0.06);
  border: 1px dashed var(--border);
  border-radius: 12px;
}

.sync-advanced.hidden {
  display: none;
}

@media (max-width: 560px) {
  .sync-stats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

.history-sync-panel {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.history-sync-panel.hidden {
  display: none;
}

.history-actions {
  display: flex;
  gap: 12px;
}

.history-inline-field {
  display: flex;
  gap: 10px;
  align-items: center;
}

.history-inline-field .text-field {
  flex: 1;
}

.btn-inline-secondary {
  flex: 0 0 auto;
  min-width: 78px;
  padding: 12px 14px;
  font-size: 15px;
}

.history-sync-helper {
  color: var(--text-dim);
  font-size: 12px;
  line-height: 1.45;
}

.history-sync-advanced {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 14px;
  background: rgba(127, 127, 127, 0.06);
  border: 1px dashed var(--border);
  border-radius: 12px;
}

.history-sync-advanced.hidden {
  display: none;
}

.history-actions .btn-secondary {
  flex: 1;
}

.history-note {
  margin: 0;
  color: var(--text-dim);
  font-size: 13px;
  line-height: 1.45;
}

#backup-summary {
  margin-top: -2px;
}

.history-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.history-selection-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-top: 12px;
}

.history-selection-count {
  color: var(--text-dim);
  font-size: 13px;
  font-weight: 600;
}

.danger-btn {
  color: #b42318;
  border-color: color-mix(in srgb, #b42318 28%, var(--border));
}

.danger-btn:disabled {
  color: var(--text-dim);
  border-color: var(--border);
}

.history-filter-btn {
  padding: 8px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.history-filter-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}

#history-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 52vh;
  overflow-y: auto;
}

.history-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
  padding: 14px 16px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.02), transparent), var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  font-size: 14px;
}

.history-item.selectable {
  cursor: pointer;
}

.history-item.selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 18%, transparent);
}

.history-item-check {
  flex: 0 0 auto;
  width: 20px;
  height: 20px;
  accent-color: var(--accent);
}

.history-item-main {
  min-width: 0;
  flex: 1 1 auto;
}

.history-item-side {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
  flex: 0 0 auto;
}

.history-item .h-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 4px 8px;
  border-radius: 999px;
  background: var(--accent);
  color: white;
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
}

.history-item .h-date {
  color: var(--text-dim);
  font-size: 12px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.history-item .h-score {
  font-weight: 600;
  color: var(--text-strong);
  font-variant-numeric: tabular-nums;
}

.history-item .h-detail {
  color: var(--text-dim);
  font-size: 12px;
  margin-top: 4px;
}

.history-item .h-discipline {
  font-size: 11px;
  color: var(--accent);
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.history-item .h-loci,
.history-item .h-note {
  color: var(--text-dim);
  font-size: 12px;
  margin-top: 4px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.history-item .h-loci {
  color: var(--text);
}

.history-item .h-editable {
  cursor: text;
  padding: 2px 6px;
  margin-left: -6px;
  border-radius: 6px;
  min-height: 1em;
  transition: background 0.15s;
}

.history-item .h-editable:hover {
  background: color-mix(in srgb, var(--surface) 85%, #000 15%);
}

.history-item .h-editable:focus {
  outline: none;
  background: color-mix(in srgb, var(--surface) 75%, #000 25%);
  box-shadow: 0 0 0 2px var(--accent);
}

.history-item .h-editable:empty::before {
  content: attr(data-placeholder);
  color: var(--text-dim);
  opacity: 0.55;
}

.status-note.pending {
  color: #f59e0b;
}

@media (max-width: 420px) {
  .history-overview-grid {
    grid-template-columns: 1fr;
  }

  .history-sync-head {
    flex-direction: column;
  }

  .history-sync-summary-row {
    flex-direction: column;
    gap: 2px;
  }

  .history-sync-summary-value {
    text-align: left;
  }

  .history-actions {
    flex-direction: column;
  }

  .history-inline-field {
    flex-direction: column;
    align-items: stretch;
  }

  .history-item {
    align-items: flex-start;
  }

  .history-item-side {
    align-items: flex-start;
  }

  .history-item .h-date {
    text-align: left;
  }

  .history-selection-bar {
    flex-direction: column;
    align-items: stretch;
  }
}

/* Safe area for iPhone notch */
@supports (padding-top: env(safe-area-inset-top)) {
  #app {
    padding-top: calc(20px + env(safe-area-inset-top));
    padding-bottom: calc(20px + env(safe-area-inset-bottom));
  }
}
