/* 작업 상황판 - 폰박스(PhoneBox)풍
   새까만 바탕 + 짙은 회색 카드 + 엷은 테두리. 카드 이름은 영어 대문자, 카드마다 정해진 색.
   빨강은 승인 대기에만 쓴다. */

:root {
  --bg: #000;
  --card: #111214;
  --card-photo: rgba(17, 18, 20, 0.8); /* 배경 사진이 있을 때 살짝 비치는 카드 */
  --line: rgba(255, 255, 255, 0.08);
  --text: #f3f3f3;
  --sub: #a3a5aa;
  --muted: #62656b;
  --green: #78e04a;
  --blue: #3d9bff;
  --orange: #ff9d2e;
  --purple: #a875ff;
  --red: #ff4a4a;
  --radius: 22px;
  --gap: 14px;
  /* 화면 크기에 맞춰 글자와 여백이 같이 커지고 작아지게 하는 기준 단위 */
  --u: min(1vh, 0.6vw);
  --font: "Roboto", "Segoe UI", "Malgun Gothic", "Apple SD Gothic Neo", "Noto Sans KR", system-ui, sans-serif;
  --mono: "Roboto Mono", "Consolas", "D2Coding", monospace;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}

button { font: inherit; color: inherit; }

/* ── 배경 ─────────────────────────────────────────── */
.bg {
  position: fixed;
  inset: 0;
  z-index: 0;
  background: #000 center / cover no-repeat;
}
/* 사진 위에 검은 막을 덮어서 은은하게만 보이게 */
.bg::after {
  content: "";
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.68);
  display: none;
}
body.has-photo .bg::after { display: block; }
body[data-theme="night"] .bg::after { background: rgba(0, 0, 0, 0.85); }

/* ── 맨 위 줄 ─────────────────────────────────────── */
.top {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 48px;
  padding: 0 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  z-index: 5;
}
.conn {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: max(14px, calc(var(--u) * 2.4));
  color: var(--sub);
}
.conn { min-width: 0; white-space: nowrap; }
#conn-text { overflow: hidden; text-overflow: ellipsis; }
.bg-btn { white-space: nowrap; flex: none; }
.conn-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--muted); flex: none; }
body[data-conn="ok"] .conn-dot { background: var(--green); }

.top-right { position: relative; display: flex; align-items: center; gap: 14px; }
.mini-clock {
  font-weight: 300;
  font-size: max(18px, calc(var(--u) * 3.6));
  font-variant-numeric: tabular-nums;
}
body.clock-here .mini-clock { visibility: hidden; } /* 지금 페이지에 큰 시계가 있으면 숨김 */

.bg-btn {
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 14px;
  color: var(--sub);
  font-size: 13px;
  cursor: pointer;
}
.bg-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  min-width: 210px;
  padding: 6px;
  display: flex;
  flex-direction: column;
  background: #18191c;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 14px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.6);
}
.bg-menu[hidden] { display: none; }
.bg-menu button {
  background: none;
  border: 0;
  border-radius: 9px;
  padding: 11px 12px;
  text-align: left;
  font-size: 15px;
  cursor: pointer;
}
.bg-menu button:hover { background: rgba(255, 255, 255, 0.06); }
.bg-note { margin: 4px 12px 8px; font-size: 12px; color: var(--muted); }

/* ── 옆으로 넘기는 페이지 ─────────────────────────── */
.pages {
  position: fixed;
  inset: 0;
  z-index: 1;
  display: flex;
  overflow-x: auto;
  overflow-y: hidden;
  scroll-snap-type: x mandatory;
  overscroll-behavior-x: contain;
  scrollbar-width: none;
}
.pages::-webkit-scrollbar { display: none; }

.page {
  flex: 0 0 100%;
  height: 100%;
  min-width: 0;
  padding: 56px 28px 44px;
  /* 페이지마다 16x16 칸. 위젯은 칸 단위로 자리와 크기를 가진다 (1-4) */
  display: grid;
  grid-template-columns: repeat(16, minmax(0, 1fr));
  grid-template-rows: repeat(16, minmax(0, 1fr));
  gap: var(--gap);
  overflow: hidden;
  scroll-snap-align: start;
  scroll-snap-stop: always;
  container-type: size; /* 카드 여백이 페이지 크기를 기준으로 정해지게 */
}

/* ── 카드 공통 ────────────────────────────────────── */
.card {
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  text-align: left;
  /* 위젯 크기를 기준으로 글자 크기가 정해지게 하는 단위 (컨테이너 쿼리).
     카드 안의 글자는 모두 이 --u 를 쓰므로 위젯을 키우면 글자도 커진다 */
  container-type: size;
  --u: min(2.2cqh, 1.6cqw);
  padding: clamp(10px, 3cqmin, 28px) clamp(12px, 3.4cqmin, 32px);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
body.has-photo .card { background: var(--card-photo); }

.label {
  margin: 0 0 calc(var(--u) * 1.4);
  font-size: max(11px, calc(var(--u) * 1.9));
  font-weight: 700;
  letter-spacing: 0.32em;
  text-transform: uppercase;
  color: var(--muted);
}
.c-green { color: var(--green); }
.c-blue { color: var(--blue); }
.c-orange { color: var(--orange); }
.c-purple { color: var(--purple); }
.c-red { color: var(--red); }

/* 숫자는 아주 얇게 크게 */
.value {
  margin: 0;
  font-size: calc(var(--u) * 9);
  font-weight: 200;
  line-height: 1.05;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.text {
  margin: calc(var(--u) * 1) 0 0;
  font-size: max(15px, calc(var(--u) * 2.9));
  font-weight: 400;
  line-height: 1.3;
  color: #d9dadd;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.text.sub { color: var(--sub); }
.text:empty { display: none; }

.bar {
  margin-top: auto;
  height: max(6px, calc(var(--u) * 1.1));
  border-radius: 99px;
  background: rgba(255, 255, 255, 0.1);
  overflow: hidden;
}
.bar > span { display: block; height: 100%; width: 0; background: var(--green); border-radius: inherit; }

.spark { margin-top: auto; width: 100%; height: calc(var(--u) * 7); display: block; }
svg .line { fill: none; stroke: currentColor; stroke-width: 2; vector-effect: non-scaling-stroke; }
svg .area { fill: currentColor; opacity: 0.12; stroke: none; }

/* 데이터를 한 번도 못 받았으면 내용을 숨긴다 ('할 일 없음'으로 오해하지 않게) */
body[data-has-data="no"] .dv { visibility: hidden; }

/* ── 홈: 시계 ─────────────────────────────────────── */
.clock-card { justify-content: center; cursor: pointer; }
.clock-time {
  display: flex;
  align-items: flex-start;
  font-size: calc(var(--u) * 22);
  font-weight: 100;
  line-height: 0.95;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}
.clock-time sup {
  margin: 0.12em 0 0 0.18em;
  font-size: 0.24em;
  font-weight: 300;
  color: #d6d6d6;
}
.clock-date {
  margin-top: calc(var(--u) * 1.6);
  font-size: max(16px, calc(var(--u) * 3.4));
  font-weight: 300;
  color: #e2e2e2;
}

/* ── 홈: 승인 카드 ────────────────────────────────── */
.approval-card { cursor: pointer; justify-content: flex-start; }
.approval-card.on { border-color: rgba(255, 74, 74, 0.75); }
.approval-card.on .label { color: var(--red); }
.pulse {
  position: absolute;
  top: calc(var(--u) * 3.6);
  right: calc(var(--u) * 3.6);
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--red);
  box-shadow: 0 0 12px var(--red);
  display: none;
  animation: pulse 1.6s ease-in-out infinite;
}
.approval-card.on .pulse { display: block; }
@keyframes pulse { 50% { opacity: 0.35; } }

.big-ko {
  margin: calc(var(--u) * 0.6) 0 0;
  font-size: calc(var(--u) * 7.2);
  font-weight: 400;
  line-height: 1.15;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.approval-card:not(.on) .big-ko, .ap-empty .big-ko { font-weight: 300; color: var(--sub); }

/* ── 승인 자세히 위젯 ─────────────────────────────── */
/* 넓으면 오른쪽에 목록, 좁으면 아래에 목록 (2건 이상일 때만) */
.ap-wrap { flex: 1; min-height: 0; display: flex; flex-direction: column; gap: calc(var(--u) * 2.4); }
.ap-main { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.ap-side { display: none; min-height: 0; flex-direction: column; }
.approve-card.multi .ap-side { display: flex; max-height: 38%; }
@container (min-width: 640px) {
  .approve-card.multi .ap-wrap { display: grid; grid-template-columns: minmax(0, 2.3fr) minmax(0, 1fr); }
  .approve-card.multi .ap-side { max-height: none; border-left: 1px solid var(--line); padding-left: calc(var(--u) * 2.4); }
}
.ap-body, .ap-empty { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.ap-body[hidden], .ap-empty[hidden] { display: none; }
.ap-head {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.6em;
  font-size: max(15px, calc(var(--u) * 2.9));
  color: var(--sub);
}
.ap-star { width: 1.1em; height: 1.1em; color: var(--orange); flex: none; }
.ap-wait { display: inline-flex; align-items: center; gap: 0.4em; margin-left: 0.4em; color: var(--red); }
.ap-wait::before { content: ""; width: 0.5em; height: 0.5em; border-radius: 50%; background: var(--red); }
.ap-title {
  margin: calc(var(--u) * 2) 0 0;
  font-size: calc(var(--u) * 7.4);
  font-weight: 700;
  line-height: 1.15;
  word-break: keep-all;
}
.ap-desc {
  margin: calc(var(--u) * 1.2) 0 0;
  font-size: max(16px, calc(var(--u) * 3.2));
  font-weight: 300;
  color: var(--sub);
}
.ap-detail {
  margin-top: calc(var(--u) * 3);
  padding: calc(var(--u) * 2.6) calc(var(--u) * 3);
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid var(--line);
  border-radius: 16px;
  font-family: var(--mono);
  font-size: max(15px, calc(var(--u) * 3));
  line-height: 1.75;
}
.ap-detail:empty { display: none; }
.ap-detail p { margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ap-actions { margin-top: auto; padding-top: calc(var(--u) * 2); display: flex; justify-content: flex-end; }
.btn-green {
  padding: calc(var(--u) * 2) calc(var(--u) * 6);
  border-radius: 16px;
  background: #2fe05a;
  color: #04140a;
  font-weight: 700;
  font-size: max(16px, calc(var(--u) * 3.2));
  text-decoration: none;
}
.ap-empty { justify-content: center; }

.ap-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; overflow: auto; }
.ap-list button {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 12px 14px;
  text-align: left;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--line);
  border-radius: 14px;
  cursor: pointer;
}
.ap-list button.sel { border-color: rgba(255, 74, 74, 0.6); }
.ap-list .n { font-size: max(15px, calc(var(--u) * 2.7)); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ap-list .m { font-size: 13px; color: var(--red); }

/* ── 진행 · 끝난 작업 · 다음 · 예정 위젯 ───────────── */
.w-progress .value, .w-done .value, .w-next .value, .w-schedule .value { font-size: calc(var(--u) * 11.5); }
.bar-row { display: flex; align-items: center; gap: 16px; margin-top: calc(var(--u) * 2.6); }
.bar-row .bar { flex: 1; margin: 0; }
.pct { font-size: max(15px, calc(var(--u) * 3)); font-weight: 300; }
#jp-others { margin-top: auto; }

.done-wrap {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr);
  gap: calc(var(--u) * 3);
}
.done-list {
  list-style: none;
  margin: calc(var(--u) * 1.6) 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: calc(var(--u) * 1.1);
  font-size: max(14px, calc(var(--u) * 2.7));
}
.done-list li { display: flex; gap: 1em; white-space: nowrap; overflow: hidden; }
.done-list .t { font-family: var(--mono); color: #d0d0d0; }
.done-list .n { overflow: hidden; text-overflow: ellipsis; }
.done-list .more { color: var(--sub); }
.chart { display: flex; flex-direction: column; justify-content: flex-end; min-height: 0; }
.chart svg { width: 100%; height: calc(var(--u) * 18); min-height: 50px; }
.axis { display: flex; justify-content: space-between; margin-top: 6px; font-size: 12px; color: var(--sub); }
/* 오늘 끝난 작업 위젯이 좁으면 목록만, 아주 낮으면 숫자만 */
@container (max-width: 420px) {
  .done-wrap { grid-template-columns: minmax(0, 1fr); }
  .chart { display: none; }
}
@container (max-height: 200px) {
  .done-list { display: none; }
}

.divider { margin: auto 0 calc(var(--u) * 1.6); padding-top: calc(var(--u) * 1.6); border-bottom: 1px solid var(--line); }
.sched-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; font-size: max(14px, calc(var(--u) * 2.7)); color: #d9dadd; }
.sched-list li { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sched-list .d { font-family: var(--mono); margin-right: 0.8em; }

/* 노트북: 깨어 있으면 보라 심장 박동 선, 아니면 회색 평평한 선 */
.laptop .value { color: var(--muted); }
.laptop .value { font-size: calc(var(--u) * 7.5); } /* 한글 문구라 숫자보다 작게 */
.laptop .spark { color: var(--muted); }
.laptop .beat { display: none; }
.laptop.awake .value { color: var(--text); }
.laptop.awake .spark { color: var(--purple); }
.laptop.awake .beat { display: inline; }
.laptop.awake .flat { display: none; }

/* ── 클로드 코드 · Aside: 프로젝트별 한 줄 ─────────── */
.c-white { color: #e6e6e6; }
.agent-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: calc(var(--u) * 1.3);
  font-size: max(15px, calc(var(--u) * 3));
  overflow: hidden;
}
.agent-list li { display: flex; align-items: center; gap: 0.6em; white-space: nowrap; min-width: 0; }
.agent-list .n { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.agent-list .st { color: var(--sub); }
.agent-list .t { color: var(--muted); font-variant-numeric: tabular-nums; min-width: 3.2em; text-align: right; }
.agent-list .empty, .agent-list .more { color: var(--muted); }
/* 신호등 점 */
.sig { width: 0.62em; height: 0.62em; border-radius: 50%; flex: none; }
.sig.approval { background: var(--red); box-shadow: 0 0 8px var(--red); }
.sig.done { background: var(--orange); }
.sig.working { background: var(--blue); }
.sig.idle { background: #f2f2f2; }

/* ── 예약 현황 트리 · 작업 진행 트리 (1-5) ──────────── */
/* 줄을 누르면 아래에 예약(또는 SNS별 진행)이 펼쳐진다. 빨강은 승인에만 쓰므로 경고는 주황 */
.tree {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: calc(var(--u) * 1.2);
  font-size: max(14px, calc(var(--u) * 2.9));
  /* 펼쳐서 위젯보다 길어지면 위젯 안에서 위아래로 스크롤.
     브라우저에는 위아래만 맡기고(pan-y), 옆으로 밀기는 app.js 가 받아 페이지를 넘긴다
     (브라우저에 맡기면 트리 맨 아래에서 옆으로 밀 때 크롬 '뒤로 가기'가 될 때가 있음) */
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior-y: contain;
  touch-action: pan-y;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.25) transparent;
  min-height: 0;
}
.tree-card > .label, .tree-foot { flex: none; } /* 제목과 아래 글은 줄어들지 않고 트리만 스크롤 */
body.editing .tree { overflow: hidden; touch-action: none; } /* 편집 중에는 위젯 끌기가 먼저 */
.tree > li { flex: none; min-width: 0; }
.tree .empty { color: var(--muted); }
.tree-row {
  display: flex;
  align-items: center;
  gap: 0.55em;
  width: 100%;
  padding: 0.1em 0;
  border: 0;
  background: none;
  text-align: left;
  white-space: nowrap;
  cursor: pointer;
  min-width: 0;
}
.tree-row .arrow { flex: none; width: 0.9em; color: var(--muted); }
.tree-row .n { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.tree-row .m { flex: none; color: var(--sub); font-variant-numeric: tabular-nums; }
.tree-row .m.warn { color: var(--orange); }
.tree-row .m.ok { color: var(--green); }
.tree .finished .n { color: var(--sub); }
.tree-sub {
  list-style: none;
  margin: 0.35em 0 0.2em 1.45em;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.3em;
  font-size: 0.86em;
  color: #d9dadd;
}
.tree-sub li { display: flex; align-items: center; gap: 0.6em; white-space: nowrap; font-variant-numeric: tabular-nums; }
.tree-sub .mark { width: 1em; text-align: center; color: var(--sub); }
.tree-sub .ok, .tree-sub .ok .mark { color: var(--green); }
.tree-sub .past { color: var(--muted); }
.tree-sub .cn { width: 6.5em; flex: none; overflow: hidden; text-overflow: ellipsis; }
.tree-sub .bar { flex: 1; margin: 0; }
.tree-sub .cnt { flex: none; min-width: 3.2em; text-align: right; color: var(--sub); }
/* 좁은 위젯에서는 '다음 예약' 시각을 숨겨서 이름과 경고가 보이게 */
@container (max-width: 300px) { .tree-row .next { display: none; } }
.tree-foot { margin: auto 0 0; padding-top: calc(var(--u) * 1); font-size: max(12px, calc(var(--u) * 2.1)); color: var(--muted); }
.tree-foot:empty { display: none; }

/* ── 업무 메일 (1-5): 있으면 주황, 없으면 차분하게, 예전 값·실패는 회색 ── */
.mail-card { justify-content: center; }
.mail-card.unread { border-color: var(--orange); }
.mail-card.unread .label, .mail-card.unread .big-ko { color: var(--orange); }
.mail-card.stale .big-ko, .mail-card.stale .text { color: var(--muted); }

/* 12시간 넘은 승인 요청: 빨강 대신 회색 */
.ap-wait.old { color: var(--muted); }
.ap-wait.old::before { background: var(--muted); }
.ap-list .m.old { color: var(--muted); }

/* ── 페이지 점 ────────────────────────────────────── */
.dots {
  position: fixed;
  bottom: 10px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 5;
  display: flex;
  gap: 4px;
}
.dots button { width: 24px; height: 24px; padding: 0; border: 0; background: none; cursor: pointer; display: grid; place-items: center; }
.dots button::after { content: ""; width: 8px; height: 8px; border-radius: 50%; background: rgba(255, 255, 255, 0.25); }
.dots button[aria-current="true"]::after { background: #fff; }

/* ── 승인 대기 중 빨간 테두리 ─────────────────────── */
.alert-frame {
  position: fixed;
  inset: 3px;
  z-index: 6;
  border: 2px solid var(--red);
  border-radius: 18px;
  pointer-events: none;
  display: none;
}
body.alert .alert-frame { display: block; }

/* ── 새 승인 3·2·1 알림 ──────────────────────────── */
.toast {
  position: fixed;
  left: 28px;
  bottom: 46px;
  z-index: 7;
  max-width: calc(100vw - 56px);
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 16px;
  background: #141518;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 20px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.6);
}
.toast[hidden] { display: none; }
.ring { position: relative; width: 52px; height: 52px; flex: none; }
.ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring circle { fill: none; stroke-width: 4; }
.ring-bg { stroke: rgba(255, 255, 255, 0.12); }
.ring-fg { stroke: var(--green); stroke-linecap: round; stroke-dasharray: 119.4; stroke-dashoffset: 0; }
.toast.run .ring-fg { animation: ring 3s linear forwards; }
@keyframes ring { to { stroke-dashoffset: 119.4; } }
.ring span { position: absolute; inset: 0; display: grid; place-items: center; font-size: 20px; font-weight: 300; }
.toast-text { display: flex; flex-direction: column; gap: 2px; padding-left: 16px; border-left: 1px solid var(--line); min-width: 0; }
.toast-text strong { font-size: 17px; font-weight: 600; }
.toast-text span { font-size: 13px; color: var(--sub); }
.toast button {
  padding: 8px 14px;
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 10px;
  font-size: 14px;
  white-space: nowrap;
  cursor: pointer;
}
#toast-go { background: rgba(255, 255, 255, 0.12); }

/* ── 야간: 화면 전체를 어둡게 낮춘다 (빨간 테두리는 그대로 남김) ──
   예전에는 화면 전체에 filter 를 걸었는데, 폰에서는 위젯이 움직일 때마다 화면 전체를 다시 계산해서 끊겼다.
   지금은 반투명 검은 막 한 장을 위에 덮기만 한다 (막은 손가락 입력을 막지 않음) */
body::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 5;              /* 위젯·맨 위 줄·점 위, 빨간 테두리(6)·알림(7) 아래 */
  background: #000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.6s;
}
body[data-theme="night"]::after { opacity: 0.45; }

/* ── 연결 끊김: 화면 전체를 회색으로 (절대 규칙 5번) ── */
body[data-conn="offline"] .pages,
body[data-conn="offline"] .top,
body[data-conn="offline"] .dots,
body[data-conn="offline"] .bg { filter: grayscale(1) brightness(0.5); }
body[data-conn="offline"][data-theme="night"] .pages { filter: grayscale(1) brightness(0.35); }
body[data-conn="offline"] .alert-frame,
body[data-conn="offline"] .toast { display: none; }

.offline {
  position: fixed;
  inset: 0;
  z-index: 8;
  display: grid;
  place-items: center;
  background: rgba(60, 60, 60, 0.25);
  pointer-events: none;
}
.offline[hidden] { display: none; }
.offline-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 26px 40px;
  text-align: center;
  background: rgba(32, 32, 34, 0.94);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 22px;
}
.offline-box strong { font-size: max(26px, calc(var(--u) * 6)); font-weight: 300; letter-spacing: 0.04em; color: #ddd; }
.offline-box span { font-size: max(15px, calc(var(--u) * 2.8)); color: #bbb; }
.offline-box small { font-size: 13px; color: #888; }

/* ── 좁은 세로 화면 (폴드5 접은/펼친 화면) ─────────── */
/* 위젯 안 글자는 위젯 크기를 따르므로, 여기서는 맨 위 줄과 칸 사이만 줄인다 */
@media (max-width: 760px) {
  :root { --u: min(1.15vw, 5.5px); --gap: 8px; }
  .top, .edit-bar { padding: 0 12px; }
  .top-right { gap: 6px; }
  .bg-btn { padding: 5px 10px; }
  .edit-title { display: none; }  /* 좁은 화면에서는 버튼 자리를 넓게 */
  /* 편집 버튼이 오른쪽으로 숨지 않게 두 줄로.
     앞에 body 를 붙인 건, 아래쪽 '편집 화면' 기본 규칙(높이 48px)이 이 규칙을 덮어서
     첫 줄 버튼이 화면 위로 잘려 나갔기 때문 (주소 표시줄과 겹쳐 보이던 원인).
     버튼 줄은 맨 위 가장자리에서 조금 내리고(카메라 구멍 자리 env(...)도 피함), 버튼은 손가락 크기로 */
  body .edit-bar { height: auto; padding: calc(16px + env(safe-area-inset-top, 0px)) 10px 8px; }
  body .edit-actions { flex-wrap: wrap; justify-content: flex-end; gap: 8px; }
  body .edit-actions button { min-height: 40px; padding: 8px 14px; font-size: 14px; }
  .edit-bar .add-menu { top: calc(100% + 4px); }
  body.editing .page { padding-top: calc(124px + env(safe-area-inset-top, 0px)); }
  .page { padding: 52px 12px 40px; }
  .toast { left: 12px; right: 12px; bottom: 44px; flex-wrap: wrap; }
}

/* ── 편집 화면 (1-4) ──────────────────────────────── */
body.editing .top { display: none; }
.edit-bar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 48px;
  padding: 0 28px;
  z-index: 9;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: rgba(0, 0, 0, 0.85);
  border-bottom: 1px solid var(--line);
}
.edit-bar[hidden] { display: none; }
.edit-title { font-size: 14px; color: var(--sub); white-space: nowrap; }
.edit-actions { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; }
.edit-actions button {
  padding: 7px 12px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 10px;
  background: transparent;
  font-size: 13px;
  white-space: nowrap;
  cursor: pointer;
}
.edit-actions button.primary { background: #f2f2f2; color: #000; border-color: #f2f2f2; font-weight: 700; }
.edit-actions button:disabled { opacity: 0.35; cursor: default; }
.add-menu { top: 52px; right: 12px; max-height: 70vh; overflow: auto; }

/* 칸 눈금: 16x16 칸 사이 틈을 옅은 줄로 보여 준다.
   예전에는 작은 상자 256개(페이지마다)를 만들었는데 폰에서 무거워서, 배경 무늬 한 장으로 바꿨다 */
body.editing .page {
  background-image:
    linear-gradient(to right, transparent calc(100% - var(--gap)), rgba(255, 255, 255, 0.07) 0),
    linear-gradient(to bottom, transparent calc(100% - var(--gap)), rgba(255, 255, 255, 0.07) 0);
  background-size: calc((100% + var(--gap)) / 16) calc((100% + var(--gap)) / 16);
  background-origin: content-box;
  background-clip: content-box;
}

body.editing .widget {
  z-index: 1;
  will-change: transform;  /* 움직일 위젯을 미리 따로 그려 두어서 끌 때 덜 끊기게 */
  touch-action: none;      /* 끄는 동안 페이지가 옆으로 밀리지 않게 */
  cursor: grab;
  user-select: none;
  outline: 1px dashed rgba(255, 255, 255, 0.35);
  outline-offset: -1px;
}
body.editing .widget.dragging { z-index: 3; cursor: grabbing; opacity: 0.85; outline: 2px solid #f2f2f2; }
body.editing .widget.bad { outline: 2px solid var(--red); }  /* 겹쳐서 놓을 수 없는 자리 */

/* 끄는 동안 '여기에 떨어진다'를 보여 주는 점선 상자 */
.drop-ghost {
  z-index: 0;
  pointer-events: none;
  border: 2px dashed rgba(255, 255, 255, 0.55);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.05);
  transition: all 120ms ease-out;
}
.drop-ghost.bad { border-color: var(--red); background: rgba(255, 74, 74, 0.08); }

/* 움직임을 줄이도록 설정한 기기에서는 미끄러짐 없이 바로 */
@media (prefers-reduced-motion: reduce) {
  .widget, .drop-ghost { transition: none !important; }
}
body.editing .widget > :not(.w-name):not(.w-del):not(.w-resize) { pointer-events: none; opacity: 0.55; }
.w-name, .w-del, .w-resize { display: none; }
body.editing .w-name {
  display: block;
  position: absolute;
  left: 10px; bottom: 8px;
  z-index: 2;
  padding: 3px 8px;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.75);
  font-size: 12px;
  color: #f2f2f2;
}
body.editing .w-del {
  display: grid;
  place-items: center;
  position: absolute;
  top: 6px; right: 6px;
  z-index: 2;
  width: 32px; height: 32px;
  border: 0;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.75);
  font-size: 15px;
  cursor: pointer;
}
body.editing .w-resize {
  display: block;
  position: absolute;
  right: 0; bottom: 0;
  z-index: 2;
  width: 30px; height: 30px;
  cursor: nwse-resize;
  background: linear-gradient(135deg, transparent 50%, rgba(255, 255, 255, 0.7) 50%);
  border-bottom-right-radius: var(--radius);
}

/* 편집 화면에서 잠깐 뜨는 안내 */
.hint {
  position: fixed;
  left: 50%;
  bottom: 48px;
  transform: translateX(-50%);
  z-index: 10;
  max-width: calc(100vw - 32px);
  padding: 10px 16px;
  border-radius: 12px;
  background: #1c1d20;
  border: 1px solid rgba(255, 255, 255, 0.18);
  font-size: 14px;
  text-align: center;
}
.hint[hidden] { display: none; }
