:root {
  --bg: #f4f5f8;
  --card: #ffffff;
  --card-2: #f8f9fb;
  --text: #14171c;
  --muted: #667085;
  --border: #e3e6eb;
  --accent: #2563eb;
  --accent-weak: #e8f0fe;
  --accent-text: #ffffff;
  --danger: #d32f2f;
  --danger-weak: #fdecec;
  --warn: #a15c07;
  --warn-weak: #fff5e1;
  --success: #15803d;
  --hover: #eef1f5;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .07);
  --shadow-lg: 0 12px 32px rgba(16, 24, 40, .18);
  --radius: 14px;
  --nav-h: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --card: #181b21;
    --card-2: #1e222a;
    --text: #e7e9ee;
    --muted: #9aa3b2;
    --border: #2a2f38;
    --accent: #5b8dff;
    --accent-weak: #1c2847;
    --accent-text: #0b1020;
    --danger: #f87171;
    --danger-weak: #3a1d1f;
    --warn: #fbbf24;
    --warn-weak: #3a2f12;
    --success: #4ade80;
    --hover: #222731;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow-lg: 0 12px 32px rgba(0, 0, 0, .55);
  }
}

/* ---------- 基本 ---------- */
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 system-ui, -apple-system, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Yu Gothic UI", Meiryo, sans-serif;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}
h1, h2, h3, p { margin: 0; }
.ic { flex-shrink: 0; }
label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 600; color: var(--muted); }
input, textarea {
  font: inherit; font-weight: 400; color: var(--text); background: var(--card-2);
  border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; width: 100%; min-width: 0;
  transition: border-color .15s, box-shadow .15s;
}
textarea { resize: vertical; }
input:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-weak); background: var(--card); }
input::placeholder, textarea::placeholder { color: var(--muted); opacity: .75; }
button, .btn {
  font: inherit; font-size: 14px; font-weight: 600; color: var(--text); background: var(--card); cursor: pointer;
  border: 1px solid var(--border); border-radius: 10px; padding: 8px 14px; white-space: nowrap;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  transition: background .15s, border-color .15s, transform .08s;
}
button:hover { background: var(--hover); }
button:active { transform: scale(.98); }
button:focus-visible, a:focus-visible { outline: 3px solid var(--accent-weak); outline-offset: 1px; }
button:disabled { opacity: .55; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
button.primary:hover { filter: brightness(1.06); }
button.danger, button.danger-ghost { color: var(--danger); }
button.danger-ghost { border-color: transparent; background: none; }
button.danger-ghost:hover { background: var(--danger-weak); }
button.danger-solid { background: var(--danger); border-color: var(--danger); color: #fff; }
button.ghost { border-color: transparent; background: none; color: var(--accent); }
button.ghost:hover { background: var(--accent-weak); }
button.link { border: none; background: none; color: var(--accent); padding: 6px; font-weight: 500; }
button.block { width: 100%; }
button.small { padding: 6px 10px; font-size: 13px; }
.icon-btn {
  width: 40px; height: 40px; padding: 0; border-radius: 10px; border: none; background: none; color: var(--muted);
  display: inline-flex; align-items: center; justify-content: center; text-decoration: none; flex-shrink: 0;
}
.icon-btn:hover { background: var(--hover); color: var(--text); }
.row { display: flex; gap: 6px; align-items: center; }
.row > input { flex: 1; }
.mono { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.hint { font-size: 12px; color: var(--muted); font-weight: 400; }
.error { color: var(--danger); font-size: 13px; }
.error:empty, .success:empty { display: none; }
.success { color: var(--success); font-size: 13px; }
.card {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 16px; display: flex; flex-direction: column; gap: 14px;
}
.card h2, .card h3 { font-size: 15px; }
.note { display: flex; gap: 10px; align-items: flex-start; font-size: 13px; padding: 12px 14px; border-radius: 12px; font-weight: 400; }
.note.warn { background: var(--warn-weak); color: var(--warn); }
.badge { margin-left: 6px; font-size: 11px; font-weight: 600; color: var(--accent); background: var(--accent-weak); border-radius: 999px; padding: 1px 8px; vertical-align: 1px; }

/* パスワード入力欄 (右端に表示ボタン) */
.input-wrap { position: relative; display: flex; }
.input-wrap input { padding-right: 46px; }
.icon-btn.in-input { position: absolute; right: 2px; top: 50%; transform: translateY(-50%); width: 38px; height: 38px; }

/* 強さメーター */
.meter { display: flex; align-items: center; gap: 10px; margin-top: -4px; }
.meter-bar { display: grid; grid-template-columns: repeat(5, 1fr); gap: 4px; flex: 1; }
.meter-bar i { height: 5px; border-radius: 3px; background: var(--border); }
.meter-label { font-size: 12px; color: var(--muted); font-weight: 600; min-width: 7.5em; text-align: right; }
.meter[data-score="-1"] { display: none; }
.meter[data-score="0"] i:nth-child(-n+1) { background: #dc2626; }
.meter[data-score="1"] i:nth-child(-n+2) { background: #ea580c; }
.meter[data-score="2"] i:nth-child(-n+3) { background: #ca8a04; }
.meter[data-score="3"] i:nth-child(-n+4) { background: #16a34a; }
.meter[data-score="4"] i { background: #15803d; }

/* ---------- ログイン / ロック画面 ---------- */
.auth {
  min-height: 100dvh; display: grid; place-items: center;
  padding: max(24px, env(safe-area-inset-top)) 16px max(24px, var(--safe-b));
}
.auth-card { width: 100%; max-width: 400px; display: flex; flex-direction: column; gap: 20px; }
.brand { display: flex; align-items: center; gap: 14px; }
.brand-name { font-size: 20px; font-weight: 700; }
.logo { display: inline-grid; place-items: center; width: 30px; height: 30px; border-radius: 9px; background: var(--accent); color: #fff; flex-shrink: 0; }
.logo.big { width: 52px; height: 52px; border-radius: 15px; }
.tabs { display: grid; grid-template-columns: 1fr 1fr; background: var(--hover); border-radius: 12px; padding: 4px; gap: 4px; }
.tabs button { border: none; background: none; color: var(--muted); border-radius: 9px; padding: 8px; }
.tabs button.on { background: var(--card); color: var(--text); box-shadow: var(--shadow); }
.auth-form { display: flex; flex-direction: column; gap: 14px; background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); }
.auth-form button.primary { padding: 12px; font-size: 15px; }

/* ---------- アプリ本体 ---------- */
.shell { min-height: 100dvh; }
.topbar { display: none; }
.pane-head {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 6px;
  padding: max(10px, env(safe-area-inset-top)) 12px 10px; min-height: 60px;
  background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
}
.pane-head h1, .pane-head h2 { flex: 1; font-size: 20px; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding-left: 4px; }
.pane-head .spacer { flex: 1; }
.pane-head .head-actions { display: flex; gap: 4px; }
.count { font-size: 13px; font-weight: 600; color: var(--muted); background: var(--hover); border-radius: 999px; padding: 1px 9px; margin-left: 8px; vertical-align: 3px; }
.pane-body { padding: 4px 16px 24px; display: flex; flex-direction: column; gap: 14px; }

/* 検索 */
.search { position: relative; margin: 0 16px; }
.search .ic { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.search input { padding-left: 40px; border-radius: 12px; background: var(--card); }
.sync-info { font-size: 12px; color: var(--muted); padding: 8px 20px 4px; }
.sync-info.offline { color: var(--warn); }
.sync-btn.spinning .ic { animation: spin .9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* 一覧 */
.items { list-style: none; margin: 0; padding: 4px 8px 16px; }
.item { display: flex; align-items: center; gap: 2px; border-radius: 12px; }
.item:hover { background: var(--hover); }
.item.selected { background: var(--accent-weak); }
.item-main { flex: 1; min-width: 0; display: flex; align-items: center; gap: 12px; padding: 10px 8px; border: none; background: none; text-align: left; justify-content: flex-start; }
.item-main:hover { background: none; }
.meta { display: flex; flex-direction: column; min-width: 0; }
.meta strong { font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.meta .sub { font-size: 13px; color: var(--muted); font-weight: 400; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .quick { margin-right: 4px; }
.avatar {
  --hue: 220;
  width: 40px; height: 40px; border-radius: 12px; flex-shrink: 0; display: grid; place-items: center;
  font-weight: 700; font-size: 17px; color: hsl(var(--hue) 70% 32%); background: hsl(var(--hue) 75% 92%);
}
@media (prefers-color-scheme: dark) { .avatar { color: hsl(var(--hue) 80% 80%); background: hsl(var(--hue) 35% 22%); } }
.avatar.big { width: 64px; height: 64px; border-radius: 18px; font-size: 28px; }
.empty { display: flex; flex-direction: column; align-items: center; gap: 12px; padding: 48px 16px; color: var(--muted); text-align: center; }
.empty .ic { opacity: .5; }
.placeholder { height: 100%; min-height: 300px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; color: var(--muted); }
.placeholder .ic { opacity: .4; }

/* 詳細 */
.hero { display: flex; align-items: center; gap: 16px; padding: 4px 4px 6px; }
.hero-text { min-width: 0; }
.hero h2 { font-size: 22px; font-weight: 700; word-break: break-word; }
.fields { padding: 0; gap: 0; overflow: hidden; }
.field-row { display: flex; align-items: center; gap: 8px; padding: 12px 8px 12px 16px; min-height: 64px; }
.field-row + .field-row { border-top: 1px solid var(--border); }
.field-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.label { font-size: 12px; font-weight: 600; color: var(--muted); }
.value { word-break: break-all; }
.link-text { color: var(--accent); }
.field-actions { display: flex; gap: 2px; }
.secret { font-size: 16px; letter-spacing: .06em; word-break: break-all; }
.secret.revealed { letter-spacing: .02em; }
.notes { margin: 0; white-space: pre-wrap; word-break: break-word; font: inherit; }
.detail-pane > .pane-body > button.danger-ghost { align-self: center; margin-top: 8px; }

/* 編集 */
.edit-form { display: flex; flex-direction: column; min-height: calc(100dvh - 60px); }
.edit-form .pane-body { flex: 1; }
.label-row { display: flex; align-items: center; justify-content: space-between; }
.label-row button { padding: 2px 8px; font-size: 13px; }
.actionbar {
  position: sticky; bottom: 0; z-index: 5; display: grid; grid-template-columns: 1fr 2fr; gap: 10px;
  padding: 12px 16px calc(12px + var(--safe-b)); background: color-mix(in srgb, var(--bg) 90%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); border-top: 1px solid var(--border);
}
.actionbar button { padding: 12px; font-size: 15px; }

/* 生成 */
.gen-output { font-size: 22px; line-height: 1.5; word-break: break-all; text-align: center; padding: 18px 8px; background: var(--card-2); border-radius: 12px; user-select: all; }
.gen-output .d { color: var(--accent); }
.gen-output .s { color: #c2410c; }
@media (prefers-color-scheme: dark) { .gen-output .s { color: #fb923c; } }
.gen-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.gen-actions button { padding: 12px; }
.opt { display: flex; align-items: center; justify-content: space-between; gap: 12px; font-size: 14px; color: var(--text); font-weight: 500; }
.opt.inline { flex-direction: row; }
.opt input[type="range"] { flex: 1; max-width: 60%; accent-color: var(--accent); padding: 0; border: none; background: none; box-shadow: none; }
input.switch {
  appearance: none; -webkit-appearance: none; width: 48px; height: 28px; border-radius: 999px; padding: 0; flex-shrink: 0;
  background: var(--border); border: none; position: relative; cursor: pointer; transition: background .2s;
}
input.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.3); transition: transform .2s; }
input.switch:checked { background: var(--accent); }
input.switch:checked::after { transform: translateX(20px); }
input.switch:focus { box-shadow: 0 0 0 3px var(--accent-weak); }

/* 設定 */
.devices { list-style: none; margin: 0; padding: 0; }
.devices li { display: flex; align-items: center; gap: 12px; padding: 10px 0; }
.devices li + li { border-top: 1px solid var(--border); }
.device-ic { width: 36px; height: 36px; border-radius: 10px; background: var(--hover); color: var(--muted); display: grid; place-items: center; flex-shrink: 0; }
.devices .who { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.devices .who span.muted { font-size: 12px; }
.steps { margin: 0; padding-left: 20px; display: flex; flex-direction: column; gap: 4px; font-size: 14px; }

/* 下部メニュー (スマホ・拡張機能のポップアップ) */
.bottom-nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: grid; grid-template-columns: repeat(5, 1fr); align-items: end;
  height: calc(var(--nav-h) + var(--safe-b)); padding: 0 6px var(--safe-b);
  background: color-mix(in srgb, var(--card) 92%, transparent); backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid var(--border);
}
.nav-btn {
  height: var(--nav-h); flex-direction: column; gap: 3px; border: none; background: none; border-radius: 12px;
  color: var(--muted); font-size: 11px; font-weight: 600; padding: 6px 0;
}
.nav-btn:hover { background: none; color: var(--text); }
.nav-btn.active { color: var(--accent); }
.nav-btn .nav-ic { display: grid; place-items: center; width: 52px; height: 30px; border-radius: 999px; transition: background .2s; }
.nav-btn.active .nav-ic { background: var(--accent-weak); }
.nav-btn.add .nav-ic { width: 52px; height: 52px; margin-top: -26px; border-radius: 18px; background: var(--accent); color: var(--accent-text); box-shadow: 0 6px 16px color-mix(in srgb, var(--accent) 45%, transparent); }
.nav-btn.add.active .nav-ic { background: var(--accent); }
.nav-btn.add { color: var(--text); }

/* 通知・確認 */
.toasts { position: fixed; left: 0; right: 0; bottom: calc(var(--nav-h) + var(--safe-b) + 12px); z-index: 50; display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; padding: 0 16px; }
.toast {
  display: flex; align-items: center; gap: 10px; max-width: 480px; padding: 11px 16px; border-radius: 12px; font-size: 14px; font-weight: 500;
  background: #1f2430; color: #fff; box-shadow: var(--shadow-lg); animation: toast-in .2s ease-out; pointer-events: auto;
}
.toast.ok .ic { color: #4ade80; }
.toast.error { background: #b42318; }
.toast.out { opacity: 0; transform: translateY(8px); transition: opacity .25s, transform .25s; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }
.overlay { position: fixed; inset: 0; z-index: 60; background: rgba(10, 12, 16, .45); display: flex; align-items: flex-end; justify-content: center; animation: fade .15s; }
.sheet {
  width: 100%; max-width: 480px; background: var(--card); border-radius: 20px 20px 0 0; padding: 22px 20px calc(18px + var(--safe-b));
  display: flex; flex-direction: column; gap: 10px; box-shadow: var(--shadow-lg); animation: sheet-up .22s ease-out;
}
.sheet h2 { font-size: 17px; }
.sheet p { font-size: 14px; }
.sheet-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 10px; }
.sheet-actions button { padding: 12px; font-size: 15px; }
@keyframes fade { from { opacity: 0; } }
@keyframes sheet-up { from { transform: translateY(40px); opacity: .5; } }
.update-banner {
  position: fixed; left: 12px; right: 12px; bottom: calc(var(--nav-h) + var(--safe-b) + 12px); z-index: 40;
  max-width: 480px; margin: 0 auto; display: flex; align-items: center; justify-content: space-between; gap: 8px;
  background: var(--card); border: 1px solid var(--border); border-radius: 14px; padding: 10px 12px 10px 16px; box-shadow: var(--shadow-lg);
}

/* ---------- 狭い画面: 1 画面ずつ表示 ---------- */
@media (max-width: 759px) {
  .main { padding-bottom: calc(var(--nav-h) + var(--safe-b) + 8px); }
  .shell[data-view="list"] .detail-pane,
  .shell:not([data-view="list"]) .list-pane { display: none; }
  /* 編集中は下部メニューの代わりに「キャンセル / 保存」を出す */
  .shell[data-view="edit"] .bottom-nav { display: none; }
  .shell[data-view="edit"] .main { padding-bottom: 0; }
  body:has(.shell[data-view="edit"]) .toasts,
  body:has(.shell[data-view="edit"]) .update-banner { bottom: calc(84px + var(--safe-b)); }
  .pane-body { padding-left: max(16px, env(safe-area-inset-left)); padding-right: max(16px, env(safe-area-inset-right)); }
}
@media (max-width: 759px) and (pointer: coarse) {
  /* iOS は 16px 未満の入力欄にフォーカスすると画面を拡大してしまう */
  input, textarea { font-size: 16px; }
  .item-main { padding: 12px 8px; }
  .icon-btn { width: 44px; height: 44px; }
}

/* ---------- 広い画面 (PC): 左に一覧・右に詳細 ---------- */
@media (min-width: 760px) {
  .bottom-nav { display: none; }
  .toasts { bottom: 24px; }
  .update-banner { bottom: 24px; }
  .topbar {
    display: flex; align-items: center; justify-content: space-between; gap: 12px; height: 60px; padding: 0 20px;
    background: var(--card); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 10;
  }
  .brand-sm { border: none; background: none; font-size: 16px; font-weight: 700; padding: 6px 8px; gap: 10px; }
  .brand-sm:hover { background: none; }
  .top-actions { display: flex; gap: 6px; }
  .top-btn { padding: 8px 14px; }
  .top-btn.active:not(.primary) { background: var(--accent-weak); border-color: transparent; color: var(--accent); }
  .main { display: grid; grid-template-columns: minmax(300px, 380px) 1fr; height: calc(100dvh - 60px); }
  .pane { overflow-y: auto; }
  .list-pane { border-right: 1px solid var(--border); background: var(--card); }
  .list-pane .pane-head { background: color-mix(in srgb, var(--card) 88%, transparent); }
  .list-pane .search input { background: var(--card-2); }
  .detail-pane .pane-head .back { display: none; }
  .detail-pane .pane-head { padding-left: 20px; padding-right: 20px; }
  .detail-pane .pane-body { max-width: 680px; width: 100%; margin: 0 auto; padding: 8px 24px 32px; }
  .edit-form { min-height: 100%; }
  .edit-form .pane-body { flex: 1; }
  .actionbar { grid-template-columns: auto auto; justify-content: end; padding: 12px 24px; }
  .actionbar button { min-width: 120px; }
  .detail-pane .actionbar { padding-right: max(24px, calc((100% - 680px) / 2 + 24px)); }
  .overlay { align-items: center; }
  .sheet { border-radius: 18px; max-width: 420px; }
}
