/* 奏志日記 — 絵本・スクラップブック風デザイン */

:root {
  --paper:      #f6ecd9;   /* 生成りの紙 */
  --paper-2:    #fdf8ee;   /* カード地 */
  --ink:        #4a3f35;   /* 文字（焦げ茶） */
  --ink-soft:   #8a7c6b;
  --accent:     #e08a5b;   /* 水彩オレンジ（バスの色） */
  --accent-2:   #7fa86b;   /* 若草 */
  --line:       #e3d5bd;
  --shadow:     rgba(74, 63, 53, 0.14);
  --danger:     #c0584b;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Zen Maru Gothic", system-ui, sans-serif;
  color: var(--ink);
  background-color: var(--paper);
  background-image:
    radial-gradient(circle at 20% 15%, rgba(224,138,91,0.07), transparent 45%),
    radial-gradient(circle at 85% 80%, rgba(127,168,107,0.08), transparent 45%);
  background-attachment: fixed;
  min-height: 100vh;
  padding-bottom: 76px; /* タブバー分 */
}

h1, h2, .brand-name, .login-title, .card-date { font-family: "Yomogi", "Zen Maru Gothic", cursive; }

/* ---------- ヘッダー ---------- */
.app-header {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 12px 18px;
  background: rgba(246,236,217,0.92);
  backdrop-filter: blur(6px);
  border-bottom: 2px dashed var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; }
.brand-icon { font-size: 26px; }
.brand-name { font-size: 22px; font-weight: 700; }
.header-actions { display: flex; align-items: center; gap: 10px; }
.role-badge {
  font-size: 12px; color: var(--ink-soft);
  background: var(--paper-2); border: 1px solid var(--line);
  padding: 3px 10px; border-radius: 999px;
}

/* ---------- ボタン ---------- */
.btn {
  font-family: inherit; font-size: 14px; font-weight: 500;
  border: none; border-radius: 999px; padding: 9px 16px;
  cursor: pointer; display: inline-flex; align-items: center; gap: 6px;
  transition: transform .08s ease, box-shadow .15s ease, background .15s ease;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--accent); color: #fff; box-shadow: 0 3px 10px var(--shadow); }
.btn-primary:hover { background: #d57a4b; }
.btn-ghost { background: transparent; color: var(--ink-soft); }
.btn-ghost:hover { background: rgba(0,0,0,0.04); }
.btn-danger { background: transparent; color: var(--danger); border: 1px solid var(--danger); }
.btn-block { width: 100%; justify-content: center; padding: 12px; font-size: 16px; }
.btn:disabled { opacity: .6; cursor: default; }

/* ---------- ビュー ---------- */
.main { max-width: 1040px; margin: 0 auto; padding: 18px; }
.view { display: none; }
.view.active { display: block; animation: fade .25s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ---------- ログイン ---------- */
#view-login.active { display: flex; min-height: 80vh; align-items: center; justify-content: center; }
.login-card {
  background: var(--paper-2); border: 1px solid var(--line);
  border-radius: 22px; padding: 36px 30px; width: min(380px, 92vw);
  text-align: center; box-shadow: 0 10px 34px var(--shadow);
}
.login-icon { font-size: 52px; }
.login-title { font-size: 30px; margin: 6px 0 2px; }
.login-sub { color: var(--ink-soft); margin: 0 0 22px; font-size: 14px; }
.login-form { display: flex; flex-direction: column; gap: 14px; text-align: left; }
.login-form label, .field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--ink-soft); }
.login-form input, .field input, .field textarea {
  font-family: inherit; font-size: 16px; color: var(--ink);
  background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 11px 13px;
  width: 100%; box-sizing: border-box;
}
.login-form input:focus, .field input:focus, .field textarea:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(224,138,91,0.15);
}

/* ---------- 今日まだ書いてない案内 ---------- */
.today-nudge {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  background: #fffaf0; border: 1px solid var(--accent); border-radius: 14px;
  padding: 12px 16px; margin-bottom: 18px;
}
.today-nudge .nudge-text { font-size: 14px; font-weight: 700; color: var(--ink); }

/* ---------- タグ絞り込みバー ---------- */
.tag-filter { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.tagf-chip { font-family: inherit; font-size: 13px; color: var(--ink-soft); background: var(--paper-2); border: 1px solid var(--line); border-radius: 999px; padding: 5px 13px; cursor: pointer; transition: all .12s ease; }
.tagf-chip:hover { border-color: var(--accent); }
.tagf-chip.active { background: var(--accent); color: #fff; border-color: var(--accent); font-weight: 700; }

/* ---------- 一覧（カードグリッド） ---------- */
.entry-grid {
  display: grid; gap: 20px;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
}
.card {
  background: var(--paper-2); border-radius: 14px; overflow: hidden;
  box-shadow: 0 4px 14px var(--shadow); cursor: pointer;
  border: 1px solid var(--line);
  transition: transform .12s ease, box-shadow .15s ease;
  transform: rotate(-0.4deg);
}
.card:nth-child(even) { transform: rotate(0.5deg); }
.card:hover { transform: rotate(0) translateY(-3px); box-shadow: 0 10px 24px var(--shadow); }
.card-img { aspect-ratio: 4/3; background: #efe4cf; overflow: hidden; }
.card-img img { width: 100%; height: 100%; object-fit: cover; display: block; }
.card-img-placeholder { display: flex; align-items: center; justify-content: center; font-size: 46px; opacity: .5; }
.card-body { padding: 12px 14px 14px; }
.card-meta { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.card-date { font-size: 17px; font-weight: 700; color: var(--accent); }
.card-age { font-size: 12px; color: var(--ink-soft); }
.card-text { margin: 8px 0; font-size: 14px; line-height: 1.7; white-space: pre-wrap; }
.card-tags, .read-tags { display: flex; flex-wrap: wrap; gap: 6px; }
.tag { font-size: 11px; background: rgba(127,168,107,0.16); color: var(--accent-2); padding: 2px 9px; border-radius: 999px; }

/* ---------- カレンダーモード ---------- */
.cal-header { display: flex; align-items: center; justify-content: center; gap: 18px; margin-bottom: 14px; }
.cal-title { font-size: 22px; margin: 0; min-width: 150px; text-align: center; }
.cal-nav { font-size: 22px; line-height: 1; padding: 6px 14px; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.cal-dow { text-align: center; font-size: 12px; color: var(--ink-soft); padding: 4px 0; font-weight: 700; }
.cal-dow.sun { color: var(--danger); }
.cal-dow.sat { color: #5b86c0; }
.cal-cell {
  position: relative; aspect-ratio: 1; border-radius: 10px;
  background: var(--paper-2); border: 1px solid var(--line); overflow: hidden;
}
.cal-cell.cal-empty { background: transparent; border: none; }
.cal-cell.has { cursor: pointer; }
.cal-cell.has:hover { transform: translateY(-2px); box-shadow: 0 6px 16px var(--shadow); transition: all .12s ease; }
.cal-cell.today { border-color: var(--accent); border-width: 2px; }
.cal-num { position: absolute; top: 3px; left: 6px; font-size: 12px; color: var(--ink-soft); z-index: 2; font-weight: 700; }
.cal-cell.has .cal-num { color: #fff; text-shadow: 0 1px 3px rgba(0,0,0,0.5); }
.cal-thumb { width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; font-size: 22px; opacity: .5; }
.cal-cell.has .cal-thumb { opacity: 1; }
.cal-thumb img { width: 100%; height: 100%; object-fit: cover; }
.cal-badge { position: absolute; bottom: 4px; right: 4px; z-index: 2; font-size: 10px; background: var(--accent); color: #fff; border-radius: 999px; padding: 1px 6px; }
/* 管理者は空き日もクリックできる（カーソルで示す） */
body.is-admin .cal-cell:not(.has):not(.cal-empty) { cursor: pointer; }
body.is-admin .cal-cell:not(.has):not(.cal-empty):hover { background: #fffaf0; border-color: var(--accent); border-style: dashed; }

/* ---------- 絵本めくりモード ---------- */
.book-stage { display: flex; align-items: center; justify-content: center; gap: 12px; margin-top: 8px; }
.book-arrow {
  flex: 0 0 auto; width: 46px; height: 46px; border-radius: 50%;
  border: 1px solid var(--line); background: var(--paper-2); color: var(--accent);
  font-size: 26px; line-height: 1; cursor: pointer; box-shadow: 0 3px 10px var(--shadow);
  transition: transform .08s ease, opacity .15s ease;
}
.book-arrow:hover:not(:disabled) { transform: scale(1.08); }
.book-arrow:active:not(:disabled) { transform: scale(0.96); }
.book-arrow:disabled { opacity: .3; cursor: default; }
.book-spread {
  display: flex; width: min(820px, 100%); aspect-ratio: 16/10;
  background: var(--paper-2); border: 1px solid var(--line); border-radius: 16px;
  overflow: hidden; box-shadow: 0 12px 34px var(--shadow);
  /* 中央の綴じ目（背） */
  background-image: linear-gradient(to right, transparent calc(50% - 10px), rgba(74,63,53,0.10) 50%, transparent calc(50% + 10px));
  transition: transform .17s ease, opacity .17s ease; transform-origin: center;
}
.book-spread.flip-next { opacity: 0; transform: translateX(-26px) rotateY(7deg); }
.book-spread.flip-prev { opacity: 0; transform: translateX(26px) rotateY(-7deg); }
.book-page { flex: 1; min-width: 0; padding: 18px; display: flex; flex-direction: column; }
.book-left { align-items: center; justify-content: center; }
.book-img { width: 100%; height: 100%; border-radius: 10px; background: #efe4cf; display: flex; align-items: center; justify-content: center; font-size: 54px; overflow: hidden; }
.book-img img { width: 100%; height: 100%; object-fit: cover; }
.book-right { overflow: auto; }
.book-meta { display: flex; align-items: baseline; gap: 10px; margin-bottom: 10px; flex-wrap: wrap; }
.book-date { font-family: "Yomogi", cursive; font-size: 22px; color: var(--accent); }
.book-age { font-size: 13px; color: var(--ink-soft); }
.book-text { flex: 1; line-height: 2; white-space: pre-wrap; font-size: 15px; }
.book-tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }
.book-counter { text-align: center; color: var(--ink-soft); font-size: 13px; margin-top: 12px; }

@media (max-width: 640px) {
  .book-spread { flex-direction: column; aspect-ratio: auto; min-height: 60vh; background-image: none; }
  .book-left { max-height: 42vh; }
  .book-arrow { width: 40px; height: 40px; font-size: 22px; }
  .book-stage { gap: 6px; }
}

/* ---------- 成長記録 ---------- */
.growth-form { background: var(--paper-2); border: 1px solid var(--line); border-radius: 16px; padding: 18px 20px; max-width: 620px; margin: 0 auto 22px; box-shadow: 0 5px 16px var(--shadow); }
.growth-form-title { margin: 0 0 14px; font-size: 18px; }
.g-row { display: flex; gap: 14px; }
.g-row .field { flex: 1; min-width: 0; }
.growth-charts { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; max-width: 900px; margin: 0 auto 22px; }
.chart-card { background: var(--paper-2); border: 1px solid var(--line); border-radius: 16px; padding: 16px; box-shadow: 0 4px 14px var(--shadow); }
.chart-card h3 { margin: 0 0 10px; font-size: 16px; color: var(--ink); }
.chart-box { position: relative; height: 220px; }
.growth-list { max-width: 620px; margin: 0 auto; display: flex; flex-direction: column; gap: 8px; }
.growth-row { display: grid; grid-template-columns: 1fr auto auto auto auto; align-items: center; gap: 10px; background: var(--paper-2); border: 1px solid var(--line); border-radius: 12px; padding: 10px 14px; }
.growth-row .g-date { font-weight: 700; color: var(--accent); }
.growth-row .g-age { font-size: 12px; color: var(--ink-soft); }
.growth-row .g-val { font-size: 14px; min-width: 56px; text-align: right; }
.g-del { border: none; background: transparent; color: var(--danger); font-size: 18px; cursor: pointer; line-height: 1; }

@media (max-width: 640px) {
  .growth-charts { grid-template-columns: 1fr; }
  .growth-row { grid-template-columns: 1fr auto auto; row-gap: 4px; }
  .growth-row .g-age { grid-column: 1 / -1; }
}

/* 「この日の記録」チップ（成長記録） */
.growth-chip { display: inline-block; font-size: 11px; color: var(--accent-2); background: rgba(127,168,107,0.14); border: 1px solid rgba(127,168,107,0.3); border-radius: 999px; padding: 2px 8px; margin-top: 6px; white-space: nowrap; }
.book-growth { margin: 6px 0; }
.book-growth .growth-chip { font-size: 13px; }

/* ---------- 体調ログ ---------- */
.health-form { background: var(--paper-2); border: 1px solid var(--line); border-radius: 16px; padding: 16px 18px; max-width: 620px; margin: 0 auto 16px; box-shadow: 0 4px 14px var(--shadow); }
.health-form-title { margin: 0 0 12px; font-size: 17px; display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.health-who { font-size: 12px; color: var(--accent-2); font-weight: 700; }
.h-form-row { display: flex; gap: 12px; }
.h-form-row .h-f-date { flex: 2; min-width: 0; }
.h-form-row .h-f-time { flex: 1; min-width: 0; }
.health-search { display: block; width: 100%; max-width: 620px; margin: 0 auto 14px; box-sizing: border-box; font-family: inherit; font-size: 15px; color: var(--ink); background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 10px 13px; }
.health-search:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(224,138,91,0.15); }
.health-list { max-width: 620px; margin: 0 auto; }
.h-dayhead { font-family: "Yomogi", cursive; font-size: 15px; color: var(--accent); margin: 16px 0 6px; border-bottom: 1px dashed var(--line); padding-bottom: 3px; }
.h-dayhead .h-age { font-family: "Zen Maru Gothic", sans-serif; font-size: 11px; color: var(--ink-soft); }
.h-row { display: flex; align-items: center; gap: 10px; padding: 7px 4px; border-bottom: 1px solid rgba(227,213,189,0.5); }
.h-time { font-size: 12px; color: var(--ink-soft); min-width: 42px; }
.h-note { flex: 1; font-size: 14px; line-height: 1.5; }
.h-who { font-size: 10px; padding: 1px 7px; border-radius: 999px; white-space: nowrap; }
.h-who-m { background: rgba(224,138,91,0.16); color: var(--accent); }
.h-who-p { background: rgba(127,168,107,0.16); color: var(--accent-2); }
.h-del { border: none; background: transparent; color: var(--danger); font-size: 16px; cursor: pointer; line-height: 1; opacity: .5; }
.h-del:hover { opacity: 1; }

.empty, .soon, .loading { text-align: center; color: var(--ink-soft); padding: 60px 20px; }
.empty-icon, .soon-icon { font-size: 48px; }
.empty p, .soon p { line-height: 1.8; }

/* ---------- 作成・編集フォーム ---------- */
.entry-form { background: var(--paper-2); border: 1px solid var(--line); border-radius: 18px; padding: 22px; max-width: 620px; margin: 0 auto; box-shadow: 0 6px 20px var(--shadow); }
.entry-form-title { margin: 0 0 16px; font-size: 24px; }
.field { margin-bottom: 16px; }
.entry-age { margin: -8px 0 16px; font-size: 13px; color: var(--accent-2); font-weight: 500; }
.photo-preview {
  aspect-ratio: 4/3; background: #efe4cf; border: 2px dashed var(--line);
  border-radius: 14px; display: flex; align-items: center; justify-content: center;
  cursor: pointer; overflow: hidden; margin-bottom: 16px;
}
.photo-preview img { width: 100%; height: 100%; object-fit: cover; }
.photo-hint { color: var(--ink-soft); font-size: 14px; }
.entry-actions { display: flex; align-items: center; gap: 10px; }
.entry-actions .spacer { flex: 1; }
.entry-dirty { display: inline-flex; align-items: center; font-size: 12px; color: #c0843b; font-weight: 700; animation: dirtyPulse 1.6s ease-in-out infinite; }
@keyframes dirtyPulse { 0%, 100% { opacity: 1; } 50% { opacity: .45; } }
.tag-suggest { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin: -6px 0 16px; }
.tag-suggest-label { font-size: 12px; color: var(--ink-soft); }
.tag-suggest-chip { font-family: inherit; font-size: 12px; color: var(--accent-2); background: rgba(127,168,107,0.12); border: 1px dashed var(--accent-2); border-radius: 999px; padding: 3px 10px; cursor: pointer; transition: background .12s ease; }
.tag-suggest-chip:hover { background: rgba(127,168,107,0.24); }

/* ---------- 読むだけモーダル ---------- */
.modal { position: fixed; inset: 0; background: rgba(74,63,53,0.5); display: none; align-items: center; justify-content: center; z-index: 50; padding: 18px; }
.modal.open { display: flex; }
.modal-box { background: var(--paper-2); border-radius: 18px; padding: 22px; width: min(520px, 94vw); max-height: 88vh; overflow: auto; position: relative; box-shadow: 0 14px 40px rgba(0,0,0,0.3); }
.modal-close { position: absolute; top: 10px; right: 12px; border: none; background: transparent; font-size: 26px; color: var(--ink-soft); cursor: pointer; }
.read-img { aspect-ratio: 4/3; background: #efe4cf; border-radius: 12px; overflow: hidden; display: flex; align-items: center; justify-content: center; font-size: 46px; }
.read-img img { width: 100%; height: 100%; object-fit: cover; }
.read-meta { margin-top: 14px; font-family: "Yomogi", cursive; font-size: 18px; color: var(--accent); }
.read-text { line-height: 1.9; white-space: pre-wrap; }

/* ---------- 下部タブ ---------- */
.tab-bar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 30;
  display: flex; background: rgba(253,248,238,0.96); backdrop-filter: blur(6px);
  border-top: 2px dashed var(--line); padding: 6px 4px env(safe-area-inset-bottom);
}
.tab-btn {
  flex: 1; border: none; background: transparent; cursor: pointer;
  font-family: inherit; font-size: 11px; color: var(--ink-soft);
  display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 7px 0;
}
.tab-btn span { font-size: 20px; }
.tab-btn.active { color: var(--accent); font-weight: 700; }

/* ---------- バナー ---------- */
.banner {
  position: fixed; left: 50%; bottom: 90px;
  transform: translateX(-50%) translateY(20px);
  background: var(--ink); color: #fff; padding: 11px 20px; border-radius: 999px;
  font-size: 14px; opacity: 0; pointer-events: none; transition: all .25s ease; z-index: 100;
  box-shadow: 0 6px 20px rgba(0,0,0,0.25); max-width: 90vw;
}
.banner.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.banner-error { background: var(--danger); }
.banner-success { background: var(--accent-2); }

@media (max-width: 520px) {
  .app-header { flex-wrap: wrap; }
  .brand-name { font-size: 20px; }
  .btn { padding: 8px 13px; font-size: 13px; }
}
