:root {
  color-scheme: light dark;
  --bg: #f6f6f3;
  --surface: #ffffff;
  --text: #20241f;
  --muted: #646a62;
  --line: #d9dbd4;
  --accent: #245c54;
  --accent-text: #ffffff;
  --warn: #9a4a12;
  --warn-bg: #fbeee1;
  --ok: #2c7a4b;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161917;
    --surface: #202421;
    --text: #e9ece7;
    --muted: #a2a9a0;
    --line: #3a403b;
    --accent: #6cc2b4;
    --accent-text: #10201d;
    --warn: #f0b27f;
    --warn-bg: #3a2a1c;
    --ok: #6fce94;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

[hidden] { display: none !important; }

.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 16px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

h1 { margin: 0; font-size: 18px; font-weight: 650; }

.status { display: flex; align-items: center; gap: 6px; font-size: 14px; color: var(--muted); }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--warn); }
.status.ok .dot { background: var(--ok); }

.top-actions { display: flex; align-items: center; gap: 12px; margin-left: auto; flex-wrap: wrap; }
.setting { display: flex; align-items: center; gap: 6px; font-size: 14px; color: var(--muted); }

select, textarea, .button { font: inherit; color: inherit; }

select {
  padding: 4px 6px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
}

.button {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border: 1px solid var(--accent);
  border-radius: 6px;
  background: var(--accent);
  color: var(--accent-text);
  font-size: 14px;
  font-weight: 550;
  line-height: 1.4;
  text-decoration: none;
  cursor: pointer;
}

.button:disabled { opacity: .45; cursor: default; }

.button.quiet {
  border-color: var(--line);
  background: transparent;
  color: var(--text);
  font-weight: 450;
}

.button.danger { border-color: var(--warn); color: var(--warn); }

kbd { font: inherit; font-size: 12px; font-weight: 400; opacity: .8; }

.banner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 16px;
  padding: 10px 16px;
  background: var(--warn-bg);
  color: var(--warn);
}

main { max-width: 860px; margin: 0 auto; padding: 16px; }

.composer {
  padding: 12px;
  border: 2px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
}

.composer.active { border-color: var(--accent); }

.composer-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}

.composer-head label { font-size: 14px; font-weight: 600; color: var(--muted); }
.composer.active .composer-head label { color: var(--accent); }

textarea {
  display: block;
  width: 100%;
  border: 0;
  outline: 0;
  resize: none;
  background: transparent;
}

#composer { min-height: 112px; max-height: 40vh; overflow-y: auto; font-size: 17px; }

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 34px;
  margin: 24px 0 8px;
}

h2 { margin: 0; font-size: 14px; font-weight: 650; color: var(--muted); }

.cards { display: flex; flex-direction: column; gap: 10px; }

.card {
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
}

.card.flash { border-color: var(--accent); }
.card textarea {
  overflow: hidden;
  min-height: 28px;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--line);
}

.card-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 14px;
  font-size: 13px;
  color: var(--muted);
}

.card-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 6px 4px 0;
  border: 0;
  background: none;
  color: var(--text);
  font: inherit;
  font-size: 14px;
  font-weight: 550;
  text-align: left;
  cursor: pointer;
}

.card-preview {
  overflow: hidden;
  margin-top: 4px;
  padding-left: 22px;
  color: var(--muted);
  font-size: 14px;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: pointer;
}

.caret { display: inline-block; width: 16px; font-size: 18px; line-height: 1; text-align: center; transition: transform .12s; }
.card-toggle[aria-expanded="true"] .caret { transform: rotate(90deg); }

.card-head .spacer { flex: 1; }
.keep { display: flex; align-items: center; gap: 5px; color: var(--text); cursor: pointer; }
.keep input { width: 16px; height: 16px; margin: 0; accent-color: var(--accent); }

.empty { margin: 8px 0; font-size: 14px; color: var(--muted); }

@media (max-width: 600px) {
  .top-actions { margin-left: 0; width: 100%; justify-content: space-between; }
  #break-key { display: none; }
}

.login-page { display: grid; min-height: 100vh; place-items: center; padding: 16px; }

.login {
  display: flex;
  flex-direction: column;
  width: min(100%, 360px);
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
}

.login h1 { margin-bottom: 16px; font-size: 22px; }
.login label { margin-bottom: 4px; font-size: 14px; color: var(--muted); }

.login input {
  margin-bottom: 14px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: transparent;
  color: inherit;
  font: inherit;
}

.login .button { justify-content: center; padding: 9px 12px; }
.login-error { margin: 0 0 14px; font-size: 14px; color: var(--warn); }

.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 16px; }

#search {
  flex: 1 1 220px;
  min-width: 0;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: inherit;
  font: inherit;
  font-size: 14px;
}

.section-actions { display: flex; gap: 8px; }
.select-box { width: 16px; height: 16px; margin: 0; accent-color: var(--accent); }

.card-title {
  width: 100%;
  margin-top: 8px;
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: transparent;
  color: inherit;
  font: inherit;
  font-size: 14px;
  font-weight: 600;
}

.card-preview strong { color: var(--text); font-weight: 600; }
.card-copied { color: var(--ok); }
.offscreen { position: fixed; top: -1000px; left: -1000px; }

.composer-actions { display: flex; flex-wrap: wrap; gap: 8px; }
body.dropping .composer { border-color: var(--accent); border-style: dashed; }

.card-image {
  display: block;
  max-width: 100%;
  max-height: 72px;
  margin-top: 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  cursor: pointer;
}

.card.open .card-image { max-height: 60vh; }
