/* 공통 바탕과 컴포넌트. 색·크기는 tokens.css 변수만 쓴다.
   테두리 없이: 구분은 여백, 눌러지는 것은 면 색(--sunken), 강조는 에스프레소로 채움. */

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 400 var(--fs-md) / 1.55 var(--sans);
  letter-spacing: -0.01em;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; letter-spacing: inherit; }
button { cursor: pointer; }
h1, h2, h3 { margin: 0; font-weight: 700; }
p { margin: 0; }
ul, ol { margin: 0; padding: 0; list-style: none; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

/* ── 글자 ───────────────────────────── */
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--text-3); }
.small { font-size: var(--fs-sm); }
.xs { font-size: var(--fs-xs); }
.eyebrow { font-size: var(--fs-sm); color: var(--text-3); }
.title-xl { font-size: var(--fs-2xl); font-weight: 700; line-height: 1.25; letter-spacing: -0.025em; }
.title-lg { font-size: var(--fs-xl); font-weight: 700; line-height: 1.3; letter-spacing: -0.02em; }
.section-title {
  display: flex; align-items: baseline; justify-content: space-between; gap: var(--s3);
  font-size: var(--fs-lg); font-weight: 700; letter-spacing: -0.02em;
  padding: var(--s8) 0 var(--s3);
}
.section-title small { font-size: var(--fs-sm); font-weight: 400; letter-spacing: 0; color: var(--text-3); }

/* ── 화면 틀 ───────────────────────────── */
.page { max-width: var(--max-w); margin: 0 auto; padding: 0 var(--s5) calc(var(--nav-h) + var(--s10)); }
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: var(--s1);
  height: 52px; padding: 0 var(--s2);
  background: var(--bg);
}
.topbar h1 { font-size: var(--fs-lg); flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.brand { font-size: var(--fs-lg); font-weight: 800; letter-spacing: -0.04em; }
.brand__mark { width: 24px; height: 24px; margin-right: 6px; vertical-align: -5px; }
.brand i { font-style: normal; color: var(--terracotta); }

/* ── 버튼: 테두리 없음. 주 버튼은 채움, 보조는 옅은 면 ───────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 48px; padding: 0 var(--s5);
  border: 0; border-radius: var(--r2);
  background: var(--sunken); color: var(--text);
  font-weight: 600; white-space: nowrap;
}
.btn:hover { background: var(--press); }
.btn--primary { background: var(--espresso); color: var(--paper-50); }
.btn--primary:hover { background: var(--espresso-hover); }
.btn--sm { height: 36px; padding: 0 var(--s3); font-size: var(--fs-sm); }
.btn--block { width: 100%; }
.btn:disabled { color: var(--text-disabled); background: var(--sunken); cursor: default; }
.icon-btn {
  display: inline-grid; place-items: center; width: 40px; height: 40px;
  border: 0; border-radius: var(--r2); background: transparent; color: var(--text);
}
.icon-btn:hover { background: var(--sunken); }
.icon { width: 18px; height: 18px; stroke: currentColor; stroke-width: 1.75; fill: none; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.link { color: var(--text-3); background: none; border: 0; padding: 0; text-decoration: underline; text-underline-offset: 3px; }
.link:hover { color: var(--text); }

/* ── 테마 탭: 글자만, 고른 것만 진하게 + 짧은 막대 ───────────────────────────── */
.tabs { display: flex; gap: var(--s5); overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs button {
  position: relative; flex: none; padding: var(--s3) 0; border: 0; background: none;
  color: var(--text-3); font-weight: 500;
}
.tabs button[aria-pressed='true'] { color: var(--text); font-weight: 700; }
.tabs button[aria-pressed='true']::after {
  content: ''; position: absolute; left: 0; right: 0; bottom: 4px; height: 2px; border-radius: 1px; background: var(--text);
}

/* ── 입력 ───────────────────────────── */
.select {
  height: 36px; padding: 0 30px 0 var(--s3);
  border: 0; border-radius: var(--r2);
  background: var(--sunken) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%236e6254' stroke-width='1.6' stroke-linecap='round'/%3E%3C/svg%3E") no-repeat right 12px center;
  appearance: none; font-size: var(--fs-sm); font-weight: 600;
}
.select:hover { background-color: var(--press); }
.input, .textarea { width: 100%; padding: var(--s3) var(--s4); border: 0; border-radius: var(--r2); background: var(--sunken); }
.input { height: 48px; }
.input::placeholder, .textarea::placeholder { color: var(--text-disabled); }
/* 입력칸은 테두리 대신 면이 밝아지는 것으로 포커스를 보여 준다 (커서도 진하게) */
.input:focus-visible, .textarea:focus-visible { outline: none; background: var(--surface); box-shadow: var(--float); caret-color: var(--espresso); }
.input[type='search']::-webkit-search-cancel-button { appearance: none; }
.textarea { resize: vertical; line-height: 1.6; }
.label { display: block; font-weight: 600; margin-bottom: var(--s2); }

/* ── 카페 한 줄: 선 없이 여백으로 ───────────────────────────── */
.cafe-row {
  display: grid; grid-template-columns: 28px 1fr auto; align-items: center; gap: var(--s3);
  margin: 0 calc(var(--s3) * -1); padding: var(--s3); border-radius: var(--r2);
}
.cafe-row:hover { background: var(--sunken); }
.cafe-row--plain { grid-template-columns: 1fr auto; }
.cafe-row .rank { font-size: var(--fs-lg); font-weight: 700; text-align: center; color: var(--text-3); font-variant-numeric: tabular-nums; }
.cafe-row .rank--1 { color: var(--terracotta); }
.cafe-row .rank--none { color: var(--text-disabled); }
.cafe-row .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cafe-row .meta { display: flex; flex-wrap: wrap; gap: 0 var(--s2); margin-top: 2px; font-size: var(--fs-sm); color: var(--text-3); }
.cafe-row .meta > * + *::before { content: '·'; margin-right: var(--s2); }
.cafe-row .right { text-align: right; }
.score { font-size: var(--fs-xl); font-weight: 700; line-height: 1; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.score--empty { font-size: var(--fs-sm); font-weight: 500; color: var(--text-3); }
.cafe-row .right small { display: block; margin-top: 4px; font-size: var(--fs-xs); color: var(--text-3); }

/* ── 작은 표시 ───────────────────────────── */
.live { display: inline-flex; align-items: center; gap: 5px; font-size: var(--fs-sm); font-weight: 600; }
.live::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.live--1 { color: var(--calm); }
.live--2 { color: var(--normal); }
.live--3 { color: var(--busy); }
.live--4 { color: var(--full); }
.grade { display: inline-block; padding: 2px 7px; border-radius: var(--r1); background: var(--sunken); font-size: var(--fs-xs); font-weight: 600; color: var(--text-2); }
.grade--high { background: var(--espresso); color: var(--paper-50); }

/* 항목별 막대 */
.bars { display: grid; gap: var(--s3); }
.bar { display: grid; grid-template-columns: 64px 1fr 32px; align-items: center; gap: var(--s3); font-size: var(--fs-sm); color: var(--text-2); }
.bar__track { height: 6px; border-radius: 3px; background: var(--sunken); overflow: hidden; }
.bar__fill { height: 100%; border-radius: 3px; background: var(--espresso); }
.bar b { text-align: right; font-size: var(--fs-md); color: var(--text); font-variant-numeric: tabular-nums; }

/* 진행도 */
.progress { height: 6px; border-radius: 3px; background: var(--sunken); overflow: hidden; }
.progress > i { display: block; height: 100%; border-radius: 3px; background: var(--espresso); }

/* 안내 상자 */
.note { padding: var(--s3) var(--s4); border-radius: var(--r2); background: var(--sunken); font-size: var(--fs-sm); color: var(--text-2); }
.empty { padding: var(--s8) 0; text-align: center; color: var(--text-3); font-size: var(--fs-sm); }

/* ── 아래 메뉴 ───────────────────────────── */
.nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 1000;
  display: grid; grid-template-columns: repeat(3, 1fr);
  height: var(--nav-h); padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface);
}
.nav a { display: grid; place-items: center; align-content: center; gap: 3px; font-size: 11px; color: var(--text-disabled); }
.nav a .icon { width: 20px; height: 20px; }
.nav a[aria-current='page'] { color: var(--text); font-weight: 700; }
.nav__brand { display: none !important; }
.nav--wide-only { display: none; } /* 입력 화면: 휴대폰에선 아래 메뉴 숨김 */

/* 넓은 화면(PC): 메뉴는 모든 화면에서 맨 위 가로 줄에 고정 (화면을 옮겨도 자리가 안 바뀌게) */
@media (min-width: 900px) {
  body { padding-top: var(--topnav); }
  .nav, .nav--wide-only {
    display: flex; align-items: center; gap: var(--s1);
    top: 0; bottom: auto; height: var(--topnav); padding: 0 var(--s6);
  }
  .nav a { display: flex; align-items: center; gap: 6px; height: 40px; padding: 0 var(--s3); border-radius: var(--r2); font-size: var(--fs-md); }
  .nav a:hover { background: var(--sunken); color: var(--text); }
  .nav a[aria-current='page'] { background: var(--sunken); }
  .nav a .icon { width: 18px; height: 18px; }
  .nav .nav__brand { display: flex !important; margin-right: var(--s6); padding-left: 0; }
  .nav .nav__brand:hover { background: none; }
  .nav__brand img { width: 30px; height: 30px; }
  /* 위쪽 줄(뒤로·제목)은 본문과 같은 폭에 맞춘다 */
  .topbar { top: var(--topnav); max-width: var(--page-w); margin: 0 auto; padding: 0 var(--s6); }
  .topbar:has(+ .page--mid) { max-width: 880px; }
  .topbar:has(+ .page--narrow) { max-width: 640px; }
  .topbar--detail h1 { visibility: hidden; } /* 상세: 카페 이름이 본문에 크게 있으니 */
  .topbar--brand { display: none; } /* 로고는 위쪽 메뉴에 있으니 */
  .page { max-width: var(--page-w); padding: var(--s6) var(--s8) var(--s10); }
  .page--mid { max-width: 880px; }
  .page--narrow { max-width: 640px; }
  .toast { bottom: var(--s6); }
}

/* ── 알림 ───────────────────────────── */
/* 아래에서 살짝 올라오며 나타나고, 내려가며 사라진다 (--toast-from: 나타나기 전 위치. 위쪽에 뜨는 화면은 음수) */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--nav-h) + var(--s4)); z-index: 2000;
  max-width: calc(100% - 32px); padding: var(--s3) var(--s4);
  background: var(--ink-900); color: var(--paper-50); border-radius: var(--r2); font-size: var(--fs-sm);
  box-shadow: var(--float); pointer-events: none;
  opacity: 0; visibility: hidden; transform: translate(-50%, var(--toast-from, 14px));
  transition: opacity 0.2s ease, transform 0.25s cubic-bezier(0.2, 0.8, 0.2, 1), visibility 0s linear 0.25s;
}
.toast.is-on { opacity: 1; visibility: visible; transform: translate(-50%, 0); transition-delay: 0s; }
@media (prefers-reduced-motion: reduce) { .toast { transition: opacity 0.15s ease, visibility 0s linear 0.15s; } }

/* ── 비회원 잠금: 빈 틀 + 로그인 안내 ── */
.locked { margin-top: var(--s2); padding: var(--s5); border-radius: var(--r2); background: var(--sunken); }
.locked__ghost { display: grid; gap: var(--s3); margin-bottom: var(--s5); opacity: 0.55; }
.locked__ghost .bar__track { background: var(--paper-300); }
.locked__ghost b { color: var(--text-3); }
.locked__cta { display: grid; justify-items: center; gap: var(--s2); text-align: center; }
.locked__cta .icon { width: 22px; height: 22px; color: var(--text-3); }
.locked__title { font-weight: 700; }
.locked__cta .btn { margin-top: var(--s2); }

/* ── 비교 담기 ── */
.cafe-item { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: var(--s1); }
.cmp-toggle {
  display: grid; place-items: center; width: 32px; height: 32px; margin-right: calc(var(--s1) * -1);
  border: 0; border-radius: 50%; background: none; color: var(--text-3);
}
.cmp-toggle:hover { background: var(--sunken); color: var(--text); }
.cmp-toggle[aria-pressed='true'] { background: var(--espresso); color: var(--paper-50); }
.cmp-toggle .icon { width: 16px; height: 16px; }
/* 글자 있는 담기 버튼 (카드·상세) */
.btn[data-cmp][aria-pressed='true'] { background: var(--espresso); color: var(--paper-50); }

/* 아래 비교 바 */
.tray {
  position: fixed; left: var(--s3); right: var(--s3); bottom: calc(var(--nav-h) + var(--s3)); z-index: 1100;
  display: flex; align-items: center; gap: var(--s3); padding: var(--s2) var(--s2) var(--s2) var(--s4);
  border-radius: var(--r-sheet); background: var(--ink-900); color: var(--paper-50); box-shadow: var(--float);
}
.tray__list { flex: 1; min-width: 0; display: flex; gap: var(--s2); overflow-x: auto; scrollbar-width: none; }
.tray__list li { flex: none; display: flex; align-items: center; gap: 2px; max-width: 150px; font-size: var(--fs-sm); font-weight: 600; }
.tray__list span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tray__list li + li::before { content: '·'; margin-right: var(--s2); color: var(--ink-300); }
.tray__list button { display: grid; place-items: center; width: 24px; height: 24px; border: 0; border-radius: 50%; background: none; color: var(--ink-300); }
.tray__list button:hover { color: var(--paper-50); }
.tray__list .icon { width: 14px; height: 14px; }
.tray .btn--primary { flex: none; background: var(--paper-50); color: var(--ink-900); }
.tray .btn--primary:hover { background: var(--paper-200); }
.tray__hint { flex: none; padding-right: var(--s3); font-size: var(--fs-sm); color: var(--ink-300); }
/* 비교 바가 떠 있으면 목록 끝이 가려지지 않게 */
.has-tray .page { padding-bottom: calc(var(--nav-h) + 96px); }

@media (min-width: 900px) {
  .tray { left: 50%; right: auto; bottom: var(--s6); width: min(560px, calc(100% - 48px)); transform: translateX(-50%); }
  .has-tray .page { padding-bottom: 112px; }
}

/* 임시 점수 (순위 전): 정식 점수보다 흐리게 */
.score--provisional { color: var(--text-3); }
