:root {
  --bg: #f6f8fb;
  --card: #ffffff;
  --ink: #3a4252;
  --muted: #8a93a6;
  --line: #e6eaf2;
  --sleep: #5b8def;       /* 寝ていた時間の青 */
  --sleep-soft: #eaf1ff;
  --red: #e8615a;         /* カスタム項目の赤 */
  --red-soft: #ffe6e4;
  --accent: #5b8def;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, "Hiragino Kaku Gothic ProN", "Yu Gothic", sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.6;
}

.hidden { display: none !important; }

/* ---- ログイン画面 ---- */
#login-view {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  padding: 24px 16px;
}
.login-card {
  background: var(--card);
  padding: 40px 36px;
  border-radius: 20px;
  box-shadow: 0 8px 30px rgba(60, 80, 120, 0.08);
  text-align: center;
  max-width: 400px;
}
.login-logo { border-radius: 18px; margin-bottom: 10px; }
.login-card h1 { margin: 0 0 6px; font-size: 26px; }
.login-card .tagline { color: var(--muted); margin: 0 0 22px; }
.feature-list {
  list-style: none;
  padding: 0;
  margin: 0 0 26px;
  text-align: left;
  font-size: 14px;
  color: var(--ink);
}
.feature-list li {
  padding: 8px 4px;
  border-bottom: 1px dashed var(--line);
  display: flex;
  align-items: center;
  gap: 10px;
}
.feature-list li:last-child { border-bottom: none; }
.feature-emoji { font-size: 18px; }
.google-btn {
  display: inline-block;
  background: var(--accent);
  color: #fff;
  text-decoration: none;
  padding: 12px 28px;
  border-radius: 999px;
  font-weight: 600;
}

/* ---- 全体レイアウト ---- */
#app-view {
  max-width: 920px;
  margin: 0 auto;
  padding: 20px 16px 60px;
}
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.app-header h1 { font-size: 22px; margin: 0; }
.user-box { display: flex; align-items: center; gap: 14px; font-size: 14px; color: var(--muted); }
.logout-link { color: var(--muted); }

.card {
  background: var(--card);
  border-radius: 16px;
  padding: 20px 22px;
  margin-bottom: 18px;
  box-shadow: 0 4px 18px rgba(60, 80, 120, 0.05);
}
.card h2 { font-size: 16px; margin: 0 0 16px; }

/* ---- フォーム ---- */
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.time-row { display: flex; gap: 8px; }
.time-row input {
  flex: 1;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  font-size: 15px;
  color: var(--ink);
}
.now-btn {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 10px;
  padding: 0 16px;
  cursor: pointer;
  color: var(--accent);
  font-weight: 600;
}
.submit-btn {
  width: 100%;
  margin-top: 6px;
  padding: 12px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}
.form-msg { font-size: 13px; margin: 10px 0 0; min-height: 18px; }
.form-msg.error { color: #d9534f; }
.form-msg.ok { color: var(--accent); }
.hint { font-size: 12px; color: var(--muted); margin: 12px 0 0; }

/* ---- 月ナビ ---- */
.month-nav {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}
.month-nav h2 { margin: 0; flex: 1; text-align: center; min-width: 120px; }
.month-nav button {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 10px;
  padding: 8px 14px;
  cursor: pointer;
  color: var(--ink);
}
.print-btn { color: var(--accent); font-weight: 600; }

/* ---- 月間グリッド ---- */
#grid { width: 100%; }
.grid-head, .grid-row {
  display: grid;
  /* 日付ラベル + 48マス（30分×48 = 24時間） */
  grid-template-columns: 64px repeat(48, 1fr) 56px;
  align-items: stretch;
}
.grid-head {
  font-size: 10px;
  color: var(--muted);
  border-bottom: 1px solid var(--line);
  /* スクロール・ピンチ拡大しても時刻の見出しを画面上部に固定する */
  position: sticky;
  top: var(--vv-top, 0px);
  z-index: 5;
  background: var(--card);
  padding-top: 4px;
  box-shadow: 0 2px 4px rgba(60, 80, 120, 0.06);
}
.grid-head .hour {
  text-align: left;
  border-left: 1px solid var(--line);
  padding-bottom: 2px;
  grid-column: span 4; /* 2時間ごとにラベル */
}
.grid-head .corner, .grid-head .total-h { padding-bottom: 2px; }
.grid-head .total-h { text-align: center; }

.grid-row { border-bottom: 1px solid var(--line); height: 22px; overflow: hidden; }
.grid-row:hover { background: #fafbfe; }
.day-label {
  font-size: 11px;
  color: var(--ink);
  display: flex;
  align-items: center;
  padding-left: 2px;
  white-space: nowrap;
}
.day-label.sat { color: #4178d4; }
.day-label.sun { color: #d9534f; }

.cell {
  border-left: 1px solid #f0f3f9;
  cursor: pointer;
  /* 縦スクロール＋2本指ピンチ拡大は残しつつ、1本指の横なぞりで塗れる */
  touch-action: pan-y pinch-zoom;
}
.cell.fill-blue { background: var(--sleep); }
.cell.fill-red { background: var(--red); }
/* 青と赤が重なるマスは斜めに半分ずつ */
.cell.fill-blue.fill-red {
  background: linear-gradient(135deg, var(--sleep) 0 50%, var(--red) 50% 100%);
}
.cell.selecting { background: var(--sleep-soft); box-shadow: inset 0 0 0 1px var(--sleep); }
.cell.selecting-red { background: var(--red-soft); box-shadow: inset 0 0 0 1px var(--red); }
.cell.erasing { background: #f0f0f0; box-shadow: inset 0 0 0 1px #b8b8b8; }
/* 2時間ごとに薄い区切り線 */
.cell.tick { border-left: 1px solid var(--line); }
/* 0時・6時・12時・18時は少し太い線（左）。右端の24時は右に太い線 */
.cell.tick-major { border-left: 2px solid #b9c2d4; }
.cell.tick-major-right { border-right: 2px solid #b9c2d4; }

.day-total {
  font-size: 11px;
  color: var(--muted);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding-right: 4px;
  white-space: nowrap; /* 合計時間が長くても折り返さない（行高・日付がずれないように） */
}

.legend { font-size: 12px; color: var(--muted); margin-top: 12px; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.legend-box { width: 14px; height: 14px; border-radius: 3px; display: inline-block; }
.legend-box.blue { background: var(--sleep); }
.legend-box.red { background: var(--red); }
.legend-box.red { margin-left: 10px; }
.legend-note { margin-left: 6px; }

/* 塗る色の切り替えバー */
.pen-bar { display: flex; align-items: center; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; }
.pen-label { font-size: 13px; color: var(--muted); }
.pen-btn {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--line); background: #fff; color: var(--ink);
  border-radius: 999px; padding: 7px 14px; cursor: pointer; font-size: 14px;
}
.pen-btn.active { border-color: var(--accent); box-shadow: 0 0 0 2px var(--sleep-soft); font-weight: 600; }
.pen-btn .swatch { width: 14px; height: 14px; border-radius: 4px; display: inline-block; }
.swatch.blue { background: var(--sleep); }
.swatch.red { background: var(--red); }
.edit-red { border: none; background: none; color: var(--muted); cursor: pointer; font-size: 13px; }

/* 一覧の色ドット */
.rec-dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; margin-right: 8px; vertical-align: middle; }
.rec-dot.blue { background: var(--sleep); }
.rec-dot.red { background: var(--red); }

/* ---- 記録一覧 ---- */
#record-list { list-style: none; padding: 0; margin: 0; }
#record-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 4px;
  border-bottom: 1px solid var(--line);
  font-size: 14px;
}
#record-list .rec-dur { color: var(--muted); font-size: 13px; }
#record-list .del-btn {
  border: none;
  background: none;
  color: #d9534f;
  cursor: pointer;
  font-size: 13px;
}
.empty { color: var(--muted); font-size: 14px; padding: 8px 0; }

.print-title { display: none; }

/* ---- ログイン画面の注記 ---- */
.login-note { font-size: 12px; color: var(--muted); margin: 18px 0 0; line-height: 1.7; }
.login-note a { color: var(--accent); }

/* ---- 使い方ガイド ---- */
.howto {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 14px;
  margin-bottom: 12px;
  font-size: 13px;
}
.howto summary { cursor: pointer; color: var(--accent); font-weight: 600; }
.howto ul { margin: 10px 0 4px; padding-left: 4px; list-style: none; }
.howto li { padding: 5px 0; line-height: 1.7; }

/* ---- データ・アカウント操作 ---- */
.data-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.data-btn {
  display: inline-block; text-decoration: none;
  border: 1px solid var(--line); background: #fff; color: var(--ink);
  border-radius: 10px; padding: 10px 16px; font-size: 14px; cursor: pointer;
}
.danger-btn {
  border: 1px solid #e6b3b0; background: #fff; color: #d9534f;
  border-radius: 10px; padding: 10px 16px; font-size: 14px; cursor: pointer;
}
.danger-btn:hover { background: #fff5f5; }

/* ---- フッター ---- */
.app-footer { text-align: center; font-size: 12px; color: var(--muted); margin-top: 28px; }
.app-footer a { color: var(--muted); }
.app-footer .copyright { margin-top: 8px; }

/* 応援ボタン（押したい人だけが押す、控えめな寄付リンク） */
.support-row { margin-top: 14px; }
.support-btn {
  display: inline-block;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 999px;
  padding: 8px 18px;
  font-size: 13px;
  text-decoration: none;
  color: var(--ink) !important;
}
.support-btn:hover { border-color: var(--accent); color: var(--accent) !important; }

/* ---- 法務ページ（プライバシー・規約） ---- */
.legal {
  max-width: 720px; margin: 0 auto; padding: 32px 20px 60px;
  color: var(--ink); line-height: 1.9;
}
.legal h1 { font-size: 24px; margin: 0 0 20px; }
.legal h2 { font-size: 16px; margin: 28px 0 8px; }
.legal p, .legal li { font-size: 14px; }
.legal ul { padding-left: 1.2em; }
.legal a { color: var(--accent); }
.legal-back { font-size: 13px; margin-bottom: 8px; }
.legal-date { color: var(--muted); font-size: 13px; margin-top: 28px; }

/* ---- 印刷 ---- */
@media print {
  @page { size: A4 landscape; margin: 10mm; }
  body { background: #fff; }
  .no-print { display: none !important; }
  #app-view { max-width: none; padding: 0; }
  .card { box-shadow: none; padding: 0; margin: 0; }
  .print-title { display: block; text-align: center; margin: 0 0 8px; font-size: 16px; }
  .grid-row { height: 16px; }
  .grid-head { position: static; box-shadow: none; }
  .cell.fill-blue, .cell.fill-red { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  #print-area { page-break-inside: avoid; }
}
