:root {
  --bg: #f4f6fa; --card: #ffffff; --line: #d9dfe8; --ink: #14213d; --muted: #5b6577;
  --navy: #1f3864; --accent: #2f5597; --danger: #b42318; --focus: #f2a900;
  --c-yellow: #fff4c2; --c-green: #dcf3e3; --c-blue: #dcebff; --c-pink: #ffe1ea; --c-purple: #ebe3ff; --c-gray: #eceef1;
  --r: 14px; --fs: 16px;
  color-scheme: light;
}
html.dark {
  --bg: #0f1420; --card: #1a2233; --line: #2c3850; --ink: #eef2f8; --muted: #a8b3c7;
  --navy: #9db8ff; --accent: #8fb0ff; --danger: #ff8a80;
  --c-yellow: #3a3418; --c-green: #183526; --c-blue: #182c48; --c-pink: #3d1d29; --c-purple: #2a2147; --c-gray: #262d3a;
  color-scheme: dark;
}
html.big { --fs: 20px; }
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  font: var(--fs)/1.55 -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Malgun Gothic", "Noto Sans KR", "Segoe UI", sans-serif;
  background: var(--bg); color: var(--ink);
  word-break: keep-all; overflow-wrap: anywhere;
  padding-bottom: calc(96px + env(safe-area-inset-bottom));
}
button, input, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.muted { color: var(--muted); font-size: .88em; }

.top {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 10px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px; background: var(--bg);
}
.brand { display: flex; align-items: center; gap: 8px; margin: 0; font-size: 1.15em; color: var(--navy); white-space: nowrap; }
.brand img { border-radius: 7px; }
.status { margin-left: auto; font-size: .8em; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.status.ok::before { content: "● "; color: #1a7f37; }
.status.off::before { content: "● "; color: #9aa4b2; }
.status.busy::before { content: "● "; color: #f2a900; }

.pill {
  min-height: 44px; padding: 0 16px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--card); cursor: pointer; font-weight: 600; white-space: nowrap;
}
.pill:hover { border-color: var(--accent); }
.pill.strong { background: var(--accent); color: #fff; border-color: var(--accent); }
html.dark .pill.strong { color: #0f1420; }
.pill.danger { color: var(--danger); }

.search-wrap { padding: 0 16px 10px; position: sticky; top: 60px; z-index: 4; background: var(--bg); }
#search {
  width: 100%; min-height: 48px; padding: 0 16px; border-radius: var(--r);
  border: 1px solid var(--line); background: var(--card);
}

.trash-bar { display: flex; align-items: center; gap: 10px; margin: 0 16px 10px; padding: 10px 14px; border-radius: var(--r); background: var(--c-gray); }
.trash-bar .pill { margin-left: auto; }

.list {
  display: grid; gap: 12px; padding: 0 16px;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); align-items: start;
}
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--r);
  padding: 14px 16px 10px; cursor: pointer; box-shadow: 0 1px 2px rgba(20, 33, 61, .06);
}
.card:hover { border-color: var(--accent); }
.card .text { white-space: pre-wrap; display: -webkit-box; -webkit-line-clamp: 10; -webkit-box-orient: vertical; overflow: hidden; }
.card .foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 8px; font-size: .8em; color: var(--muted); }
.card .foot .pill { min-height: 36px; font-size: .95em; }
.card.mark { box-shadow: 0 0 0 2px var(--focus); }
.c-yellow { background: var(--c-yellow); } .c-green { background: var(--c-green); } .c-blue { background: var(--c-blue); }
.c-pink { background: var(--c-pink); } .c-purple { background: var(--c-purple); } .c-gray { background: var(--c-gray); }
.empty { text-align: center; color: var(--muted); padding: 48px 16px; }

.composer {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6; display: flex; align-items: flex-end; gap: 8px;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom)); background: var(--bg); border-top: 1px solid var(--line);
}
#input {
  flex: 1; min-height: 52px; max-height: 40vh; resize: none; padding: 13px 16px; border-radius: 26px;
  border: 1.5px solid var(--accent); background: var(--card); line-height: 1.45;
}
.round { min-width: 52px; height: 52px; border-radius: 26px; border: 0; cursor: pointer; font-weight: 700; }
.save { padding: 0 20px; background: var(--navy); color: #fff; }
html.dark .save { color: #0f1420; }
.mic { background: var(--card); border: 1px solid var(--line); color: var(--accent); display: grid; place-items: center; }
.mic.on { background: #d92d20; color: #fff; border-color: #d92d20; }

.sheet {
  position: fixed; inset: 0; z-index: 20; background: var(--bg); display: flex; flex-direction: column;
  padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom);
}
.sheet[hidden] { display: none; }
.sheet-bar { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 16px; border-bottom: 1px solid var(--line); }
.colors { display: flex; gap: 10px; padding: 12px 16px 4px; flex-wrap: wrap; }
.colors button { width: 40px; height: 40px; border-radius: 50%; border: 2px solid var(--line); cursor: pointer; background: var(--card); }
.colors button[aria-checked="true"] { border: 3px solid var(--accent); box-shadow: 0 0 0 2px var(--card) inset; }
.colors .c-yellow { background: var(--c-yellow); } .colors .c-green { background: var(--c-green); } .colors .c-blue { background: var(--c-blue); }
.colors .c-pink { background: var(--c-pink); } .colors .c-purple { background: var(--c-purple); } .colors .c-gray { background: var(--c-gray); }
.conflict { margin: 8px 16px 0; padding: 10px 12px; border-radius: 10px; background: var(--c-yellow); font-size: .9em; }
.ed-text { flex: 1; margin: 12px 16px 16px; padding: 16px; border-radius: var(--r); border: 1px solid var(--line); background: var(--card); resize: none; line-height: 1.6; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.chips button { flex: none; min-height: 40px; padding: 0 14px; border-radius: 999px; border: 1px solid var(--accent); background: var(--card); color: var(--accent); font-weight: 700; cursor: pointer; }
.groups { overflow-y: auto; padding: 8px 16px 32px; }
.group { background: var(--card); border: 1px solid var(--line); border-left: 5px solid var(--accent); border-radius: var(--r); padding: 6px 16px 14px; margin-top: 12px; }
.group h2 { font-size: 1.05em; color: var(--navy); margin: 10px 0 6px; }
.row { display: flex; align-items: flex-start; gap: 12px; padding: 12px 0; cursor: pointer; border-top: 1px solid var(--line); }
.row:first-of-type { border-top: 0; }
.row span { display: flex; flex-direction: column; }
.row small { color: var(--muted); font-size: .85em; }
.switch {
  appearance: none; flex: none; width: 52px; height: 30px; border-radius: 15px; background: #b6bfcc; position: relative; cursor: pointer; margin: 2px 0 0; transition: background .15s;
}
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; transition: left .15s; box-shadow: 0 1px 2px rgba(0,0,0,.3); }
.switch:checked { background: #1a7f37; }
.switch:checked::after { left: 25px; }
.link-box { display: flex; flex-direction: column; gap: 6px; padding: 12px 0; border-top: 1px solid var(--line); }
.link-box small { color: var(--muted); }
.qr { align-self: flex-start; background: #fff; padding: 8px; border-radius: 10px; line-height: 0; }
.qr img { width: 168px; height: 168px; image-rendering: pixelated; }
.btns { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 6px; }
.btns.col { flex-direction: column; align-items: stretch; }
#btnSyncNow { margin-top: 6px; }

.toast {
  position: fixed; left: 50%; bottom: calc(90px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 30;
  background: #14213d; color: #fff; padding: 10px 18px; border-radius: 999px; font-size: .9em; box-shadow: 0 4px 16px rgba(0,0,0,.2);
}

@media (min-width: 900px) {
  .composer { left: 50%; transform: translateX(-50%); max-width: 860px; border: 1px solid var(--line); border-bottom: 0; border-radius: 18px 18px 0 0; }
  .sheet { left: 50%; transform: translateX(-50%); max-width: 760px; border-left: 1px solid var(--line); border-right: 1px solid var(--line); box-shadow: 0 0 0 100vmax rgba(15, 20, 32, .45); }
}

@media (max-width: 600px) {
  .list { grid-template-columns: 1fr; gap: 10px; }
  .card .text { -webkit-line-clamp: 4; }
  .brand { font-size: 1.05em; }
  .status { font-size: 0; flex: none; }
  .status::before { font-size: 18px; }
}
