:root {
  --blue: #1E88E5;
  --blue-dark: #1565C0;
  --bg: #F4F6F8;
  --card: #FFFFFF;
  --line: #E1E6EA;
  --text: #1A1F24;
  --muted: #6B7680;
  --danger: #D9534F;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Segoe UI", sans-serif;
  background: var(--bg); color: var(--text);
  font-size: 17px; line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}

.hidden { display: none !important; }
.screen { min-height: 100vh; }

/* ---- 起動／ログイン確認画面 ---- */
#screen-gate {
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(160deg, var(--blue), var(--blue-dark));
  padding: 24px;
}
.gate-box {
  width: 100%; max-width: 360px; background: var(--card);
  border-radius: 18px; padding: 28px 22px; text-align: center;
  box-shadow: 0 12px 40px rgba(0,0,0,.18);
}
.gate-title { margin: 0 0 4px; font-size: 24px; }
.gate-sub { margin: 0 0 18px; color: var(--muted); font-size: 15px; }
.gate-sub.error { color: var(--danger); }

/* ---- 共通ボタン ---- */
.btn {
  border: none; border-radius: 12px; padding: 13px 18px;
  font-size: 16px; font-weight: 600; cursor: pointer;
}
.btn-primary { background: var(--blue); color: #fff; }
.btn-primary:active { background: var(--blue-dark); }
.btn-ghost { background: transparent; color: var(--blue); border: 1.5px dashed var(--line); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:active { background: #b52b27; }
.btn-danger:disabled { opacity: .5; }
.btn-block { width: 100%; }
.btn-save { padding: 9px 18px; }
.btn-icon {
  background: transparent; border: none; font-size: 20px;
  width: 42px; height: 42px; border-radius: 10px; cursor: pointer; color: var(--text);
}
.btn-icon:active { background: rgba(0,0,0,.06); }

.msg { color: var(--muted); font-size: 14px; margin: 12px 0 0; }
.msg.error { color: var(--danger); }

/* ---- アプリバー ---- */
.appbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 8px;
  padding: calc(8px + var(--safe-top)) 10px 8px;
  background: var(--card); border-bottom: 1px solid var(--line);
}
.appbar-title { flex: 1; font-weight: 700; font-size: 17px; text-align: center;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---- 一覧 ---- */
.list-body { padding: 10px 12px calc(24px + var(--safe-bottom)); }
.list-item {
  background: var(--card); border: 1px solid var(--line); border-radius: 14px;
  padding: 14px 16px; margin-bottom: 10px; cursor: pointer;
}
.list-item:active { background: #f0f4f8; }
.list-item-title { font-weight: 600; font-size: 16px; margin: 0 0 4px; }
.list-item-meta { color: var(--muted); font-size: 13px; margin: 0; }

/* ---- 編集 ---- */
.edit-body { padding: 12px 12px calc(40px + var(--safe-bottom)); }
.field-label { display: block; font-size: 13px; color: var(--muted); margin: 10px 2px 6px; font-weight: 600; }
.title-input {
  width: 100%; padding: 12px 14px; font-size: 18px; font-weight: 700;
  border: 1.5px solid var(--line); border-radius: 12px; resize: none;
  font-family: inherit; line-height: 1.4;
}

.block {
  background: var(--card); border: 1px solid var(--line);
  border-radius: 14px; padding: 10px 12px 6px; margin-bottom: 10px;
}
.block-head { display: flex; align-items: center; gap: 6px; margin-bottom: 6px; }
.style-select {
  font-size: 14px; padding: 6px 8px; border: 1px solid var(--line);
  border-radius: 9px; background: #fff; color: var(--text); flex: 0 0 auto;
}
.mark-badge {
  font-size: 11px; color: #9a6b00; background: #fff4d6;
  border-radius: 7px; padding: 3px 7px;
}
.block-ops { margin-left: auto; display: flex; gap: 2px; }
.block-ops .btn-icon { width: 38px; height: 38px; font-size: 18px; }

.block-text-area {
  width: 100%; border: none; outline: none; resize: none;
  font-size: 17px; line-height: 1.6; font-family: inherit;
  padding: 2px; background: transparent; color: var(--text);
}
.op-add-below {
  width: auto; height: auto; font-size: 13px; color: var(--muted);
  padding: 6px 4px; display: block;
}

/* 見出しの見た目を本文と区別（編集中も構造が分かるように） */
.block[data-style="h1"] .block-text-area,
.block[data-style="h2"] .block-text-area { font-size: 20px; font-weight: 700; }
.block[data-style="h3"] .block-text-area { font-size: 18px; font-weight: 700; }
.block[data-style="h4"] .block-text-area { font-size: 17px; font-weight: 700; color: var(--muted); }
.block[data-style="blockquote"] .block-text-area {
  border-left: 3px solid var(--blue); padding-left: 10px; color: #37474F; font-style: italic;
}
.block[data-list="bullet"] .block-text-area,
.block[data-list="number"] .block-text-area { padding-left: 16px; }
.block[data-list="bullet"] .block-text-area::before { content: "• "; color: var(--muted); }
.block[data-list="number"] .block-text-area::before { content: "1. "; color: var(--muted); }
.list-badge { color: #1a5e8a; background: #e3f0fa; }

.block-other { background: #eef2f5; }
.other-label { font-weight: 700; font-size: 15px; }
.other-note { color: var(--muted); font-size: 13px; margin: 2px 0 6px; }

/* ---- トースト ---- */
.toast {
  position: fixed; left: 50%; bottom: calc(24px + var(--safe-bottom));
  transform: translateX(-50%);
  background: #263238; color: #fff; padding: 12px 20px;
  border-radius: 24px; font-size: 15px; z-index: 100;
  box-shadow: 0 8px 24px rgba(0,0,0,.3); max-width: 90%;
}
.toast.error { background: var(--danger); }

.dirty-dot { color: var(--blue); }

.publish-zone { margin-top: 28px; padding-top: 18px; border-top: 1px solid var(--line); }
.publish-note { font-size: 13px; color: var(--muted); margin: 0 2px 10px; }
