:root {
  --bg: #fef7ff;
  --surface: #ffffff;
  --text: #1d1b20;
  --muted: #625b71;
  --line: #e0dce6;
  --primary: #6750a4;
  --on-primary: #ffffff;
  --primary-soft: #eaddff;
  --danger: #b3261e;
  --radius: 14px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141218;
    --surface: #211f26;
    --text: #e6e0e9;
    --muted: #cac4d0;
    --line: #36343b;
    --primary: #d0bcff;
    --on-primary: #381e72;
    --primary-soft: #4f378b;
    --danger: #f2b8b5;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Noto Sans KR", "Malgun Gothic", system-ui, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

button, input { font: inherit; color: inherit; }

/* 16px+ font keeps iOS Safari from zooming on focus */
input {
  width: 100%;
  min-width: 0;
  height: 48px;
  padding: 0 14px;
  font-size: 17px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
}
input:focus { border-color: var(--primary); box-shadow: 0 0 0 1px var(--primary); }
input[type="search"]::-webkit-search-decoration { display: none; }

.btn {
  height: 48px;
  padding: 0 20px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--primary);
  font-weight: 600;
  font-size: 16px;
  cursor: pointer;
}
.btn.primary { background: var(--primary); color: var(--on-primary); }
.btn.danger { color: var(--danger); }
.btn:active { opacity: .75; }

/* Header / search */
.top {
  position: sticky;
  top: 0;
  z-index: 10;
  padding: calc(env(safe-area-inset-top) + 12px) calc(env(safe-area-inset-right) + 16px) 12px calc(env(safe-area-inset-left) + 16px);
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}

.search {
  display: grid;
  grid-template-columns: 2fr 1fr 1fr;
  gap: 8px;
}
.search .btn { grid-column: 1 / -1; }

/* Results */
main {
  max-width: 640px;
  margin: 0 auto;
  padding: 12px calc(env(safe-area-inset-right) + 16px) calc(env(safe-area-inset-bottom) + 96px) calc(env(safe-area-inset-left) + 16px);
}

.status { margin: 8px 4px 12px; color: var(--muted); font-size: 14px; }
.status:empty { display: none; }

.results { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }

.card {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 14px 8px 14px 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.card .info { flex: 1; min-width: 0; }
.card .apt { font-size: 15px; color: var(--muted); overflow-wrap: anywhere; }
.card .unit { font-size: 17px; font-weight: 600; margin-top: 2px; }
.card .pwd {
  display: inline-block;
  margin-top: 8px;
  padding: 6px 12px;
  border: 0;
  border-radius: 8px;
  background: var(--primary-soft);
  font-size: 22px;
  font-weight: 700;
  letter-spacing: .04em;
  overflow-wrap: anywhere;
  text-align: left;
  cursor: pointer;
}
.card .pwd.empty { font-size: 15px; font-weight: 400; color: var(--muted); letter-spacing: 0; }

.icon-btn {
  flex: none;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  display: grid;
  place-items: center;
}
.icon-btn:active { background: var(--line); }
.icon-btn svg { width: 22px; height: 22px; }

/* Floating add button */
.fab {
  position: fixed;
  right: calc(env(safe-area-inset-right) + 20px);
  bottom: calc(env(safe-area-inset-bottom) + 20px);
  width: 60px;
  height: 60px;
  border: 0;
  border-radius: 18px;
  background: var(--primary);
  color: var(--on-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  box-shadow: 0 4px 14px rgba(0, 0, 0, .25);
  cursor: pointer;
}
.fab svg { width: 28px; height: 28px; }
.fab:active { transform: scale(.95); }

/* Bottom-sheet dialogs */
.sheet {
  width: 100%;
  max-width: 480px;
  margin: auto auto 0;
  padding: 20px calc(env(safe-area-inset-right) + 20px) calc(env(safe-area-inset-bottom) + 16px) calc(env(safe-area-inset-left) + 20px);
  border: 0;
  border-radius: 24px 24px 0 0;
  background: var(--surface);
  color: var(--text);
}
.sheet::backdrop { background: rgba(0, 0, 0, .4); }
.sheet form { display: grid; gap: 10px; }
.sheet h2 { margin: 0 0 4px; font-size: 18px; }
.sheet p { margin: 4px 0 8px; font-size: 16px; }
.sheet .row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.sheet .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }

@media (min-width: 600px) {
  .sheet { margin: auto; border-radius: 24px; }
}

.emoji-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.emoji-row button {
  height: 44px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: transparent;
  font-size: 20px;
  cursor: pointer;
}
.emoji-row button:active { background: var(--primary-soft); }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom) + 96px);
  transform: translateX(-50%);
  max-width: calc(100% - 32px);
  padding: 10px 16px;
  border-radius: 10px;
  background: var(--text);
  color: var(--bg);
  font-size: 14px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s;
}
.toast.show { opacity: 1; }
