:root {
  --bg: #0F2E36;
  --bg-deep: #0A2228;
  --card: #16414B;
  --card-strong: #1C4F5A;
  --line: rgba(92, 200, 210, 0.18);
  --text: #E8F5F6;
  --muted: #9CC0C5;
  --accent: #5CC8D2;
  --accent-ink: #062A30;
  --error: #FF8A80;
  --radius: 16px;
  --tabbar-h: 64px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100dvh;
  background: radial-gradient(120% 60% at 50% -10%, #154450 0%, var(--bg) 55%, var(--bg-deep) 100%) fixed;
  color: var(--text);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Pretendard", "Noto Sans KR", "Malgun Gothic", sans-serif;
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 16px);
}

.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
[hidden] { display: none !important; }

.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(env(safe-area-inset-top) + 12px) 20px 12px;
  background: rgba(15, 46, 54, 0.88);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 19px; letter-spacing: 0.02em; }
.topbar-note { font-size: 12px; color: var(--muted); }

main { max-width: 560px; margin: 0 auto; padding: 8px 16px 0; }
.view-title { font-size: 24px; margin: 16px 4px 12px; }
.section-title { font-size: 17px; margin: 24px 4px 8px; color: var(--muted); font-weight: 600; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

.search-box { display: flex; gap: 8px; align-items: center; }
input[type="search"], input[type="text"] {
  flex: 1; min-width: 0;
  height: 48px; padding: 0 14px;
  border-radius: 12px; border: 1px solid var(--line);
  background: var(--card); color: var(--text); font: inherit;
}
input::placeholder { color: #7FA5AA; }
input:focus-visible, button:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

button, .primary-button, .secondary-button, .text-button, .danger-button { font: inherit; cursor: pointer; text-decoration: none; }
.primary-button {
  display: inline-flex; align-items: center; justify-content: center;
  height: 48px; padding: 0 18px; border: 0; border-radius: 12px;
  background: var(--accent); color: var(--accent-ink); font-weight: 700;
}
.primary-button:active { filter: brightness(0.92); }
.primary-button:disabled { opacity: 0.55; }
.primary-button.wide { width: 100%; margin-top: 8px; }
.secondary-button {
  height: 44px; padding: 0 14px; border-radius: 12px;
  border: 1px solid var(--accent); background: transparent; color: var(--accent); font-weight: 600;
}
.danger-button { height: 44px; padding: 0 16px; border-radius: 12px; border: 0; background: var(--error); color: #3A0E0B; font-weight: 700; }
.text-button { background: none; border: 0; color: var(--accent); padding: 8px 4px; font-size: 14px; }
.icon-button {
  width: 48px; height: 48px; flex: none; border-radius: 12px;
  border: 1px solid var(--line); background: var(--card); color: var(--accent);
  display: grid; place-items: center;
}
.icon-button svg { width: 22px; height: 22px; fill: currentColor; }
.icon-button.listening { background: var(--accent); color: var(--accent-ink); animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 8px rgba(92, 200, 210, 0.2); } }

.origin-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 8px 4px 0; font-size: 13px; }
.status { min-height: 1.5em; margin: 8px 4px; font-size: 14px; color: var(--muted); }
.status.error { color: var(--error); }

.card-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.card, .result {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px;
}
.result { display: flex; gap: 12px; align-items: center; width: 100%; text-align: left; color: inherit; }
.result:active { background: var(--card-strong); }
.result-main { flex: 1; min-width: 0; }
.result-name { font-weight: 700; font-size: 16px; }
.result-address { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.result-meta { flex: none; text-align: right; font-size: 13px; color: var(--accent); font-weight: 600; }
.result-category { display: block; color: var(--muted); font-weight: 400; font-size: 12px; }

.chip {
  display: inline-block; margin: 0; padding: 2px 10px; border-radius: 999px;
  background: rgba(92, 200, 210, 0.14); color: var(--accent); font-size: 12px; font-weight: 600;
}
.chip:empty { display: none; }

.favorite { display: flex; gap: 12px; align-items: center; }
.favorite-icon {
  width: 40px; height: 40px; flex: none; border-radius: 12px; display: grid; place-items: center;
  background: rgba(92, 200, 210, 0.14); color: var(--accent);
}
.favorite-icon svg { width: 22px; height: 22px; fill: currentColor; }
.favorite-actions { display: flex; flex-direction: column; align-items: flex-end; }
.favorite-actions .danger-link { color: var(--error); }

.empty { text-align: center; padding: 32px 16px; color: var(--muted); }

.pair-card { text-align: center; }
.pair-card p { margin: 4px 0 8px; }
.pair-code {
  font: 700 44px/1.1 ui-monospace, "SF Mono", Menlo, monospace; letter-spacing: 0.18em;
  color: var(--accent); margin: 8px 0; padding-left: 0.18em;
}
.row-buttons { display: flex; justify-content: center; gap: 12px; margin-top: 12px; align-items: center; }

.device { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.device-name { font-weight: 700; }
.device-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); margin-right: 6px; }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6;
  display: grid; grid-template-columns: repeat(3, 1fr);
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
  background: rgba(10, 34, 40, 0.94); backdrop-filter: blur(12px); border-top: 1px solid var(--line);
}
.tabbar a { display: grid; place-items: center; align-content: center; gap: 2px; color: var(--muted); text-decoration: none; font-size: 12px; }
.tabbar svg { width: 24px; height: 24px; fill: currentColor; }
.tabbar a[aria-current="page"] { color: var(--accent); font-weight: 700; }

dialog.sheet {
  width: 100%; max-width: 560px; margin: auto auto 0; padding: 0; border: 0;
  border-radius: 22px 22px 0 0; background: #133A43; color: var(--text);
  max-height: 88dvh;
}
dialog.sheet::backdrop { background: rgba(3, 14, 17, 0.6); }
.sheet-inner { padding: 10px 20px calc(20px + env(safe-area-inset-bottom)); display: grid; gap: 6px; }
.sheet-handle { width: 40px; height: 4px; border-radius: 2px; background: var(--line); margin: 0 auto 8px; }
.sheet h2 { margin: 4px 0 0; font-size: 21px; }
.sheet p { margin: 0; }
.save-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 12px; }
.field-label { font-size: 13px; color: var(--muted); margin-top: 10px; }
.inline-field { display: flex; gap: 8px; }
.close-button { justify-self: center; margin-top: 4px; }

.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 16px); transform: translateX(-50%);
  z-index: 20; max-width: calc(100% - 32px); padding: 12px 18px; border-radius: 12px;
  background: var(--accent); color: var(--accent-ink); font-weight: 600; box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}
.toast.error { background: var(--error); color: #3A0E0B; }

/* 그리드 열이 줄바꿈 없는 긴 주소에 맞춰 늘어나 화면 밖으로 넘치지 않도록 */
.card-list, .sheet-inner { grid-template-columns: minmax(0, 1fr); }
dialog.sheet { max-width: min(560px, 100vw); }
.sheet .chip { justify-self: start; }
.favorite-actions .text-button, .device > .text-button { white-space: nowrap; }
.toast { width: max-content; text-align: center; }
.status:empty { min-height: 0; margin: 4px 0; }
.dev-code-note { margin: 10px 0 0; text-align: center; }
