:root {
  --bg: #f6f8fb;
  --card: #ffffff;
  --ink: #3a4252;
  --muted: #8a93a6;
  --line: #e6eaf2;
  --sleep: #5b8def;       /* 寝ていた時間の青 */
  --sleep-soft: #eaf1ff;
  --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;
  align-items: center;
  justify-content: center;
}
.login-card {
  background: var(--card);
  padding: 48px 40px;
  border-radius: 20px;
  box-shadow: 0 8px 30px rgba(60, 80, 120, 0.08);
  text-align: center;
  max-width: 360px;
}
.login-card h1 { margin: 0 0 8px; font-size: 26px; }
.login-card p { color: var(--muted); margin: 0 0 28px; }
.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.sleep { background: var(--sleep); }
.cell.selecting { background: var(--sleep-soft); box-shadow: inset 0 0 0 1px var(--sleep); }
.cell.erasing { background: #ffe2e2; box-shadow: inset 0 0 0 1px #e06a6a; }
/* 2時間ごとに薄い区切り線 */
.cell.tick { border-left: 1px solid var(--line); }

.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; }
.legend-box { width: 14px; height: 14px; background: var(--sleep); border-radius: 3px; display: inline-block; }

/* ---- 記録一覧 ---- */
#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; }

/* ---- 印刷 ---- */
@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.sleep { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  #print-area { page-break-inside: avoid; }
}
