:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --text: #1c2430;
  --muted: #637083;
  --border: #e1e5eb;
  --accent: #d93a2b;
  --accent-dark: #b52d20;
  --active: #fff3e6;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
}

* { box-sizing: border-box; }
/* Class rules like `.tag-form { display: grid }` would otherwise override the hidden attribute. */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

a { color: inherit; }

button, input, textarea { font: inherit; color: inherit; }

.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 18px;
  text-decoration: none;
}
.brand-mark { width: 28px; height: 28px; display: block; }
.topbar > form { flex: 1; max-width: 520px; margin-left: auto; display: flex; gap: 8px; }
.account { display: flex; align-items: center; gap: 8px; font-size: 14px; margin-left: auto; }
.topbar > form + .account { margin-left: 0; }
.account form { margin: 0; }

/* ---------- Auth ---------- */
.auth { padding: 48px 20px; }
.auth-card { max-width: 400px; margin: 0 auto; padding: 24px; display: grid; gap: 8px; }
.auth-card h1 { margin: 0; font-size: 22px; }
.auth-card p { margin: 0 0 8px; }
.auth-card label { font-size: 13px; font-weight: 600; color: var(--muted); margin-top: 4px; }
.auth-card .btn-primary { margin-top: 12px; padding: 10px; }
.auth-switch { text-align: center; margin-top: 8px !important; }
.badge { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .03em; padding: 1px 6px; border-radius: 4px; background: var(--text); color: #fff; }
/* ---------- Explore ---------- */
.explore {
  display: grid; grid-template-columns: 360px minmax(0, 1fr); gap: 16px;
  padding: 16px 20px; height: calc(100vh - 57px); min-height: 480px;
}
.explore-side { display: flex; flex-direction: column; min-height: 0; overflow: hidden; }
.explore-side-head { padding: 12px; border-bottom: 1px solid var(--border); display: grid; gap: 6px; }
.explore-count { font-size: 13px; }
.explore-list { overflow-y: auto; flex: 1; }
.explore-list .tag-item { grid-template-columns: 64px 1fr; align-items: center; }
.explore-thumb { width: 64px; height: 48px; object-fit: cover; border-radius: 6px; background: #ddd; display: block; }
.explore-item-body { min-width: 0; }
.explore-item-meta { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.explore-map-wrap { min-height: 0; }
#explore-map { height: 100%; }
.explore-popup { display: grid; gap: 4px; }
.explore-popup img { width: 100%; border-radius: 6px; display: block; aspect-ratio: 16 / 9; object-fit: cover; }
.explore-popup a.popup-time { text-decoration: none; }
.dot-pin { background: var(--accent); border: 2px solid #fff; border-radius: 50%; box-shadow: 0 1px 3px rgba(0,0,0,.4); }
.cluster-pin {
  display: grid; place-items: center; border-radius: 50%;
  background: color-mix(in srgb, var(--accent) 85%, transparent); color: #fff; font-weight: 700; font-size: 13px;
  border: 3px solid color-mix(in srgb, #fff 70%, transparent); box-shadow: 0 1px 4px rgba(0,0,0,.35);
}
.nav-link { text-decoration: none; font-weight: 600; color: var(--muted); }
.nav-link:hover, .nav-link.current { color: var(--text); }

/* ---------- Profile ---------- */
.profile-head { display: flex; align-items: center; gap: 16px; margin: 8px 0 20px; }
.profile-head h1 { margin: 0; font-size: 26px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.profile-you { font-size: 16px; font-weight: 400; }
.avatar {
  width: 64px; height: 64px; flex: none; border-radius: 50%; display: grid; place-items: center;
  background: var(--accent); color: #fff; font-size: 28px; font-weight: 700;
}
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.stat { padding: 14px 16px; }
.stat-value { font-size: 28px; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.2; }
.stat-value.stat-date { font-size: 20px; padding-top: 6px; }
.stat-label { color: var(--muted); font-size: 13px; margin-top: 2px; }
.recent-tags { padding: 6px; }
.recent-tags a.tag-item { text-decoration: none; }
.recent-date { font-size: 13px; white-space: nowrap; }
a.tag-author { text-decoration: none; }
a.tag-author:hover { text-decoration: underline; }
a.profile-link { text-decoration: none; }
a.profile-link:hover { text-decoration: underline; }
.tag-author { font-size: 12px; color: var(--muted); font-weight: 400; }

.input {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
}
.input:focus { outline: 2px solid color-mix(in srgb, var(--accent) 35%, transparent); border-color: var(--accent); }
textarea.input { resize: vertical; min-height: 64px; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  cursor: pointer;
  white-space: nowrap;
  text-decoration: none;
}
.btn:hover { background: var(--bg); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn-primary:hover { background: var(--accent-dark); }
.btn-small { padding: 3px 9px; font-size: 13px; }
.btn-ghost { border-color: transparent; background: transparent; color: var(--muted); }

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

.muted { color: var(--muted); }
.error-banner { background: #fdecea; color: #8a1f13; padding: 10px 14px; border-radius: 8px; margin-bottom: 16px; }

/* ---------- Home ---------- */
.home { max-width: 1100px; margin: 0 auto; padding: 32px 20px 60px; }
.hero { text-align: center; padding: 24px 0 32px; }
.hero h1 { font-size: 34px; line-height: 1.2; margin: 0 0 8px; }
.hero p { margin: 0 0 22px; color: var(--muted); font-size: 17px; }
.hero form { display: flex; gap: 8px; max-width: 620px; margin: 0 auto; }
.hero .input { padding: 12px 14px; font-size: 16px; }
.hero .btn { padding: 12px 20px; }
.hero .search-box { max-width: 620px; margin: 0 auto; text-align: left; z-index: 1100; }

.section-title { font-size: 18px; margin: 32px 0 12px; }
#world-map { height: 420px; }

.video-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 16px; }
.video-card { overflow: hidden; text-decoration: none; display: block; }
.video-card img { display: block; width: 100%; aspect-ratio: 16 / 9; object-fit: cover; background: #ddd; }
.video-card .meta { padding: 10px 12px; }
.video-card .title { font-weight: 600; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.video-card:hover { border-color: #c8ced8; }

/* ---------- Watch ---------- */
.watch {
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr);
  gap: 16px;
  padding: 16px 20px;
  max-width: 1600px;
  margin: 0 auto;
}
.watch-left { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.watch-right { position: sticky; top: 16px; height: calc(100vh - 32px - 56px); min-height: 420px; display: flex; flex-direction: column; gap: 8px; }
.map-wrap { position: relative; flex: 1; min-height: 0; }

.player-wrap { aspect-ratio: 16 / 9; overflow: hidden; background: #000; border-radius: var(--radius); }
.player-wrap iframe, .player-wrap #player { width: 100%; height: 100%; display: block; border: 0; }

.video-title { font-size: 18px; margin: 0; }

.toolbar { display: flex; align-items: center; gap: 12px; padding: 10px 14px; flex-wrap: wrap; }
.clock { font-variant-numeric: tabular-nums; font-weight: 600; font-size: 18px; min-width: 70px; }
.toolbar .spacer { flex: 1; }
.toggle { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: 14px; cursor: pointer; user-select: none; }
kbd { font: 12px ui-monospace, monospace; padding: 1px 5px; border: 1px solid var(--border); border-bottom-width: 2px; border-radius: 4px; background: var(--bg); }

#map { height: 100%; border-radius: var(--radius); }
#map.placing { cursor: crosshair; }
.map-hint {
  position: absolute; z-index: 500; top: 12px; left: 50%; transform: translateX(-50%);
  background: var(--text); color: #fff; padding: 6px 12px; border-radius: 20px; font-size: 13px;
  pointer-events: none; box-shadow: var(--shadow);
}

/* Tag form */
.tag-form { padding: 14px; display: grid; gap: 10px; border-color: var(--accent); }
.tag-form h2 { margin: 0; font-size: 16px; display: flex; align-items: center; gap: 8px; }
.tag-form .row { display: flex; gap: 8px; align-items: center; }
.tag-form label { font-size: 13px; font-weight: 600; color: var(--muted); display: block; margin-bottom: 3px; }
.time-adjust { display: inline-flex; align-items: center; gap: 4px; margin-left: auto; font-weight: 400; }
.time-adjust .value { font-variant-numeric: tabular-nums; min-width: 64px; text-align: center; font-weight: 600; color: var(--accent); }
.coords { font: 13px ui-monospace, monospace; color: var(--muted); }
.form-actions { display: flex; gap: 8px; justify-content: flex-end; }
.form-error { color: #b42318; font-size: 14px; }

.search-box { position: relative; z-index: 1100; }
.search-row { display: flex; gap: 8px; align-items: center; }
.search-results {
  position: absolute; left: 0; right: 0; top: calc(100% + 4px);
  margin: 0; padding: 4px; list-style: none; background: var(--surface);
  border: 1px solid var(--border); border-radius: 8px; box-shadow: 0 6px 20px rgba(0,0,0,.12);
  max-height: 260px; overflow-y: auto;
}
.search-results li { padding: 7px 10px; border-radius: 6px; cursor: pointer; font-size: 14px; }
.search-results li:hover, .search-results li.hl { background: var(--bg); }

/* Tag list */
.tags-header { display: flex; align-items: baseline; justify-content: space-between; padding: 12px 14px 4px; }
.tags-header h2 { margin: 0; font-size: 16px; }
.tag-list { list-style: none; margin: 0; padding: 4px 6px 8px; }
.tag-item {
  display: grid; grid-template-columns: auto 1fr auto; gap: 4px 12px; align-items: start;
  padding: 9px 8px; border-radius: 8px; cursor: pointer;
}
.tag-item:hover { background: var(--bg); }
.tag-item.active { background: var(--active); box-shadow: inset 3px 0 0 var(--accent); }
.tag-time {
  font-variant-numeric: tabular-nums; font-weight: 600; color: var(--accent);
  background: color-mix(in srgb, var(--accent) 10%, transparent); padding: 1px 7px; border-radius: 5px; font-size: 14px;
}
.tag-name { font-weight: 600; overflow-wrap: anywhere; }
.tag-notes { grid-column: 2 / 4; color: var(--muted); font-size: 14px; white-space: pre-line; overflow-wrap: anywhere; }
.tag-delete { opacity: 0; }
.tag-item:hover .tag-delete, .tag-delete:focus-visible { opacity: 1; }
.tag-delete.confirm { opacity: 1; color: #b42318; }
.empty { padding: 24px 14px; text-align: center; color: var(--muted); }

/* Numbered map pins */
.pin {
  width: 28px; height: 28px; border-radius: 50% 50% 50% 0; transform: rotate(-45deg);
  background: #5b6779; border: 2px solid #fff; box-shadow: 0 1px 4px rgba(0,0,0,.35);
  display: grid; place-items: center;
}
.pin span { transform: rotate(45deg); color: #fff; font: 600 11px system-ui, sans-serif; }
.pin.active { background: var(--accent); }
.pin.draft { background: #1d7af3; }
.leaflet-popup-content { margin: 10px 12px; font-size: 14px; }
.popup-time { color: var(--accent); font-weight: 600; cursor: pointer; }

@media (max-width: 900px) {
  .watch { grid-template-columns: 1fr; padding: 12px; }
  .watch-right { position: relative; top: 0; height: 55vh; min-height: 320px; order: -1; }
  .watch-left > .player-wrap, .watch-left > .video-title, .watch-left > .toolbar { order: -2; }
  .watch { display: flex; flex-direction: column; }
  .watch-left { display: contents; }
  .topbar > form { display: none; }
  .explore { grid-template-columns: 1fr; grid-template-rows: 55vh auto; height: auto; padding: 12px; }
  .explore-map-wrap { order: -1; }
  .explore-side { max-height: 70vh; }
  .account .muted { display: none; }
  .hero form { flex-direction: column; }
  .tag-delete { opacity: 1; }
}
