* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: var(--font-md);
  -webkit-tap-highlight-color: transparent;
}

/* App shell: centered column, max-width ~480px on wider viewports. */
body {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
}

#appbar,
#screen,
#tabbar {
  width: 100%;
  max-width: 480px;
}

a {
  color: inherit;
  text-decoration: none;
}

button {
  font: inherit;
}

/* --- App bar --- */

#appbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--surface);
  border-bottom: 1px solid var(--sage-100);
  padding-top: env(safe-area-inset-top);
}

.appbar-inner {
  height: var(--appbar-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--space-4);
}

.appbar-title {
  font-size: var(--font-lg);
  font-weight: 600;
  color: var(--text);
}

.appbar-actions {
  display: flex;
  gap: var(--space-2);
}

.icon-button {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 44px;
  border-radius: var(--radius-md);
  color: var(--text-muted);
}

.icon-button:hover,
.icon-button:active {
  background: var(--sage-50);
  color: var(--accent);
}

.icon-button svg {
  width: 22px;
  height: 22px;
}

/* --- Screen --- */

#screen {
  flex: 1;
  width: 100%;
  min-height: calc(100vh - var(--appbar-height) - var(--tabbar-height));
  padding-bottom: calc(var(--tabbar-height) + env(safe-area-inset-bottom) + var(--space-4));
  transition: opacity 0.12s ease;
}

.screen-inner {
  padding: var(--space-5) var(--space-4);
}

.screen-inner--centered {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 60vh;
  text-align: center;
}

.screen-title {
  font-size: var(--font-xl);
  font-weight: 700;
  margin: 0 0 var(--space-4);
  color: var(--text);
}

.screen-empty {
  color: var(--text-muted);
  font-size: var(--font-md);
  line-height: 1.5;
  margin: 0 0 var(--space-3);
}

.empty-state {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  padding: var(--space-5) var(--space-4);
  text-align: center;
}

.placeholder-card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  padding: var(--space-5) var(--space-4);
  max-width: 360px;
}

.placeholder-card--disabled {
  opacity: 0.85;
}

.btn {
  min-height: 44px;
  padding: 0 var(--space-5);
  border: none;
  border-radius: var(--radius-md);
  background: var(--accent);
  color: #fff;
  font-size: var(--font-md);
  font-weight: 600;
  cursor: pointer;
}

.btn--disabled,
.btn:disabled {
  background: var(--sage-300);
  color: var(--sage-50);
  cursor: not-allowed;
}

/* --- Tab bar --- */

#tabbar {
  position: fixed;
  left: 50%;
  bottom: 0;
  transform: translateX(-50%);
  width: 100%;
  max-width: 480px;
  display: flex;
  background: var(--surface);
  border-top: 1px solid var(--sage-100);
  padding-bottom: env(safe-area-inset-bottom);
  z-index: 10;
}

.tab-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-height: 56px;
  min-width: 44px;
  padding: var(--space-2) 0;
  color: var(--text-muted);
}

.tab-item.is-active {
  color: var(--accent);
}

.tab-icon {
  display: flex;
  width: 22px;
  height: 22px;
}

.tab-icon svg {
  width: 100%;
  height: 100%;
}

.tab-label {
  font-size: 0.7rem;
  font-weight: 500;
}

.tab-item--soon {
  opacity: 0.5;
  position: relative;
}

.tab-badge {
  position: absolute;
  top: 2px;
  right: 18%;
  font-size: 0.55rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  background: var(--sage-300);
  color: var(--sage-900);
  border-radius: 999px;
  padding: 1px 5px;
}

/* --- Player screen --- */

.player-screen {
  display: flex;
  flex-direction: column;
}

.player-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-3) var(--space-4);
}

.player-back {
  min-height: 44px;
  padding: 0 var(--space-2);
  border: none;
  background: none;
  color: var(--accent);
  font-size: var(--font-md);
  font-weight: 600;
  cursor: pointer;
}

.player-date {
  color: var(--text-muted);
  font-size: var(--font-sm);
  font-weight: 500;
}

/* Letterboxed video stage — canvas overlays the video pixel-for-pixel. */
.player-stage {
  position: relative;
  width: 100%;
  aspect-ratio: 3 / 4;
  background: #000;
  overflow: hidden;
}

.player-video,
.player-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.player-video {
  object-fit: contain;
  background: #000;
}

.player-canvas {
  pointer-events: none;
}

.player-controls {
  padding: var(--space-4);
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

.player-scrub {
  width: 100%;
  height: 44px;
  accent-color: var(--accent);
}

.ctl-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-4);
}

.ctl-btn {
  min-width: 56px;
  min-height: 44px;
  padding: 0 var(--space-3);
  border: 1px solid var(--sage-100);
  border-radius: var(--radius-md);
  background: var(--surface);
  color: var(--text);
  font-size: var(--font-md);
  cursor: pointer;
}

.ctl-btn--primary {
  min-width: 72px;
  min-height: 52px;
  border: none;
  background: var(--accent);
  color: #fff;
  font-size: var(--font-lg);
}

.seg-group {
  display: flex;
  align-self: center;
  border: 1px solid var(--sage-100);
  border-radius: var(--radius-md);
  overflow: hidden;
}

.seg-btn {
  min-width: 64px;
  min-height: 44px;
  border: none;
  background: var(--surface);
  color: var(--text-muted);
  font-size: var(--font-sm);
  font-weight: 600;
  cursor: pointer;
}

.seg-btn + .seg-btn {
  border-left: 1px solid var(--sage-100);
}

.seg-btn.is-active {
  background: var(--accent);
  color: #fff;
}

.toggle-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: var(--space-2);
}

.toggle-btn {
  min-height: 44px;
  padding: 0 var(--space-4);
  border: 1px solid var(--sage-100);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text-muted);
  font-size: var(--font-sm);
  font-weight: 600;
  cursor: pointer;
}

.toggle-btn.is-on {
  background: var(--sage-100);
  border-color: var(--sage-300);
  color: var(--sage-700);
}

.event-chips {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: var(--space-2);
}

.event-chip {
  min-height: 44px;
  padding: 0 var(--space-4);
  border: 1px solid var(--sage-300);
  border-radius: 999px;
  background: var(--sage-50);
  color: var(--sage-700);
  font-size: var(--font-sm);
  font-weight: 600;
  cursor: pointer;
}

.player-error {
  padding: var(--space-6) var(--space-4);
  text-align: center;
}

.player-error-title {
  font-size: var(--font-lg);
  font-weight: 700;
  margin: 0 0 var(--space-2);
  color: var(--text);
}

/* --- Import screen --- */

.import-body {
  display: flex;
  flex-direction: column;
  gap: var(--space-5);
}

.import-dropzone {
  background: var(--surface);
  border: 2px dashed var(--sage-300);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  padding: var(--space-6) var(--space-4);
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-3);
  cursor: pointer;
}

.import-dropzone:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.import-dropzone-icon {
  display: flex;
  width: 48px;
  height: 48px;
  color: var(--accent);
}

.import-dropzone-icon svg {
  width: 100%;
  height: 100%;
}

.import-dropzone-title {
  font-size: var(--font-lg);
  font-weight: 700;
  margin: 0;
  color: var(--text);
}

.import-dropzone-hint {
  font-size: var(--font-sm);
  color: var(--text-muted);
  margin: 0;
  max-width: 320px;
  line-height: 1.5;
}

.import-dropzone-link {
  font-size: var(--font-sm);
  font-weight: 600;
  color: var(--accent);
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.import-handedness-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-2);
}

.import-handedness-label {
  font-size: var(--font-sm);
  font-weight: 600;
  color: var(--text-muted);
}

.import-handedness .seg-btn {
  padding: 0 var(--space-4);
}

.import-progress {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  padding: var(--space-5) var(--space-4);
}

.import-step {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  color: var(--text-muted);
  font-size: var(--font-md);
}

.import-step-dot {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: var(--sage-100);
  flex-shrink: 0;
}

.import-step--active {
  color: var(--text);
  font-weight: 600;
}

.import-step--active .import-step-dot {
  background: var(--accent);
}

.import-step--done {
  color: var(--text);
}

.import-step--done .import-step-dot {
  background: var(--sage-600);
}

.import-step--error {
  color: var(--danger);
}

.import-step--error .import-step-dot {
  background: var(--danger);
}

.import-success {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-4);
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  padding: var(--space-5) var(--space-4);
  text-align: center;
}

.import-success-thumb {
  width: 100%;
  max-width: 280px;
  aspect-ratio: 3 / 4;
  object-fit: cover;
  border-radius: var(--radius-md);
  background: var(--sage-100);
}

.import-success-title {
  font-size: var(--font-lg);
  font-weight: 700;
  margin: 0;
  color: var(--text);
}

.import-success-actions {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  width: 100%;
  max-width: 280px;
}

.btn--secondary {
  background: var(--sage-100);
  color: var(--sage-900);
}

.import-error {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  padding: var(--space-5) var(--space-4);
  text-align: center;
}

.import-error-title {
  font-size: var(--font-lg);
  font-weight: 700;
  margin: 0 0 var(--space-2);
  color: var(--danger);
}

.import-error-actions {
  margin-top: var(--space-4);
  display: flex;
  justify-content: center;
}

/* --- Sessions screen --- */

.session-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.session-card {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  padding: var(--space-3);
  cursor: pointer;
  min-height: 44px;
}

.session-card-thumb {
  width: 64px;
  height: 64px;
  border-radius: var(--radius-md);
  overflow: hidden;
  background: var(--sage-100);
  flex-shrink: 0;
}

.session-card-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.session-card-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.session-card-name {
  font-weight: 600;
  color: var(--text);
  font-size: var(--font-md);
}

.session-card-date {
  font-size: var(--font-sm);
  color: var(--text-muted);
}

.session-card-count {
  flex-shrink: 0;
  font-size: var(--font-sm);
  font-weight: 600;
  color: var(--sage-700);
  background: var(--sage-50);
  border-radius: 999px;
  padding: var(--space-1) var(--space-3);
  white-space: nowrap;
}

.session-detail-header {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin-bottom: var(--space-4);
}

.session-detail-title {
  margin: 0;
}

/* --- Swing grid (Sessions detail / Favourites / Imported) --- */

.swing-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-3);
}

.swing-tile {
  position: relative;
  background: var(--surface);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-card);
  overflow: hidden;
  cursor: pointer;
}

.swing-tile-thumb {
  width: 100%;
  aspect-ratio: 3 / 4;
  background: var(--sage-100);
}

.swing-tile-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.swing-tile-star,
.swing-tile-menu {
  position: absolute;
  top: var(--space-2);
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.35);
  color: #fff;
  cursor: pointer;
}

.swing-tile-star {
  right: var(--space-2);
}

.swing-tile-star svg {
  width: 18px;
  height: 18px;
}

.swing-tile-star.is-on {
  color: #facc15;
}

.swing-tile-menu {
  left: var(--space-2);
  font-size: var(--font-lg);
  font-weight: 700;
  line-height: 1;
}

.swing-tile-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
}

.swing-tile-time {
  font-size: var(--font-sm);
  font-weight: 600;
  color: var(--text);
}

.swing-tile-chip {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  padding: 1px 6px;
  border-radius: 999px;
  background: var(--sage-100);
  color: var(--sage-700);
}

.swing-tile-chip--failed {
  background: rgba(192, 86, 79, 0.15);
  color: var(--danger);
}

/* --- Imported screen --- */

.imported-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  margin-bottom: var(--space-4);
}

.imported-header .screen-title {
  margin: 0;
}

/* --- Settings screen --- */

.settings-section {
  margin-bottom: var(--space-5);
}

.settings-section-title {
  font-size: var(--font-sm);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-muted);
  margin: 0 0 var(--space-2);
}

.settings-card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  padding: 0 var(--space-4);
}

.settings-row {
  padding: var(--space-3) 0;
  border-bottom: 1px solid var(--sage-100);
}

.settings-row:last-child {
  border-bottom: none;
}

.settings-row-label {
  font-size: var(--font-md);
  color: var(--text);
  font-weight: 500;
}

.settings-row-note {
  margin: var(--space-1) 0 0;
  font-size: var(--font-sm);
  color: var(--text-muted);
  line-height: 1.4;
}

.settings-row--seg {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  flex-wrap: wrap;
}

.settings-row-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-2);
}

.settings-row-value {
  font-size: var(--font-sm);
  font-weight: 600;
  color: var(--accent);
}

.settings-slider {
  width: 100%;
  height: 44px;
  accent-color: var(--accent);
}

/* Accessible switch */

.switch {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  min-height: 44px;
  cursor: pointer;
}

.switch-input {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.switch-track {
  flex-shrink: 0;
  width: 44px;
  height: 26px;
  border-radius: 999px;
  background: var(--sage-100);
  border: 1px solid var(--sage-300);
  position: relative;
  transition: background 0.15s ease;
}

.switch-thumb {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #fff;
  box-shadow: var(--shadow-card);
  transition: transform 0.15s ease;
}

.switch-input:checked + .switch-track {
  background: var(--accent);
  border-color: var(--accent);
}

.switch-input:checked + .switch-track .switch-thumb {
  transform: translateX(18px);
}

.switch-input:focus-visible + .switch-track {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Storage usage bar */

.storage-usage {
  padding: var(--space-2) 0;
}

.storage-usage-bar {
  width: 100%;
  height: 10px;
  border-radius: 999px;
  background: var(--sage-100);
  overflow: hidden;
}

.storage-usage-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 999px;
}

/* --- Help / Recording guide --- */

.guide-section {
  display: flex;
  gap: var(--space-3);
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  padding: var(--space-4);
  margin-bottom: var(--space-4);
}

.guide-icon {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  background: var(--sage-50);
  color: var(--accent);
}

.guide-icon svg {
  width: 22px;
  height: 22px;
}

.guide-body {
  flex: 1;
  min-width: 0;
}

.guide-title {
  font-size: var(--font-md);
  font-weight: 700;
  margin: 0 0 var(--space-2);
  color: var(--text);
}

.guide-text {
  margin: 0 0 var(--space-2);
  color: var(--text-muted);
  line-height: 1.5;
  font-size: var(--font-sm);
}

.guide-stats {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin-top: var(--space-1);
}

.guide-stat {
  display: inline-block;
  font-size: var(--font-sm);
  font-weight: 600;
  color: var(--sage-700);
  background: var(--sage-50);
  border-radius: 999px;
  padding: var(--space-1) var(--space-3);
}

.guide-diagram {
  width: 100%;
  max-width: 220px;
  margin-top: var(--space-3);
}

.guide-diagram svg {
  width: 100%;
  height: auto;
}
