:root {
  --bg: #FAFAFC;
  --panel: #FFFFFF;
  --panel-hover: #F3F2FE;
  --border: #ECECF4;
  --text: #1F2333;
  --muted: #6B7280;
  --accent: #C9A24B;
  --acc1: #C9A24B;
  --acc2: #0B1F3A;
  --grad: linear-gradient(120deg, #0B1F3A, #122C4F 55%, #C9A24B);
  --accent-soft: rgba(201, 162, 75, 0.12);
  --danger: #d9453d;
  --ok: #059669;
  --radius: 12px;
}

* { box-sizing: border-box; margin: 0; -webkit-tap-highlight-color: transparent; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, "Hiragino Sans", "Noto Sans JP", sans-serif;
  font-size: 15px;
  line-height: 1.5;
  max-width: 640px;
  margin: 0 auto;
  padding-bottom: env(safe-area-inset-bottom);
}

header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  padding-top: calc(12px + env(safe-area-inset-top));
  position: sticky;
  top: 0;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 1px 12px rgba(40, 40, 90, .06);
  z-index: 10;
}
.hspacer { flex: 1; }

/* ヘッダーのロゴマーク（brandは背景クリップで文字を塗るので画像は外に置く） */
.brand-logo { width: 26px; height: 26px; border-radius: 7px; flex-shrink: 0; cursor: pointer; }

.brand {
  font-weight: 800;
  font-size: 16px;
  letter-spacing: .02em;
  background: var(--grad);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  cursor: pointer; /* クリックでトップへ戻る */
}
.badge {
  font-size: 9.5px; font-weight: 800; letter-spacing: .14em; color: #fff;
  background: linear-gradient(120deg, var(--acc1), var(--acc2));
  border-radius: 99px; padding: 3px 10px;
  box-shadow: 0 1px 6px rgba(201, 162, 75, .35);
}

.view { padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.hidden { display: none !important; }
.col { display: flex; flex-direction: column; gap: 10px; }
.row { display: flex; gap: 8px; align-items: center; }
.row input { flex: 1; min-width: 0; }
.note { color: var(--muted); font-size: 13px; }
.error { color: var(--danger); min-height: 1em; font-size: 13px; }

input, textarea, select, button { font: inherit; color: var(--text); }

input, textarea, select {
  width: 100%;
  padding: 12px 14px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  outline: none;
  font-size: 16px; /* iOSのズーム防止 */
}
input:focus, textarea:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

label { display: flex; flex-direction: column; gap: 4px; color: var(--muted); font-size: 13px; }

button {
  padding: 12px 16px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 15px;
}
button.primary {
  background: linear-gradient(120deg, var(--acc1), var(--acc2));
  border-color: transparent;
  color: #fff;
  font-weight: 800;
  box-shadow: 0 3px 12px rgba(201, 162, 75, .35);
}
button.primary:hover { filter: brightness(1.08); }
button.danger { color: var(--danger); border-color: rgba(217, 69, 61, 0.4); }
button.mini { padding: 6px 10px; font-size: 13px; border-radius: 9px; }
.icon-btn { padding: 8px 12px; }
/* SVGアイコンだけのボタン（表示切替/コピー）は正方形に揃える */
button.icon-only { display: inline-flex; align-items: center; justify-content: center; padding: 6px; width: 30px; height: 30px; color: var(--muted); }
button.icon-only:hover { color: var(--accent); }
button.icon-only svg { display: block; }
/* コピーは「カーソルを合わせた時だけ」表示。タッチ端末では常に出す（タップできなくなるため） */
@media (hover: hover) {
  .copy-btn { opacity: 0; transition: opacity .15s; }
  .field:hover .copy-btn, .field:focus-within .copy-btn,
  .row:hover .copy-btn, .row:focus-within .copy-btn { opacity: 1; }
}
/* クリック後に青いフォーカス枠が残らないよう、キーボード操作時だけリングを出す */
button:focus { outline: none; }
button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.unlock-box { display: flex; flex-direction: column; gap: 12px; text-align: center; margin-top: 10vh; }
.unlock-icon { font-size: 48px; }

ul#entryList { list-style: none; display: flex; flex-direction: column; gap: 8px; padding: 0; }
#entryList li {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  transition: border-color .12s, box-shadow .12s, background .12s;
}
#entryList li:hover { border-color: #E6CD8F; box-shadow: 0 3px 14px rgba(201,162,75,.16); }
#entryList li:active { background: var(--panel-hover); }

.avatar {
  width: 38px; height: 38px;
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
}
.entry-info { min-width: 0; flex: 1; }
.entry-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.entry-sub { color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.fab {
  position: fixed;
  right: 20px;
  bottom: calc(20px + env(safe-area-inset-bottom));
  width: 58px; height: 58px;
  border-radius: 50%;
  background: linear-gradient(120deg, var(--acc1), var(--acc2));
  color: #fff;
  font-size: 26px;
  border: none;
  box-shadow: 0 6px 20px rgba(201, 162, 75, 0.45);
  z-index: 20;
}

.sheet {
  position: fixed;
  inset: 0;
  background: rgba(28, 35, 51, 0.4);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 30;
}
.sheet-card {
  background: var(--bg);
  width: 100%;
  max-width: 640px;
  max-height: 88vh;
  overflow-y: auto;
  border-radius: 18px 18px 0 0;
  padding: 20px 16px calc(20px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.sheet-actions { margin-top: 6px; }
.sheet-actions button { flex: 1; }

.detail-head { display: flex; align-items: center; gap: 12px; }
.detail-title { font-size: 18px; font-weight: 700; word-break: break-all; }
.detail-chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { font-size: 12px; font-weight: 600; border: 1px solid var(--border); border-radius: 999px; padding: 3px 12px; color: var(--muted); background: var(--panel); }

.field {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.field-body { flex: 1; min-width: 0; }
.field-label { font-size: 11px; color: var(--muted); }
.field-value { font-size: 15px; word-break: break-all; font-family: ui-monospace, "SF Mono", monospace; }
.field-value a { color: var(--accent); text-decoration: none; }
.field-value.masked { letter-spacing: 0.15em; }
.field-value.notes { white-space: pre-wrap; font-family: inherit; }
.totp-code { font-size: 24px; font-weight: 700; color: var(--accent); letter-spacing: 0.12em; }
.totp-timer { font-size: 12px; color: var(--muted); }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(90px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: #1c2333;
  color: #fff;
  padding: 10px 20px;
  border-radius: 999px;
  font-size: 13px;
  z-index: 50;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
}

.legal-links { font-size: 12px; color: var(--muted); margin-top: 8px; }
.legal-links a { color: var(--accent); text-decoration: none; }

/* ===== MindKing風ロック画面：ブラーブロブ背景＋中央カード ===== */
#view-unlock { padding: 0; min-height: 100vh; display: flex; align-items: center; justify-content: center; position: relative; overflow: hidden; background: var(--bg); }
.lg-blob { position: fixed; border-radius: 50%; filter: blur(90px); opacity: .45; pointer-events: none; z-index: 0; animation: blobfloat 16s ease-in-out infinite alternate; }
.lg-blob.b1 { width: 480px; height: 480px; background: #EDE0C0; top: -140px; left: -120px; }
.lg-blob.b2 { width: 420px; height: 420px; background: #C7D2E0; bottom: -120px; right: -100px; animation-delay: -8s; }
@keyframes blobfloat { from { transform: translate(0,0) scale(1); } to { transform: translate(40px,30px) scale(1.12); } }
@media (prefers-reduced-motion: reduce){ .lg-blob{ animation: none; } }

.unlock-card {
  position: relative; z-index: 1;
  background: #fff; border: 1px solid var(--border); border-radius: 20px;
  box-shadow: 0 24px 70px rgba(40,40,90,.15);
  padding: 34px 30px; width: min(92vw, 400px);
  display: flex; flex-direction: column; gap: 10px;
  margin: 24px; text-align: center;
}
/* macOSログイン風：丸アバター＋名前＋ピル型入力欄 */
.lg-avatar {
  width: 74px; height: 74px;
  border-radius: 50%;
  margin: 0 auto 4px;
  box-shadow: 0 8px 24px rgba(40, 40, 90, 0.22);
}
.unlock-user { font-size: 16px; font-weight: 700; letter-spacing: 0.04em; margin-bottom: 10px; cursor: pointer; }
.unlock-card input { font-size: 16px; text-align: left; background: #F9FAFB; }
.unlock-card input:focus { background: #fff; }
.mac-pass-wrap { position: relative; width: min(100%, 250px); margin: 0 auto; }
.mac-pass-wrap input {
  width: 100%;
  border-radius: 999px;
  text-align: center;
  padding: 11px 38px;
  background: #F3F4F8;
  border-color: transparent;
}
.mac-pass-wrap input:focus { background: #fff; border-color: var(--accent); }
.mac-go {
  position: absolute;
  right: 6px; top: 50%;
  transform: translateY(-50%);
  width: 30px; height: 30px;
  border-radius: 50%;
  padding: 0;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 15px;
  color: #fff;
  border: none;
  background: linear-gradient(120deg, var(--acc1), var(--acc2));
  opacity: 0;
  transition: opacity 0.15s;
}
/* 入力があるときだけ→ボタンを出す（macOSと同じ挙動） */
.mac-pass-wrap input:not(:placeholder-shown) + .mac-go { opacity: 1; }
button.unlock-hint {
  background: none; border: none; box-shadow: none;
  color: var(--muted); font-size: 13px;
  cursor: pointer; padding: 4px;
}
button.unlock-hint:active { color: var(--accent); }
.keep-row {
  display: flex; align-items: center; justify-content: center; gap: 7px;
  font-size: 12.5px; color: var(--muted);
  margin: 2px 0 8px; cursor: pointer; user-select: none;
}
.keep-row input { width: auto; margin: 0; accent-color: var(--accent, #C9A24B); }
.ghost { background: #fff; border: 1px solid var(--border); color: var(--text); }

/* ロック画面ではヘッダーを隠す（bodyにlocked時のクラス付与） */
body.locked header { display: none; }

/* ===== レスポンシブ：PCの広い画面では幅を活かして複数カラムに ===== */
@media (min-width: 820px) {
  /* body全体の640px制限を解除（ロック画面のシルクを全面に出すためにも必要） */
  body { max-width: none; }
  /* 一覧は常に縦1列。カードを横に並べると拡張の大画面タブと見た目が食い違うため */
  #view-main { padding: 16px 24px 80px; }
}

/* ---------- 金庫オープニングアニメーション ---------- */

#introOverlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: radial-gradient(circle at 50% 42%, #ffffff 0%, var(--bg) 70%);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 22px;
  transition: opacity 0.45s ease;
}
#introOverlay.done { opacity: 0; pointer-events: none; }
#introOverlay.done .vault-door { transform: scale(1.35); }

.vault-door {
  position: relative;
  width: 150px;
  height: 150px;
  transition: transform 0.45s ease;
}

.vault-ring {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 3px solid var(--accent);
  box-shadow: 0 0 46px rgba(201, 162, 75, 0.35), inset 0 0 26px rgba(201, 162, 75, 0.14);
  animation: ring-glow 1.4s ease both;
}
@keyframes ring-glow {
  0% { box-shadow: 0 0 0 rgba(201, 162, 75, 0); border-color: #d0d5e4; }
  60% { border-color: #d0d5e4; }
  100% { box-shadow: 0 0 46px rgba(201, 162, 75, 0.35), inset 0 0 26px rgba(201, 162, 75, 0.14); border-color: var(--accent); }
}

/* ダイヤル：解錠の組み合わせを回すように左右に回転して止まる */
.vault-dial {
  position: absolute;
  inset: 16px;
  border-radius: 50%;
  border: 2px solid #d0d5e4;
  background: radial-gradient(circle, #ffffff 30%, #e8ebf4 100%);
  box-shadow: inset 0 2px 8px rgba(28, 35, 51, 0.08);
  animation: dial-spin 1.15s cubic-bezier(0.55, 0.05, 0.25, 1) both;
}
@keyframes dial-spin {
  0% { transform: rotate(-240deg); }
  55% { transform: rotate(70deg); }
  80% { transform: rotate(-25deg); }
  100% { transform: rotate(0deg); }
}
.vault-dial span {
  position: absolute;
  left: calc(50% - 1.5px);
  top: 7px;
  width: 3px;
  height: 13px;
  background: #9aa3b8;
  border-radius: 2px;
  transform-origin: 1.5px 52px;
}
.vault-dial span:nth-child(2) { transform: rotate(45deg); }
.vault-dial span:nth-child(3) { transform: rotate(90deg); }
.vault-dial span:nth-child(4) { transform: rotate(135deg); }
.vault-dial span:nth-child(5) { transform: rotate(180deg); }
.vault-dial span:nth-child(6) { transform: rotate(225deg); }
.vault-dial span:nth-child(7) { transform: rotate(270deg); }
.vault-dial span:nth-child(8) { transform: rotate(315deg); }

.vault-core {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 42px;
}
.vault-core .lock-closed { position: absolute; animation: lock-out 0.25s 1.05s ease both; }
.vault-core .lock-open { position: absolute; animation: lock-in 0.45s 1.1s cubic-bezier(0.34, 1.56, 0.64, 1) both; }
@keyframes lock-out { from { opacity: 1; transform: scale(1); } to { opacity: 0; transform: scale(0.7); } }
@keyframes lock-in { from { opacity: 0; transform: scale(0.5) rotate(-14deg); } to { opacity: 1; transform: scale(1) rotate(0); } }

.vault-brand {
  font-size: 17px;
  font-weight: 800;
  letter-spacing: 0.28em;
  color: var(--text);
  animation: brand-in 0.6s 0.75s ease both;
}
@keyframes brand-in {
  from { opacity: 0; transform: translateY(10px); letter-spacing: 0.5em; }
  to { opacity: 1; transform: none; letter-spacing: 0.28em; }
}

@media (prefers-reduced-motion: reduce) {
  #introOverlay { display: none !important; }
}

/* ============================================================
   広い画面（PC）: Chrome拡張の大画面タブと同じ3カラムレイアウト
   スマホ幅では sidebar / detailPane を隠し、従来の1カラムに戻る
   ============================================================ */

#sidebar, #detailPane, #listHeader { display: none; }
.layout, .main-col { display: contents; }

@media (min-width: 900px) {
  /* 1カラム時の読みやすさ用に body へ入れている max-width を、3カラムでは外す */
  body:not(.locked) {
    max-width: none; height: 100vh; overflow: hidden;
    display: flex; flex-direction: column;
  }
  body:not(.locked) #view-main { gap: 0; }
  body:not(.locked) header { position: static; }
  #view-main { flex: 1; min-height: 0; padding: 0; max-width: none; }

  .layout { display: flex; height: 100%; min-height: 0; }
  .main-col {
    display: flex; flex-direction: column; gap: 10px;
    flex: 1; min-width: 0; overflow-y: auto; padding: 16px 18px;
  }

  /* --- サイドバー --- */
  #sidebar {
    display: block; width: 270px; flex-shrink: 0;
    background: linear-gradient(180deg, #f2f5fe, #eef1fb);
    border-right: 1px solid var(--border);
    overflow-y: auto; padding: 14px 10px;
  }
  #sideNav { display: flex; flex-direction: column; gap: 2px; }
  /* 拡張の大画面タブと同じ指定（紺→金の向き・影まで揃える） */
  .side-new {
    display: flex; align-items: center; justify-content: center; gap: 6px;
    width: 100%; padding: 13px; margin-bottom: 12px;
    border: none; border-radius: 999px; cursor: pointer;
    background: linear-gradient(to right, #0B1F3A, #122C4F 55%, #C9A24B); /* 左＝紺 → 右＝金 */
    color: #fff; font-weight: 800; font-size: 14px;
    box-shadow: 0 4px 16px rgba(201, 162, 75, 0.4);
  }
  .side-new:hover { filter: brightness(1.08); border: none; }
  .side-group {
    font-size: 11px; color: #6d7eb5; font-weight: 700;
    text-transform: uppercase; letter-spacing: .06em;
    margin: 12px 0 4px; padding: 0 10px;
  }
  .side-item {
    display: flex; align-items: center; gap: 8px;
    width: 100%; padding: 8px 10px; border: none; background: none;
    border-radius: 10px; cursor: pointer; text-align: left;
    color: var(--text); font-size: 13.5px;
  }
  .side-item:hover { background: rgba(11, 31, 58, .06); }
  .side-item.active { background: rgba(201, 162, 75, .16); font-weight: 700; }
  .side-icon { flex-shrink: 0; font-size: 15px; }
  .side-label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .side-count { flex-shrink: 0; font-size: 11px; color: var(--muted); }
  .side-item.active .side-count { color: #8a6d1d; }
  .side-toggle {
    width: 16px; height: 16px; flex-shrink: 0; display: inline-flex;
    align-items: center; justify-content: center; color: var(--muted);
    transition: transform .12s;
  }
  .side-toggle.open { transform: rotate(90deg); }
  .side-item .depth-pad { display: inline-block; flex-shrink: 0; }

  /* --- 一覧 --- */
  .list-header { display: block; font-size: 16px; font-weight: 800; }
  .list-header .list-count { font-weight: 600; color: var(--muted); font-size: 13px; margin-left: 6px; }
  #searchInput { max-width: 560px; }
  #entryList li.selected { background: rgba(201, 162, 75, .12); }

  /* --- 詳細ペイン --- */
  #detailPane {
    display: block; width: 380px; flex-shrink: 0;
    border-left: 1px solid var(--border); background: var(--panel);
    overflow-y: auto; padding: 18px;
  }
  .pane-hint { color: var(--muted); font-size: 13px; text-align: center; margin-top: 28px; }
  #paneActions { margin-top: 16px; }

  /* --- 拡張の大画面タブと同じ文字・行のサイズに揃える --- */
  body:not(.locked) { font-size: 13.5px; }
  #entryList li { padding: 11px 14px; gap: 8px; }
  #entryList .avatar { width: 34px; height: 34px; border-radius: 9px; font-size: 16px; }
  .entry-sub { font-size: 11px; }
  ul#entryList { gap: 6px; }

  /* サイドバーに新規作成があるので、丸い＋ボタンは出さない */
  .fab { display: none; }
}
