/* ============================================================
   기상부장 MVP — 모바일 스타일시트
   기능명세서 v0.2 §4 화면 구성

   레이아웃 원칙: 변경분이 화면 최상단, 하루 예보는 그 아래.
   기존 날씨 앱과 정보 위계가 정반대라는 점이 이 화면의 전부다.

   모바일 앱 셸 구조 —
     [헤더 고정] · [본문 스크롤] · [컨트롤바 고정]
   position:fixed 대신 flex 컬럼 + 100dvh 를 쓴다.
   iOS 사파리에서 fixed 요소가 키보드·주소창에 밀리는 문제를 피하기 위함.
   ============================================================ */

/* ---------- 토큰 ----------
   다크가 기본, 라이트는 :root[data-theme="light"] 로 덮는다.
   기기 설정(prefers-color-scheme)은 JS가 부팅 시 읽어 data-theme 를 확정하므로
   여기에 미디어 쿼리를 중복해서 두지 않는다. */
:root {
  --bg: #0f1319;
  --panel: #171d26;
  --panel-2: #1e2632;
  --line: #2a3340;
  --text: #e6ebf2;
  --muted: #8b98a9;
  --accent: #4a9eff;
  --high: #ff6b5a;
  --normal: #ffb648;
  --ok: #3ddc97;

  /* 반투명 틴트 — 배경 밝기가 뒤바뀌면 같은 알파로는 안 보인다 */
  --tint-high: rgba(255, 107, 90, .12);
  --tint-high-line: rgba(255, 107, 90, .35);
  --tint-ok: rgba(61, 220, 151, .10);
  --tint-ok-line: rgba(61, 220, 151, .28);
  --tint-warn: rgba(255, 182, 72, .07);
  --tint-now: rgba(74, 158, 255, .08);
  --scrim: rgba(0, 0, 0, .55);
  --shadow: 0 24px 60px rgba(0, 0, 0, .45);
  --press: var(--line);

  --radius: 14px;
  --radius-sm: 12px;

  /* 터치 타겟 최소 크기 */
  --tap: 44px;

  /* 노치 · 홈바 여백 */
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
  --sar: env(safe-area-inset-right, 0px);

  color-scheme: dark;
}

:root[data-theme="light"] {
  --bg: #f4f6f9;
  --panel: #ffffff;
  --panel-2: #f0f3f7;
  --line: #dde3ec;
  --text: #16202c;
  --muted: #6b7787;
  --accent: #1a73e8;
  --high: #d93a2b;
  --normal: #c77700;
  --ok: #1a8f5f;

  --tint-high: rgba(217, 58, 43, .09);
  --tint-high-line: rgba(217, 58, 43, .30);
  --tint-ok: rgba(26, 143, 95, .09);
  --tint-ok-line: rgba(26, 143, 95, .26);
  --tint-warn: rgba(199, 119, 0, .10);
  --tint-now: rgba(26, 115, 232, .07);
  --scrim: rgba(20, 28, 38, .45);
  --shadow: 0 20px 50px rgba(22, 32, 44, .20);
  --press: #e4e9f0;

  color-scheme: light;
}

/* ---------- 기본 ---------- */
* { box-sizing: border-box; }

html {
  height: 100%;
  -webkit-text-size-adjust: 100%;   /* 가로 전환 시 글자 크기 튀는 것 방지 */
  text-size-adjust: 100%;
}

body {
  margin: 0;
  height: 100vh;
  height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo",
               "Pretendard", "Malgun Gothic", sans-serif;
  line-height: 1.5;
  overscroll-behavior: none;                    /* 당겨서 새로고침 · 고무줄 튕김 차단 */
  -webkit-tap-highlight-color: transparent;     /* 탭할 때 회색 박스 제거 */
  transition: background-color .18s ease, color .18s ease;
}

/* 앱 셸 — 헤더/본문/컨트롤바 3단 */
.app {
  display: flex;
  flex-direction: column;
  height: 100%;
  padding-left: var(--sal);
  padding-right: var(--sar);
}

/* ---------- 헤더 (가상 시계 F-03 · baseline 표기 F-01) ---------- */
.hd {
  flex: 0 0 auto;
  padding: calc(12px + var(--sat)) 16px 12px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  user-select: none;
  -webkit-user-select: none;
}

.h-top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
}

.brand { font-size: 18px; font-weight: 700; letter-spacing: -0.02em; }

.clock {
  font-size: 12px;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
  text-align: right;
  line-height: 1.35;
}

.baseline-note { margin-top: 3px; font-size: 12px; color: var(--muted); }
.baseline-note b { color: var(--text); font-weight: 600; }

/* ---------- 본문 (스크롤 영역) ---------- */
.scroll {
  flex: 1 1 auto;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 12px 14px 20px;
}

/* ---------- 배너 ---------- */
.banner {
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  margin-bottom: 12px;
  font-size: 14px;
  font-weight: 600;
  border: 1px solid transparent;
}

.banner.changed {
  background: var(--tint-high);
  border-color: var(--tint-high-line);
  color: var(--high);
}

.banner.clean {
  background: var(--tint-ok);
  border-color: var(--tint-ok-line);
  color: var(--ok);
}

.banner.done {
  background: var(--panel-2);
  border-color: var(--line);
  color: var(--muted);
}

/* ---------- 변경 카드 (F-05) ---------- */
#cards {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

#cards:not(:empty) { margin-bottom: 18px; }

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-left: 4px solid var(--normal);
  border-radius: var(--radius-sm);
  padding: 13px 14px;
  animation: pop .28s ease-out;
}

.card.high { border-left-color: var(--high); }

@keyframes pop {
  from { opacity: 0; transform: translateY(-6px); }
  to   { opacity: 1; transform: none; }
}

.card-head {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 15px;
}

.card-head .sev {
  margin-left: auto;
  font-size: 11px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--panel-2);
  color: var(--muted);
  border: 1px solid var(--line);
  white-space: nowrap;
}

.card.high .sev { color: var(--high); border-color: var(--tint-high-line); }

/* '무엇 대비' 변한 것인지가 항상 보여야 한다 */
.compare {
  display: flex;
  align-items: center;
  gap: 7px;
  flex-wrap: wrap;
  margin-top: 9px;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}

.compare .base  { color: var(--muted); }
.compare .arrow { color: var(--muted); }
.compare .now   { font-weight: 700; }

.compare .delta {
  font-size: 12.5px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--panel-2);
  border: 1px solid var(--line);
}

.card.high .delta { color: var(--high); }

/* 하늘상태 전환은 같은 시각의 강수 카드에 합쳐 한 줄로 붙는다 */
.shift {
  margin-top: 7px;
  font-size: 13px;
  font-weight: 600;
  color: var(--high);
}

/* F-08 한 줄 행동 조언 */
.advice {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--line);
  font-size: 13px;
  color: var(--muted);
}

/* ---------- 하루 예보 (F-02) ---------- */
.section-title {
  font-size: 12px;
  color: var(--muted);
  margin: 0 2px 8px;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
}

#hourly {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}

/* 시각 · 기온 · 하늘 · 강수확률 · 풍속 · 변경 칩 */
.row {
  display: grid;
  grid-template-columns: 40px 38px 24px 42px 56px 1fr;
  align-items: center;
  gap: 6px;
  padding: 11px 12px;
  font-size: 13.5px;
  font-variant-numeric: tabular-nums;
  border-top: 1px solid var(--line);
}

.row:first-child { border-top: none; }

.row.past { opacity: .4; }
.row.now  { background: var(--tint-now); }

/* 임계치 미달이라도 baseline과 다르면 옅게 강조한다.
   T+2에서 "예보는 바뀌었는데 카드는 안 뜬다"가 눈에 보여야 한다. */
.row.diff      { background: var(--tint-warn); }
.row.diff-high { background: var(--tint-high); }

.row .hh { color: var(--muted); }
.row.now .hh { color: var(--accent); font-weight: 700; }

/* 변경 꼬리표 — 좁은 화면에서도 살아남게 칩으로 만든다 */
.row .tag { justify-self: end; }

.row .tag:not(:empty) {
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 2px 7px;
  white-space: nowrap;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
}

.row.diff-high .tag:not(:empty) {
  color: var(--high);
  border-color: var(--tint-high-line);
}

/* ---------- 컨트롤바 (F-07) — 하단 고정 ---------- */
.bar {
  flex: 0 0 auto;
  background: var(--panel);
  border-top: 1px solid var(--line);
  padding: 10px 12px calc(10px + var(--sab));
  user-select: none;
  -webkit-user-select: none;
}

/* 재생 컨트롤 — 4등분, 최소 44px */
.transport {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.tbtn {
  min-height: 52px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 6px 2px;
  font: inherit;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 11px;
  cursor: pointer;
  touch-action: manipulation;          /* 더블탭 확대 방지 */
  transition: background .12s, border-color .12s, transform .08s;
}

.tbtn .ico { font-size: 17px; line-height: 1; }
.tbtn .lab { font-size: 10.5px; font-weight: 600; color: var(--muted); }

.tbtn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.tbtn.primary .lab { color: rgba(255, 255, 255, .85); }

.tbtn.on { border-color: var(--ok); }
.tbtn.on .ico, .tbtn.on .lab { color: var(--ok); }

.tbtn:disabled { opacity: .35; }

/* 보조 컨트롤 — 알림 / 실 데이터 / 테마 */
.aux {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}

.abtn {
  flex: 1 1 0;
  min-height: var(--tap);
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 11px;
  padding: 8px 10px;
  cursor: pointer;
  touch-action: manipulation;
  transition: background .12s, border-color .12s, transform .08s;
}

/* 테마 토글 — 아이콘만, 고정 폭 */
.abtn.narrow {
  flex: 0 0 var(--tap);
  padding: 8px 0;
  font-size: 17px;
  line-height: 1;
}

.abtn.on { border-color: var(--ok); color: var(--ok); }
.abtn:disabled { opacity: .45; }

.hint {
  margin-top: 8px;
  font-size: 11.5px;
  line-height: 1.45;
  color: var(--muted);
}

/* 마우스가 있는 기기에서만 hover — 모바일에서 hover가 눌린 채 남는 문제 방지 */
@media (hover: hover) and (pointer: fine) {
  .tbtn:hover:not(:disabled),
  .abtn:hover:not(:disabled) { border-color: var(--accent); }
}

/* 터치 피드백은 :active 로 */
.tbtn:active:not(:disabled),
.abtn:active:not(:disabled) { transform: scale(.97); background: var(--press); }

.tbtn:focus-visible,
.abtn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- 알림 팝업 (OS 알림과 함께 뜨는 인앱 모달) ---------- */
#popup {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(20px + var(--sat)) 18px calc(20px + var(--sab));
  background: var(--scrim);
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s ease-out;
}

#popup.show { opacity: 1; pointer-events: auto; }

#popup .popup-box {
  width: 100%;
  max-width: 380px;
  max-height: 100%;
  overflow-y: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-top: 4px solid var(--high);
  border-radius: 16px;
  padding: 22px 20px 16px;
  box-shadow: var(--shadow);
  text-align: center;
  transform: scale(.92) translateY(8px);
  transition: transform .22s cubic-bezier(.2, .9, .3, 1.2);
}

#popup.show .popup-box { transform: none; }

#popup .p-icon { font-size: 34px; line-height: 1; }
#popup .p-title { margin-top: 8px; font-size: 16px; font-weight: 700; }
#popup .p-sub { margin-top: 4px; font-size: 12px; color: var(--muted); }

#popup .p-list {
  list-style: none;
  margin: 14px 0 0;
  padding: 0;
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

#popup .p-list li {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 11px;
  padding: 10px 12px;
}

#popup .p-when { font-size: 12px; color: var(--muted); font-weight: 600; }
#popup .p-change { margin-top: 2px; font-size: 14px; font-variant-numeric: tabular-nums; }
#popup .p-change b { color: var(--high); }
#popup .p-advice { margin-top: 4px; font-size: 12.5px; color: var(--muted); }

#popup .p-actions { margin-top: 16px; }

#popup .p-actions button {
  width: 100%;
  min-height: var(--tap);
  font: inherit;
  font-size: 15px;
  font-weight: 700;
  color: #fff;
  background: var(--accent);
  border: 1px solid var(--accent);
  border-radius: 11px;
  cursor: pointer;
  touch-action: manipulation;
}

#popup .p-actions button:active { transform: scale(.98); }

#popup .p-timer { margin-top: 9px; font-size: 11px; color: var(--muted); min-height: 15px; }

/* ---------- 움직임 최소화 설정 존중 ---------- */
@media (prefers-reduced-motion: reduce) {
  .card { animation: none; }
  body, #popup, #popup .popup-box, .tbtn, .abtn { transition: none; }
  .tbtn:active, .abtn:active { transform: none; }
}

/* ---------- 아주 좁은 화면 (iPhone SE 등) ---------- */
@media (max-width: 360px) {
  .scroll { padding: 10px 10px 16px; }
  .row { grid-template-columns: 36px 34px 22px 38px 0 1fr; padding: 10px 9px; font-size: 12.5px; }
  .row > :nth-child(5) { display: none; }   /* 풍속 열 접기 */
  .tbtn .lab { font-size: 9.5px; }
}

/* ---------- 가로 모드 — 컨트롤바가 화면을 다 먹지 않게 ---------- */
@media (orientation: landscape) and (max-height: 480px) {
  .hd { padding-top: calc(8px + var(--sat)); padding-bottom: 8px; }
  .bar { padding-top: 8px; }
  .tbtn { min-height: 44px; }
  .tbtn .lab { display: none; }
  .hint { display: none; }
}

/* ---------- 넓은 화면(태블릿·데스크톱)에서는 가운데 정렬 ---------- */
@media (min-width: 620px) {
  .app { max-width: 560px; margin: 0 auto; border-left: 1px solid var(--line); border-right: 1px solid var(--line); }
}
