/* =========================================================
   components.css : カード・ボタン・ゲージなど部品ごとのスタイル
   ========================================================= */

/* ---------------- カード ---------------- */
.card {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 16px;
}
.card + .card { margin-top: 12px; }
.card__title { font-size: 14px; font-weight: 800; margin-bottom: 10px; }

/* ---------------- ボタン ---------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 40px;
  padding: 0 18px;
  border-radius: var(--radius);
  font-weight: 700;
  background: var(--c-primary);
  color: #fff;
  transition: background .15s, opacity .15s;
  white-space: nowrap;
}
.btn:hover { background: var(--c-primary-dark); }
.btn:disabled { opacity: .45; cursor: not-allowed; }

.btn--ghost {
  background: transparent;
  color: var(--c-text-sub);
  border: 1px solid var(--c-border);
}
.btn--ghost:hover { background: var(--c-surface-2); color: var(--c-primary); }

.btn--danger { background: var(--c-danger); }
.btn--danger:hover { background: #c93a3e; }

.btn--wide { width: 100%; }
.btn--sm { height: 32px; padding: 0 12px; font-size: 13px; }

/* ---------------- アバター ---------------- */
.avatar {
  flex: 0 0 auto;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: #fff;
  font-weight: 800;
  width: 40px;
  height: 40px;
  font-size: 15px;
  user-select: none;
}
.avatar--sm { width: 30px; height: 30px; font-size: 12px; }
.avatar--lg { width: 72px; height: 72px; font-size: 26px; }

/* ---------------- 投稿カード（タイムライン） ---------------- */
.post__head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.post__name { font-weight: 700; }
.post__time { color: var(--c-text-weak); font-size: 12px; }

.post__body { display: flex; gap: 12px; }

/* 教材サムネイル。画像が無いときは科目色のプレースホルダになる */
.thumb {
  flex: 0 0 auto;
  width: 78px;
  height: 100px;
  border-radius: var(--radius-sm);
  background: var(--c-primary);
  color: #fff;
  display: grid;
  place-items: center;
  text-align: center;
  padding: 6px;
  font-size: 11px;
  font-weight: 700;
  line-height: 1.4;
  overflow: hidden;
}
.thumb--sm { width: 54px; height: 70px; font-size: 10px; }
/* 画像のあるサムネイル（表紙・アップロード画像） */
.thumb--img {
  padding: 0;
  background: var(--c-surface-2);
  border: 1px solid var(--c-border);
}
.thumb--img img { width: 100%; height: 100%; object-fit: cover; }

.post__info { flex: 1; min-width: 0; }
.post__material { font-weight: 700; margin-bottom: 4px; }
.post__duration {
  font-size: 20px;
  font-weight: 800;
  color: var(--c-primary);
  letter-spacing: .01em;
}
.post__memo {
  margin-top: 8px;
  padding: 8px 10px;
  background: var(--c-surface-2);
  border-radius: var(--radius-sm);
  color: var(--c-text-sub);
  font-size: 13px;
  white-space: pre-wrap;
}

/* 投稿カードの LoC まとめ（平均LoC＋スパークライン） */
.post__loc {
  margin-top: 10px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  background: var(--c-surface-2);
}
.post__loc-label { font-size: 11px; color: var(--c-text-sub); font-weight: 700; }
.post__loc-value { font-size: 17px; font-weight: 800; }
.sparkline { flex: 1; height: 28px; width: 100%; }

/* 投稿カードのフッター（いいね・コメント） */
.post__foot {
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid var(--c-border);
  display: flex;
  gap: 6px;
}
.action-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: var(--radius);
  color: var(--c-text-sub);
  font-size: 13px;
  font-weight: 600;
  transition: background .15s, color .15s;
}
.action-btn:hover { background: var(--c-surface-2); color: var(--c-primary); }
.action-btn.is-on { color: var(--c-accent); }
.action-btn.is-on svg { fill: var(--c-accent); }

/* ---------------- いま勉強中（ライブ表示） ---------------- */
.live {
  background: linear-gradient(135deg, #f2f2ff, #fff);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-lg);
  padding: 14px;
  margin-bottom: 18px;
}
.live__head { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.live__title { font-size: 14px; font-weight: 800; }
.live__dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--c-danger);
  animation: pulse 1.6s infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%      { opacity: .4; transform: scale(.8); }
}

/* 横並びカード（はみ出す分は横スクロール） */
.live__list {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  padding-bottom: 6px;
  scrollbar-width: thin;
}
.live-card {
  flex: 0 0 132px;
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  padding: 12px 10px;
  text-align: center;
  box-shadow: var(--shadow-sm);
}
.live-card__name {
  font-size: 12px;
  font-weight: 700;
  margin-top: 8px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.live-card__material {
  font-size: 11px;
  color: var(--c-text-weak);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.live-card__timer {
  margin-top: 6px;
  font-size: 13px;
  font-weight: 800;
  color: var(--c-text-sub);
}

/* ---------------- 円形LoCゲージ ---------------- */
/* SVG の stroke-dasharray を使って進捗リングを描く */
.gauge { position: relative; display: inline-grid; place-items: center; }
.gauge svg { transform: rotate(-90deg); display: block; }
.gauge__track { stroke: var(--c-border); fill: none; }
.gauge__bar {
  fill: none;
  stroke-linecap: round;
  stroke: var(--loc-color, var(--c-primary));
  transition: stroke-dashoffset .5s ease, stroke .5s ease;
}
.gauge__center {
  position: absolute;
  display: grid;
  place-items: center;
  line-height: 1.1;
}
.gauge__value { font-weight: 800; }
.gauge__unit { font-size: 9px; color: var(--c-text-weak); font-weight: 700; }

/* LoC の3段階に応じた色。JS が状態クラスを付け替える */
.is-loc-high { --loc-color: var(--c-loc-high); }
.is-loc-mid  { --loc-color: var(--c-loc-mid); }
.is-loc-low  { --loc-color: var(--c-loc-low); }
.loc-color   { color: var(--loc-color, var(--c-primary)); }

/* ---------------- 教材カード（記録する） ---------------- */
.material-card {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  padding: 12px;
  display: flex;
  gap: 10px;
  align-items: center;
  text-align: left;
  width: 100%;
  transition: border-color .15s, transform .15s, box-shadow .15s;
}
.material-card:hover {
  border-color: var(--c-primary);
  transform: translateY(-2px);
  box-shadow: var(--shadow);
}
.material-card__title {
  font-weight: 700;
  font-size: 13px;
  line-height: 1.4;
}
.material-card__meta { font-size: 11px; color: var(--c-text-weak); }

/* 科目の見出しにつける色チップ */
.subject-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 800;
}
.subject-chip::before {
  content: "";
  width: 10px; height: 10px;
  border-radius: 3px;
  background: var(--chip-color, var(--c-primary));
}

/* ---------------- 計測画面 ---------------- */
.camera-box {
  position: relative;
  background: #11131f;
  border-radius: var(--radius);
  overflow: hidden;
  aspect-ratio: 4 / 3;
}
.camera-box video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scaleX(-1); /* 鏡写しにして自然に見せる */
}
.camera-box__off {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: #8b90a8;
  font-size: 12px;
  background: #11131f;
}

/* 計測中のステージ：カメラ映像の上に継続時間・LoC・推移を重ねる */
.stage {
  position: relative;
  background: #11131f;
  border-radius: var(--radius);
  overflow: hidden;
  aspect-ratio: 16 / 9;
  min-height: 320px;
  color: #fff;
}
.stage video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scaleX(-1); /* 鏡写しにして自然に見せる */
}
/* 外カメラは鏡写しにすると左右が逆に見えるので、そのまま映す */
.stage video.is-rear { transform: none; }
.stage__off {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: #8b90a8;
  font-size: 12px;
  background: #11131f;
}
/* 映像の明るさに関係なく読めるよう、上下を暗くしてから文字を置く */
.stage__top,
.stage__bottom {
  position: absolute;
  left: 0;
  right: 0;
  padding: 14px 16px;
  text-shadow: 0 1px 3px rgba(0, 0, 0, .6);
}
.stage__top {
  top: 0;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  background: linear-gradient(rgba(0, 0, 0, .62), rgba(0, 0, 0, 0));
  padding-bottom: 28px;
}
.stage__bottom {
  bottom: 0;
  display: flex;
  align-items: flex-end;
  gap: 16px;
  background: linear-gradient(rgba(0, 0, 0, 0), rgba(0, 0, 0, .72) 40%);
  padding-top: 32px;
}
.stage__label { font-size: 12px; font-weight: 700; opacity: .85; }
.stage__sub   { font-size: 12px; opacity: .8; }
.stage__timer {
  font-size: 44px;
  font-weight: 800;
  letter-spacing: .02em;
  line-height: 1.1;
}
.stage__chart {
  position: relative;
  flex: 1;
  min-width: 0;
  height: 110px;
}
.stage__loc { text-align: right; flex-shrink: 0; }
.stage__loc-num {
  font-size: 64px;
  font-weight: 800;
  line-height: 1;
}
.stage .status {
  background: rgba(0, 0, 0, .5);
  border-color: rgba(255, 255, 255, .25);
  color: #fff;
  text-shadow: none;
}
@media (max-width: 640px) {
  .stage { aspect-ratio: 3 / 4; min-height: 0; }
  .stage__timer { font-size: 34px; }
  .stage__loc-num { font-size: 48px; }
  .stage__chart { height: 90px; }
}

.chart-box { position: relative; height: 200px; }
.chart-box--sm { height: 160px; }

/* 接続状態のバッジ */
.status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--c-surface-2);
  color: var(--c-text-sub);
  border: 1px solid var(--c-border);
}
.status::before {
  content: "";
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--c-text-weak);
}
.status--live::before  { background: var(--c-success); }
.status--mock::before  { background: var(--c-accent); }
.status--error::before { background: var(--c-danger); }

/* エラー・注意書き */
.notice {
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  background: var(--c-primary-light);
  color: var(--c-primary-dark);
}
.notice--error { background: #fdecec; color: #b32c30; }
.notice--warn  { background: #fff6e5; color: #9a6a00; }

/* ---------------- フォーム ---------------- */
.field { margin-bottom: 12px; }
.field__label {
  display: block;
  font-size: 12px;
  font-weight: 700;
  color: var(--c-text-sub);
  margin-bottom: 4px;
}
.input, .select, .textarea {
  width: 100%;
  border: 1px solid var(--c-border);
  border-radius: var(--radius-sm);
  background: var(--c-surface);
  padding: 9px 12px;
  transition: border-color .15s;
}
.input:focus, .select:focus, .textarea:focus {
  border-color: var(--c-primary);
  outline: none;
}
.textarea { min-height: 84px; resize: vertical; }

.checkbox {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  font-size: 13px;
  color: var(--c-text-sub);
  cursor: pointer;
}
.checkbox input { margin-top: 4px; accent-color: var(--c-primary); }

/* ---------------- レポートの統計カード ---------------- */
.stat {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  padding: 14px;
  text-align: center;
}
.stat__label { font-size: 11px; color: var(--c-text-sub); font-weight: 700; }
.stat__value { font-size: 24px; font-weight: 800; margin-top: 2px; }
.stat__unit  { font-size: 12px; color: var(--c-text-weak); font-weight: 700; }

/* カウントダウン */
.countdown {
  background: linear-gradient(135deg, var(--c-primary), #8a7cf0);
  color: #fff;
  border-radius: var(--radius-lg);
  padding: 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.countdown__num { font-size: 40px; font-weight: 800; line-height: 1; }
.countdown__label { font-size: 12px; opacity: .85; }

/* ---------------- さがす ---------------- */
.search-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: 999px;
  padding: 0 16px;
  height: 44px;
  margin-bottom: 16px;
}
.search-bar input {
  flex: 1;
  border: none;
  background: none;
  outline: none;
}
.search-bar svg { color: var(--c-text-weak); }

.find-card {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  padding: 16px 12px;
  text-align: center;
  font-weight: 700;
  font-size: 13px;
  transition: border-color .15s, transform .15s;
}
.find-card:hover { border-color: var(--c-primary); transform: translateY(-2px); }
.find-card__icon {
  width: 42px; height: 42px;
  margin: 0 auto 8px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--c-primary-light);
  color: var(--c-primary);
}

.article {
  display: flex;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--c-border);
}
.article:last-child { border-bottom: none; }
.article__thumb {
  flex: 0 0 96px;
  height: 64px;
  border-radius: var(--radius-sm);
  background: var(--c-primary-light);
  color: var(--c-primary);
  display: grid;
  place-items: center;
  font-size: 11px;
  font-weight: 800;
}
.article__title { font-weight: 700; font-size: 13px; line-height: 1.5; }

/* ---------------- プロフィール ---------------- */
.profile-head {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 8px;
}
.profile-head__name { font-size: 19px; font-weight: 800; }

.info-list { display: grid; gap: 8px; }
.info-list__row {
  display: grid;
  grid-template-columns: 110px 1fr;
  gap: 8px;
  padding-bottom: 8px;
  border-bottom: 1px dashed var(--c-border);
  font-size: 13px;
}
.info-list__row:last-child { border-bottom: none; padding-bottom: 0; }
.info-list__key { color: var(--c-text-sub); font-weight: 700; }

.tag {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--c-primary-light);
  color: var(--c-primary-dark);
  font-size: 12px;
  font-weight: 700;
  margin: 0 6px 6px 0;
}

/* ---------------- モーダル ---------------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(20, 22, 35, .45);
  display: grid;
  place-items: center;
  padding: 16px;
}
.modal {
  background: var(--c-surface);
  border-radius: var(--radius-lg);
  padding: 20px;
  width: min(440px, 100%);
  max-height: 88vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
}
.modal__title { font-size: 16px; font-weight: 800; margin-bottom: 12px; }
.modal__foot { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }

/* ---------------- トースト ---------------- */
.toast-root {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  z-index: 80;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}
.toast {
  background: #2b2e42;
  color: #fff;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 700;
  box-shadow: var(--shadow-lg);
  animation: toast-in .2s ease;
}
@keyframes toast-in {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* 空状態の表示 */
.empty {
  text-align: center;
  color: var(--c-text-weak);
  padding: 40px 10px;
  font-size: 13px;
}

/* ---------------- フォームの補足 ---------------- */
.field__req {
  margin-left: 6px;
  padding: 1px 6px;
  border-radius: 4px;
  background: var(--c-primary-light);
  color: var(--c-primary-dark);
  font-size: 10px;
}
.field__hint { margin-top: 4px; font-size: 11px; color: var(--c-text-weak); }
.field.is-invalid .input,
.field.is-invalid .select,
.field.is-invalid .textarea { border-color: var(--c-danger); }

/* 文字だけのボタン（リンク風） */
.link-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: var(--c-primary);
  font-weight: 700;
}
.link-btn:hover { text-decoration: underline; }

/* ---------------- ログイン・新規登録・初回設定 ---------------- */
.auth {
  min-height: 100vh;
  display: grid;
  place-items: start center;
  padding: 48px 16px 64px;
}
.auth__inner { width: min(400px, 100%); }
.auth__inner--wide { width: min(620px, 100%); }
.auth__logo { justify-content: center; padding-bottom: 18px; }
.auth__card { padding: 24px; }
.auth__title { font-size: 19px; font-weight: 800; margin-bottom: 16px; }
.auth__welcome { margin-bottom: 16px; }
.auth__welcome .auth__title { margin-bottom: 6px; }
.auth__submit { margin-top: 6px; }
.auth__card .notice--error { margin-bottom: 12px; }
.auth__switch {
  margin-top: 16px;
  text-align: center;
  font-size: 13px;
  color: var(--c-text-sub);
}
.auth__switch a { color: var(--c-primary); font-weight: 700; }
.auth__switch a:hover { text-decoration: underline; }

/* ---------------- プロフィールの入力フォーム ---------------- */
.profile-form .notice--error { margin-top: 12px; }
.profile-form__avatar {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 14px;
}
.profile-form__foot {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 16px;
}
.profile-head__edit { margin-left: auto; align-self: flex-start; }

/* アイコンの色を選ぶ丸いボタン */
.color-picker { display: flex; flex-wrap: wrap; gap: 8px; }
.color-picker__item {
  position: relative;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--swatch);
  cursor: pointer;
  box-shadow: 0 0 0 2px var(--c-surface), 0 0 0 3px transparent;
  transition: box-shadow .15s, transform .15s;
}
.color-picker__item:hover { transform: scale(1.08); }
.color-picker__item input {
  position: absolute;
  inset: 0;
  opacity: 0;
  margin: 0;
  cursor: pointer;
}
.color-picker__item:has(input:checked) {
  box-shadow: 0 0 0 2px var(--c-surface), 0 0 0 4px var(--swatch);
}
.color-picker__item:has(input:focus-visible) {
  outline: 2px solid var(--c-primary);
  outline-offset: 4px;
}

/* ---------------- 教材の追加 ---------------- */
/* 2択の切り替え（バーコード／独自教材） */
.segmented {
  display: flex;
  gap: 4px;
  padding: 4px;
  margin-bottom: 12px;
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
}
.segmented__item {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 38px;
  border-radius: var(--radius-sm);
  font-weight: 700;
  color: var(--c-text-sub);
  transition: background .15s, color .15s;
}
.segmented__item:hover { color: var(--c-primary); }
.segmented__item.is-active { background: var(--c-primary-light); color: var(--c-primary-dark); }

/* バーコード読み取りのプレビュー。文字を読むので鏡写しにしない */
.scan-box {
  max-width: 420px;
  margin-bottom: 12px;
  aspect-ratio: 16 / 10;
}
.scan-box video { transform: none; }
.scan-box__guide {
  position: absolute;
  left: 12%;
  right: 12%;
  top: 32%;
  bottom: 32%;
  border: 2px solid rgba(255, 255, 255, .85);
  border-radius: var(--radius-sm);
  box-shadow: 0 0 0 999px rgba(0, 0, 0, .35);
  pointer-events: none;
}

.isbn-form .input { max-width: 240px; }

.material-form__image {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  margin-bottom: 14px;
}
.material-form__image label.btn { cursor: pointer; }
.material-form__image .link-btn { margin-left: 8px; }

.new-category {
  padding: 12px;
  margin-bottom: 12px;
  border-radius: var(--radius);
  background: var(--c-surface-2);
  border: 1px dashed var(--c-border);
}
.new-category .field:last-child { margin-bottom: 0; }

/* 教材がまだ無いときの案内 */
.empty-state {
  text-align: center;
  padding: 36px 20px;
}
.empty-state__icon {
  width: 60px;
  height: 60px;
  margin: 0 auto 12px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--c-primary-light);
  color: var(--c-primary);
}
.empty-state__title { font-size: 16px; font-weight: 800; margin-bottom: 6px; }
.empty-state__actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin-top: 16px;
}
