:root {
  color-scheme: dark;
  --bg: #11120f;
  --surface: #191b17;
  --surface-2: #22251f;
  --surface-3: #2d3129;
  --text: #f5f3ed;
  --muted: #b8b3a7;
  --line: #383d33;
  --accent: #18b184;
  --accent-strong: #22c997;
  --accent-soft: rgba(24, 177, 132, 0.16);
  --warn: #d36f43;
  --danger: #df5f5f;
  --shadow: 0 24px 70px rgba(0, 0, 0, 0.32);
}

body[data-theme="light"] {
  color-scheme: light;
  --bg: #f6f4ef;
  --surface: #ffffff;
  --surface-2: #ede9df;
  --surface-3: #e1dccc;
  --text: #1a1d18;
  --muted: #6c6b62;
  --line: #d9d3c3;
  --accent: #087e63;
  --accent-strong: #0a9977;
  --accent-soft: rgba(8, 126, 99, 0.12);
  --shadow: 0 24px 60px rgba(62, 57, 44, 0.16);
}

* {
  box-sizing: border-box;
}

html {
  height: 100%;
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100%;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    linear-gradient(135deg, rgba(24, 177, 132, 0.12), transparent 28rem),
    linear-gradient(180deg, var(--bg), color-mix(in srgb, var(--bg), #000 8%));
  color: var(--text);
}

@media (min-width: 901px) {
  html,
  body {
    height: 100%;
    overflow: hidden;
  }
}

button,
input {
  font: inherit;
}

button,
a {
  touch-action: manipulation;
}

button {
  border: 0;
}

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

.topbar {
  width: min(1440px, calc(100vw - 32px));
  height: 64px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: auto minmax(320px, 1fr) auto;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  color: var(--text);
  text-decoration: none;
}

.brand-mark {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: var(--accent);
  color: #06150f;
  font-weight: 900;
  letter-spacing: 0;
}

.brand strong,
.section-heading h2,
.player-header h2 {
  letter-spacing: 0;
}

.brand small {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 0.78rem;
}

.top-actions {
  display: flex;
  align-items: center;
  justify-self: end;
  gap: 8px;
}

.top-search {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: end;
}

.top-search-field {
  display: grid;
  gap: 4px;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 850;
}

.top-search-field input {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--text);
  padding: 0 12px;
  outline: none;
}

.top-search-field input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.search-assist {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  left: 0;
  z-index: 30;
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--muted);
  padding: 10px;
  box-shadow: var(--shadow);
}

.search-assist[hidden] {
  display: none;
}

.search-assist button {
  min-height: 34px;
  border-radius: 7px;
  background: var(--accent);
  color: #06150f;
  cursor: pointer;
  font-weight: 850;
  padding: 0 12px;
}

.ghost-button,
.text-button,
.control-button,
#loadButton {
  min-height: 38px;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 800;
}

.ghost-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 74px;
  padding: 0 13px;
  border: 1px solid var(--line);
  background: color-mix(in srgb, var(--surface), transparent 26%);
  color: var(--text);
  text-decoration: none;
}

.icon-action {
  min-width: 38px;
  width: 38px;
  padding: 0;
}

.compact-action {
  min-width: auto;
}

.ghost-button:hover,
.text-button:hover {
  background: var(--surface-3);
}

.app-shell {
  width: min(1440px, calc(100vw - 32px));
  margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(0, 1fr) clamp(280px, 26vw, 360px);
  gap: 12px;
  height: calc(100vh - 74px);
  min-height: 0;
  padding: 0 0 12px;
}

.practice-area,
.side-panel {
  display: grid;
  gap: 8px;
  align-content: start;
  min-height: 0;
}

.practice-area {
  grid-template-rows: minmax(0, 1fr);
}

.side-panel {
  grid-auto-rows: min-content;
  overflow: hidden;
  padding-right: 2px;
}

.player-panel,
.card,
.coach-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: color-mix(in srgb, var(--surface), transparent 4%);
  box-shadow: var(--shadow);
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--accent);
  font-size: 0.72rem;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.player-header h2,
.section-heading h2 {
  margin: 0;
}

#loadButton,
.main-action {
  background: var(--accent);
  color: #06150f;
}

#loadButton,
.control-button,
.text-button {
  padding: 0 15px;
}

#loadButton:hover,
.main-action:hover {
  background: var(--accent-strong);
}

.player-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto auto auto;
  min-height: 0;
  overflow: hidden;
}

.player-header {
  min-height: 62px;
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: start;
  padding: 10px 14px;
}

.player-header h2 {
  display: -webkit-box;
  overflow: hidden;
  font-size: clamp(0.98rem, 1.25vw, 1.2rem);
  line-height: 1.15;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.player-header a {
  color: inherit;
  text-decoration: none;
}

.player-header a:hover {
  color: var(--accent);
}

.video-meta {
  margin: 5px 0 0;
  font-size: 0.9rem;
  color: var(--muted);
}

.video-frame {
  position: relative;
  width: 100%;
  height: 100%;
  min-height: 220px;
  overflow: hidden;
  background: #050605;
}

#player,
#player iframe {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.empty-state {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  gap: 8px;
  text-align: center;
  color: var(--muted);
}

.empty-state strong {
  color: var(--text);
  font-size: clamp(2.5rem, 7vw, 5.8rem);
  line-height: 0.95;
}

.empty-state.is-hidden {
  display: none;
}

.primary-controls,
.status-row {
  display: grid;
  gap: 8px;
  padding: 7px 14px;
}

.primary-controls {
  grid-template-columns: minmax(150px, 1.2fr) repeat(4, minmax(0, 1fr));
  background: color-mix(in srgb, var(--surface), #000 5%);
}

.control-button {
  min-height: 38px;
  background: var(--surface-2);
  color: var(--text);
  font-size: 0.94rem;
}

.control-button small {
  display: block;
  margin-top: 1px;
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 800;
}

.control-button:hover {
  background: var(--surface-3);
}

.button-kicker {
  display: inline-grid;
  place-items: center;
  min-width: 28px;
  height: 28px;
  margin-right: 8px;
  border-radius: 6px;
  border: 1px solid color-mix(in srgb, var(--line), var(--text) 15%);
  background: color-mix(in srgb, var(--surface), #fff 7%);
  font-size: 0.82rem;
}

.text-button {
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--text);
}

.status-row {
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  padding-top: 0;
}

.status {
  min-height: 24px;
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  color: var(--muted);
  font-weight: 800;
}

.status[data-tone="error"] {
  color: var(--danger);
}

.coach-panel {
  display: none;
  position: relative;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1px;
  overflow: hidden;
  background: var(--line);
}

.coach-panel[hidden] {
  display: none;
}

.coach-panel article {
  display: flex;
  gap: 12px;
  padding: 12px;
  background: var(--surface);
}

.coach-dismiss {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 1;
  min-height: 30px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface-2);
  color: var(--muted);
  cursor: pointer;
  font-size: 0.78rem;
  font-weight: 850;
  padding: 0 9px;
}

.coach-panel h3 {
  margin: 0 0 5px;
  font-size: 0.95rem;
}

.coach-panel p {
  margin: 0;
  color: var(--muted);
  line-height: 1.45;
}

.coach-panel p {
  display: -webkit-box;
  overflow: hidden;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.step-number {
  flex: 0 0 auto;
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 900;
}

.card {
  padding: 10px 12px;
}

.section-heading {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: start;
  margin-bottom: 8px;
}

.section-heading h2 {
  font-size: 1.25rem;
}

.recent-list {
  display: grid;
  gap: 8px;
}

.recent-empty {
  padding: 12px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  line-height: 1.45;
}

.recent-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 34px;
  gap: 8px;
  align-items: center;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
}

.recent-item button {
  min-height: 34px;
  border-radius: 7px;
  background: transparent;
  color: var(--text);
  cursor: pointer;
}

.recent-title {
  display: block;
  overflow: hidden;
  color: var(--text);
  font-weight: 850;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.recent-meta {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.82rem;
}

.delete-recent {
  width: 34px;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--muted);
  padding: 0;
}

.delete-recent svg {
  width: 18px;
  height: 18px;
  fill: currentColor;
}

.delete-recent:hover {
  border-color: color-mix(in srgb, var(--danger), var(--line) 35%);
  color: var(--danger);
}

.command-list {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.command-list li {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 5px 0;
  border-bottom: 1px solid var(--line);
}

.command-list li:last-child {
  border-bottom: 0;
}

.command-list span {
  color: var(--muted);
  text-align: right;
}

.voice-state {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  margin-bottom: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
  padding: 10px;
}

.voice-state strong,
.voice-state span {
  display: block;
}

.voice-state strong {
  color: var(--text);
}

.voice-state span {
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.84rem;
  line-height: 1.3;
}

.voice-toggle {
  min-height: 38px;
  border-radius: 8px;
  background: var(--accent);
  color: #06150f;
  cursor: pointer;
  font-weight: 900;
  padding: 0 12px;
}

.is-listening .voice-state {
  border-color: color-mix(in srgb, var(--accent), var(--line) 25%);
  background: var(--accent-soft);
}

.voice-disabled .command-list {
  opacity: 0.45;
}


.mic-help {
  display: grid;
  gap: 6px;
  margin: 0 14px 12px;
  padding: 12px 14px;
  border: 1px solid color-mix(in srgb, var(--danger), transparent 45%);
  border-radius: 8px;
  background: color-mix(in srgb, var(--danger), transparent 88%);
  color: var(--text);
  line-height: 1.4;
}

.mic-help span {
  color: var(--muted);
}

.mic-help[hidden] {
  display: none;
}

.modal {
  width: min(760px, calc(100vw - 28px));
  max-height: min(720px, calc(100vh - 28px));
  border: 1px solid var(--line);
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  padding: 0;
  box-shadow: var(--shadow);
}

.modal::backdrop {
  background: rgba(0, 0, 0, 0.62);
  backdrop-filter: blur(5px);
}

.modal-panel {
  display: grid;
  gap: 18px;
  max-height: inherit;
  overflow: auto;
  padding: 18px;
  background: var(--surface);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: start;
}

.modal-header h2 {
  margin: 0;
  font-size: 1.55rem;
}

.modal-close,
.donate-button {
  min-height: 40px;
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
  font-weight: 850;
  padding: 0 14px;
}

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

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

.help-grid section,
.permission-grid section {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
  padding: 12px;
}

.help-grid h3,
.permission-grid h3 {
  margin: 0 0 7px;
}

.help-grid p,
.permission-grid p,
.donate-panel p {
  margin: 0;
  color: var(--muted);
  line-height: 1.45;
}

.modal-subhead {
  margin: 4px 0 -8px;
}

.donate-button {
  justify-self: start;
  background: var(--accent);
  color: #06150f;
}

.focus-exit {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 20;
  min-height: 44px;
  border-radius: 8px;
  background: var(--accent);
  color: #06150f;
  cursor: pointer;
  font-weight: 900;
  padding: 0 16px;
  box-shadow: var(--shadow);
}

.focus-exit[hidden] {
  display: none;
}

.video-focused .button-kicker {
  display: none;
}

body.focus-mode {
  overflow: hidden;
}

body.focus-mode .topbar,
body.focus-mode .side-panel,
body.focus-mode .player-header,
body.focus-mode .primary-controls,
body.focus-mode .status-row,
body.focus-mode .mic-help,
body.focus-mode .coach-panel {
  display: none;
}

body.focus-mode .app-shell,
body.focus-mode .practice-area,
body.focus-mode .player-panel {
  width: 100vw;
  height: 100vh;
  margin: 0;
  padding: 0;
  gap: 0;
  border: 0;
}

body.focus-mode .player-panel {
  border-radius: 0;
}

body.focus-mode .video-frame {
  width: 100vw;
  height: 100vh;
  min-height: 0;
  aspect-ratio: auto;
}

@media (max-width: 1040px) and (min-width: 901px) {
  .app-shell {
    grid-template-columns: minmax(0, 1fr) 300px;
  }

  .coach-panel {
    display: none;
  }
}

@media (max-width: 900px) {
  html,
  body {
    overflow: auto;
  }

  .topbar {
    width: min(100vw - 20px, 1440px);
    height: auto;
    min-height: 62px;
    padding: 10px 0;
    grid-template-columns: auto auto;
  }

  .top-search {
    grid-column: 1 / -1;
    order: 3;
  }

  .app-shell {
    width: min(100vw - 20px, 1440px);
    height: auto;
    grid-template-columns: 1fr;
    padding-bottom: 16px;
  }

  .practice-area,
  .player-panel {
    display: grid;
    grid-template-rows: auto;
  }

  .side-panel {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    overflow: visible;
  }

  .coach-panel {
    display: grid;
  }

  .video-frame {
    height: auto;
    min-height: 0;
    aspect-ratio: 16 / 9;
  }
}

@media (max-width: 760px) {
  .topbar {
    width: min(100vw - 20px, 1440px);
    min-height: auto;
    padding: 12px 0;
    align-items: start;
  }

  .brand small {
    display: none;
  }

  .app-shell {
    padding-bottom: 16px;
  }

  .primary-controls,
  .status-row,
  .coach-panel,
  .side-panel {
    grid-template-columns: 1fr;
  }

  .player-header {
    min-height: auto;
    padding: 14px;
  }

  .mic-badge {
    display: none;
  }

  .primary-controls,
  .status-row {
    padding-left: 12px;
    padding-right: 12px;
  }

  .control-button,
  #loadButton,
  .top-search-field input {
    min-height: 52px;
  }

  .button-kicker {
    display: none;
  }
}

@media (max-width: 640px) {
  .help-grid,
  .permission-grid {
    grid-template-columns: 1fr;
  }

  .modal-panel {
    padding: 14px;
  }
}

@media (max-width: 900px) and (orientation: landscape) {
  html,
  body {
    width: 100vw;
    height: 100vh;
    overflow: hidden;
  }

  .topbar,
  .coach-panel,
  .side-panel,
  .player-header,
  .primary-controls,
  .status-row,
  .mic-help {
    display: none;
  }

  .app-shell,
  .practice-area,
  .player-panel {
    width: 100vw;
    height: 100vh;
    margin: 0;
    padding: 0;
    gap: 0;
    border: 0;
  }

  .player-panel {
    border-radius: 0;
  }

  .video-frame {
    width: 100vw;
    height: 100vh;
    aspect-ratio: auto;
  }
}
