/* theme.css — ダッシュボード全体のライトテーマ (生成りの白 + 墨色 + ディープブルー)。
   配置が /trial/ 配下なのは tailwind-play.js と同じ理由: Cloudflare Access の
   バイパスは /trial* のみで、/assets/* だと未認証の体験会参加者に 302 (Access
   ログイン) が返ってしまう。公開ページ (trial.html) が読むアセットはここに置くこと。
   色と共通コンポーネントの単一情報源。JS (app.js / admin.js / trial-teacher.js) が
   付け外しする状態クラス (.dot-* / .badge-* / .bar-* / .btn-* / .toast-* / .is-active) は
   すべてここで定義する — Tailwind Play CDN の JIT (動的クラスの初出未生成) に依存させない。
   注意: Tailwind の生成 style は head 末尾にランタイム注入され本ファイルより後勝ちになるため、
   要素セレクタは body 前置で specificity を上げて preflight に負けないようにしている。 */

:root {
  color-scheme: light;
  --bg: #f7f6f2;           /* 生成りのオフホワイト */
  --surface-1: #ffffff;    /* カード */
  --surface-2: #f3f1ec;    /* ネスト面・code 表示 */
  --surface-3: #eae7e0;    /* hover 面 */
  --border: rgba(35, 33, 29, 0.08);
  --border-strong: rgba(35, 33, 29, 0.18);
  --text-hi: #23211d;      /* 見出し (墨色インク) */
  --text: #44413b;         /* 本文 */
  --text-dim: #8a867c;     /* 補足 */
  --accent: #23211d;       /* 墨色 = 主アクション */
  --accent-hover: #3a3731;
  --accent-ink: #ffffff;   /* 墨色ボタン上の文字 */
  --info: #2f56c6;         /* ディープブルー = 「接続」/ フォーカス */
  --info-hover: #2848a8;
  --info-ink: #ffffff;
  --ok: #1d8a4a;
  --warn: #b07d10;
  --danger: #c2362f;
  --font-sans: "Hiragino Kaku Gothic ProN", "Hiragino Sans", "Noto Sans JP", "Yu Gothic UI", Meiryo, system-ui, sans-serif;
  --font-display: "Space Grotesk", var(--font-sans);
  font-family: var(--font-sans); /* :root は preflight の html { font-family } より強い */
}

@font-face {
  font-family: "Space Grotesk";
  font-style: normal;
  font-weight: 300 700;
  font-display: swap;
  /* この CSS からの相対パス (= /trial/fonts/) — Access バイパス圏内に置く */
  src: url("fonts/space-grotesk-var.woff2") format("woff2");
}

/* 背景: 生成りベース + 右上に微かなブルーの気配。body は透過にして
   背面の #fx-bg (負 z-index の canvas) を見せる — body に背景を塗ると
   負 z-index の子よりも手前に描画されて canvas が隠れるので塗らないこと。 */
html {
  background: radial-gradient(1100px 600px at 85% -10%, rgba(47, 86, 198, 0.05), transparent 60%) var(--bg);
  min-height: 100%;
}
body {
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

#fx-bg {
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
}

.font-display {
  font-family: var(--font-display);
  letter-spacing: 0.01em;
}

::selection {
  background: var(--info);
  color: var(--info-ink);
}

/* ---- ネイティブ要素 (body 前置で preflight より強く) ---- */
body input:not([type="checkbox"]):not([type="radio"]):not([type="file"]),
body select,
body textarea {
  background: #ffffff;
  border: 1px solid var(--border-strong);
  color: var(--text-hi);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 14px;
  transition: border-color 0.15s;
}
body input::placeholder,
body textarea::placeholder {
  color: var(--text-dim);
}
body input:focus-visible,
body select:focus-visible,
body textarea:focus-visible {
  outline: 2px solid var(--info);
  outline-offset: 1px;
}
body input[type="file"] {
  color: var(--text-dim);
  font-size: 13px;
  min-width: 0;
}
body input[type="file"]::file-selector-button {
  background: var(--surface-2);
  color: var(--text-hi);
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  padding: 6px 10px;
  margin-right: 10px;
  font-size: 12px;
  font-family: inherit;
  cursor: pointer;
}
body input[type="file"]::file-selector-button:hover {
  border-color: var(--info);
}
body summary {
  cursor: pointer;
}
body summary:hover {
  color: var(--text-hi);
}

/* ---- カード / 面 ---- */
.card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 1px 2px rgba(35, 33, 29, 0.05), 0 4px 16px rgba(35, 33, 29, 0.04);
}
.well {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
}
.modal-panel {
  background: var(--surface-1);
  border: 1px solid var(--border-strong);
  border-radius: 14px;
  box-shadow: 0 24px 60px rgba(35, 33, 29, 0.2);
}

/* ---- ボタン ---- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 600;
  line-height: 1.2;
  padding: 9px 14px;
  border-radius: 8px;
  border: 1px solid transparent;
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
  transition: background-color 0.15s, border-color 0.15s, color 0.15s, transform 0.15s;
}
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }
.btn:focus-visible { outline: 2px solid var(--info); outline-offset: 2px; }
.btn svg { flex: none; }
.btn-sm { padding: 7px 11px; font-size: 12px; }
.btn-xs { padding: 5px 9px; font-size: 11px; border-radius: 6px; }

.btn-accent { background: var(--accent); color: var(--accent-ink); }
.btn-accent:hover { background: var(--accent-hover); }
.btn-info { background: var(--info); color: var(--info-ink); }
.btn-info:hover { background: var(--info-hover); }
.btn-danger { background: rgba(194, 54, 47, 0.08); color: #a32b24; border-color: rgba(194, 54, 47, 0.35); }
.btn-danger:hover { background: rgba(194, 54, 47, 0.15); }
.btn-warn { background: rgba(176, 125, 16, 0.1); color: #8a6210; border-color: rgba(176, 125, 16, 0.35); }
.btn-warn:hover { background: rgba(176, 125, 16, 0.18); }
.btn-ghost { background: transparent; color: var(--text); border-color: var(--border-strong); }
.btn-ghost:hover { background: var(--surface-3); color: var(--text-hi); }

/* 診断モーダルのタブ (app.js setDiagTab が is-active をトグルする) */
.diag-tab.is-active {
  background: var(--text-hi);
  color: #ffffff;
  border-color: var(--text-hi);
}

/* ---- 状態ドット (app.js STATE_COLORS / trial-teacher.js sessionDotColor が付け外し) ---- */
.dot {
  display: inline-block;
  flex: none;
  width: 12px;
  height: 12px;
  border-radius: 9999px;
}
.dot-sm { width: 10px; height: 10px; }
.dot-idle { background: #d8d4cb; box-shadow: inset 0 0 0 1px rgba(35, 33, 29, 0.18); }
.dot-busy { background: #d09a1d; animation: fx-pulse 1.6s ease-in-out infinite; }
.dot-ok { background: var(--ok); box-shadow: 0 0 0 3px rgba(29, 138, 74, 0.15); }
.dot-danger { background: var(--danger); box-shadow: 0 0 0 3px rgba(194, 54, 47, 0.15); }

@keyframes fx-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

/* ---- バッジ (trial-teacher.js stateBadge が付け外し) ---- */
.badge {
  display: inline-block;
  font-size: 11px;
  line-height: 1;
  padding: 4px 9px;
  border-radius: 9999px;
  border: 1px solid transparent;
  white-space: nowrap;
}
.badge-idle { background: var(--surface-2); color: var(--text); border-color: var(--border); }
.badge-warn { background: rgba(176, 125, 16, 0.1); color: #8a6210; border-color: rgba(176, 125, 16, 0.3); }
.badge-ok { background: rgba(29, 138, 74, 0.1); color: #166e3b; border-color: rgba(29, 138, 74, 0.3); }
.badge-danger { background: rgba(194, 54, 47, 0.08); color: #a32b24; border-color: rgba(194, 54, 47, 0.3); }
.badge-muted { background: transparent; color: var(--text-dim); border-color: var(--border); }

/* ---- 進捗バー (app.js が .bar-fill の className を状態で差し替える) ---- */
.bar {
  height: 6px;
  border-radius: 9999px;
  background: var(--surface-3);
  border: 1px solid var(--border);
  overflow: hidden;
}
.bar-fill {
  display: block;
  height: 100%;
  border-radius: inherit;
  transition: width 0.6s cubic-bezier(0.22, 1, 0.36, 1);
}
.bar-ok { background: linear-gradient(90deg, #1d8a4a, #27a35d); }
.bar-warn { background: linear-gradient(90deg, #b07d10, #d09a1d); }
.bar-danger { background: linear-gradient(90deg, #c2362f, #d9534b); }

/* ---- トースト (admin.js showToast が付け外し) ---- */
.toast-ok { background: rgba(29, 138, 74, 0.1); color: #166e3b; border: 1px solid rgba(29, 138, 74, 0.35); }
.toast-danger { background: rgba(194, 54, 47, 0.08); color: #a32b24; border: 1px solid rgba(194, 54, 47, 0.35); }

/* ---- 3D 演出 ---- */

/* CSS だけで回る二重ワイヤーフレーム — ローディング表示 */
.fx-spinner {
  position: relative;
  display: inline-block;
  width: 30px;
  height: 30px;
  perspective: 140px;
}
.fx-spinner::before,
.fx-spinner::after {
  content: "";
  position: absolute;
  inset: 2px;
  border: 1.5px solid var(--info);
  border-radius: 2px;
  animation: fx-spin-a 2.6s linear infinite;
}
.fx-spinner::after {
  border-color: rgba(35, 33, 29, 0.35);
  animation: fx-spin-b 3.4s linear infinite;
}
@keyframes fx-spin-a {
  from { transform: rotateX(0deg) rotateY(0deg); }
  to { transform: rotateX(360deg) rotateY(180deg); }
}
@keyframes fx-spin-b {
  from { transform: rotateY(0deg) rotateX(0deg); }
  to { transform: rotateY(-360deg) rotateX(180deg); }
}

/* trial.html のフェーズアイコン: JS は dataset.icon を切り替えるだけで、
   data-for が一致する子だけを表示する */
.fx-phase-icon { display: flex; justify-content: center; min-height: 36px; }
.fx-phase-icon > * { display: none; }
.fx-phase-icon[data-icon="wait"] > [data-for="wait"],
.fx-phase-icon[data-icon="build"] > [data-for="build"],
.fx-phase-icon[data-icon="error"] > [data-for="error"] { display: inline-block; }

/* ポインタ追従チルト (fx.js が inline transform を書く)。
   注意: transform は包含ブロックを作るので data-tilt の子孫に position:fixed を置かないこと
   (モーダルは全て body 直下に置く)。 */
[data-tilt] {
  transition: transform 0.45s cubic-bezier(0.22, 1, 0.36, 1);
  will-change: transform;
}

/* 登場アニメーション。fx.js が <html> に .fx-ready を付けてから発動する
   (fx.js が読めなかった場合に不可視のまま残るのを防ぐ)。
   transform ではなく translate プロパティを使い、チルトの inline transform と衝突させない。 */
.fx-ready [data-reveal] {
  opacity: 0;
  translate: 0 14px;
  transition: opacity 0.6s ease, translate 0.6s cubic-bezier(0.22, 1, 0.36, 1);
}
.fx-ready [data-reveal].is-in {
  opacity: 1;
  translate: 0 0;
}

@media (prefers-reduced-motion: reduce) {
  .fx-ready [data-reveal] { opacity: 1; translate: none; transition: none; }
  [data-tilt] { transition: none; }
  .fx-spinner::before, .fx-spinner::after { animation-duration: 60s; }
  .dot-busy { animation: none; }
  .bar-fill { transition: none; }
}
