:root {
  --bg: #f4f6f5;
  --surface: #ffffff;
  --text: #17201d;
  --muted: #66716d;
  --line: #e2e7e5;
  --brand: #0f5c4d;
  --brand-soft: #e3f0ec;
  --up: #d6293a;     /* 한국식: 상승 빨강 */
  --down: #1f63d6;   /* 하락 파랑 */
  --radius: 14px;
  --nav-h: 64px;
  font-size: 16px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1413;
    --surface: #1a2120;
    --text: #e8eeec;
    --muted: #93a09b;
    --line: #2a3432;
    --brand: #4fc3a6;
    --brand-soft: #1d3530;
    --up: #ff6b78;
    --down: #6aa5ff;
  }
}
:root[data-size="large"] { font-size: 20px; }

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Malgun Gothic", "Noto Sans KR", sans-serif;
  line-height: 1.45;
  padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom));
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
a { color: inherit; text-decoration: none; }

/* 상단바 */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: var(--brand); color: #fff;
}
@media (prefers-color-scheme: dark) { .topbar { background: var(--surface); color: var(--text); border-bottom: 1px solid var(--line); } }
.topbar h1 { margin: 0; font-size: 1.15rem; font-weight: 700; }
.topbar-actions { display: flex; gap: 4px; }
.icon-btn {
  min-width: 44px; height: 44px; border-radius: 10px;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 1.1rem; font-weight: 700;
}
.icon-btn:active { background: rgba(255,255,255,.15); }
.icon-btn .big { font-size: 1.35em; }
.icon-btn[aria-pressed="true"] { background: rgba(255,255,255,.22); }
.icon-btn.spinning { animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

main { max-width: 720px; margin: 0 auto; padding: 12px 16px; }
.tab { display: none; }
.tab.active { display: block; }
.updated { margin: 2px 0 10px; font-size: .8rem; color: var(--muted); }
.section-title { font-size: 1.05rem; margin: 22px 0 8px; }

[hidden] { display: none !important; }
.user-btn { font-size: .85rem; font-weight: 600; padding: 0 10px; }

/* 로그인 */
.login { min-height: calc(100vh - 140px); display: flex; align-items: center; justify-content: center; padding: 24px 16px; }
.login-card {
  width: 100%; max-width: 360px; background: var(--surface); border: 1px solid var(--line);
  border-radius: 18px; padding: 28px 22px; display: flex; flex-direction: column; gap: 12px; text-align: center;
}
.login-card img { align-self: center; border-radius: 18px; }
.login-card h2 { margin: 4px 0 0; font-size: 1.3rem; }
.login-sub, .login-help { margin: 0; color: var(--muted); font-size: .88rem; }
.login-card label { display: flex; flex-direction: column; gap: 4px; text-align: left; font-size: .88rem; font-weight: 600; }
.login-card input {
  font: inherit; font-size: 1.05rem; padding: 12px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--bg); color: var(--text);
}
.login-card input:focus { outline: 2px solid var(--brand); outline-offset: 1px; }
.login-error { margin: 0; min-height: 1.2em; color: var(--up); font-size: .88rem; }
.primary-btn {
  padding: 14px; border-radius: 12px; background: var(--brand); color: #fff; font-weight: 700; font-size: 1.05rem;
}
@media (prefers-color-scheme: dark) { .primary-btn { color: #0f1413; } }
.primary-btn:disabled { opacity: .6; }

/* AI 브리핑 */
.briefing {
  background: var(--brand-soft); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; margin-bottom: 14px;
}
.briefing .label { font-size: .75rem; font-weight: 700; color: var(--brand); letter-spacing: .02em; }
.briefing h2 { font-size: 1.15rem; margin: 4px 0 8px; line-height: 1.35; }
.briefing .summary { margin: 0 0 10px; }
.briefing ol { margin: 0; padding: 0; list-style: none; counter-reset: pt; }
.briefing li { counter-increment: pt; padding: 8px 0 8px 30px; position: relative; border-top: 1px solid var(--line); }
.briefing li::before {
  content: counter(pt); position: absolute; left: 0; top: 9px;
  width: 20px; height: 20px; border-radius: 50%; background: var(--brand); color: var(--surface);
  font-size: .72rem; font-weight: 700; display: flex; align-items: center; justify-content: center;
}
.briefing .pt-title { font-weight: 700; }
.briefing .pt-body { font-size: .92rem; }
.briefing .pt-src { display: flex; flex-wrap: wrap; gap: 4px 10px; margin-top: 3px; font-size: .75rem; }
.briefing .pt-src a { color: var(--muted); text-decoration: underline; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.briefing .housing-note { margin: 8px 0 0; padding-top: 8px; border-top: 1px solid var(--line); font-size: .92rem; }
.briefing .foot { margin-top: 10px; font-size: .72rem; color: var(--muted); }

/* 시황 */
.group-title { font-size: .85rem; color: var(--muted); margin: 14px 0 6px; font-weight: 600; }
.grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
:root[data-size="large"] .grid { grid-template-columns: 1fr; }
.quote {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px 14px;
}
.quote .name { font-size: .85rem; color: var(--muted); }
.quote .price { font-size: 1.3rem; font-weight: 700; font-variant-numeric: tabular-nums; margin-top: 2px; }
.quote .chg { font-size: .9rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.up { color: var(--up); }
.down { color: var(--down); }
.flat { color: var(--muted); }

/* 뉴스 */
.chips { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 6px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; padding: 7px 14px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--surface); font-size: .9rem;
}
.chip[aria-selected="true"] { background: var(--brand); border-color: var(--brand); color: #fff; }
@media (prefers-color-scheme: dark) { .chip[aria-selected="true"] { color: #0f1413; } }
.news-list { list-style: none; margin: 0; padding: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.news-list li + li { border-top: 1px solid var(--line); }
.news-list a { display: block; padding: 12px 14px; }
.news-list a:active { background: var(--brand-soft); }
.news-title { font-weight: 600; }
.news-meta { font-size: .78rem; color: var(--muted); margin-top: 3px; }

/* 청약 */
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px; margin-bottom: 10px;
}
.card-head { display: flex; justify-content: space-between; gap: 8px; align-items: flex-start; }
.card h3 { margin: 0; font-size: 1.05rem; }
.badge {
  flex: none; font-size: .78rem; font-weight: 700; padding: 3px 9px; border-radius: 999px;
  background: var(--brand-soft); color: var(--brand);
}
.badge.hot { background: var(--up); color: #fff; }
.badge.done { background: var(--line); color: var(--muted); }
.card dl { display: grid; grid-template-columns: auto 1fr; gap: 3px 12px; margin: 10px 0 0; font-size: .9rem; }
.card dt { color: var(--muted); }
.card dd { margin: 0; }
.card .more { display: inline-block; margin-top: 10px; font-size: .9rem; font-weight: 600; color: var(--brand); }

/* 상태 */
.empty, .error {
  background: var(--surface); border: 1px dashed var(--line); border-radius: var(--radius);
  padding: 24px 16px; text-align: center; color: var(--muted);
}
.error { border-color: var(--up); }
.skeleton { height: 76px; border-radius: var(--radius); background: var(--line); opacity: .5; animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .25; } }

/* 하단 탭 */
.bottomnav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface); border-top: 1px solid var(--line);
}
.bottomnav button {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  font-size: .78rem; color: var(--muted);
}
.bottomnav .nav-icon { font-size: 1.35rem; line-height: 1; }
.bottomnav button.active { color: var(--brand); font-weight: 700; }

@media (prefers-reduced-motion: reduce) {
  .icon-btn.spinning, .skeleton { animation: none; }
}
