/* Windows has no flag emoji, so country flags show as two letters there. This font draws only the
   flag characters (unicode-range); where the system already has flags it is never downloaded. */
@font-face {
  font-family: "Twemoji Country Flags";
  unicode-range: U+1F1E6-1F1FF, U+1F3F4, U+E0062-E0063, U+E0065, U+E0067, U+E006C, U+E006E, U+E0073-E0074, U+E0077, U+E007F;
  src: url("/assets/TwemojiCountryFlags.woff2") format("woff2");
  font-display: swap;
}

/*
 * Colors are the primary colors of Kanna Yanagi's character design, written in OKLCH (lightness,
 * chroma, hue on the OKLab wheel) so lightness and contrast stay predictable across hues:
 *   cream skin/dress  oklch(0.94 0.033 63)    amber hair  oklch(0.80 0.117 74)
 *   orange hair tips  oklch(0.68 0.12 54)     olive frame oklch(0.62 0.093 125)
 *   forest green hat/dress oklch(0.25 0.023 142)
 * Light is a cream page with forest-green text and orange for accents; dark is the forest green
 * itself with cream text and amber accents. Text pairs are at least 4.5:1 (checked, not eyeballed).
 *
 * theme.js and app.js set data-theme ("light" or "dark": what the page shows) on <html>; auto
 * resolves to the OS setting there. Without scripts the OS preference alone picks the theme.
 * Dark values appear twice (that fallback, and data-theme="dark") because CSS can't share one block.
 */
:root {
  color-scheme: light;
  --bg: oklch(0.965 0.014 75);
  --card: oklch(0.99 0.006 75);
  --text: oklch(0.25 0.025 142);
  --muted: oklch(0.48 0.03 125);
  --border: oklch(0.885 0.02 70);
  --accent: oklch(0.54 0.13 50);
  --danger: oklch(0.5 0.17 27);
  --danger-bg: oklch(0.96 0.018 27);
  --ok: oklch(0.42 0.09 140);
  --ok-bg: oklch(0.95 0.04 125);
  --radius: 12px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    color-scheme: dark;
    --bg: oklch(0.18 0.014 145);
    --card: oklch(0.225 0.02 142);
    --text: oklch(0.94 0.018 75);
    --muted: oklch(0.72 0.025 110);
    --border: oklch(0.33 0.03 140);
    --accent: oklch(0.78 0.12 65);
    --danger: oklch(0.74 0.15 27);
    --danger-bg: oklch(0.27 0.06 27);
    --ok: oklch(0.8 0.13 130);
    --ok-bg: oklch(0.28 0.05 140);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: oklch(0.18 0.014 145);
  --card: oklch(0.225 0.02 142);
  --text: oklch(0.94 0.018 75);
  --muted: oklch(0.72 0.025 110);
  --border: oklch(0.33 0.03 140);
  --accent: oklch(0.78 0.12 65);
  --danger: oklch(0.74 0.15 27);
  --danger-bg: oklch(0.27 0.06 27);
  --ok: oklch(0.8 0.13 130);
  --ok-bg: oklch(0.28 0.05 140);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

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

.mini-player {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 10;
  width: min(360px, calc(100vw - 32px));
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.35);
  overflow: hidden;
}
.mini-player[hidden] { display: none; }
.mini-head { display: flex; align-items: center; gap: 8px; padding: 6px 6px 6px 12px; font-size: 13px; }
.mini-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mini-open { flex: none; color: var(--muted); text-decoration: none; }
.mini-open:hover { color: var(--text); }
.mini-frame { aspect-ratio: 16 / 9; background: #000; }
.mini-frame iframe { display: block; width: 100%; height: 100%; border: 0; }

.credits { max-width: 960px; margin: 24px auto; padding: 0 16px; font-size: 12px; }
.credits a { color: inherit; }

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  max-width: 960px;
  margin: 0 auto;
  padding: 20px 16px 4px;
}

h1 { margin: 0; font-size: 22px; letter-spacing: -0.01em; }
h1 span { color: var(--accent); }
h2 { margin: 0 0 8px; font-size: 16px; }

main { max-width: 960px; margin: 0 auto; padding: 12px 16px 48px; }

.account { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 14px; min-width: 0; }
.account span, .user-link { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-link { color: inherit; text-decoration: none; padding: 6px 10px; border-radius: 8px; }
.user-link:hover { color: var(--text); }
.user-link.active { color: var(--text); background: var(--card); }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  margin-top: 16px;
}
.card.narrow { max-width: 440px; margin: 48px auto 0; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }

.muted { color: var(--muted); }
button.link { padding: 0; border: 0; background: none; color: var(--accent); font: inherit; text-decoration: underline; cursor: pointer; }
.error { color: var(--danger); background: var(--danger-bg); padding: 8px 12px; border-radius: 8px; }
.notice { color: var(--ok); background: var(--ok-bg); padding: 8px 12px; border-radius: 8px; }

button {
  font: inherit;
  cursor: pointer;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  padding: 7px 14px;
}
button.ghost { padding: 4px 10px; font-size: 14px; }
button.danger { color: var(--danger); border-color: var(--danger); }
button:hover { border-color: var(--muted); }
button:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
button:disabled { opacity: 0.6; cursor: default; }

dl { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 0; }
dt { color: var(--muted); }
dd { margin: 0; overflow-wrap: anywhere; }

.table-wrap { overflow-x: auto; margin-top: 8px; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 9px 10px 9px 0; border-top: 1px solid var(--border); white-space: nowrap; }
th { color: var(--muted); font-weight: 500; border-top: 0; }
.badge {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 999px;
  font-size: 12px;
  background: var(--ok-bg);
  color: var(--ok);
}

.badge.members { background: var(--border); color: var(--muted); margin-left: 4px; }

.nav { display: flex; gap: 4px; }
.nav a { color: var(--muted); text-decoration: none; padding: 6px 10px; border-radius: 8px; }
.nav a:hover { color: var(--text); }
.nav a.active { color: var(--text); background: var(--card); }

.name-form { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.name-form input {
  flex: 1 1 180px;
  min-width: 0;
  box-sizing: border-box;
  padding: 10px 12px;
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
}
#display-name-cancel { margin-top: 12px; }
dd .ghost { margin-left: 8px; }
.plain-list { list-style: none; margin: 12px 0; padding: 0; }
.plain-list li { display: flex; align-items: center; flex-wrap: wrap; gap: 4px; padding: 6px 0; }
.plain-list .ghost { margin-left: auto; }

.search-row { display: flex; gap: 8px; align-items: stretch; }
.search { position: relative; flex: 1; min-width: 0; }
.icon-button { flex: none; display: grid; place-items: center; width: 42px; padding: 0; color: var(--muted); }
.icon-button svg { width: 20px; height: 20px; }
.icon-button:hover, .icon-button[aria-expanded="true"] { color: var(--text); }

/* The date panel (quick ranges and a calendar for "date:" terms), opened from the button beside the search box. */
.dp-presets { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.dp-exclude { display: flex; align-items: center; gap: 6px; margin-top: 10px; font-size: 13px; color: var(--muted); }
.date-picker {
  position: absolute;
  top: 100%;
  right: 0;
  z-index: 4;
  width: 300px;
  max-width: 100%;
  margin-top: 4px;
  padding: 12px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.25);
}
.dp-head { display: flex; gap: 6px; align-items: center; }
.dp-head select {
  flex: 1;
  min-width: 0;
  padding: 6px 8px;
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
}
.dp-head .ghost { padding: 4px 10px; font-size: 18px; line-height: 1; }
.dp-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; margin-top: 8px; }
.dp-weekdays span { text-align: center; font-size: 12px; color: var(--muted); }
.dp-day { padding: 6px 0; border: 0; border-radius: 6px; background: transparent; font-size: 13px; }
.dp-day:hover { background: var(--bg); }
.dp-day.today { box-shadow: inset 0 0 0 1px var(--accent); }
.dp-day.inside { background: var(--bg); }
.dp-day.edge, .dp-day.edge:hover { background: var(--accent); color: var(--card); }
.date-picker #dp-summary { min-height: 1.5em; margin: 10px 0 0; font-size: 13px; }
.dp-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 10px; }
#dp-apply:disabled { opacity: 0.5; cursor: default; }
.suggestions {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  z-index: 3;
  margin: 4px 0 0;
  padding: 4px;
  list-style: none;
  max-height: 320px;
  overflow-y: auto;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.25);
}
.suggestions li { display: flex; gap: 10px; align-items: baseline; padding: 7px 10px; border-radius: 6px; cursor: pointer; }
.suggestions li:hover, .suggestions li[aria-selected="true"] { background: var(--bg); }
.suggestions li[aria-selected="true"] { box-shadow: inset 2px 0 0 var(--accent); }
.suggestions .kind { flex: none; min-width: 64px; font-size: 12px; color: var(--muted); }
.suggestions .value { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.search input {
  width: 100%;
  box-sizing: border-box;
  padding: 10px 12px;
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
}

/* Stays at the top while the list scrolls; --search-bar-height (set in app.js) keeps the video header below it. */
.search-bar { position: sticky; top: 0; z-index: 2; padding: 4px 0 0; background: var(--card); }
/* The match count, inside the right end of the search box (clear of the browser's own clear button). */
.search-count {
  position: absolute;
  top: 50%;
  right: 38px;
  transform: translateY(-50%);
  font-size: 13px;
  color: var(--muted);
  pointer-events: none;
  white-space: nowrap;
}
.search input { padding-right: 9.5rem; }

/* One button that cycles auto -> light -> dark: the icon is how the page looks now, the label the mode. */
.theme-toggle {
  flex: none;
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  min-width: 44px;
  padding: 4px 6px;
  border: 0;
  background: transparent;
  color: var(--muted);
  line-height: 0;
}
.theme-toggle:hover { color: var(--text); }
.theme-icons { position: relative; width: 18px; height: 18px; }
.theme-icons svg { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; transition: opacity 120ms linear; }
:root[data-theme="light"] .theme-sun, :root[data-theme="dark"] .theme-moon { opacity: 1; }
.theme-labels { position: relative; width: 100%; height: 10px; }
.theme-labels span {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  font-size: 9px;
  line-height: 1;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  transition: opacity 120ms linear;
}
:root[data-theme-mode="auto"] .theme-label-auto,
:root[data-theme-mode="light"] .theme-label-light,
:root[data-theme-mode="dark"] .theme-label-dark { opacity: 1; }
@media (prefers-reduced-motion: reduce) {
  .theme-icons svg, .theme-labels span { transition: none; }
}

.stamps { list-style: none; margin: 0 0 12px; padding: 0; }
.stamps li { display: flex; gap: 14px; padding: 10px 0; border-top: 1px solid var(--border); }
.stamps li:first-child { border-top: 0; }
.stamp-time { flex: none; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--text); text-decoration: none; }
.stamp-time:hover { text-decoration: underline; }
.stamp-body { min-width: 0; }
.stamp-comment { white-space: pre-wrap; overflow-wrap: anywhere; }
.stamps li { position: relative; }
.history-toggle { display: inline-grid; vertical-align: middle; place-items: center; width: 28px; height: 28px; margin: -6px 0 -6px 4px; padding: 0; border: 0; background: none; color: var(--muted); cursor: pointer; opacity: 0; }
.history-toggle svg { width: 18px; height: 18px; }
.history-toggle:hover, .history-toggle[aria-expanded="true"] { color: var(--text); }
.stamps li:hover .history-toggle, .history-toggle:focus-visible, .history-toggle[aria-expanded="true"] { opacity: 1; }
@media (hover: none) { .history-toggle { opacity: 1; } } /* no hover on touch screens */
.stamp-history { margin-top: 6px; font-size: 13px; }
.history-row { display: flex; gap: 10px; padding: 3px 0; }
.history-when { flex: none; min-width: 7em; }
.history-what { min-width: 0; flex: 1; overflow-wrap: anywhere; }
.history-state { flex: none; }
.groups { list-style: none; margin: 0 0 12px; padding: 0; }
.group { margin-top: 18px; }
.group:first-child { margin-top: 0; }
/* Sticks within .group-top, which holds the header and every row but the last (that one follows it,
   outside), so the header scrolls away with the last row instead of covering it. */
.group-head { position: sticky; top: var(--search-bar-height, 0px); z-index: 1; display: flex; align-items: center; gap: 12px; padding: 8px 0; background: var(--card); }
.group-head .thumb { flex: none; width: 80px; height: 45px; border-radius: 4px; background: var(--border); object-fit: cover; display: block; }
.group-head .video-text { min-width: 0; }
.group-head .video-title { color: var(--text); text-decoration: none; font-weight: 600; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; line-clamp: 2; overflow: hidden; overflow-wrap: anywhere; }
.group-head .video-sub { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.group-head .video-sub a { color: inherit; }
.group .stamps { margin: 0; }
.group .stamps li:first-child { border-top: 1px solid var(--border); }

.confirm { margin: 12px 0; padding: 12px; border: 1px solid var(--danger); border-radius: 8px; }
.confirm p { margin: 0 0 12px; }
.confirm-actions { display: flex; gap: 8px; flex-wrap: wrap; }
