/* 색은 아래 변수만 쓴다. 라이트·다크 세 경우(시스템 다크, 강제 라이트, 강제 다크)를 모두 처리한다. */
:root{
  --bg:#f3f5f7; --surface:#ffffff; --sunk:#e9edf1; --line:#d5dce3;
  --fg:#16202b; --muted:#5b6876; --accent:#1f5f8b; --accent-soft:#dbe8f2;
  --ok:#1d7a4f; --ok-soft:#dcf0e5; --warn:#a86a07; --warn-soft:#f7ead0; --bad:#b4372b; --bad-soft:#f6dcd8;
  --sans:"IBM Plex Sans KR", "Apple SD Gothic Neo", "Malgun Gothic", system-ui, sans-serif;
  --mono:"IBM Plex Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;
}
@media (prefers-color-scheme: dark){:root:not([data-theme="light"]){
  --bg:#0f1419; --surface:#171e25; --sunk:#1f2830; --line:#2c3843;
  --fg:#e3e9ef; --muted:#93a1ae; --accent:#6aaee0; --accent-soft:#1c3446;
  --ok:#55c08a; --ok-soft:#173326; --warn:#e2a945; --warn-soft:#3a2d14; --bad:#ec7a6c; --bad-soft:#3d1f1b;
  color-scheme:dark}}
:root[data-theme="dark"]{
  --bg:#0f1419; --surface:#171e25; --sunk:#1f2830; --line:#2c3843;
  --fg:#e3e9ef; --muted:#93a1ae; --accent:#6aaee0; --accent-soft:#1c3446;
  --ok:#55c08a; --ok-soft:#173326; --warn:#e2a945; --warn-soft:#3a2d14; --bad:#ec7a6c; --bad-soft:#3d1f1b;
  color-scheme:dark}
*{box-sizing:border-box}
[hidden]{display:none!important}
body{margin:0;background:var(--bg);color:var(--fg);font-family:var(--sans);font-size:15px;line-height:1.55}
/* 폰(400px)이 기준. 좌우 여백은 최소 16px, 페이지 전체가 가로로 밀리면 안 된다. */
.wrap{max-width:960px;margin:0 auto;padding-block:20px 48px;
  padding-left:max(16px, env(safe-area-inset-left, 0px));padding-right:max(16px, env(safe-area-inset-right, 0px));
  display:flex;flex-direction:column;gap:14px}
.head{display:flex;flex-direction:column;gap:4px}
h1{font-size:1.5rem;margin:0;font-weight:700}
h2{font-size:1.05rem;margin:0;font-weight:600}
.sub{color:var(--muted);margin:0;font-size:.86rem}
.hint{color:var(--muted);font-size:.82rem;margin:0}
.num{font-family:var(--mono);font-variant-numeric:tabular-nums}
.panel{background:var(--surface);border:1px solid var(--line);border-radius:10px;padding:16px;display:flex;flex-direction:column;gap:12px;min-width:0}
.panel-head{display:flex;justify-content:space-between;align-items:baseline;gap:8px;flex-wrap:wrap}
.field{display:flex;flex-direction:column;gap:4px;min-width:0}
.field label{font-size:.78rem;color:var(--muted);font-weight:500}
input,select,textarea{font:inherit;color:var(--fg);background:var(--bg);border:1px solid var(--line);border-radius:6px;padding:8px 10px;width:100%;min-width:0}
textarea{resize:vertical}
input:focus-visible,select:focus-visible,textarea:focus-visible,button:focus-visible{outline:2px solid var(--accent);outline-offset:1px}
button{font:inherit;cursor:pointer;border-radius:6px;border:1px solid var(--line);background:var(--surface);color:var(--fg);padding:8px 12px;font-size:.88rem;font-weight:500;min-height:38px}
button:hover{border-color:var(--accent)}
button.primary{background:var(--accent);border-color:var(--accent);color:var(--surface)}
.token{display:flex;gap:8px;align-items:center;flex-wrap:wrap}
.token label{font-size:.78rem;color:var(--muted);font-weight:500}
.token input{flex:1 1 160px;width:auto}

/* ── 앱 허브 ── */
.head-row{display:flex;justify-content:space-between;align-items:center;gap:8px}
button.ghost{background:transparent}
button:disabled{opacity:.6;cursor:default}
button.danger{color:var(--bad)}
button.danger.armed{background:var(--bad);border-color:var(--bad);color:var(--surface)}
.edit-bar{display:flex;align-items:center;gap:10px;flex-wrap:wrap}
#status{min-height:1.3em}
#status:empty{display:none}

/* 분류 칩: 줄바꿈으로 넘친다(가로 스크롤 없음) */
.chips{display:flex;flex-wrap:wrap;gap:6px}
.chip{min-height:34px;padding:5px 12px;border-radius:999px;font-size:.84rem;background:var(--surface);color:var(--muted)}
.chip[aria-pressed="true"]{background:var(--accent);border-color:var(--accent);color:var(--surface)}

/* 카드 목록: 폰은 한 줄에 하나, 넓으면 여러 개 */
.list{display:grid;grid-template-columns:repeat(auto-fill, minmax(min(100%, 280px), 1fr));gap:14px}
.empty{color:var(--muted);margin:24px 0;text-align:center;grid-column:1 / -1}
.card{background:var(--surface);border:1px solid var(--line);border-radius:12px;overflow:hidden;display:flex;flex-direction:column;min-width:0}
.card.is-hidden{opacity:.65}
.card-main{display:flex;flex-direction:column;color:inherit;text-decoration:none;flex:1;min-width:0}
a.card-main:hover .card-name{color:var(--accent)}
a.card-main:focus-visible{outline:2px solid var(--accent);outline-offset:-2px}

/* 대표 화면: 그림이 없으면 이모지를 크게 */
.shot{position:relative;height:150px;background:var(--sunk);border-bottom:1px solid var(--line);display:grid;place-items:center;overflow:hidden}
.shot img{position:absolute;inset:0;width:100%;height:100%;object-fit:cover;object-position:top center;opacity:0}
.shot.has-img img{opacity:1}
.shot.has-img .shot-emoji{visibility:hidden}
.shot-emoji{font-size:3.4rem;line-height:1}

.card-body{padding:12px 14px 14px;display:flex;flex-direction:column;gap:6px;min-width:0}
.card-title{display:flex;align-items:center;gap:6px;font-size:1.05rem;min-width:0}
.card-name{overflow-wrap:anywhere}
.card-summary{margin:0;color:var(--muted);font-size:.88rem;overflow-wrap:anywhere}
.card-summary:empty{display:none}
.card-usage{margin:0;color:var(--muted);font-size:.78rem}
.card-note{margin:0;color:var(--muted);font-size:.76rem}
.tags{display:flex;flex-wrap:wrap;gap:5px}
.pill{font-size:.74rem;padding:2px 8px;border-radius:999px;background:var(--sunk);color:var(--muted);border:1px solid transparent;white-space:nowrap}
.pill-status.s-live{background:var(--ok-soft);color:var(--ok)}
.pill-status.s-dev{background:var(--accent-soft);color:var(--accent)}
.pill-status.s-stop{background:var(--sunk);color:var(--muted);border-color:var(--line)}
.tone-bad{background:var(--bad-soft);color:var(--bad)}
.tone-warn{background:var(--warn-soft);color:var(--warn)}
.tone-muted{background:transparent;color:var(--muted);border-color:var(--line)}
.card-actions{display:flex;gap:8px;padding:0 14px 14px;flex-wrap:wrap}
.card-actions button{flex:1 1 auto}

/* ── 보기 방식(목록/격자) ── */
.head-actions{display:flex;align-items:center;gap:8px}
.seg{display:inline-flex;border:1px solid var(--line);border-radius:8px;overflow:hidden}
.seg button{border:0;border-radius:0;min-height:36px;padding:4px 12px;font-size:.82rem;background:var(--surface);color:var(--muted)}
.seg button+button{border-left:1px solid var(--line)}
.seg button[aria-pressed="true"]{background:var(--accent-soft);color:var(--accent);font-weight:600}

/* 3×3 격자: 폰(400px)에서 한 줄에 3칸 */
.list.grid3{grid-template-columns:repeat(3, minmax(0, 1fr));gap:10px}
.tile{display:flex;flex-direction:column;gap:4px;min-width:0;color:inherit;text-decoration:none}
.tile.is-hidden{opacity:.55}
.tile-shot{height:auto;aspect-ratio:1;border:1px solid var(--line);border-radius:14px;background:var(--surface)}
.tile-shot .shot-emoji{font-size:2.4rem}
a.tile:active .tile-shot{transform:scale(.97)}
a.tile:focus-visible{outline:2px solid var(--accent);outline-offset:2px;border-radius:14px}
.tile-dot{position:absolute;top:7px;right:7px;width:10px;height:10px;border-radius:50%;border:2px solid var(--surface);z-index:1}
.dot-ok{background:var(--ok)} .dot-bad{background:var(--bad)} .dot-warn{background:var(--warn)} .dot-muted{background:var(--muted)}
.tile-name{font-size:.84rem;font-weight:600;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;text-align:center;padding:0 2px}
.tile-sub{font-size:.7rem;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;text-align:center;color:var(--muted)}
.tone-text-bad{color:var(--bad)} .tone-text-warn{color:var(--warn)}
