:root {
  --bg: #f5f6f8;
  --card: #ffffff;
  --border: #e2e5ea;
  --text: #1f2430;
  --muted: #6b7280;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --green: #16a34a;
  --red: #dc2626;
  --amber: #d97706;
  --radius: 10px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Hiragino Kaku Gothic ProN", "Yu Gothic", Meiryo, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.muted { color: var(--muted); }

/* ---- topbar ---- */
.topbar { background: #fff; border-bottom: 1px solid var(--border); }
.topbar-inner {
  max-width: 1000px; margin: 0 auto; padding: 12px 20px;
  display: flex; align-items: center; gap: 16px;
}
.brand { font-weight: 700; font-size: 1.1rem; color: var(--text); }
.tabs { display: flex; gap: 8px; margin-left: 8px; }
.tab {
  padding: 6px 14px; border-radius: 999px; font-size: .9rem;
  color: var(--muted); background: #eef1f6;
}
.tab:hover { text-decoration: none; background: #e2e6ee; }
.tab.active { background: var(--accent); color: #fff; }
.logout-form { margin-left: auto; }
.linklike { background: none; border: 0; padding: 0; font: inherit; color: var(--muted); cursor: pointer; }
.linklike:hover { text-decoration: underline; }

.container { max-width: 1000px; margin: 0 auto; padding: 24px 20px 60px; }

h1 { font-size: 1.5rem; margin: 0 0 4px; }
h2 { font-size: 1.15rem; margin: 28px 0 12px; }

.card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 18px 20px; margin-bottom: 18px;
}

/* ---- buttons ---- */
.btn {
  display: inline-block; background: var(--accent); color: #fff; border: none;
  border-radius: 8px; padding: 8px 16px; font-size: .9rem; cursor: pointer;
  transition: background .15s;
}
.btn:hover { background: var(--accent-hover); text-decoration: none; }
.btn-sm { padding: 5px 10px; font-size: .82rem; }
.btn-ghost { background: #eef1f6; color: var(--text); }
.btn-ghost:hover { background: #e2e6ee; }
.btn-danger { background: #fdecec; color: var(--red); }
.btn-danger:hover { background: #fbdcdc; }
.btn:disabled { opacity: .55; cursor: default; }

/* ---- forms ---- */
input, select, textarea {
  padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px;
  font-size: .92rem; font-family: inherit; background: #fff; color: var(--text);
}
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(37,99,235,.25); border-color: var(--accent); }
textarea { resize: vertical; min-height: 84px; }
label { font-size: .85rem; color: var(--muted); display: block; margin-bottom: 4px; }
.form-row { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; }
.form-row .field { flex: 1; min-width: 140px; }

/* ---- table ---- */
table { width: 100%; border-collapse: collapse; }
th, td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border); font-size: .9rem; vertical-align: middle; }
th { color: var(--muted); font-weight: 600; font-size: .8rem; }
tr:last-child td { border-bottom: none; }

/* ---- badges / rank ---- */
.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: .78rem; font-weight: 600; }
.badge-green { background: #dcfce7; color: var(--green); }
.badge-amber { background: #fef3c7; color: var(--amber); }
.badge-gray  { background: #eceef2; color: var(--muted); }
.rank { font-weight: 700; font-size: 1.05rem; }
.rank.in { color: var(--green); }
.rank-out, .rank.out { color: var(--muted); font-weight: 500; }
.cooldown { color: var(--amber); font-size: .7rem; }

/* ---- flash / banner ---- */
.flash { padding: 12px 16px; border-radius: 8px; margin-bottom: 16px; font-size: .9rem; }
.flash-ok  { background: #dcfce7; color: #166534; }
.flash-err { background: #fee2e2; color: #991b1b; }
.banner { background: #fff7ed; border: 1px solid #fed7aa; color: #9a3412; padding: 12px 14px; border-radius: 8px; font-size: .85rem; margin-bottom: 16px; }
.empty { color: var(--muted); text-align: center; padding: 28px 0; font-size: .9rem; }

.channel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.channel-head .meta { font-size: .82rem; }
.toolbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; gap: 10px; flex-wrap: wrap; }

.spin { display: inline-block; width: 13px; height: 13px; border: 2px solid rgba(255,255,255,.4); border-top-color: #fff; border-radius: 50%; animation: spin .7s linear infinite; vertical-align: -2px; }
.btn-ghost .spin, .ghost .spin { border-color: #cbd5e1; border-top-color: var(--accent); }
@keyframes spin { to { transform: rotate(360deg); } }

.login-wrap { max-width: 360px; margin: 80px auto; }
.inline { display: inline; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
small.hint, .hint { color: var(--muted); font-size: .78rem; }
.back { display: inline-block; margin-bottom: 6px; font-size: .82rem; }

/* ---- landing chooser ---- */
.home-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 18px; margin-top: 20px; }
.home-card {
  display: block; text-decoration: none; background: #fff; border: 1px solid var(--border);
  border-radius: 14px; padding: 28px 24px; transition: .12s; color: var(--text);
}
.home-card:hover { border-color: var(--accent); box-shadow: 0 6px 20px rgba(37,99,235,.10); transform: translateY(-2px); text-decoration: none; }
.home-card .ic { font-size: 2.2rem; }
.home-card h2 { margin: 10px 0 6px; }
.home-card p { margin: 0; color: var(--muted); font-size: .88rem; }

/* ---- site cards (web list) ---- */
.sites { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.site { display: block; text-decoration: none; border: 1px solid var(--border); border-radius: 12px; padding: 16px; background: #fff; transition: .12s; position: relative; color: var(--text); }
.site:hover { border-color: var(--accent); box-shadow: 0 4px 14px rgba(37,99,235,.08); transform: translateY(-1px); text-decoration: none; }
.site .host { font-size: 1rem; font-weight: 700; display: flex; align-items: center; gap: 7px; }
.site .url { color: var(--muted); font-size: .75rem; margin-top: 3px; word-break: break-all; }
.site .meta { display: flex; gap: 14px; margin-top: 12px; font-size: .75rem; color: var(--muted); }
.site .meta b { color: var(--text); font-size: .88rem; }
.site .del-site { position: absolute; top: 10px; right: 10px; }

/* ---- YouTube: 追跡動画・検出動画の表示 ---- */
.vthumb { width: 48px; height: 36px; object-fit: cover; border-radius: 4px; flex: 0 0 auto; }
.tracked { display: flex; align-items: center; gap: 6px; margin-top: 5px; font-size: .74rem; max-width: 300px; }
.tracked a { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.vfound { font-size: .72rem; max-width: 240px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-top: 3px; }

/* ---- 使い方ガイド / はじめてナビ ---- */
.help-toc ol { margin: 8px 0 0; padding-left: 1.4em; }
.help-toc li { margin: 2px 0; font-size: .9rem; }
.help-steps { display: flex; flex-direction: column; gap: 14px; margin-top: 6px; }
.help-step { display: flex; gap: 12px; align-items: flex-start; }
.help-step p { margin: 4px 0; font-size: .9rem; }
.help-step ul { margin: 4px 0; padding-left: 1.3em; font-size: .88rem; }
.stepnum {
  flex: 0 0 auto; width: 26px; height: 26px; border-radius: 50%;
  background: var(--accent); color: #fff; font-weight: 700; font-size: .85rem;
  display: flex; align-items: center; justify-content: center; margin-top: 2px;
}
.help-list { padding-left: 1.3em; font-size: .9rem; }
.help-list li { margin: 6px 0; }
.help-faq dt { font-weight: 700; font-size: .92rem; margin-top: 14px; }
.help-faq dt:first-child { margin-top: 0; }
.help-faq dd { margin: 4px 0 0 0; font-size: .88rem; color: var(--muted); }
code { background: #eef1f6; border-radius: 4px; padding: 1px 6px; font-size: .85em; }

/* 各画面上部の「はじめてガイド」バー */
.quickguide {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px 18px;
  background: #eff6ff; border: 1px solid #bfdbfe; border-radius: var(--radius);
  padding: 10px 16px; margin-bottom: 18px; font-size: .85rem;
}
.quickguide .qstep { display: flex; align-items: center; gap: 7px; color: var(--text); }
.quickguide .stepnum { width: 20px; height: 20px; font-size: .72rem; margin-top: 0; }
.quickguide .qhelp { margin-left: auto; white-space: nowrap; }

/* ---- toast ---- */
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: #1f2430; color: #fff; padding: 10px 18px; border-radius: 8px; font-size: .82rem; opacity: 0; transition: opacity .2s; pointer-events: none; z-index: 50; }
.toast.show { opacity: 1; }

/* ---- graph modal ---- */
.overlay { position: fixed; inset: 0; background: rgba(15,23,42,.5); display: none; align-items: center; justify-content: center; z-index: 40; padding: 16px; }
.overlay.show { display: flex; }
.modal { background: #fff; border-radius: 14px; width: 100%; max-width: 740px; padding: 20px; }
.modal h3 { margin: 0 0 2px; font-size: 1rem; }
.modal .msub { color: var(--muted); font-size: .75rem; margin: 0 0 14px; word-break: break-all; }
.ranges { display: flex; gap: 6px; margin-bottom: 12px; }
.ranges button { background: #eef1f6; color: var(--text); border: none; border-radius: 8px; padding: 5px 12px; font-size: .82rem; cursor: pointer; }
.ranges button.active { background: var(--accent); color: #fff; }
.legend { display: flex; gap: 16px; font-size: .78rem; color: var(--muted); margin-bottom: 6px; }
.legend .dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 5px; vertical-align: -1px; }
.closeX { float: right; background: transparent; border: none; color: var(--muted); font-size: 1.15rem; padding: 0 4px; cursor: pointer; }

@media (max-width: 640px) {
  .topbar-inner { flex-wrap: wrap; }
  .tabs { margin-left: 0; }
  th.opt, td.opt { display: none; }
}
