/* 라이트 팔레트는 대비를 계산해서 정한 값이다. 흰 카드(#fff) / 페이지 배경 두 면 모두에서
   본문 4.5:1, 보조 텍스트 7:1 이상을 만족하고, 중성색 채도는 HSB 5% 미만(쿨 계열만)이며,
   카드와 배경의 명도차는 라이트 UI 한계인 7% 안에 든다. 숫자를 바꿀 때 같이 확인할 것. */
:root {
  color-scheme: light;
  --bg: #eff3f3; /* 밝기 95.3% — 카드와 명도차 4.7% */
  --fg: #171717; /* 17.9:1 */
  --fg-secondary: #212121; /* 16.1:1 — 제목 */
  --fg-dim: #585959; /* 7.0:1 카드 / 6.3:1 배경 — 설명·메타 */
  --fg-faint: #6d6f6f; /* 5.1:1 카드 / 4.5:1 배경 — 날짜·푸터·글리프 */
  --card: #ffffff;
  --surface: #f5f9f9;
  --surface-hover: #f2f7f7;
  --line: #dbdfdf; /* 구분선 — 카드 안에서만 쓴다 */
  --edge: #c2c5c5; /* 컨테이너 경계 — 카드(1.74:1)와 배경(1.55:1) 양쪽에서 구분된다 */
  --line-strong: #a9adad;
  --accent: #3ecf8e;
  --accent-deep: #0b7e58; /* 5.1:1 — 링크·포커스 링으로 쓰므로 텍스트 기준을 넘겨야 한다 */
  --accent-soft: #d8f0e4;
  --active: #1c1c1c;
  --active-fg: #ffffff;
  --danger-bg: #fff1f0;
  --danger-fg: #b42318;
  --danger-line: #f0b8b3;
  --shadow-raised: 0 1px 2px rgba(20, 30, 30, 0.05), 0 8px 16px rgba(20, 30, 30, 0.05);
  --radius-xs: 4px;
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #171717;
  --fg: #ededed;
  --fg-secondary: #d6d6d6;
  --fg-dim: #a1a1a1;
  --fg-faint: #737373;
  --card: #1c1c1c;
  --surface: #202020;
  --surface-hover: #252525;
  --line: #2d2d2d;
  --edge: #2d2d2d;
  --line-strong: #424242;
  --accent: #3ecf8e;
  --accent-deep: #52d9a0;
  --accent-soft: #173b2c;
  --active: #ededed;
  --active-fg: #171717;
  --danger-bg: #3a1f1e;
  --danger-fg: #ffb4ad;
  --danger-line: #713936;
  --shadow-raised: 0 1px 2px rgba(0, 0, 0, 0.25), 0 12px 32px rgba(0, 0, 0, 0.12);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #171717;
    --fg: #ededed;
    --fg-secondary: #d6d6d6;
    --fg-dim: #a1a1a1;
    --fg-faint: #737373;
    --card: #1c1c1c;
    --surface: #202020;
    --surface-hover: #252525;
    --line: #2d2d2d;
    --edge: #2d2d2d;
    --line-strong: #424242;
    --accent: #3ecf8e;
    --accent-deep: #52d9a0;
    --accent-soft: #173b2c;
    --active: #ededed;
    --active-fg: #171717;
    --danger-bg: #3a1f1e;
    --danger-fg: #ffb4ad;
    --danger-line: #713936;
    --shadow-raised: 0 1px 2px rgba(0, 0, 0, 0.25), 0 12px 32px rgba(0, 0, 0, 0.12);
  }
}

* { box-sizing: border-box; }

html {
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
}

/* 본문 16px/24px, 폭 672px. 크기 램프는 12 / 13 / 14 / 16 / 18 / 20 만 쓴다 (SPEC 6.6). */
body {
  margin: 0 auto;
  width: 100%;
  max-width: 672px;
  min-height: 100vh;
  padding: 0 14px calc(40px + env(safe-area-inset-bottom));
  background: var(--bg);
  color: var(--fg);
  font: 16px/1.5 "Helvetica Neue", Helvetica, -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Pretendard", sans-serif;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button,
input { font: inherit; }

button,
a,
input { -webkit-tap-highlight-color: transparent; }

button:focus-visible,
a:focus-visible,
input:focus-visible {
  outline: 2px solid var(--accent-deep);
  outline-offset: 2px;
}

.top { padding-top: calc(10px + env(safe-area-inset-top)); }

.bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 46px;
}

.bar h1 {
  margin: 6px 0;
  font-size: 20px;
  font-weight: 500;
  letter-spacing: -0.025em;
}

.bar h1 a {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  color: inherit;
  text-decoration: none;
}

.bar h1 img {
  display: block;
  border: 1px solid var(--edge);
  border-radius: var(--radius-sm);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
}

.bar h1 a:hover { color: var(--fg-secondary); }
.bar h1 a:active { opacity: 0.7; }

button {
  min-height: 34px;
  padding: 7px 14px;
  border: 1px solid var(--edge);
  border-radius: var(--radius-sm);
  background: var(--card);
  box-shadow: 0 1px 2px rgba(20, 30, 30, 0.04);
  color: var(--fg-secondary);
  font-size: 14px;
  font-weight: 500;
  line-height: 1;
  cursor: pointer;
  transition: background-color 160ms var(--ease-out), border-color 160ms var(--ease-out), color 160ms var(--ease-out), transform 160ms var(--ease-out), box-shadow 160ms var(--ease-out);
}

button:hover {
  border-color: var(--line-strong);
  background: var(--surface-hover);
}

button:active { transform: translateY(1px); }

button.on {
  border-color: var(--active);
  background: var(--active);
  color: var(--active-fg);
  box-shadow: none;
}


#themeToggle {
  display: grid;
  width: 34px;
  min-width: 34px;
  height: 34px;
  min-height: 34px;
  place-items: center;
  padding: 0;
  color: var(--fg-dim);
  font-size: 18px;
  font-weight: 400;
}

#themeToggle:hover {
  border-color: var(--accent-deep);
  color: var(--accent-deep);
}

#banner,
#sourceBanner.src-alert {
  margin: 8px 0;
  padding: 10px 12px;
  border: 1px solid var(--danger-line);
  border-radius: var(--radius-sm);
  background: var(--danger-bg);
  color: var(--danger-fg);
  font-size: 14px;
  font-weight: 500;
}

/* 소스 1~2개가 직전 실행에서만 실패한 것은 정상 범위다 (SPEC 4.2). 빨간불로 만들지 않는다. */
#sourceBanner.src-warn {
  margin: 8px 0;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--fg-dim);
  font-size: 13px;
}

#q {
  width: 100%;
  height: 44px;
  margin: 8px 0 5px;
  padding: 9px 12px;
  border: 1px solid var(--edge);
  border-radius: var(--radius-sm);
  outline: none;
  background: var(--card);
  box-shadow: 0 1px 2px rgba(20, 30, 30, 0.04);
  color: var(--fg);
  caret-color: var(--accent-deep);
  transition: border-color 160ms var(--ease-out), box-shadow 160ms var(--ease-out), background-color 160ms var(--ease-out);
}

#q::placeholder { color: var(--fg-faint); }

#q:hover { border-color: var(--line-strong); }

#q:focus {
  border-color: var(--accent-deep);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 15%, transparent);
}

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 7px 0;
}

/* display:flex가 UA의 [hidden]{display:none}을 이기므로 명시적으로 되돌린다 */
.chip-row[hidden] {
  display: none;
}

.chip-row button {
  position: relative;
  min-height: 30px;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  color: var(--fg-dim);
  font-size: 13px;
  font-weight: 500;
}

.chip-row button.on {
  padding-left: 23px;
  color: var(--active-fg);
}

.chip-row button.on::before {
  position: absolute;
  top: 50%;
  left: 10px;
  width: 6px;
  height: 6px;
  border-radius: 999px;
  background: var(--accent);
  content: "";
  transform: translateY(-50%);
}

/* 배너를 지나쳐 스크롤해도 어느 소스가 멈췄는지 남는다. 색만 바꿔 레이아웃이 밀리지 않게 한다.
   상태를 지고 있는 건 테두리가 아니라 글자색이다 — 라이트 6.57:1 / 다크 10.05:1로 본문 기준을 넘긴다.
   테두리(1.72:1)는 보조 표시이고, 이 값은 컨테이너 경계인 --edge(1.74:1)와 같은 급이다. */
.chip-row button[data-state="stalled"] {
  border-color: var(--danger-line);
  color: var(--danger-fg);
}

.chip-row button[data-state="stalled"].on {
  border-color: var(--danger-fg);
  background: var(--danger-fg);
  color: var(--danger-bg);
}

.chip-row button[data-state="stalled"].on::before { background: var(--danger-bg); }

#countLine {
  display: flex;
  align-items: center;
  gap: 7px;
  min-height: 23px;
  margin: 8px 0 5px;
  color: var(--fg-dim);
  font-size: 14px;
}

#countLine:not(:empty)::before {
  width: 7px;
  height: 7px;
  flex: 0 0 auto;
  border-radius: 999px;
  background: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
  content: "";
}

#list:not(:empty) {
  margin-top: 12px;
  border: 1px solid var(--edge);
  border-radius: var(--radius-lg);
  background: var(--card);
  box-shadow: var(--shadow-raised);
}

.day-head {
  position: sticky;
  top: 0;
  z-index: 2;
  margin: 0;
  padding: 9px 14px;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--card) 94%, transparent);
  color: var(--fg-dim);
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.01em;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.day-head:first-child { border-radius: var(--radius-lg) var(--radius-lg) 0 0; }

.item-wrap { position: relative; }
/* last-of-type이라 뒤에 '남은 N건 보기' 버튼이 붙어도 마지막 행의 밑줄이 사라진다 */
.item-wrap:last-of-type .row { border-bottom: 0; }

.row {
  position: relative;
  display: block;
  min-height: 64px;
  padding: 12px 52px 12px 14px;
  border-bottom: 1px solid var(--line);
  color: inherit;
  text-decoration: none;
  transition: background-color 160ms var(--ease-out);
}

.row:hover { background: var(--surface-hover); }
.row:active { opacity: 0.72; }

.row .t {
  display: block;
  color: var(--fg-secondary);
  font-weight: 500;
  letter-spacing: -0.01em;
  overflow-wrap: anywhere;
}

.row .d {
  display: -webkit-box;
  margin-top: 3px;
  overflow: hidden;
  color: var(--fg-dim);
  font-size: 14px;
  line-height: 1.55;
  overflow-wrap: anywhere;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.row .when {
  margin-left: 7px;
  color: var(--fg-faint);
  font-size: 13px;
  font-weight: 400;
  letter-spacing: 0;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  margin-right: 7px;
  padding: 2px 6px;
  border: 1px solid var(--edge);
  border-radius: var(--radius-xs);
  background: var(--surface);
  color: var(--fg-dim);
  font-size: 12px;
  font-weight: 500;
  line-height: 1.35;
  vertical-align: 2px;
}

.badge::before {
  width: 5px;
  height: 5px;
  flex: 0 0 auto;
  border-radius: 999px;
  background: var(--accent);
  content: "";
}

.ext {
  position: absolute;
  top: 50%;
  right: 12px;
  display: grid;
  width: 30px;
  height: 30px;
  place-items: center;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  color: var(--fg-faint);
  font-size: 16px;
  text-decoration: none;
  transform: translateY(-50%);
  transition: color 160ms var(--ease-out), background-color 160ms var(--ease-out), border-color 160ms var(--ease-out), transform 160ms var(--ease-out);
}

.ext:hover {
  border-color: var(--line);
  background: var(--card);
  color: var(--accent-deep);
  transform: translateY(-50%) translateY(-1px);
}

.ext:active { transform: translateY(-50%) translateY(1px); }

.empty {
  margin: 0;
  padding: 28px 18px;
  border-radius: var(--radius-lg);
  color: var(--fg-dim);
  font-size: 14px;
  text-align: center;
}

.more-btn {
  width: calc(100% - 24px);
  margin: 12px;
  border-color: var(--accent-deep);
  background: var(--accent);
  color: #171717;
}

.more-btn:hover {
  border-color: var(--accent-deep);
  background: var(--accent-deep);
  color: #171717;
}

.status {
  margin: 0;
  padding: 13px 14px;
  color: var(--fg-dim);
  font-size: 14px;
}

.foot {
  display: flex;
  justify-content: center;
  min-height: 28px;
  margin-top: 26px;
  color: var(--fg-faint);
  font-size: 13px;
  text-align: center;
}

@media (max-width: 520px) {
  body { padding-inline: 12px; }

  button { min-height: 36px; }

  .chip-row button {
    min-height: 36px;
  }

  #themeToggle {
    width: 36px;
    min-width: 36px;
    height: 36px;
    min-height: 36px;
  }

  .row {
    min-height: 68px;
    padding: 13px 50px 13px 13px;
  }

  .day-head { padding-inline: 13px; }
  .ext { right: 10px; width: 36px; height: 36px; }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}
