:root {
  --bg: #f4f6f5;
  --surface: #ffffff;
  --text: #17201d;
  --muted: #5b6763;
  --line: #d9e0dd;
  --accent: #1f6f5c;
  --accent-text: #ffffff;
  --danger: #b42318;
  --danger-bg: #fdecea;
  --focus: #2e8b73;
  --warn-bg: #fff7e0;
  --warn-line: #e8c96a;
  --radius: 12px;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101514;
    --surface: #1a2120;
    --text: #e8eeec;
    --muted: #9aa8a3;
    --line: #2d3735;
    --accent: #4fb89c;
    --accent-text: #08201a;
    --danger: #ff8a80;
    --danger-bg: #3a1714;
    --focus: #6fd0b5;
    --warn-bg: #2e2714;
    --warn-line: #6b5a24;
  }
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.6 system-ui, -apple-system, "Hiragino Sans", "Noto Sans JP", sans-serif;
}

h1, h2 { margin: 0; line-height: 1.3; }
h1 { font-size: 1.2rem; }
h2 { font-size: 1.05rem; }
p { margin: 0; }

#app { max-width: 560px; margin: 0 auto; }

.view { min-height: 100dvh; padding-bottom: calc(96px + env(safe-area-inset-bottom)); }
.view-center {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 20px;
  padding: calc(24px + env(safe-area-inset-top)) 16px calc(24px + env(safe-area-inset-bottom));
}

.brand { display: flex; flex-direction: column; align-items: center; gap: 8px; }
.brand h1 { font-size: 1.4rem; }
.lead, .center { text-align: center; }
.lead { color: var(--muted); }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
}
.stack { display: flex; flex-direction: column; gap: 12px; }
.row { display: flex; gap: 8px; }
.row.end { justify-content: flex-end; flex-wrap: wrap; }
.grow { flex: 1; }

.field { display: flex; flex-direction: column; gap: 4px; }
.field > span, .field > label { font-size: 0.875rem; color: var(--muted); }

input, textarea {
  width: 100%;
  min-width: 0;
  font: inherit;
  font-size: 16px; /* iOS の自動ズームを防ぐ */
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
}
textarea { resize: vertical; }
input:focus-visible, textarea:focus-visible, button:focus-visible, summary:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}
.input-row { display: flex; gap: 6px; }
.input-row input { flex: 1; }
#f-password, #f-username { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 8px 16px;
  font: inherit;
  font-weight: 600;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  cursor: pointer;
  touch-action: manipulation;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.danger { color: var(--danger); border-color: var(--danger); background: transparent; }
.btn.link { background: none; border: none; color: var(--accent); font-weight: 500; text-decoration: underline; }
.btn.small { min-height: 44px; padding: 6px 10px; font-size: 0.875rem; white-space: nowrap; }
.btn.big { min-height: 56px; font-size: 1.05rem; }
.btn:disabled { opacity: 0.55; cursor: default; }
.btn[data-busy] { cursor: progress; }

.icon { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.bar {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: calc(8px + env(safe-area-inset-top)) 8px 8px 16px;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.bar h1 { flex: 1; }
.bar-actions { display: flex; gap: 4px; }
.bar-spacer { width: 44px; }
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  color: var(--text);
  background: none;
  border: none;
  border-radius: 10px;
  cursor: pointer;
}
.content { padding: 16px; }

.search { margin-bottom: 12px; }
.note-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.note-item {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  padding: 12px 16px;
  font: inherit;
  text-align: left;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  cursor: pointer;
}
.note-item strong, .note-item span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.note-item span { font-size: 0.875rem; color: var(--muted); }
.empty { padding: 32px 0; text-align: center; color: var(--muted); }

.fab {
  position: fixed;
  right: max(16px, calc(50vw - 280px + 16px));
  bottom: calc(20px + env(safe-area-inset-bottom));
  min-height: 52px;
  padding: 0 22px;
  font: inherit;
  font-weight: 700;
  color: var(--accent-text);
  background: var(--accent);
  border: none;
  border-radius: 26px;
  box-shadow: 0 4px 14px rgb(0 0 0 / 0.2);
  cursor: pointer;
}

.passkey-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.passkey-list li { display: flex; align-items: center; justify-content: space-between; gap: 8px; }

.banner {
  margin-bottom: 12px;
  padding: 12px 16px;
  border-radius: var(--radius);
  background: var(--warn-bg);
  border: 1px solid var(--warn-line);
}
.banner p { font-size: 0.9rem; }
.status { font-size: 0.9rem; font-weight: 600; }

.hint { font-size: 0.875rem; color: var(--muted); }
.error { color: var(--danger); font-size: 0.875rem; }
.error:empty { display: none; }
.notice {
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--surface);
  border: 1px solid var(--line);
  text-align: center;
}

.forgot { color: var(--muted); font-size: 0.875rem; }
.forgot summary { cursor: pointer; text-align: center; padding: 8px; }
.forgot p { margin: 8px 0 12px; }
.forgot .btn { width: 100%; }

dialog {
  width: min(92vw, 420px);
  padding: 20px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
}
dialog::backdrop { background: rgb(0 0 0 / 0.45); }
dialog [data-dialog-message] { color: var(--muted); }

.toast {
  position: fixed;
  left: 50%;
  top: calc(68px + env(safe-area-inset-top));
  transform: translateX(-50%);
  box-shadow: 0 4px 14px rgb(0 0 0 / 0.2);
  max-width: calc(100vw - 32px);
  padding: 10px 16px;
  color: var(--surface);
  background: var(--text);
  border-radius: 10px;
  font-size: 0.9rem;
  z-index: 10;
}
.toast[data-kind="error"] { background: var(--danger); color: #fff; }

/* 他のアプリに切り替えたとき、アプリ切り替え画面のサムネイルにメモが映らないよう隠す */
.cover { display: none; }
body.covered #app, body.covered dialog, body.covered .toast { visibility: hidden; }
body.covered .cover {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
}

.noscript { padding: 24px; text-align: center; }
