:root {
  --bg: #14161c; --card: #1e2129; --card2: #262a34; --line: #323744; --text: #eceef3; --dim: #9aa1b1;
  --acc: #ffb547; --acc-ink: #1b1406; --ok: #5bd18b; --bad: #ff6b6b; --blue: #6aa8ff;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.45 system-ui, -apple-system, "Apple SD Gothic Neo", "Noto Sans KR", sans-serif; }
body { padding: env(safe-area-inset-top) 0 calc(76px + env(safe-area-inset-bottom)); }
.loading { padding: 40vh 0; text-align: center; color: var(--dim); }
.wrap { max-width: 560px; margin: 0 auto; padding: 14px 14px 30px; }
h1 { font-size: 22px; margin: 6px 2px 14px; display: flex; align-items: center; gap: 8px; }
h1 small { font-size: 13px; color: var(--dim); font-weight: 500; margin-left: auto; }
h2 { font-size: 15px; color: var(--dim); margin: 22px 4px 8px; font-weight: 600; }
.card { background: var(--card); border-radius: 16px; padding: 14px; margin-bottom: 10px; }
.row { display: flex; align-items: center; gap: 10px; }
.row.wrapr { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.dim { color: var(--dim); font-size: 14px; }
.small { font-size: 13px; }
.ok { color: var(--ok); } .bad { color: var(--bad); } .accent { color: var(--acc); }
button, .btn { font: inherit; border: 0; border-radius: 12px; padding: 10px 14px; background: var(--card2); color: var(--text); cursor: pointer; }
button:active { transform: scale(.97); }
button.primary { background: var(--acc); color: var(--acc-ink); font-weight: 700; }
button.danger { background: #3a2226; color: var(--bad); }
button.ghost { background: transparent; color: var(--dim); padding: 6px 8px; }
button.chip { padding: 7px 12px; border-radius: 999px; font-size: 14px; }
button.chip.on { background: var(--acc); color: var(--acc-ink); font-weight: 700; }
button:disabled { opacity: .45; }
.btns { display: flex; flex-wrap: wrap; gap: 8px; }
.btns.full > * { flex: 1; }
input, select, textarea { font: inherit; color: var(--text); background: var(--card2); border: 1px solid var(--line); border-radius: 10px; padding: 9px 10px; width: 100%; }
input[type=time] { font-size: 26px; font-weight: 700; padding: 4px 10px; width: auto; min-width: 0; letter-spacing: 1px; }
input[type=number] { width: 84px; }
input[type=checkbox] { width: 20px; height: 20px; accent-color: var(--acc); }
textarea { min-height: 60px; resize: vertical; }
label.f { display: block; margin: 12px 0 5px; color: var(--dim); font-size: 14px; }

.next { background: linear-gradient(135deg, #2b2416, #1e2129 60%); }
.next .big { font-size: 34px; font-weight: 800; letter-spacing: .5px; }
.next .when { color: var(--acc); font-weight: 700; }
.rest { background: #1d2a22; color: #b9ecc9; border-radius: 12px; padding: 10px 12px; margin-top: 10px; font-size: 14px; }
.off-list { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.off-list span { background: #2a3a30; border-radius: 999px; padding: 4px 4px 4px 10px; font-size: 13px; display: inline-flex; align-items: center; gap: 2px; }
.off-list span button { padding: 0 8px; background: transparent; color: #b9ecc9; }

.rule { display: flex; gap: 12px; align-items: center; cursor: pointer; }
.rule .t { font-size: 30px; font-weight: 800; min-width: 92px; }
.rule.disabled .t, .rule.disabled .grow { opacity: .4; }
.rule .name { font-weight: 700; }
.rule .sum { color: var(--dim); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sw { position: relative; width: 50px; height: 30px; flex: none; }
.sw input { opacity: 0; width: 100%; height: 100%; position: absolute; margin: 0; z-index: 1; cursor: pointer; }
.sw span { position: absolute; inset: 0; background: var(--line); border-radius: 999px; transition: .2s; }
.sw span::after { content: ""; position: absolute; width: 24px; height: 24px; left: 3px; top: 3px; border-radius: 50%; background: #fff; transition: .2s; }
.sw input:checked + span { background: var(--acc); }
.sw input:checked + span::after { transform: translateX(20px); }

.days { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.days button { padding: 10px 0; border-radius: 10px; }
.days button.on { background: var(--acc); color: var(--acc-ink); font-weight: 700; }
.days button.sun { color: #ff8f8f; } .days button.sat { color: #8fb8ff; }
.days button.on.sun, .days button.on.sat { color: var(--acc-ink); }
.seg { display: flex; flex-wrap: wrap; gap: 6px; }

.step { background: var(--card2); border-radius: 12px; padding: 10px; margin-bottom: 8px; border-left: 4px solid var(--line); }
.step.cond { border-left-color: var(--blue); }
.step .hd { display: flex; align-items: center; gap: 6px; margin-bottom: 6px; color: var(--dim); font-size: 13px; }
.step .hd b { color: var(--text); }
.step select { margin-bottom: 6px; }
.step .params { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; font-size: 14px; color: var(--dim); }
.step .params textarea, .step .params input[type=text] { flex-basis: 100%; }
.vars { font-size: 12px; color: var(--dim); margin-top: 4px; }
.vars code { background: #333847; padding: 1px 5px; border-radius: 5px; color: #cfd5e3; cursor: pointer; }

.tmpl { display: grid; gap: 8px; }
.tmpl button { text-align: left; padding: 12px; }
.tmpl button b { display: block; }
.tmpl button span { color: var(--dim); font-size: 13px; }

.log { font-size: 13px; border-top: 1px solid var(--line); padding: 8px 0; }
.log:first-child { border-top: 0; }

nav.tabs { position: fixed; bottom: 0; left: 0; right: 0; background: #181b22f0; backdrop-filter: blur(10px); display: flex; padding: 6px 6px calc(6px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); z-index: 5; }
nav.tabs button { flex: 1; background: transparent; color: var(--dim); font-size: 13px; padding: 8px 0; }
nav.tabs button.on { color: var(--acc); font-weight: 700; }
nav.tabs button i { display: block; font-style: normal; font-size: 20px; }

.sheet-bg { position: fixed; inset: 0; background: #0009; z-index: 10; display: flex; align-items: flex-end; justify-content: center; }
.sheet-bg.center { align-items: center; padding: 20px; }
.sheet { background: var(--bg); width: 100%; max-width: 560px; max-height: 92vh; max-height: 92dvh; overflow: auto; overscroll-behavior: contain; border-radius: 18px 18px 0 0; padding: 0 14px calc(20px + env(safe-area-inset-bottom)); }
.sheet .top { display: flex; align-items: center; gap: 8px; position: sticky; top: 0; background: var(--bg); padding: 12px 0 10px; z-index: 2; border-bottom: 1px solid var(--line); margin-bottom: 10px; }
.sheet .top h3 { margin: 0; flex: 1; font-size: 18px; }

#toast { position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%); background: #f1f3f8; color: #111; padding: 10px 16px; border-radius: 12px; font-size: 14px; opacity: 0; pointer-events: none; transition: .25s; z-index: 50; max-width: 90vw; text-align: center; }
#toast.show { opacity: 1; }
.code { font-size: 40px; font-weight: 800; letter-spacing: 8px; text-align: center; color: var(--acc); }
.login { max-width: 380px; margin: 14vh auto 0; padding: 20px; }
.login input { font-size: 28px; text-align: center; letter-spacing: 6px; }
.pill { display: inline-block; padding: 2px 8px; border-radius: 999px; background: var(--card2); font-size: 12px; color: var(--dim); }

/* ---- 휴대폰 화면 ---- */
@media (max-width: 600px) {
  .wrap { padding: 10px 12px 24px; }
  h1 { font-size: 19px; flex-wrap: wrap; row-gap: 2px; }
  h1 small { margin-left: 0; width: 100%; font-size: 12px; }
  h2 { font-size: 14px; margin: 16px 4px 6px; }
  .card { padding: 12px; border-radius: 14px; margin-bottom: 8px; }
  button, .btn { padding: 9px 12px; border-radius: 10px; }
  button.chip { padding: 6px 11px; font-size: 13.5px; }
  input, select, textarea { padding: 8px 10px; font-size: 15px; }
  .next .big { font-size: 30px; }
  .rule { gap: 10px; }
  .rule .t { font-size: 24px; min-width: 70px; }
  .sw { width: 46px; height: 28px; } .sw span::after { width: 22px; height: 22px; } .sw input:checked + span::after { transform: translateX(18px); }
  .days { gap: 4px; } .days button { padding: 8px 0; font-size: 14px; }
  .step { padding: 8px; } .step select { font-size: 14px; }
  .step .params { gap: 6px; font-size: 13px; }
  input[type=number] { width: 64px; padding: 6px 6px; }
  /* 편집 화면은 전체 화면으로 */
  .sheet-bg:not(.center) { align-items: stretch; background: var(--bg); }
  .sheet { max-height: none; height: 100%; border-radius: 0; max-width: none; }
  nav.tabs button { font-size: 12px; padding: 6px 0; } nav.tabs button i { font-size: 18px; }
  .code { font-size: 34px; letter-spacing: 6px; }
}
input[type=date] { min-height: 40px; }
input[type=date]:invalid, input[type=date][value=""] { color: var(--dim); }

/* ---- 목록 선택 모드 ---- */
.rule { -webkit-touch-callout: none; -webkit-user-select: none; user-select: none; touch-action: manipulation; }
.rule.selmode { border: 2px solid transparent; }
.rule.picked { border-color: var(--acc); background: #2b2416; }
.rule .tick { width: 26px; height: 26px; flex: none; border-radius: 50%; border: 2px solid var(--line); display: flex; align-items: center; justify-content: center; font-weight: 800; color: var(--acc-ink); }
.rule.picked .tick { background: var(--acc); border-color: var(--acc); }
.sect { display: flex; align-items: center; } .sect h2 { flex: 1; }
.selbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 6; display: flex; gap: 8px; padding: 10px 12px calc(10px + env(safe-area-inset-bottom)); background: #181b22; border-top: 1px solid var(--line); }
.selbar button { flex: 1; padding: 13px 0; font-weight: 700; }
.dialog { background: var(--card); border-radius: 18px; padding: 20px; width: 100%; max-width: 380px; }
.install { border: 1px solid #4a3c1e; }
.ip { font-size: 12px; color: var(--blue); font-family: ui-monospace, Menlo, monospace; }
