/* 어디갈펫 — main stylesheet */

/* ============ Design tokens (fluid: 320px → 600px+) ============ */
:root{
  --green:#0f5b33; --green-d:#0b4a29; --green-soft:#e8f1e1;
  --text:#1f2a22; --sub:#6b6f6c; --muted:#4c514d; --line:#e4e4e0;
  --orange:#c96e08; --red:#d2401f;
  --page:#fbfaf8; --backdrop:#eef0eb;

  --app-max:600px;
  --gutter:clamp(14px, 5vw, 22px);
  --gap:clamp(10px, 3.6vw, 16px);
  --radius:clamp(10px, 3.2vw, 14px);

  --fs-h1:clamp(20px, 6.4vw, 27px);
  --fs-h2:clamp(17px, 5.4vw, 22px);
  --fs-h3:clamp(15px, 4.5vw, 18px);
  --fs-body:clamp(13px, 4vw, 16px);
  --fs-sm:clamp(12px, 3.5vw, 14px);
  --fs-xs:clamp(11px, 3.2vw, 13px);

  --nav-h:62px;
  /* height-aware spacing: shrinks on short screens */
  --h1-mt:clamp(12px, min(6vw, 3vh), 28px);
  --sec-mt:clamp(16px, min(6.4vw, 3.2vh), 30px);

  --safe-t:env(safe-area-inset-top, 0px);
  --safe-b:env(safe-area-inset-bottom, 0px);
  --safe-l:env(safe-area-inset-left, 0px);
  --safe-r:env(safe-area-inset-right, 0px);
}
*,*::before,*::after{box-sizing:border-box;margin:0;padding:0}
html{-webkit-text-size-adjust:100%;text-size-adjust:100%;background:var(--backdrop)}
body{
  font-family:"Pretendard","Noto Sans KR",-apple-system,BlinkMacSystemFont,"Apple SD Gothic Neo","Segoe UI",Roboto,sans-serif;
  color:var(--text);background:var(--backdrop);
  -webkit-font-smoothing:antialiased;
  -webkit-tap-highlight-color:transparent;
  overscroll-behavior-y:none;
  word-break:keep-all;           /* 한국어: 단어 중간에서 줄바꿈하지 않음 */
  overflow-wrap:anywhere;
}
img,svg{display:block;max-width:100%;flex-shrink:0}
a{color:inherit;text-decoration:none}
button{font:inherit;border:0;background:none;cursor:pointer;color:inherit}
a,button{touch-action:manipulation}
:focus-visible{outline:2px solid var(--green);outline-offset:2px;border-radius:6px}
.nowrap{display:inline-block;white-space:nowrap}

.app{
  width:100%;max-width:var(--app-max);margin:0 auto;background:var(--page);
  min-height:100vh;min-height:100dvh;
  position:relative;overflow-x:hidden;overflow-x:clip; /* clip keeps sticky header working */
  padding-bottom:calc(var(--nav-h) + var(--safe-b) + 16px);
  padding-left:var(--safe-l);padding-right:var(--safe-r);
}
.main{padding:0 var(--gutter)}

/* ============ Header (sticky, under notch / Dynamic Island) ============ */
.header{
  position:sticky;top:0;z-index:20;
  display:flex;align-items:center;justify-content:space-between;gap:12px;
  padding:calc(var(--safe-t) + 10px) var(--gutter) 10px;
  background:rgba(251,250,248,.92);
  -webkit-backdrop-filter:saturate(180%) blur(12px);backdrop-filter:saturate(180%) blur(12px);
  transition:box-shadow .2s;
}
.header.scrolled{box-shadow:0 1px 0 var(--line)}
.logo{display:flex;align-items:center;gap:8px;color:var(--green);font-weight:800;font-size:clamp(19px, 5.8vw, 23px);letter-spacing:-.5px;line-height:1.2}
.logo svg{width:clamp(28px, 8.4vw, 34px);height:auto}
.emergency{
  display:flex;align-items:center;gap:6px;flex-shrink:0;
  min-height:40px;padding:0 clamp(12px,3.8vw,16px) 0 clamp(10px,3.2vw,13px);
  color:var(--red);background:#fdebe2;border:1.5px solid #f6c7b3;border-radius:999px;
  font-size:var(--fs-sm);font-weight:600;white-space:nowrap;
}
.emergency svg{width:clamp(17px,5vw,20px);height:auto}
.emergency:active{background:#fbdccf}

/* ============ Top area ============ */
.location{display:flex;align-items:center;gap:6px;min-height:40px;margin-top:2px;font-size:var(--fs-body);font-weight:500}
h1{color:var(--green);font-size:var(--fs-h1);font-weight:800;letter-spacing:-.03em;line-height:1.3;margin:var(--h1-mt) 2px clamp(10px,3.6vw,16px)}

.search{display:flex;align-items:center;gap:10px;border:1.5px solid #c9ccc7;border-radius:clamp(16px,5vw,22px);padding:0 clamp(14px,4.4vw,18px);min-height:clamp(46px,13.4vw,52px);background:#fff}
.search:focus-within{border-color:var(--green)}
.search svg{width:clamp(19px,5.6vw,22px);height:auto}
/* 16px 유지: iOS에서 입력 시 화면 확대 방지 */
.search input{border:0;outline:0;flex:1;min-width:0;font:inherit;font-size:16px;background:transparent;height:44px}
.search input::placeholder{color:#8a8d8a}
.search input::-webkit-search-cancel-button{cursor:pointer}

.condition{display:flex;align-items:center;gap:clamp(10px,3.6vw,14px);background:var(--green-soft);border-radius:var(--radius);padding:10px clamp(12px,4vw,16px) 10px 10px;margin-top:clamp(12px,4vw,16px)}
.condition img{width:clamp(44px,13vw,52px);height:auto;aspect-ratio:1;border-radius:50%;object-fit:cover;background:#fff}
.condition .txt{flex:1;min-width:0}
.condition strong{display:block;color:var(--green);font-size:var(--fs-h3);font-weight:700}
.condition span{display:block;font-size:var(--fs-xs);color:var(--muted);margin-top:1px}
.condition:active{filter:brightness(.97)}

/* ============ Segment tabs ============ */
.seg{display:flex;border-bottom:1px solid var(--line);margin-top:clamp(14px,5vw,22px)}
.seg button{flex:1;min-height:48px;padding:10px 4px 12px;font-size:var(--fs-body);color:#555;border-bottom:3px solid transparent;margin-bottom:-1px;white-space:nowrap}
.seg button.active{color:var(--green);font-weight:700;border-bottom-color:var(--green)}
.panel[hidden]{display:none}

/* ============ Sections ============ */
.section-head{display:flex;align-items:center;justify-content:space-between;gap:12px;margin:var(--sec-mt) 2px 6px}
h2{color:var(--green);font-size:var(--fs-h2);font-weight:800;letter-spacing:-.02em}
.link{display:flex;align-items:center;gap:4px;min-height:40px;color:var(--green);font-size:var(--fs-sm);font-weight:500;white-space:nowrap}

.toolbar{display:flex;justify-content:space-between;align-items:center;margin:0 2px 6px;font-size:var(--fs-sm);color:#555}
.toolbar button{display:flex;align-items:center;gap:6px;min-height:40px}

/* ============ List items ============ */
.list{display:grid;grid-template-columns:minmax(0,1fr)}
.item{display:flex;gap:var(--gap);align-items:center;padding:clamp(10px,3.2vw,14px) 0;border-bottom:1px solid var(--line)}
.item .thumb{width:42%;max-width:240px;border-radius:10px;object-fit:cover;aspect-ratio:16/9.4;height:auto;background:var(--green-soft)}
.item .body{flex:1;min-width:0}
.item h3{color:var(--green);font-size:var(--fs-h3);font-weight:800;letter-spacing:-.3px;line-height:1.3}
.item .meta{font-size:var(--fs-xs);color:var(--sub);margin-top:2px}
.item .info{font-size:var(--fs-xs);color:var(--sub);margin-top:3px;letter-spacing:-.2px;line-height:1.45}
.status{display:flex;align-items:flex-start;gap:5px;font-size:var(--fs-xs);font-weight:600;margin-top:5px;line-height:1.35}
.status svg{width:1.2em;height:1.2em;margin-top:.05em}
.status.ok{color:var(--green)}
.status.warn{color:var(--orange)}

.more{display:flex;justify-content:center;align-items:center;gap:4px;min-height:44px;color:var(--green);font-size:var(--fs-body);font-weight:500;margin:10px 0 0}

/* ============ AI banner ============ */
.ai{
  display:flex;align-items:center;gap:clamp(10px,3.6vw,14px);
  background:var(--green-soft);border-radius:var(--radius);
  padding:clamp(14px,4.4vw,18px) clamp(14px,4vw,18px);margin-top:var(--sec-mt);
}
.ai > svg{width:clamp(24px,7vw,30px);height:auto}
.ai .txt{flex:1;min-width:0}
.ai strong{display:block;color:var(--green);font-size:var(--fs-h3);font-weight:700;line-height:1.35;text-wrap:balance}
.ai span.desc{display:block;font-size:var(--fs-xs);color:var(--muted);margin-top:3px;line-height:1.45;text-wrap:balance}
.ai-btn{flex-shrink:0;background:var(--green-d);color:#fff;border-radius:999px;min-height:42px;padding:0 clamp(16px,5vw,22px);font-size:var(--fs-sm);font-weight:600;white-space:nowrap}
.ai-btn:active{background:#083b20}

/* ============ Bottom nav ============ */
.nav{
  position:fixed;bottom:0;left:50%;transform:translateX(-50%);z-index:30;
  width:100%;max-width:var(--app-max);
  display:flex;background:rgba(255,255,255,.96);
  -webkit-backdrop-filter:blur(12px);backdrop-filter:blur(12px);
  border-top:1px solid var(--line);
  height:calc(var(--nav-h) + var(--safe-b));
  padding:0 var(--safe-r) var(--safe-b) var(--safe-l);
}
.nav a{flex:1;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:3px;font-size:12px;color:#444}
.nav a svg{width:26px;height:26px;fill:none;stroke:currentColor;stroke-width:1.6;stroke-linejoin:round}
.nav a.active{color:var(--green);font-weight:600}
.nav a.active svg{fill:currentColor}

@media (hover:hover){
  .item:hover h3{text-decoration:underline;text-underline-offset:3px}
  .emergency:hover{background:#fbdccf}
  .ai-btn:hover{background:#083b20}
}

/* ===== Very narrow phones (Galaxy Fold cover, iPhone SE 1st gen) ===== */
@media (max-width:359px){
  .emergency .lbl-long{display:none}
  .item{flex-direction:column;align-items:stretch}
  .item .thumb{width:100%;max-width:none}
}
/* ===== Phones (< 440px): AI 배너 버튼을 아래 줄로 내려 문구가 한 줄씩 온전히 보이게 ===== */
@media (max-width:439px){
  .ai{flex-wrap:wrap;align-items:flex-start}
  .ai > svg{margin-top:2px}
  .ai .txt{flex:1 1 calc(100% - 50px)}
  .ai-btn{width:100%;margin-top:4px}
}
@media (min-width:360px){ .emergency .lbl-short{display:none} }

/* ===== Tablets & desktop: centered app column ===== */
@media (min-width:600px){
  :root{
    --fs-h1:27px; --fs-h2:22px; --fs-h3:18px; --fs-body:16px; --fs-sm:14px; --fs-xs:13px;
    --gutter:24px; --gap:16px; --radius:14px;
  }
  .app{box-shadow:0 0 0 1px var(--line),0 10px 40px rgba(20,50,30,.08)}
  .nav{border-left:1px solid var(--line);border-right:1px solid var(--line)}
}

/* ===== Tablets & wide screens: wider column, larger type ===== */
@media (min-width:768px){
  :root{
    --app-max:820px;
    --fs-h1:34px; --fs-h2:26px; --fs-h3:20px; --fs-body:18px; --fs-sm:16px; --fs-xs:14px;
    --gutter:32px; --gap:18px; --radius:18px; --nav-h:70px;
    --h1-mt:clamp(20px,4vh,40px); --sec-mt:clamp(24px,4vh,40px);
  }
  .logo{font-size:27px}
  .logo svg{width:38px}
  .emergency{min-height:44px;font-size:16px;padding:0 18px 0 15px}
  .search{min-height:58px;border-radius:24px}
  .search input{font-size:18px}
  .condition{padding:14px 20px 14px 14px}
  .condition img{width:60px}
  .seg button{min-height:56px}
  .item .thumb{width:36%;max-width:260px}
  .ai-btn{min-height:48px;padding:0 28px}
  .nav a{font-size:13px;gap:4px}
  .nav a svg{width:28px;height:28px}
}
@media (min-width:1024px){
  :root{--app-max:860px}
  body{padding-top:24px}
  .app{border-radius:24px 24px 0 0}
  /* rounded sticky header: ::before shows the page backdrop at the corners */
  .header{background:none;-webkit-backdrop-filter:none;backdrop-filter:none}
  .header::before,.header::after{content:"";position:absolute;inset:0;z-index:-1;pointer-events:none}
  .header::before{background:var(--backdrop)}
  .header::after{background:var(--page);border-radius:24px 24px 0 0}
  .header.scrolled{box-shadow:none}
  .header.scrolled::after{box-shadow:0 1px 0 var(--line)}
}
@media (min-width:1200px){ :root{--app-max:900px} }

/* ===== Landscape phones (short viewport) ===== */
@media (orientation:landscape) and (max-height:500px){
  :root{--nav-h:50px; --app-max:760px; --h1-mt:8px; --sec-mt:14px}
  .header{position:relative}
  .item .thumb{width:32%}
  .nav a{flex-direction:row;gap:8px}
  .nav a svg{width:22px;height:22px}
}

/* ===== Short screens ===== */
@media (max-height:700px){
  .header{padding-top:calc(var(--safe-t) + 6px);padding-bottom:6px}
}
@media (max-height:600px){
  .condition span{display:none}
  .location{min-height:34px}
}

/* Standalone (installed web app) */
@media (display-mode:standalone){
  html,body{background:var(--page)}
}
@media (prefers-reduced-motion:reduce){
  *{transition:none!important;animation:none!important;scroll-behavior:auto!important}
}
