/* テーマ変数：iOS「メモ」風。ライトを既定にし、ダークは data-theme / OS設定で上書きする */
:root {
  --bg: #ffffff;
  --surface: #ffffff;   /* メモ行の背景 */
  --field: #e9e9eb;     /* 検索欄などのグレー塗り */
  --text: #1c1c1e;
  --text-muted: #8e8e93;
  --divider: #e5e5ea;   /* 行間のヘアライン */
  --accent: #ffcc00;    /* iOSメモの黄色（作成ボタン） */
  --accent-ink: #1c1c1e;/* 黄色の上に載る文字・アイコン色 */
  --tint: #d69e00;      /* ナビの文字ボタン（白地で読める黄） */
  --danger: #ff3b30;    /* スワイプ削除の赤 */
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.22);
  --radius: 12px;
}

/* OSがダーク設定のときの既定値（手動トグルが未指定の場合に適用） */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --bg: #000000;
    --surface: #1c1c1e;
    --field: #2c2c2e;
    --text: #ffffff;
    --text-muted: #98989f;
    --divider: #38383a;
    --accent: #ffd426;
    --accent-ink: #1c1c1e;
    --tint: #ffd426;
    --danger: #ff453a;
    --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.6);
  }
}

/* 手動でダークを選んだ場合 */
:root[data-theme="dark"] {
  --bg: #000000;
  --surface: #1c1c1e;
  --field: #2c2c2e;
  --text: #ffffff;
  --text-muted: #98989f;
  --divider: #38383a;
  --accent: #ffd426;
  --accent-ink: #1c1c1e;
  --tint: #ffd426;
  --danger: #ff453a;
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.6);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Yu Gothic",
    "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  padding-bottom: env(safe-area-inset-bottom);
}

/* ===== ヘッダー（iOSのラージタイトル） ===== */
.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--bg);
  padding: max(env(safe-area-inset-top), 10px) 16px 8px;
}

.app-header__row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.app-title {
  margin: 0;
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: 0.01em;
}

/* 検索欄：グレー塗り＋虫眼鏡アイコン */
.search {
  margin-top: 10px;
}

.search__input {
  width: 100%;
  padding: 9px 14px 9px 38px;
  font-size: 16px; /* iOSでの自動ズームを防ぐため16px以上 */
  color: var(--text);
  background: var(--field);
  border: none;
  border-radius: 10px;
  outline: none;
  /* 左端の虫眼鏡アイコン（グレー） */
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%238e8e93' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cpath d='M21 21l-4.3-4.3'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: 12px center;
}

.search__input::placeholder {
  color: var(--text-muted);
}

/* iOSの検索クリア（×）ボタンの見た目を残す */
.search__input::-webkit-search-cancel-button {
  -webkit-appearance: none;
  height: 16px;
  width: 16px;
  border-radius: 50%;
  background: var(--text-muted);
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='black' d='M12 2a10 10 0 1 0 0 20 10 10 0 0 0 0-20zm3.5 12.1-1.4 1.4L12 13.4l-2.1 2.1-1.4-1.4L10.6 12 8.5 9.9l1.4-1.4L12 10.6l2.1-2.1 1.4 1.4L13.4 12z'/%3E%3C/svg%3E") center/contain no-repeat;
          mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='black' d='M12 2a10 10 0 1 0 0 20 10 10 0 0 0 0-20zm3.5 12.1-1.4 1.4L12 13.4l-2.1 2.1-1.4-1.4L10.6 12 8.5 9.9l1.4-1.4L12 10.6l2.1-2.1 1.4 1.4L13.4 12z'/%3E%3C/svg%3E") center/contain no-repeat;
  cursor: pointer;
}

/* ===== メイン ===== */
.app-main {
  max-width: 720px;
  margin: 0 auto;
  padding: 12px 16px 120px; /* FAB分の下余白 */
}

/* グループ化された角丸リスト（iOS Inset Grouped） */
.memo-list {
  list-style: none;
  margin: 0;
  padding: 0;
  background: var(--surface);
  border-radius: var(--radius);
  overflow: hidden; /* スワイプ時に削除ボタンをはみ出させない＆角丸クリップ */
}

/* 各行のラッパ（背後に削除ボタンを敷く） */
.memo-item {
  position: relative;
  overflow: hidden;
}

/* スワイプで現れる削除ボタン（背後・右側） */
.memo-item__delete {
  position: absolute;
  top: 0;
  right: 0;
  height: 100%;
  width: 88px;
  border: none;
  background: var(--danger);
  color: #fff;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
}

/* 前面の行本体（横スライドする） */
.memo-row {
  position: relative;
  background: var(--surface);
  padding: 11px 16px;
  cursor: pointer;
  touch-action: pan-y; /* 縦スクロールは許可、横は自前で処理 */
  transition: transform 0.2s ease;
  will-change: transform;
}

/* 行間のヘアライン（左を少し内側に） */
.memo-item:not(:last-child) .memo-row::after {
  content: "";
  position: absolute;
  left: 16px;
  right: 0;
  bottom: 0;
  height: 1px;
  background: var(--divider);
}

.memo-row:active {
  background: var(--field);
}

.memo-row__title {
  margin: 0;
  font-size: 1.02rem;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* 2行目：日時（濃いめ）＋本文プレビュー（グレー） */
.memo-row__sub {
  margin: 2px 0 0;
  font-size: 0.9rem;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.memo-row__time {
  color: var(--text);
}

/* 件数（iOS風に一覧の下・中央） */
.list-count {
  margin: 14px 0 0;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.8rem;
}

/* 空状態 */
.empty {
  text-align: center;
  color: var(--text-muted);
  padding: 64px 16px;
}

.empty__icon {
  font-size: 2.6rem;
  display: block;
  margin-bottom: 10px;
}

/* ===== ヘッダー右のアイコン群（同期・テーマ） ===== */
.app-header__actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ===== アイコンボタン（同期・テーマ切替） ===== */
.icon-btn {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  font-size: 1.1rem;
  background: var(--field);
  border: none;
  border-radius: 50%;
  cursor: pointer;
  color: var(--text);
}

/* 同期が接続済みのときは黄色い縁で状態を示す */
.icon-btn--on {
  box-shadow: inset 0 0 0 2px var(--accent);
}

/* ===== FAB（新規作成・黄色のペン） ===== */
.fab {
  position: fixed;
  right: max(env(safe-area-inset-right), 20px);
  bottom: max(env(safe-area-inset-bottom), 24px);
  width: 58px;
  height: 58px;
  display: grid;
  place-items: center;
  color: var(--accent-ink);
  background: var(--accent);
  border: none;
  border-radius: 50%;
  box-shadow: var(--shadow-lg);
  cursor: pointer;
  z-index: 20;
}

.fab:active {
  transform: scale(0.94);
}

/* ===== エディタ（全画面） ===== */
.editor {
  position: fixed;
  inset: 0;
  width: 100%;
  max-width: 100%;
  height: 100%;
  max-height: 100%;
  margin: 0;
  padding: 0;
  border: none;
  background: var(--bg);
  color: var(--text);
}

.editor:not([open]) {
  display: none;
}

.editor::backdrop {
  background: var(--bg);
}

.editor__form {
  display: flex;
  flex-direction: column;
  height: 100%;
}

/* 上部ナビバー */
.editor__bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: max(env(safe-area-inset-top), 10px) 12px 8px;
  border-bottom: 1px solid var(--divider);
}

.editor__bar-right {
  display: flex;
  align-items: center;
  gap: 4px;
}

.editor__navbtn {
  background: none;
  border: none;
  color: var(--tint);
  font-size: 1rem;
  padding: 6px 8px;
  cursor: pointer;
}

.editor__navbtn--done {
  font-weight: 700;
}

.editor__iconbtn {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  background: none;
  border: none;
  color: var(--tint);
  cursor: pointer;
}

/* タイトル・本文はボーダーレスでノート紙のように */
.editor__title,
.editor__body {
  width: 100%;
  color: var(--text);
  background: var(--bg);
  border: none;
  outline: none;
  font-family: inherit;
  padding: 12px 18px;
}

.editor__title {
  font-size: 1.3rem;
  font-weight: 700;
  padding-bottom: 4px;
}

.editor__title::placeholder,
.editor__body::placeholder {
  color: var(--text-muted);
}

.editor__body {
  flex: 1;
  resize: none;
  font-size: 1rem;
  line-height: 1.7;
  padding-top: 6px;
}

/* ===== 同期シート（中央のカード型ダイアログ） ===== */
.sheet {
  width: min(440px, calc(100% - 32px));
  margin: auto;
  padding: 0;
  border: none;
  border-radius: 16px;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-lg);
}

.sheet:not([open]) {
  display: none;
}

.sheet::backdrop {
  background: rgba(0, 0, 0, 0.4);
}

.sheet__form {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 16px 18px max(env(safe-area-inset-bottom), 18px);
}

.sheet__bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.sheet__title {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 700;
}

.sheet__desc {
  margin: 0;
  font-size: 0.85rem;
  color: var(--text-muted);
  line-height: 1.6;
}

.sheet__field {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.sheet__label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
}

.sheet__coderow {
  display: flex;
  gap: 8px;
}

.sheet__code,
.sheet__input {
  width: 100%;
  padding: 10px 12px;
  font-size: 16px; /* iOSの自動ズーム防止 */
  color: var(--text);
  background: var(--field);
  border: none;
  border-radius: 10px;
  outline: none;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  letter-spacing: 0.03em;
}

.sheet__code {
  flex: 1;
  min-width: 0;
}

/* シート内のボタン（グレー基調。主要動作のみ黄色） */
.sheet__btn {
  padding: 11px 14px;
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
  background: var(--field);
  border: none;
  border-radius: 10px;
  cursor: pointer;
  white-space: nowrap;
}

.sheet__btn:active {
  opacity: 0.7;
}

.sheet__btn--primary {
  color: var(--accent-ink);
  background: var(--accent);
}

.sheet__coderow .sheet__btn {
  flex: 0 0 auto;
}

.sheet__status {
  margin: 0;
  min-height: 1.2em;
  font-size: 0.85rem;
  color: var(--tint);
  text-align: center;
}
