:root {
  color-scheme: light;
  --background: #f7f7f4;
  --surface: #ffffff;
  --surface-subtle: #f0f1ed;
  --text: #20221f;
  --muted: #686d64;
  --border: #d9ddd3;
  --accent: #176b5b;
  --accent-strong: #0f4f44;
  --accent-soft: #dceee8;
  --danger: #b4233a;
  --shadow: 0 12px 28px rgba(28, 34, 30, 0.08);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.5;
  color: var(--text);
  background: var(--background);
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0;
}

button,
input,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

button:focus,
button:focus-visible,
.field input[type="text"]:focus,
.field textarea:focus,
.youtube-player iframe:focus {
  outline: 3px solid transparent;
  outline-offset: 3px;
}

a {
  color: inherit;
}

.page-shell {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.app-main {
  flex: 1;
  padding: 24px 16px 32px;
}

.has-video .app-main {
  padding-bottom: 24px;
}

.app-container {
  width: min(100%, 1180px);
  margin: 0 auto;
}

.app-header {
  max-width: 720px;
  margin: 0 auto 28px;
  text-align: center;
}

.app-header h1 {
  margin: 0;
  line-height: 1.05;
  letter-spacing: 0;
  color: #4f554d;
  font-weight: 600;
}

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

.app-header p {
  margin: 12px 0 0;
  color: var(--muted);
}

.has-video .app-header p {
  display: none;
}

.input-view {
  width: min(100%, 680px);
  margin: 0 auto;
}

.panel,
.chapters-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.form-panel {
  display: grid;
  gap: 18px;
  padding: 24px;
}

.field {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
  border: 0;
  font-weight: 600;
}

.field input[type="text"],
.field textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fbfcfa;
  color: var(--text);
  padding: 11px 12px;
  font-weight: 400;
}

.field textarea {
  min-height: 168px;
  resize: vertical;
}

.field input[type="text"]:focus,
.field textarea:focus {
  outline: 3px solid transparent;
  border-color: var(--accent);
}

.radio-row {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
  font-weight: 500;
}

.radio-row input {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
}

.button {
  min-height: 44px;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 10px 14px;
  font-weight: 700;
}

.button-primary {
  color: #ffffff;
  background: var(--accent);
}

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

.button-secondary {
  color: var(--accent-strong);
  background: var(--accent-soft);
  border-color: rgba(15, 79, 68, 0.2);
}

.button-secondary:hover {
  background: #cfe7df;
}

.button:disabled {
  cursor: wait;
  opacity: 0.75;
}

.player-grid {
  display: grid;
  grid-template-columns: minmax(0, 3fr) minmax(340px, 2fr);
  gap: 24px;
  align-items: start;
}

.player-column {
  min-width: 0;
}

.player-view:focus {
  outline: none;
}

.video-frame {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  background: #111111;
  border-radius: 4px;
}

.youtube-player {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.shortcuts {
  display: flex;
  gap: 24px;
  margin-top: 18px;
}

.shortcuts h2 {
  margin: 0 0 8px;
  font-size: 0.95rem;
}

.shortcut-list {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 12px;
  align-items: center;
}

.shortcut-row {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  width: fit-content;
  min-height: 30px;
  border: 1px solid rgba(217, 221, 211, 0.78);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.72);
  color: var(--muted);
  font-size: 0.82rem;
  padding: 3px 10px 3px 4px;
  box-shadow: 0 1px 2px rgba(28, 34, 30, 0.04);
}

.shortcut-key {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  border: 1px solid rgba(217, 221, 211, 0.82);
  border-radius: 999px;
  background: rgba(240, 241, 237, 0.62);
  color: var(--text);
  padding: 1px 7px;
  font-weight: 700;
  white-space: nowrap;
  box-shadow: inset 0 -1px 0 rgba(28, 34, 30, 0.05);
}

.shortcut-action {
  display: inline-flex;
  align-items: center;
  white-space: nowrap;
}

.gesture-target {
  flex: 1;
  min-height: 84px;
  display: grid;
  place-items: center;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  border: 2px dashed var(--border);
  border-radius: 6px;
  background: var(--surface-subtle);
  color: var(--muted);
  font-size: 0.82rem;
}

.chapters-panel {
  overflow: hidden;
}

.empty-chapters {
  padding: 36px 20px;
  text-align: center;
  color: var(--muted);
}

.table-wrap {
  max-height: 600px;
  overflow: auto;
}

.has-video .table-wrap {
  max-height: clamp(320px, calc(100dvh - 244px), 600px);
}

.chapters-table {
  width: 100%;
  border-collapse: collapse;
}

.chapters-table th,
.chapters-table td {
  padding: 12px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
  line-height: 1.5;
}

.chapters-table th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--surface);
  font-size: 0.88rem;
}

.chapters-table th:first-child {
  width: 116px;
}

.chapters-table th:last-child,
.chapters-table td:last-child {
  width: 112px;
  text-align: right;
}

.chapters-table td:first-child,
.chapters-table td:nth-child(2),
.chapters-table td:last-child {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  font-size: 0.86rem;
}

.chapters-table td:first-child,
.chapters-table td:last-child {
  white-space: nowrap;
}

.chapter-row {
  transition: background 0.15s ease;
}

.chapter-row:hover {
  background: #f5f7f3;
}

.chapter-row.active {
  background: var(--accent-soft);
}

.chapter-row button {
  width: 100%;
  font: inherit;
  line-height: inherit;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  text-align: left;
}

.chapter-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.switch-label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
  font-size: 0.76rem;
  font-weight: 500;
  white-space: nowrap;
}

.switch-label input {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

.switch-track {
  position: relative;
  width: 36px;
  height: 20px;
  flex: 0 0 auto;
  border-radius: 999px;
  background: #9ca3af;
  transition: background 0.15s ease;
}

.switch-thumb {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #ffffff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.22);
  transition: transform 0.15s ease;
}

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

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

.app-footer {
  border-top: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.58);
  padding: 14px 16px calc(14px + env(safe-area-inset-bottom));
  text-align: center;
}

.app-footer-inner {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 0.9rem;
}

.app-footer a,
.link-button {
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 0;
  text-decoration: underline;
  text-underline-offset: 3px;
  white-space: nowrap;
}

#app-version {
  white-space: nowrap;
}

.app-footer a:hover,
.link-button:hover {
  color: var(--text);
}

.footer-separator {
  color: #9aa095;
}

.footer-video-action {
  display: none;
}

.has-video .footer-video-action {
  display: inline-block;
  margin-bottom: 8px;
}

.toast-region {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 20;
  display: grid;
  gap: 8px;
  width: min(360px, calc(100vw - 32px));
}

.toast {
  border-left: 4px solid var(--accent);
  border-radius: 6px;
  background: var(--surface);
  box-shadow: var(--shadow);
  padding: 12px 14px;
}

.toast.error {
  border-left-color: var(--danger);
}

.changelog-dialog {
  width: min(640px, calc(100vw - 32px));
  max-height: min(720px, calc(100vh - 32px));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 24px 68px rgba(0, 0, 0, 0.24);
  color: var(--text);
  padding: 0;
}

.changelog-dialog::backdrop {
  background: rgba(24, 28, 25, 0.42);
}

.dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 20px 14px;
  border-bottom: 1px solid var(--border);
}

.dialog-header h2 {
  margin: 0;
}

.dialog-header p {
  margin: 4px 0 0;
  color: var(--muted);
}

.icon-button {
  display: inline-grid;
  place-items: center;
  flex: 0 0 auto;
  width: 32px;
  height: 32px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  padding: 0;
}

.icon-button:hover {
  background: var(--surface-subtle);
  color: var(--text);
}

.icon-button:focus-visible {
  outline: 3px solid rgba(23, 107, 91, 0.22);
  outline-offset: 2px;
  border-color: rgba(23, 107, 91, 0.32);
}

.icon-button svg {
  width: 18px;
  height: 18px;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
}

.changelog-list {
  max-height: 560px;
  overflow: auto;
  padding: 18px 20px 22px;
}

.changelog-release + .changelog-release {
  margin-top: 20px;
}

.changelog-release h3 {
  margin: 0 0 8px;
}

.changelog-release ul {
  margin: 0;
  padding-left: 20px;
  color: var(--muted);
}

.hidden {
  display: none !important;
}

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

@media (max-width: 840px) {
  .app-main {
    padding-inline: 12px;
  }

  .player-grid {
    grid-template-columns: 1fr;
  }

  .chapters-table th,
  .chapters-table td {
    padding: 10px 8px;
  }

  .chapters-table th:first-child {
    width: 94px;
  }

  .chapters-table th:last-child,
  .chapters-table td:last-child {
    width: 82px;
  }

  .chapter-heading {
    align-items: flex-start;
    flex-direction: column;
  }
}

@media (max-width: 560px) {
  .app-header {
    text-align: left;
  }

  .form-panel {
    padding: 18px;
  }

  .shortcuts {
    flex-direction: column;
    gap: 10px;
  }

  .shortcuts > div {
    min-width: 0;
  }

  .shortcut-list {
    gap: 8px;
  }

  .shortcut-row {
    max-width: 100%;
  }

  .shortcut-action {
    white-space: normal;
  }

  .gesture-target {
    flex: none;
    width: 100%;
    min-height: 52px;
  }
}
