:root {
  color-scheme: light dark;
  --bg: #f3f4f6;
  --surface: #ffffff;
  --ink: #17191c;
  --ink-2: #6b7078;
  --line: #e4e6ea;
  --line-strong: #c9ccd2;
  --live: #1f9d63;
  --danger: #c2413a;
  --shadow: 0 1px 2px rgba(23, 25, 28, .04), 0 12px 40px -16px rgba(23, 25, 28, .18);
  --radius: 22px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e0f11;
    --surface: #1a1c20;
    --ink: #eceef1;
    --ink-2: #8b9099;
    --line: #2a2d33;
    --line-strong: #3c4049;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 16px 48px -16px rgba(0, 0, 0, .6);
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100dvh;
  padding: calc(16px + env(safe-area-inset-top)) 20px calc(24px + env(safe-area-inset-bottom));
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.55 -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Pretendard", "Noto Sans KR", system-ui, sans-serif;
  letter-spacing: -0.005em;
  word-break: keep-all;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-areas: "side" "main" "hist";
  gap: 28px;
  max-width: 520px;
  margin-inline: auto;
}
.side { grid-area: side; }
main { grid-area: main; display: flex; justify-content: center; align-items: start; }
.hist { grid-area: hist; }
p { margin: 0; }
button, input, textarea { font: inherit; color: inherit; letter-spacing: inherit; }
:focus-visible { outline: 2px solid var(--ink); outline-offset: 3px; border-radius: 6px; }

.side { display: flex; flex-direction: column; gap: 14px; }
.name {
  border: 0;
  background: transparent;
  padding: 0;
  font-size: 20px;
  font-weight: 600;
  letter-spacing: -0.02em;
  width: 100%;
}
.name:focus-visible { outline: none; text-decoration: underline; text-underline-offset: 4px; }
#group { display: flex; flex-direction: column; gap: 10px; }
.devices { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.devices li { display: flex; align-items: center; gap: 8px; padding: 7px 0; font-size: 14px; }
.devices li::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--live); flex: none; }
.devices li.off { color: var(--ink-2); }
.devices li.off::before { background: var(--line-strong); }
.devices .dname { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.devices .rm { padding: 0 6px; font-size: 16px; line-height: 1; color: var(--ink-2); opacity: 0; }
.devices li:hover .rm, .devices .rm:focus-visible { opacity: 1; }
.devices:empty::before { content: "아직 추가한 기기가 없습니다"; font-size: 13px; color: var(--ink-2); padding: 7px 0; }
.add { width: 100%; padding: 12px 16px; }
#group .link { align-self: flex-start; }

.drop {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  aspect-ratio: 1;
  width: 100%;
  max-width: 420px;
  display: grid;
  place-items: center;
  padding: 28px;
  position: relative;
  transition: transform .18s ease, box-shadow .18s ease;
}
.drop::after {
  content: "";
  position: absolute;
  inset: 10px;
  border: 1.5px dashed var(--ink-2);
  border-radius: calc(var(--radius) - 10px);
  opacity: 0;
  transition: opacity .15s ease;
  pointer-events: none;
}
.drop.over { transform: scale(1.015); }
.drop.over::after { opacity: 1; }
.drop.over .face { opacity: .35; }
.face { width: 100%; display: flex; flex-direction: column; align-items: center; text-align: center; gap: 14px; transition: opacity .15s ease; }
.lead { font-size: 17px; font-weight: 600; letter-spacing: -0.015em; text-wrap: balance; }
.sub { font-size: 13px; color: var(--ink-2); text-wrap: balance; }
.actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; }

button { cursor: pointer; border-radius: 999px; padding: 9px 16px; border: 1px solid transparent; background: transparent; line-height: 1.2; }
button:disabled { opacity: .45; cursor: default; }
.solid { background: var(--ink); color: var(--bg); border-color: var(--ink); font-weight: 600; }
.ghost { border-color: var(--line-strong); }
.ghost:hover { border-color: var(--ink); }
.link { padding: 4px 0; color: var(--ink-2); font-size: 13px; border-radius: 4px; }
.link:hover { color: var(--ink); }
.linkform { display: flex; gap: 8px; width: 100%; max-width: 360px; }
.linkform input { flex: 1; min-width: 0; }
input:not(.name), textarea {
  background: var(--bg);
  border: 1px solid transparent;
  border-radius: 12px;
  padding: 10px 14px;
  width: 100%;
}
input:not(.name):focus, textarea:focus { border-color: var(--line-strong); outline: none; }
textarea { resize: none; text-align: left; }

.staged { display: flex; flex-direction: column; gap: 6px; width: 100%; align-items: center; }
.staged .thumb { width: 72px; height: 72px; object-fit: cover; border-radius: 12px; border: 1px solid var(--line); }
.staged .fname { font-weight: 600; letter-spacing: -0.01em; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.staged .fmeta { font-size: 13px; color: var(--ink-2); }
.staged .snippet { font-size: 13px; color: var(--ink-2); max-height: 3.1em; overflow: hidden; white-space: pre-wrap; word-break: break-word; }
.targets { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; }
.targets .ghost { font-weight: 600; padding: 12px 22px; }

.bar { width: 60%; max-width: 220px; height: 3px; background: var(--line); border-radius: 2px; overflow: hidden; }
.bar > div { height: 100%; width: 0; background: var(--ink); transition: width .12s linear; }

.hist { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.hist-head { display: flex; justify-content: space-between; align-items: baseline; padding-bottom: 6px; }
.hist-title { font-size: 13px; color: var(--ink-2); }
.inbox { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.inbox li { display: grid; grid-template-columns: 40px minmax(0, 1fr) auto; gap: 12px; align-items: center; padding: 12px 0; border-top: 1px solid var(--line); }
.inbox li:first-child { border-top: 0; }
.inbox .icon { width: 40px; height: 40px; border-radius: 10px; background: var(--surface); border: 1px solid var(--line); display: grid; place-items: center; font-size: 11px; font-weight: 600; color: var(--ink-2); overflow: hidden; }
.inbox .icon img { width: 100%; height: 100%; object-fit: cover; }
.inbox .body { min-width: 0; }
.inbox .title { font-weight: 600; letter-spacing: -0.01em; white-space: pre-wrap; word-break: break-word; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.inbox .meta { font-size: 12.5px; color: var(--ink-2); margin-top: 2px; }
.inbox .ops { display: flex; gap: 4px; }
.inbox .ops button { padding: 6px 10px; font-size: 13px; border-color: var(--line-strong); }
.inbox .ops .rm { border-color: transparent; color: var(--ink-2); font-size: 16px; padding: 4px 6px; }
.inbox .ops .rm:hover { color: var(--danger); }
.empty { font-size: 13px; color: var(--ink-2); padding-top: 4px; }

.sheet {
  border: 0;
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow);
  padding: 28px;
  width: min(92vw, 360px);
  text-align: center;
}
.sheet::backdrop { background: rgba(14, 15, 17, .45); backdrop-filter: blur(6px); }
.sheet .actions { margin-top: 18px; }
.sheet .sub { margin-top: 12px; }
#qr { display: block; margin: 0 auto; background: #fff; padding: 12px; border-radius: 14px; max-width: 100%; }

.toast {
  position: fixed;
  left: 50%;
  top: calc(14px + env(safe-area-inset-top));
  transform: translateX(-50%);
  background: var(--ink);
  color: var(--bg);
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 14px;
  max-width: calc(100% - 40px);
  z-index: 10;
  box-shadow: var(--shadow);
}

@media (prefers-reduced-motion: reduce) {
  .drop, .drop::after, .face, .bar > div { transition: none; }
}

@media (max-width: 799px) {
  .side { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; column-gap: 12px; row-gap: 10px; }
  .name { grid-column: 1 / -1; }
  #group { display: contents; }
  .devices { flex-direction: row; flex-wrap: wrap; gap: 2px 16px; }
  .devices .rm { opacity: 1; }
  .add { width: auto; padding: 10px 18px; }
  #group .link { grid-column: 1 / -1; justify-self: start; }
}
@media (min-width: 800px) {
  body { max-width: 900px; grid-template-columns: 200px minmax(0, 1fr); grid-template-areas: "side main" "side hist"; column-gap: 48px; padding-top: 40px; }
  .side { position: sticky; top: 40px; }
}
@media (min-width: 1120px) {
  body { max-width: 1240px; grid-template-columns: 200px minmax(0, 1fr) 320px; grid-template-areas: "side main hist"; column-gap: 48px; }
  .hist { position: sticky; top: 40px; max-height: calc(100dvh - 80px); overflow: auto; }
}
