/* ============================================================
   TML AI体験アプリ 共通デザインシステム
   機械学習理論研究室（長岡技術科学大学）
   --------------------------------------------------------
   配色は実物の体験キット（紙コップ・三角おはじき）に由来する:
     赤 = 1個取る / 青 = 2個取る / 黄 = 3個取る / 緑 = 石
   この4色はそのままアプリ内のデータ配色として使う。
   ============================================================ */

/* ---------- tokens: light (base) ---------- */
:root {
  /* 紙と机の中間の、わずかに青みのあるニュートラル */
  --bg:          #f5f6f8;
  --surface:     #ffffff;
  --surface-2:   #eef0f4;
  --ink:         #16191f;
  --ink-2:       #4a5160;
  --ink-3:       #7a8293;
  --line:        #dde1e8;
  --line-strong: #c3cad6;

  /* アクセント: 親サイト lab.kumoi.net の blue-700 系を継承 */
  --accent:      #1d4ed8;
  --accent-ink:  #ffffff;
  --accent-soft: #e5edff;
  --accent-line: #b6ccff;

  /* キット由来の実物色（データ配色） */
  --kit-red:     #d8433c;
  --kit-blue:    #2f6fd0;
  --kit-yellow:  #e0a326;
  --kit-green:   #35895a;
  --kit-red-soft:    #fbe7e6;
  --kit-blue-soft:   #e3edfb;
  --kit-yellow-soft: #fbf1dc;
  --kit-green-soft:  #e2f1e8;

  /* 状態色（アクセントとは別系統） */
  --good:    #1f7a4d;
  --warn:    #a86a12;
  --bad:     #b5372f;

  /* ガラス（透明コップ）表現 */
  --glass:        rgba(255, 255, 255, 0.55);
  --glass-line:   rgba(120, 132, 155, 0.45);
  --glass-shine:  rgba(255, 255, 255, 0.85);

  --radius:    10px;
  --radius-lg: 16px;
  --shadow:    0 1px 2px rgba(20, 26, 40, .06), 0 4px 14px rgba(20, 26, 40, .06);
  --shadow-lift: 0 2px 6px rgba(20, 26, 40, .10), 0 12px 28px rgba(20, 26, 40, .12);

  --font-display: "Zen Kaku Gothic New", "Hiragino Kaku Gothic ProN", "Yu Gothic", sans-serif;
  --font-body:    "Noto Sans JP", "Hiragino Kaku Gothic ProN", "Yu Gothic", sans-serif;
  --font-mono:    "Roboto Mono", ui-monospace, SFMono-Regular, Menlo, monospace;

  color-scheme: light;
}

/* ---------- tokens: dark ---------- */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg:          #14171c;
    --surface:     #1c2028;
    --surface-2:   #242933;
    --ink:         #eef1f6;
    --ink-2:       #b3bccb;
    --ink-3:       #7e8899;
    --line:        #2e3543;
    --line-strong: #414a5c;

    --accent:      #6f9bff;
    --accent-ink:  #0f1218;
    --accent-soft: #1d2942;
    --accent-line: #33477a;

    --kit-red:     #f0736a;
    --kit-blue:    #6ba4f0;
    --kit-yellow:  #f0bc55;
    --kit-green:   #5fb888;
    --kit-red-soft:    #32211f;
    --kit-blue-soft:   #1c2a3d;
    --kit-yellow-soft: #322918;
    --kit-green-soft:  #1b2e24;

    --good: #58bd8a;
    --warn: #e0b060;
    --bad:  #ef7a70;

    --glass:       rgba(200, 214, 240, 0.10);
    --glass-line:  rgba(170, 188, 216, 0.38);
    --glass-shine: rgba(235, 244, 255, 0.28);

    --shadow:      0 1px 2px rgba(0, 0, 0, .35), 0 4px 14px rgba(0, 0, 0, .35);
    --shadow-lift: 0 2px 6px rgba(0, 0, 0, .40), 0 12px 28px rgba(0, 0, 0, .45);

    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg:          #14171c;
  --surface:     #1c2028;
  --surface-2:   #242933;
  --ink:         #eef1f6;
  --ink-2:       #b3bccb;
  --ink-3:       #7e8899;
  --line:        #2e3543;
  --line-strong: #414a5c;

  --accent:      #6f9bff;
  --accent-ink:  #0f1218;
  --accent-soft: #1d2942;
  --accent-line: #33477a;

  --kit-red:     #f0736a;
  --kit-blue:    #6ba4f0;
  --kit-yellow:  #f0bc55;
  --kit-green:   #5fb888;
  --kit-red-soft:    #32211f;
  --kit-blue-soft:   #1c2a3d;
  --kit-yellow-soft: #322918;
  --kit-green-soft:  #1b2e24;

  --good: #58bd8a;
  --warn: #e0b060;
  --bad:  #ef7a70;

  --glass:       rgba(200, 214, 240, 0.10);
  --glass-line:  rgba(170, 188, 216, 0.38);
  --glass-shine: rgba(235, 244, 255, 0.28);

  --shadow:      0 1px 2px rgba(0, 0, 0, .35), 0 4px 14px rgba(0, 0, 0, .35);
  --shadow-lift: 0 2px 6px rgba(0, 0, 0, .40), 0 12px 28px rgba(0, 0, 0, .45);

  color-scheme: dark;
}

/* ---------- base ---------- */
*, *::before, *::after { box-sizing: border-box; }

html, body { margin: 0; }

body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.75;
  -webkit-font-smoothing: antialiased;
}

img { max-width: 100%; }
[hidden] { display: none !important; }

h1, h2, h3, h4 {
  font-family: var(--font-display);
  font-weight: 700;
  line-height: 1.35;
  text-wrap: balance;
  margin: 0;
}
h1 { font-size: clamp(1.5rem, 1.1rem + 1.6vw, 2.1rem); }
h2 { font-size: clamp(1.2rem, 1.0rem + 0.9vw, 1.5rem); }
h3 { font-size: 1.08rem; }
p  { margin: 0; }

a { color: var(--accent); }

:where(button, a, input, select, summary):focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 6px;
}

.num { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }

/* ---------- layout ---------- */
.app-shell {
  max-width: 940px;
  margin-inline: auto;
  padding-inline: 16px;
  padding-block: 0 56px;
}

.app-header {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  padding-block: 18px 14px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 22px;
}
.app-header__logo { height: 26px; width: auto; flex-shrink: 0; }
.app-header__title { font-family: var(--font-display); font-weight: 700; font-size: 1rem; }
.app-header__back {
  margin-left: auto;
  font-size: .82rem;
  color: var(--ink-3);
  text-decoration: none;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px 12px;
  background: var(--surface);
}
.app-header__back:hover { color: var(--accent); border-color: var(--accent-line); }

.app-title { margin-bottom: 6px; }
.app-lede { color: var(--ink-2); margin-bottom: 26px; max-width: 62ch; }

/* ---------- 3ステージ（見る → 動かす → 考える） ---------- */
/* 番号はrikasim由来の実際の学習手順を表すので、装飾ではなく情報 */
.stages {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 26px;
}
.stage-tab {
  display: flex;
  flex-direction: column;
  gap: 2px;
  text-align: left;
  font: inherit;
  cursor: pointer;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 12px;
  color: var(--ink-3);
  transition: border-color .15s, color .15s, background .15s;
}
.stage-tab:hover { border-color: var(--line-strong); color: var(--ink-2); }
.stage-tab__n {
  font-family: var(--font-mono);
  font-size: .68rem;
  letter-spacing: .12em;
}
.stage-tab__label { font-family: var(--font-display); font-weight: 700; font-size: .95rem; }
.stage-tab[aria-selected="true"] {
  background: var(--accent-soft);
  border-color: var(--accent-line);
  color: var(--accent);
}
.stage-tab[aria-selected="true"] .stage-tab__label { color: var(--accent); }

.stage-panel { display: grid; gap: 20px; }

/* ---------- surfaces ---------- */
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: var(--shadow);
}
.panel--quiet { box-shadow: none; background: var(--surface-2); border-color: transparent; }
.panel__head { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.panel__head h2, .panel__head h3 { margin: 0; }
.panel__hint { font-size: .85rem; color: var(--ink-3); }

.stack   { display: grid; gap: 14px; }
.stack-s { display: grid; gap: 8px; }
.row     { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.row--between { justify-content: space-between; }

.grid-2 { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }

/* ---------- controls ---------- */
.btn {
  font: inherit;
  font-family: var(--font-display);
  font-weight: 700;
  cursor: pointer;
  border-radius: var(--radius);
  padding: 10px 20px;
  border: 1px solid transparent;
  background: var(--accent);
  color: var(--accent-ink);
  transition: filter .15s, background .15s, border-color .15s;
  line-height: 1.4;
}
.btn:hover:not(:disabled) { filter: brightness(1.08); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn--ghost {
  background: var(--surface);
  color: var(--ink-2);
  border-color: var(--line-strong);
}
.btn--ghost:hover:not(:disabled) { color: var(--accent); border-color: var(--accent-line); background: var(--accent-soft); }
.btn--sm { padding: 6px 14px; font-size: .86rem; }
.btn--lg { padding: 13px 28px; font-size: 1.05rem; }

.field { display: grid; gap: 6px; }
.field__label { font-size: .85rem; color: var(--ink-2); font-weight: 500; }
.field__label b { font-family: var(--font-mono); color: var(--accent); font-size: 1rem; }

input[type="range"] {
  -webkit-appearance: none; appearance: none;
  width: 100%; height: 5px; border-radius: 999px;
  background: var(--line-strong); cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 19px; height: 19px; border-radius: 50%;
  background: var(--accent); border: 2px solid var(--surface);
  box-shadow: var(--shadow);
}
input[type="range"]::-moz-range-thumb {
  width: 19px; height: 19px; border-radius: 50%; border: 2px solid var(--surface);
  background: var(--accent); box-shadow: var(--shadow);
}

input[type="file"] { font-size: .88rem; color: var(--ink-2); max-width: 100%; }
input[type="file"]::file-selector-button {
  font: inherit; font-family: var(--font-display); font-weight: 700;
  margin-right: 12px; padding: 8px 16px; cursor: pointer;
  border: 0; border-radius: var(--radius);
  background: var(--accent); color: var(--accent-ink);
}

/* ---------- キット由来の要素 ---------- */
/* 三角おはじき（赤=1個取る / 青=2個 / 黄=3個） */
.token {
  display: inline-block;
  width: 20px; height: 18px;
  clip-path: polygon(50% 4%, 96% 94%, 4% 94%);
  background: var(--kit-red);
  flex-shrink: 0;
}
.token--red    { background: var(--kit-red); }
.token--blue   { background: var(--kit-blue); }
.token--yellow { background: var(--kit-yellow); }
.token--green  { background: var(--kit-green); border-radius: 50%; clip-path: none; width: 17px; height: 17px; }
.token--sm { width: 14px; height: 13px; }
.token--lg { width: 28px; height: 25px; }

/* 透明の紙コップ（番号ラベル付き） */
.cup {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1.08;
  clip-path: polygon(13% 0, 87% 0, 96% 100%, 4% 100%);
  background: var(--glass);
  border-top: 2px solid var(--glass-line);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  padding: 10px 8px 12px;
  gap: 4px;
  outline: 1px solid var(--glass-line);
  outline-offset: -1px;
}
.cup::after {
  /* ガラスのハイライト */
  content: "";
  position: absolute;
  left: 20%; top: 6%;
  width: 11%; height: 80%;
  background: linear-gradient(to bottom, var(--glass-shine), transparent);
  border-radius: 999px;
  pointer-events: none;
}
.cup__label {
  position: absolute; top: 14%; left: 50%; transform: translateX(-50%);
  font-family: var(--font-mono); font-size: .72rem; font-weight: 500;
  letter-spacing: .04em;
  color: var(--ink-2);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 1px 7px;
  white-space: nowrap;
}
.cup__contents {
  display: flex; flex-wrap: wrap; gap: 3px;
  align-items: flex-end; justify-content: center;
  max-width: 100%;
}
.cup--active { outline: 2px solid var(--accent); outline-offset: 1px; }
.cup-rack { display: grid; grid-template-columns: repeat(auto-fit, minmax(92px, 1fr)); gap: 12px; }

/* ---------- data display ---------- */
.stat-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 12px; }
.stat { display: grid; gap: 1px; }
.stat__label { font-size: .76rem; color: var(--ink-3); letter-spacing: .04em; }
.stat__value { font-family: var(--font-mono); font-size: 1.5rem; font-weight: 500; line-height: 1.2; }

.bar { display: flex; height: 22px; border-radius: 5px; overflow: hidden; background: var(--surface-2); }
.bar__seg { height: 100%; }
.bar__seg--red    { background: var(--kit-red); }
.bar__seg--blue   { background: var(--kit-blue); }
.bar__seg--yellow { background: var(--kit-yellow); }

.pill {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: .76rem; font-weight: 500;
  border-radius: 999px; padding: 2px 10px;
  background: var(--surface-2); color: var(--ink-2);
  border: 1px solid var(--line);
  white-space: nowrap;
}
.pill--good { background: var(--kit-green-soft); color: var(--good); border-color: transparent; }
.pill--bad  { background: var(--kit-red-soft);   color: var(--bad);  border-color: transparent; }
.pill--warn { background: var(--kit-yellow-soft);color: var(--warn); border-color: transparent; }
.pill--accent { background: var(--accent-soft); color: var(--accent); border-color: var(--accent-line); }

.note {
  border-left: 3px solid var(--accent-line);
  background: var(--accent-soft);
  border-radius: 0 var(--radius) var(--radius) 0;
  padding: 12px 16px;
  font-size: .92rem;
  color: var(--ink-2);
}
.note--plain { border-left-color: var(--line-strong); background: var(--surface-2); }

table.data { width: 100%; border-collapse: collapse; font-size: .9rem; }
table.data th, table.data td {
  text-align: left; padding: 7px 10px;
  border-bottom: 1px solid var(--line);
}
table.data th { font-weight: 500; color: var(--ink-3); font-size: .78rem; letter-spacing: .04em; }
table.data td.n { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.table-wrap { overflow-x: auto; }

canvas { max-width: 100%; height: auto; border-radius: var(--radius); display: block; }

.app-footer {
  margin-top: 40px; padding-top: 18px;
  border-top: 1px solid var(--line);
  font-size: .8rem; color: var(--ink-3);
  display: flex; gap: 12px; flex-wrap: wrap; justify-content: space-between;
}
.app-footer a { color: var(--ink-3); }

/* ---------- motion ---------- */
@keyframes drawPop {
  0%   { transform: translateY(-14px) scale(.7); opacity: 0; }
  60%  { transform: translateY(2px) scale(1.12); opacity: 1; }
  100% { transform: translateY(0) scale(1); opacity: 1; }
}
.is-drawn { animation: drawPop .42s cubic-bezier(.34, 1.4, .5, 1) both; }

@keyframes shakeCup {
  0%, 100% { transform: rotate(0); }
  25% { transform: rotate(-4deg); }
  75% { transform: rotate(4deg); }
}
.is-shaking { animation: shakeCup .34s ease-in-out 2; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}

/* ---------- phone ---------- */
@media (max-width: 560px) {
  body { font-size: 15px; }
  .stages { grid-template-columns: 1fr; gap: 6px; }
  .stage-tab { flex-direction: row; align-items: baseline; gap: 8px; padding: 8px 12px; }
  .panel { padding: 16px; }
  .stat__value { font-size: 1.28rem; }
}
