:root {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: #171717;
  background: #f4f4f5;
}

* { box-sizing: border-box; }
body { margin: 0; }
button, input, select { font: inherit; }
button { cursor: pointer; }

.page {
  width: min(1100px, calc(100% - 32px));
  margin: 32px auto 56px;
}

.card {
  background: #fff;
  border: 1px solid #e4e4e7;
  border-radius: 18px;
  box-shadow: 0 8px 30px rgba(0,0,0,.04);
}

.header-card, .input-card, .controls-card { padding: 22px; }
.header-card { margin-bottom: 16px; }
.header-card h1 { margin: 0 0 8px; font-size: clamp(26px, 4vw, 40px); }
.header-card p { margin: 0; color: #52525b; line-height: 1.5; }
.input-card { margin-bottom: 16px; }
label { display: block; font-weight: 650; margin-bottom: 8px; }
.url-row { display: flex; gap: 10px; }
input, select {
  width: 100%;
  border: 1px solid #d4d4d8;
  background: #fff;
  color: #18181b;
  border-radius: 10px;
  padding: 11px 12px;
  outline: none;
}
input:focus, select:focus { border-color: #71717a; box-shadow: 0 0 0 3px rgba(113,113,122,.12); }
button {
  border: 1px solid #d4d4d8;
  background: #fafafa;
  color: #18181b;
  border-radius: 10px;
  padding: 10px 14px;
}
button:hover { background: #f4f4f5; }
button.primary { background: #18181b; color: white; border-color: #18181b; }
button.primary:hover { background: #27272a; }
.message { margin-top: 10px; color: #52525b; }
.message:empty { display: none; }
.message.error { color: #b91c1c; }
.message.ok { color: #166534; }

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 390px;
  gap: 16px;
  align-items: start;
}

.player-column { display: grid; gap: 16px; min-width: 0; }
.player-card { padding: 16px; }
.player-shell {
  width: 100%;
  margin: 0 auto;
  background: #09090b;
  border-radius: 14px;
  overflow: hidden;
  transition: max-width .15s ease;
}
.player-shell.is-short {
  max-width: 460px;
  aspect-ratio: 9 / 16;
}
.player-shell.is-video {
  max-width: none;
  aspect-ratio: 16 / 9;
}
.player-shell iframe { width: 100%; height: 100%; display: block; }

.controls-card { display: grid; gap: 16px; }
.time-line { display: flex; align-items: baseline; gap: 8px; font-variant-numeric: tabular-nums; }
.time-line strong { font-size: 22px; }
.range { padding: 0; }
.ab-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.field-group { display: grid; gap: 8px; }
.field-group label { margin: 0; }
.button-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.switch-row { display: flex; align-items: center; gap: 10px; margin: 0; }
.switch-row input { width: auto; }
.speed-row { display: grid; grid-template-columns: 1fr 140px; gap: 12px; align-items: center; }
.speed-row label { margin: 0; }
.share-row button { width: 100%; }
details { border-top: 1px solid #e4e4e7; padding-top: 14px; }
summary { cursor: pointer; font-weight: 650; }
.hotkeys { display: grid; gap: 8px; margin-top: 12px; color: #52525b; }
kbd { border: 1px solid #d4d4d8; border-bottom-width: 2px; border-radius: 5px; padding: 1px 5px; background: #fafafa; color: #18181b; }


.history-card {
  padding: 18px 22px;
}
.history-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 12px;
}
.history-header h2 { margin: 0 0 4px; font-size: 18px; }
.history-header p { margin: 0; color: #71717a; font-size: 14px; }
.history-empty { color: #71717a; padding: 8px 0 2px; }
.history-list { display: grid; gap: 8px; }
.history-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 0;
  border-top: 1px solid #e4e4e7;
}
.history-info { min-width: 0; }
.history-title {
  font-weight: 650;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.history-meta {
  margin-top: 4px;
  color: #71717a;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}
.history-actions { display: flex; gap: 8px; flex: 0 0 auto; }
.danger-button { color: #b91c1c; }
.danger-button:disabled { opacity: .45; cursor: default; }

@media (max-width: 840px) {
  .layout { grid-template-columns: 1fr; }
  .controls-card { order: 2; }
}

@media (max-width: 560px) {
  .page { width: min(100% - 20px, 1100px); margin-top: 10px; }
  .url-row, .button-row, .ab-grid { grid-template-columns: 1fr; display: grid; }
  .speed-row { grid-template-columns: 1fr; }
  .history-header, .history-item { align-items: stretch; flex-direction: column; }
  .history-actions { display: grid; grid-template-columns: 1fr 1fr; }
  .history-actions button { width: 100%; }
}

@media (prefers-color-scheme: dark) {
  :root { color: #f4f4f5; background: #09090b; }
  .card { background: #18181b; border-color: #27272a; box-shadow: none; }
  .header-card p, .message, .hotkeys, .history-header p, .history-empty, .history-meta { color: #a1a1aa; }
  input, select { background: #09090b; color: #f4f4f5; border-color: #3f3f46; }
  button { background: #27272a; color: #f4f4f5; border-color: #3f3f46; }
  button:hover { background: #3f3f46; }
  button.primary { background: #f4f4f5; color: #18181b; border-color: #f4f4f5; }
  button.primary:hover { background: #e4e4e7; }
  .danger-button { color: #fca5a5; }
  details, .history-item { border-color: #27272a; }
  kbd { background: #27272a; color: #f4f4f5; border-color: #52525b; }
}


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

.lang-switch {
  display: inline-flex;
  gap: 4px;
  padding: 4px;
  border: 1px solid #e4e4e7;
  border-radius: 10px;
  flex: 0 0 auto;
}

.lang-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 42px;
  padding: 7px 9px;
  border-radius: 7px;
  color: inherit;
  text-decoration: none;
  font-weight: 700;
  font-size: 13px;
}

.lang-link:hover {
  background: #f4f4f5;
}

.lang-link.active {
  background: #18181b;
  color: #fff;
}

.seo-card {
  margin-top: 16px;
  padding: 24px;
  line-height: 1.65;
}

.seo-card h2 {
  margin: 26px 0 8px;
  font-size: 21px;
}

.seo-card h2:first-child {
  margin-top: 0;
}

.seo-card h3 {
  margin: 18px 0 6px;
  font-size: 17px;
}

.seo-card p {
  margin: 0 0 12px;
  color: #52525b;
}

.seo-card ol {
  margin: 8px 0 16px;
  padding-left: 22px;
}

.seo-card li + li {
  margin-top: 6px;
}

.seo-card code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: .92em;
  background: #f4f4f5;
  border-radius: 5px;
  padding: 2px 5px;
}

.faq {
  border-top: 1px solid #e4e4e7;
  margin-top: 24px;
  padding-top: 4px;
}

.footer {
  padding: 18px 4px 0;
  text-align: center;
  color: #71717a;
  font-size: 13px;
}

.language-gate {
  width: min(520px, calc(100% - 32px));
  margin: 12vh auto 40px;
}

.language-card {
  padding: 28px;
  text-align: center;
}

.language-card h1 {
  margin: 0 0 8px;
  font-size: 36px;
}

.language-card p {
  color: #52525b;
}

.language-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 22px;
}

.primary-link,
.secondary-link {
  display: block;
  border-radius: 10px;
  padding: 11px 14px;
  text-decoration: none;
  font-weight: 650;
}

.primary-link {
  background: #18181b;
  color: #fff;
}

.secondary-link {
  background: #fafafa;
  color: #18181b;
  border: 1px solid #d4d4d8;
}

@media (max-width: 560px) {
  .header-top {
    flex-direction: column;
  }

  .lang-switch {
    align-self: flex-start;
  }

  .seo-card {
    padding: 20px;
  }

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

@media (prefers-color-scheme: dark) {
  .lang-switch {
    border-color: #3f3f46;
  }

  .lang-link:hover {
    background: #27272a;
  }

  .lang-link.active {
    background: #f4f4f5;
    color: #18181b;
  }

  .seo-card p,
  .language-card p {
    color: #a1a1aa;
  }

  .seo-card code {
    background: #27272a;
  }

  .faq {
    border-color: #27272a;
  }

  .secondary-link {
    background: #27272a;
    color: #f4f4f5;
    border-color: #3f3f46;
  }

  .primary-link {
    background: #f4f4f5;
    color: #18181b;
  }
}

/* v6: multiple selectable A–B segments */
.segments-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.segments-heading > div { display: grid; gap: 3px; }
.segments-heading span { color: #71717a; font-size: 13px; font-weight: 400; }
.segments-list { display: grid; gap: 10px; }
.segment-card {
  border: 1px solid #e4e4e7;
  border-radius: 12px;
  padding: 12px;
  display: grid;
  gap: 12px;
  cursor: pointer;
  transition: border-color .12s ease, box-shadow .12s ease, background .12s ease;
}
.segment-card:hover { border-color: #a1a1aa; }
.segment-card.is-active {
  border-color: #71717a;
  box-shadow: 0 0 0 2px rgba(113,113,122,.12);
  background: #fafafa;
}
.segment-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.segment-title-wrap { display: flex; align-items: center; gap: 8px; }
.segment-active-badge {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 2px 7px;
  background: #e4e4e7;
  color: #52525b;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .02em;
}
.segment-remove {
  width: 32px;
  height: 32px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  line-height: 1;
}
.segment-add-row { display: grid; gap: 7px; }
.segment-add-row > button { width: 100%; }
.segment-add-hint {
  min-height: 18px;
  color: #71717a;
  font-size: 12px;
  line-height: 1.4;
}
.segment-add-hint.is-error { color: #b91c1c; }
button:disabled {
  opacity: .48;
  cursor: not-allowed;
}
button:disabled:hover { background: #fafafa; }

@media (prefers-color-scheme: dark) {
  .segments-heading span, .segment-add-hint { color: #a1a1aa; }
  .segment-add-hint.is-error { color: #fca5a5; }
  .segment-card { border-color: #3f3f46; }
  .segment-card:hover { border-color: #71717a; }
  .segment-card.is-active { background: #202024; border-color: #a1a1aa; box-shadow: 0 0 0 2px rgba(161,161,170,.12); }
  .segment-active-badge { background: #3f3f46; color: #e4e4e7; }
  button:disabled:hover { background: #27272a; }
}



/* v10: keep the original v4 geometry while fitting multi-segment controls */
.controls-card,
.player-column,
.player-card,
.history-card {
  min-width: 0;
}

.segment-card {
  padding: 10px;
  gap: 10px;
}

.segment-card .ab-grid {
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 10px;
}

.segment-card .field-group {
  min-width: 0;
  gap: 7px;
}

.segment-card input {
  min-width: 0;
}

.segment-card .field-group > button {
  min-width: 0;
  padding-left: 8px;
  padding-right: 8px;
  white-space: nowrap;
}

.segment-title-wrap {
  min-width: 0;
}

.segment-title-wrap strong {
  white-space: nowrap;
}

/* History belongs to the player column and must never affect the controls column. */
.player-column {
  align-self: start;
}

.controls-card {
  align-self: start;
}

@media (max-width: 840px) {
  .player-shell.is-short {
    max-width: 460px;
  }
}

@media (max-width: 560px) {
  .segment-card .ab-grid {
    grid-template-columns: 1fr;
  }

  .segment-card .field-group > button {
    white-space: normal;
  }
}

/* v13: history spans the same full content width as the SEO description below. */
.history-card {
  grid-column: 1 / -1;
  width: auto;
  min-width: 0;
  max-width: 100%;
  overflow: hidden;
}

.history-header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 16px;
}

.history-header > div,
.history-info {
  min-width: 0;
}

.history-list,
.history-item {
  min-width: 0;
  max-width: 100%;
}

.history-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 16px;
}

.history-title,
.history-meta {
  min-width: 0;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
}

.history-actions {
  min-width: 0;
  max-width: 100%;
}

@media (max-width: 840px) {
  /* On narrow screens: player -> controls -> history. */
  .history-card {
    grid-column: 1 / -1;
    order: 3;
  }
}

@media (max-width: 560px) {
  .history-header,
  .history-item {
    grid-template-columns: minmax(0, 1fr);
  }

  .history-actions {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  }
}
