/* 学習記録 — 見た目（形は案B「やわらかカード」、色は明るい表示が案A・暗い表示が案C） */

/* 明るい表示の色 */
:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --text: #1d2633;
  --sub: #6b7686;
  --line: #d9dee6;
  --accent: #2f6db5;
  --accent-soft: #dce8f6;
  --accent-strong: #1f4f88;
  --on-accent: #ffffff;
  --cell: #ffffff;
  --danger: #d64545;
  --on-danger: #ffffff;
  --sun: #d64545;
  --toast-bg: #1d2633;
  --toast-text: #ffffff;
  --dim: rgba(20, 28, 40, .45);
  --accent-shadow: rgba(47, 109, 181, .35);
  --card-shadow: 0 2px 8px rgba(0, 0, 0, .05);
  --r: 16px;
  --cell-r: 12px;
  --tab-h: 62px;
  color-scheme: light;
}

/* 暗い表示の色（iPhone の設定に合わせて自動で切り替わる） */
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #11161f;
    --surface: #1a2130;
    --text: #e9edf4;
    --sub: #8e99ab;
    --line: #2a3345;
    --accent: #5aa9ff;
    --accent-soft: #1d3a5e;
    --accent-strong: #9fcbff;
    --on-accent: #0b1220;
    --cell: #1a2130;
    --danger: #ff6b6b;
    --on-danger: #0b1220;
    --sun: #ff8a8a;
    --toast-bg: #5aa9ff;
    --toast-text: #0b1220;
    --dim: rgba(0, 0, 0, .6);
    --accent-shadow: rgba(90, 169, 255, .25);
    --card-shadow: 0 2px 8px rgba(0, 0, 0, .3);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Yu Gothic UI", "Meiryo", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-tap-highlight-color: transparent;
}
body.layer-open { overflow: hidden; }

button, input, textarea {
  font: inherit;
  color: inherit;
  touch-action: manipulation;
}
button { border: none; background: none; cursor: pointer; }

/* 画面の骨組み */
.screen {
  display: flex;
  flex-direction: column;
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
  min-height: 100dvh;
  padding-top: env(safe-area-inset-top);
  padding-bottom: calc(16px + env(safe-area-inset-bottom));
}
.screen.with-tabs { padding-bottom: calc(var(--tab-h) + env(safe-area-inset-bottom)); }

.appbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px 8px;
}
.app-title { font-weight: 700; font-size: 17px; }
.app-title.center { flex: 1; text-align: center; }
.gear { font-size: 22px; color: var(--sub); width: 44px; height: 40px; text-align: right; }
.back { font-size: 15px; color: var(--accent); width: 72px; height: 40px; text-align: left; font-weight: 600; }
.spacer { width: 72px; }

.content {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 4px 18px 14px;
}

/* カード */
.field, .graph-box, .save-sec {
  background: var(--surface);
  border-radius: 20px;
  padding: 10px 12px;
  box-shadow: var(--card-shadow);
  scroll-margin-top: 8px;
}
.field .label { display: block; font-size: 13px; color: var(--sub); margin-bottom: 6px; font-weight: 600; }
.field .label small { font-weight: 400; font-size: 13px; }

/* 日付の欄 */
.date-select {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border-radius: var(--r);
  background: var(--bg);
  font-size: 16px;
  cursor: pointer;
}
.date-select .caret { color: var(--sub); font-size: 14px; }
.date-input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  border: none;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
}

.chips { display: flex; gap: 8px; margin-top: 8px; }
.chip {
  flex: 1;
  padding: 10px 0;
  border-radius: 999px;
  background: var(--bg);
  font-size: 15px;
  font-weight: 600;
}
.chip.on { background: var(--accent); color: var(--on-accent); }

.textarea {
  display: block;
  width: 100%;
  min-height: 52px;
  padding: 12px 14px;
  border-radius: var(--r);
  background: var(--bg);
  border: none;
  font-size: 16px; /* 16px 未満だと iPhone が画面を拡大してしまう */
  line-height: 1.4;
  resize: none;
}
.textarea::placeholder { color: var(--sub); }

/* 時間のボタン（2列×2段） */
.times { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.tbtn {
  padding: 15px 0;
  border-radius: var(--r);
  background: var(--bg);
  font-size: 18px;
  font-weight: 700;
}
.tbtn.sel { background: var(--accent); color: var(--on-accent); }

.free { display: flex; align-items: center; gap: 8px; margin-top: 10px; font-size: 14px; color: var(--sub); }
.num-input {
  width: 84px;
  height: 40px;
  padding: 0 10px;
  border-radius: var(--r);
  border: none;
  background: var(--bg);
  font-size: 16px;
  text-align: center;
  color: var(--text);
}

textarea:focus, .num-input:focus, .date-select:focus-within {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

/* 大きなボタン */
.primary {
  margin-top: auto;
  width: 100%;
  padding: 18px 0;
  border-radius: 999px;
  background: var(--accent);
  color: var(--on-accent);
  font-size: 18px;
  font-weight: 700;
  box-shadow: 0 6px 14px var(--accent-shadow);
}
.primary:active, .secondary:active, .danger:active, .tbtn:active, .chip:active { opacity: .8; }
.secondary {
  width: 100%;
  padding: 16px 0;
  border-radius: 999px;
  border: 2px solid var(--accent);
  color: var(--accent);
  font-size: 17px;
  font-weight: 700;
}
.danger {
  width: 100%;
  padding: 14px 0;
  border-radius: 999px;
  color: var(--danger);
  border: 1px solid var(--danger);
  font-size: 16px;
  font-weight: 600;
}

.today-total { text-align: center; font-size: 14px; color: var(--sub); }
.today-total b { color: var(--text); }

/* 連続日数の札 */
.streak {
  align-self: center;
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 4px;
  background: var(--accent-soft);
  color: var(--accent-strong);
  border-radius: 999px;
  padding: 6px 20px;
  font-weight: 700;
}
.streak-label, .streak-unit { font-size: 16px; }
.streak-num { font-size: 24px; font-weight: 800; }
.streak.zero { font-size: 15px; padding: 10px 20px; }

/* 「記録しました」などのお知らせ */
.toast {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  z-index: 50;
  white-space: nowrap;
  padding: 10px 18px;
  border-radius: 999px;
  background: var(--toast-bg);
  color: var(--toast-text);
  font-size: 15px;
  font-weight: 600;
  box-shadow: 0 4px 12px rgba(0, 0, 0, .2);
  pointer-events: none;
}

/* 画面の切り替え */
.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 10;
  background: var(--surface);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar-inner { display: flex; max-width: 480px; margin: 0 auto; }
.tab {
  flex: 1;
  height: var(--tab-h);
  font-size: 13px;
  color: var(--sub);
  font-weight: 600;
}
.tab .ti { display: block; font-size: 22px; line-height: 1.2; }
.tab.on { color: var(--accent); }

/* カレンダー */
.month-nav { display: flex; align-items: center; justify-content: space-between; }
.month { font-size: 17px; font-weight: 700; }
.nav { font-size: 16px; color: var(--accent); width: 48px; height: 40px; }
.nav:disabled { opacity: .25; cursor: default; }
.cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.dow { text-align: center; font-size: 12px; color: var(--sub); padding-bottom: 2px; }
.dow.sun { color: var(--sun); }
.day {
  aspect-ratio: 1 / 1.15;
  border-radius: var(--cell-r);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: var(--cell);
  font-size: 13px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .05);
}
.day.empty { background: transparent; box-shadow: none; }
.day .d { font-weight: 600; line-height: 1.2; }
.day .m { font-size: 11px; font-weight: 700; min-height: 14px; line-height: 1.3; }
.day.rec { background: var(--accent-soft); color: var(--accent-strong); }
.day.future { opacity: .35; cursor: default; }
.day.today { outline: 2px solid var(--accent); outline-offset: -2px; }

/* 直近30日のグラフ */
.graph-box { padding: 14px; }
.graph-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 10px; }
.graph-title { font-weight: 700; font-size: 15px; }
.graph-total { font-size: 13px; color: var(--sub); }
.graph-total b { font-size: 16px; color: var(--text); }
.graph { position: relative; height: 120px; margin-left: 40px; }
.grid-line { position: absolute; left: 0; right: 0; border-top: 1px dashed var(--line); }
.grid-line span { position: absolute; left: -42px; top: -9px; font-size: 10px; color: var(--sub); }
.bars { position: absolute; inset: 0; display: flex; align-items: flex-end; gap: 2px; border-bottom: 1px solid var(--line); }
.bar { flex: 1; background: var(--accent); border-radius: 4px 4px 0 0; }
.xlabels { position: relative; height: 16px; margin-left: 40px; margin-top: 4px; }
.xlabels span { position: absolute; top: 0; font-size: 10px; color: var(--sub); white-space: nowrap; transform: translateX(-50%); }
.xlabels span.first { transform: none; }
.xlabels span.last { transform: none; left: auto !important; right: 0; }

/* 下から出る一覧・真ん中に出る確認 */
.layer { position: fixed; inset: 0; z-index: 20; display: flex; flex-direction: column; justify-content: flex-end; }
.dim { position: absolute; inset: 0; background: var(--dim); }
.sheet {
  position: relative;
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
  max-height: 75vh;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: var(--bg);
  border-radius: 20px 20px 0 0;
  padding: 18px 18px calc(24px + env(safe-area-inset-bottom));
}
.sheet-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 4px; }
.sheet-title { font-weight: 700; font-size: 16px; }
.close { color: var(--accent); font-size: 15px; font-weight: 600; height: 36px; padding-left: 12px; }
.sheet-list { display: flex; flex-direction: column; gap: 10px; overflow-y: auto; }
.item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 14px;
  border-radius: var(--r);
  background: var(--surface);
  box-shadow: var(--card-shadow);
  text-align: left;
}
.item-text { flex: 1; font-size: 15px; overflow-wrap: anywhere; white-space: pre-wrap; }
.item-text.muted { color: var(--sub); }
.item-min { font-weight: 700; white-space: nowrap; }
.chev { color: var(--sub); font-size: 20px; }
.empty-msg { text-align: center; color: var(--sub); font-size: 15px; padding: 18px 0; }
.sheet-total { text-align: right; font-size: 14px; color: var(--sub); }
.sheet-total b { color: var(--text); }

#confirm-layer { justify-content: center; z-index: 30; }
.dialog {
  position: relative;
  margin: 0 28px;
  align-self: center;
  width: calc(100% - 56px);
  max-width: 340px;
  background: var(--bg);
  border-radius: 18px;
  padding: 20px 18px 16px;
  text-align: center;
}
.dialog-title { font-weight: 700; font-size: 17px; margin-bottom: 8px; }
.dialog-body { font-size: 14px; color: var(--sub); margin-bottom: 16px; overflow-wrap: anywhere; white-space: pre-wrap; }
.dialog-btns { display: flex; gap: 10px; }
.dbtn { flex: 1; padding: 12px 0; border-radius: 999px; border: 1px solid var(--line); font-weight: 700; }
.dbtn.del { background: var(--danger); border-color: var(--danger); color: var(--on-danger); }

/* 記録の保存画面 */
.save-sec { display: flex; flex-direction: column; gap: 10px; padding: 16px; }
.save-sec h2 { font-size: 15px; }
.save-sec .primary { margin-top: 0; }
.last { font-size: 14px; }
.hint { font-size: 13px; color: var(--sub); }

/* キーボードが出ている間（iPhone）: 下に余白を足して、時間のボタンと「記録する」まで見えるようにする */
body.kb-open .tabbar { display: none; }
body.kb-open .screen { padding-bottom: 50vh; }
