:root {
  --bg: #14161f;
  --card: #1e2130;
  --ink: #e7e9f2;
  --muted: #9aa0b8;
  --line: #2e3242;
  --brand: #11131b;
  --accent: #6b78ff;
  --accent-ink: #ffffff;
  --star: #ffc24d;
  --danger: #ef5a4d;
  --watched: #28b487;
  --chip-bg: #2a2f47;
  --chip-ink: #aeb6ff;
  --radius: 14px;
  --shadow: 0 2px 12px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Zen Maru Gothic", system-ui, -apple-system, "Hiragino Sans", sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.6;
  -webkit-text-size-adjust: 100%;
}

/* ---- header ---- */
.app-header {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px; flex-wrap: wrap;
  padding: 10px 16px;
  background: var(--brand); color: #fff;
  box-shadow: var(--shadow);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; }
.brand-icon { font-size: 1.3rem; }
.brand-name { font-size: 1.05rem; }
.header-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.count-badge { font-size: .85rem; color: #8b91ad; }

/* ---- buttons ---- */
.btn {
  font-family: inherit; font-size: .95rem; font-weight: 500;
  border: none; border-radius: 999px; padding: 8px 16px;
  cursor: pointer; display: inline-flex; align-items: center; gap: 4px;
  transition: filter .15s, background .15s;
}
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { filter: brightness(1.1); }
.btn-ghost { background: rgba(255,255,255,.1); color: #e7e9f2; }
.btn-ghost:hover { filter: brightness(1.25); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-block { width: 100%; justify-content: center; padding: 12px; font-size: 1rem; }
.btn-sm { padding: 5px 12px; font-size: .85rem; }
.btn:disabled { opacity: .6; cursor: default; }

/* ---- views ---- */
.main { max-width: 760px; margin: 0 auto; padding: 16px; }
.view { display: none; }
.view.active { display: block; }

/* ---- login ---- */
.login-card {
  max-width: 380px; margin: 8vh auto 0; background: var(--card);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 28px 24px; text-align: center;
  border: 1px solid var(--line);
}
.login-icon { font-size: 2.6rem; }
.login-title { margin: 6px 0 2px; font-size: 1.4rem; }
.login-sub { margin: 0 0 18px; color: var(--muted); font-size: .92rem; }
.login-form { display: flex; flex-direction: column; gap: 12px; text-align: left; }
.login-form label { display: flex; flex-direction: column; gap: 4px; font-size: .88rem; color: var(--muted); }

input, textarea, select {
  font-family: inherit; font-size: 1rem; color: var(--ink);
  width: 100%; box-sizing: border-box;
  padding: 10px 12px; border: 1px solid var(--line);
  border-radius: 10px; background: #161925;
}
input::placeholder, textarea::placeholder { color: #6a7090; }
input:focus, textarea:focus, select:focus { outline: 2px solid var(--accent); border-color: transparent; }
textarea { resize: vertical; }

/* ---- list controls ---- */
.search-row { margin-bottom: 10px; }
.control-row {
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  margin-bottom: 12px;
}
.sort-label { display: flex; align-items: center; gap: 6px; font-size: .85rem; color: var(--muted); }
.sort-select { width: auto; min-width: 0; padding: 6px 10px; }
.watched-toggle { display: flex; align-items: center; gap: 6px; font-size: .85rem; color: var(--muted); }
.watched-toggle input { width: auto; accent-color: var(--accent); }

.tag-filter { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 14px; }
.filter-chip {
  font-family: inherit; font-size: .82rem; border: 1px solid var(--line);
  background: var(--card); color: var(--muted); border-radius: 999px;
  padding: 4px 12px; cursor: pointer;
}
.filter-chip.active { background: var(--accent); color: #fff; border-color: var(--accent); }

/* ---- cards ---- */
.video-grid { display: grid; grid-template-columns: 1fr; gap: 12px; }
@media (min-width: 560px) { .video-grid { grid-template-columns: 1fr 1fr; } }

.card {
  display: flex; flex-direction: column;
  background: var(--card); border-radius: var(--radius);
  box-shadow: var(--shadow); overflow: hidden;
  text-decoration: none; color: inherit;
  border: 1px solid var(--line); transition: border-color .15s, transform .1s;
}
.card:hover { border-color: var(--accent); }
.card:active { transform: scale(.997); }
.card.is-watched { opacity: .6; }

.card-thumb { width: 100%; aspect-ratio: 16 / 9; object-fit: cover; background: #161925; display: block; }
.card-thumb-empty {
  display: flex; align-items: center; justify-content: center;
  font-size: 2rem; color: #4b5170;
}
.card-body { padding: 12px 14px; display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.card-title { font-weight: 700; font-size: 1rem; line-height: 1.4; word-break: break-word; }
.card-meta { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: .8rem; color: var(--muted); }
.card-site { word-break: break-all; }
.stars-static span { color: #3a3f57; font-size: .9rem; }
.stars-static span.on { color: var(--star); }
.watched-badge {
  background: var(--watched); color: #06281d; font-size: .72rem; font-weight: 700;
  padding: 1px 8px; border-radius: 999px;
}
.card-tags { display: flex; flex-wrap: wrap; gap: 5px; }
.chip { font-size: .76rem; background: var(--chip-bg); color: var(--chip-ink); border-radius: 999px; padding: 2px 9px; }
.card-note { font-size: .85rem; color: var(--muted); word-break: break-word; }
.card-actions { display: flex; gap: 8px; margin-top: 4px; }
.card-actions .btn-ghost { background: #2a2f45; }

/* ---- form ---- */
.video-form {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 20px 18px; display: flex; flex-direction: column; gap: 14px;
  border: 1px solid var(--line);
}
.form-title { margin: 0 0 4px; font-size: 1.2rem; }
.field { display: flex; flex-direction: column; gap: 5px; font-size: .85rem; color: var(--muted); }
.field input, .field textarea { color: var(--ink); }
.req { color: var(--danger); font-size: .72rem; }
.field-hint { font-size: .78rem; color: var(--muted); min-height: 1em; }
.check-field { display: flex; align-items: center; gap: 8px; font-size: .92rem; color: var(--ink); }
.check-field input { width: auto; accent-color: var(--accent); }

/* ---- 自動取得・サムネ・タグ候補 ---- */
.fetch-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-top: -4px; }
.fetch-row .btn-ghost { background: #2a2f45; }
.thumb-wrap { display: flex; align-items: flex-start; gap: 10px; flex-wrap: wrap; }
.thumb-preview {
  width: 100%; max-width: 260px; aspect-ratio: 16 / 9; object-fit: cover;
  border-radius: 10px; background: #161925; border: 1px solid var(--line);
}
.suggested-tags { font-size: .82rem; color: var(--muted); }
.suggested-label { display: inline-block; margin-bottom: 4px; }
.suggest-chip {
  font-family: inherit; font-size: .82rem; border: 1px dashed var(--accent);
  background: transparent; color: var(--chip-ink); border-radius: 999px;
  padding: 3px 11px; margin: 0 5px 5px 0; cursor: pointer;
}
.suggest-chip:hover { background: var(--chip-bg); }

.star-input { display: flex; gap: 4px; font-size: 1.7rem; cursor: pointer; user-select: none; }
.star-input span { color: #3a3f57; transition: color .1s; }
.star-input span.on { color: var(--star); }

.form-actions { display: flex; align-items: center; gap: 10px; margin-top: 6px; }
.form-actions .spacer { flex: 1; }

/* ---- empty ---- */
.empty { text-align: center; color: var(--muted); padding: 40px 16px; font-size: .95rem; }

/* ---- banner ---- */
.banner {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px);
  background: #2b3050; color: #fff; padding: 10px 18px; border-radius: 999px;
  box-shadow: 0 6px 20px rgba(0,0,0,.45); font-size: .9rem; opacity: 0;
  pointer-events: none; transition: opacity .2s, transform .2s; z-index: 100; max-width: 90%;
}
.banner.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.banner-error { background: var(--danger); }
.banner-success { background: var(--watched); color: #06281d; }
