:root {
  --bg: #f4f6fa;
  --card: #ffffff;
  --text: #1c2333;
  --muted: #67718a;
  --accent: #e63946;
  --accent-dark: #c92c39;
  --border: #dde2ec;
  --link: #2563eb;
  --error-bg: #fdecec;
  --error-text: #b42318;
  --shadow: 0 1px 3px rgba(20, 30, 60, 0.08), 0 4px 16px rgba(20, 30, 60, 0.06);
  --radius: 12px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12151d;
    --card: #1c2130;
    --text: #e8ebf2;
    --muted: #9aa3b8;
    --border: #313849;
    --link: #7aa5f8;
    --error-bg: #3a1d1d;
    --error-text: #f2a099;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
  }
}

* { box-sizing: border-box; }

/* display指定を持つ要素でも hidden 属性を必ず効かせる */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Hiragino Sans", "Yu Gothic UI", "Noto Sans JP", system-ui, sans-serif;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  max-width: 900px;
  margin: 0 auto;
}
.app-header h1 { font-size: 1.25rem; margin: 0; }
.logo { margin-right: 4px; }

.icon-btn {
  background: none;
  border: none;
  font-size: 1.2rem;
  cursor: pointer;
  padding: 6px;
  border-radius: 8px;
}
.icon-btn:hover { background: var(--border); }

.view {
  max-width: 900px;
  margin: 0 auto;
  padding: 0 16px 60px;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}

.input-card { margin-bottom: 28px; }

.field-label {
  display: block;
  font-weight: 600;
  margin: 0 0 8px;
}
.field-label + .field-label, p.field-label { margin-top: 18px; }

.url-row input,
#fallback-text,
#gate-input {
  width: 100%;
  padding: 12px 14px;
  font-size: 1rem;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
}
.url-row input:focus, #fallback-text:focus, #gate-input:focus {
  outline: none;
  border-color: var(--accent);
}

.mode-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-bottom: 20px;
}

.mode-card {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 14px;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.mode-card:hover { border-color: var(--muted); }
.mode-card:has(input:checked) {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 6%, var(--card));
}
.mode-card input { position: absolute; opacity: 0; }
.mode-icon { font-size: 1.6rem; }
.mode-name { font-weight: 700; }
.mode-desc { font-size: 0.82rem; color: var(--muted); }

.primary-btn {
  display: block;
  width: 100%;
  padding: 14px;
  font-size: 1.05rem;
  font-weight: 700;
  color: #fff;
  background: var(--accent);
  border: none;
  border-radius: 10px;
  cursor: pointer;
}
.primary-btn:hover { background: var(--accent-dark); }
.primary-btn:disabled { opacity: 0.5; cursor: not-allowed; }

.text-btn {
  background: none;
  border: none;
  color: var(--link);
  font-size: 0.95rem;
  cursor: pointer;
  padding: 10px 0;
}

.history-section h2 { font-size: 1.05rem; }
.history-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 10px; }
.history-item {
  display: flex;
  gap: 12px;
  align-items: center;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px;
  cursor: pointer;
}
.history-item:hover { border-color: var(--muted); }
.hi-open {
  display: flex;
  gap: 12px;
  align-items: center;
  flex: 1;
  min-width: 0;
  border-radius: 8px;
}
.hi-open:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}
.action-btn:disabled { opacity: 0.45; cursor: not-allowed; }
.action-btn:disabled:hover { border-color: var(--border); }
.history-item img {
  width: 96px;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  border-radius: 8px;
  flex-shrink: 0;
}
.hi-meta { flex: 1; min-width: 0; }
.hi-title {
  font-weight: 600;
  font-size: 0.92rem;
  overflow-wrap: anywhere;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.hi-sub { font-size: 0.78rem; color: var(--muted); }
.hi-delete {
  background: none;
  border: none;
  font-size: 1rem;
  cursor: pointer;
  padding: 8px;
  border-radius: 8px;
  flex-shrink: 0;
}
.hi-delete:hover { background: var(--error-bg); }

.mode-badge {
  display: inline-block;
  font-size: 0.75rem;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--border);
  margin-left: 6px;
}

.video-header { display: flex; gap: 16px; margin: 10px 0 20px; }
.vh-thumb {
  width: 200px;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  border-radius: 8px;
  flex-shrink: 0;
}
.vh-meta { min-width: 0; overflow-wrap: anywhere; }
.vh-meta h2 { font-size: 1.1rem; margin: 0 0 4px; overflow-wrap: anywhere; }
.vh-meta a { color: var(--link); }

.progress {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 16px 4px;
  color: var(--muted);
}
.spinner {
  width: 18px;
  height: 18px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }

.error-box {
  background: var(--error-bg);
  color: var(--error-text);
  padding: 12px 14px;
  border-radius: 10px;
  margin: 12px 0;
}

#fallback-section { margin: 16px 0; }
#fallback-text { margin: 10px 0 14px; resize: vertical; font-size: 0.9rem; }

.summary { margin-top: 8px; overflow-wrap: break-word; }
.summary h2 {
  font-size: 1.15rem;
  border-bottom: 2px solid var(--accent);
  padding-bottom: 6px;
  margin-top: 28px;
}
.summary h2:first-child { margin-top: 4px; }
.summary h3 { font-size: 1.02rem; margin-top: 22px; }
.summary a { color: var(--link); text-decoration: none; }
.summary a:hover { text-decoration: underline; }
.summary a.ts {
  font-size: 0.85em;
  background: color-mix(in srgb, var(--link) 12%, transparent);
  padding: 1px 6px;
  border-radius: 6px;
  white-space: nowrap;
}
.summary li { margin: 4px 0; }
.summary table { border-collapse: collapse; width: 100%; display: block; overflow-x: auto; }
.summary th, .summary td { border: 1px solid var(--border); padding: 6px 10px; }

.actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 18px; }
.action-btn {
  padding: 10px 16px;
  font-size: 0.92rem;
  border: 1.5px solid var(--border);
  background: var(--card);
  color: var(--text);
  border-radius: 10px;
  cursor: pointer;
}
.action-btn:hover { border-color: var(--accent); }
.regen-modes { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 10px; }

.muted { color: var(--muted); font-size: 0.9rem; }

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 14, 24, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 100;
}
.modal { max-width: 380px; width: 100%; }
.modal h2 { margin-top: 0; }
.modal .actions { margin-top: 14px; }
#gate-input { margin-top: 8px; }

@media (max-width: 700px) {
  .mode-grid { grid-template-columns: 1fr; }
  .video-header { flex-direction: column; }
  .vh-thumb { width: 100%; }
  .actions { flex-direction: column; }
  .action-btn { width: 100%; }
}

/* 操作結果の通知バー */
.notice {
  position: fixed;
  left: 50%;
  bottom: 20px;
  transform: translateX(-50%);
  width: min(560px, calc(100% - 32px));
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--card);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 12px 14px;
  font-size: 0.9rem;
  z-index: 200;
}
#notice-text { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.notice-btn {
  flex-shrink: 0;
  padding: 6px 14px;
  border: 1.5px solid var(--accent);
  background: transparent;
  color: var(--accent);
  border-radius: 8px;
  font-weight: 700;
  cursor: pointer;
}
.notice-btn:hover { background: color-mix(in srgb, var(--accent) 10%, transparent); }
/* 通知バーが最下部のボタンを覆わないよう、表示中だけ下余白を広げる */
body.has-notice .view { padding-bottom: 160px; }

.notice-close {
  flex-shrink: 0;
  background: none;
  border: none;
  color: var(--muted);
  font-size: 0.9rem;
  cursor: pointer;
  padding: 4px;
}

/* 長いコード行がページ全体を押し広げないようにする */
.summary pre {
  overflow-x: auto;
  max-width: 100%;
}
.summary code { overflow-wrap: anywhere; }
.summary pre code { overflow-wrap: normal; }
