/* =========================================================
   暗号技術シリーズ共通デザインシステム
   全デモ（公開鍵 / 共通鍵 / もし暗号技術がなかったら / デジタル署名）で共有
   ========================================================= */

:root {
  --bg: #0d1117;
  --bg-soft: #161b22;
  --line: #2b3340;
  --text: #e6edf3;
  --text-dim: #8b949e;
  --alice: #f07636;   /* 送る人（TFL Orange） */
  --bob: #4cb1ff;     /* 受け取る人（TFL Sky） */
  --blue: #3075ff;    /* TFL Blue（強調） */
  --cyan: #82e8ff;    /* TFL Cyan（ハイライト） */
  --eve: #f85149;     /* 盗聴者・危険 */
  --gold: #e3b341;    /* 鍵 */
  --green: #3fb950;   /* 成功 */
  --shadow: rgba(0,0,0,.4);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "Hiragino Kaku Gothic ProN", "Yu Gothic", "Noto Sans JP", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.app {
  max-width: 1080px;
  margin: 0 auto;
  padding: 32px 24px 48px;
}

header h1 {
  font-size: 28px;
  margin: 0 0 4px;
  letter-spacing: .02em;
}
header p {
  margin: 0;
  color: var(--text-dim);
  font-size: 15px;
}

/* シリーズ内ナビ（任意で各ページ上部に置く） */
.series-nav {
  display: flex; flex-wrap: wrap; gap: 8px;
  margin: 16px 0 0;
  font-size: 12px;
}
.series-nav a {
  color: var(--text-dim); text-decoration: none;
  border: 1px solid var(--line); border-radius: 99px;
  padding: 4px 12px; transition: color .15s, border-color .15s;
}
.series-nav a:hover { color: var(--text); border-color: #444c56; }
.series-nav a[aria-current="page"] { color: var(--text); border-color: var(--bob); }

/* ===== ステージ ===== */
.stage {
  position: relative;
  margin: 22px 0 20px;
  height: 360px;
  background:
    radial-gradient(120% 120% at 50% 0%, #11202e 0%, var(--bg-soft) 55%, var(--bg) 100%);
  border: 1px solid var(--line);
  border-radius: 16px;
  overflow: hidden;
}

/* 人物 */
.actor {
  position: absolute;
  bottom: 28px;
  width: 150px;
  text-align: center;
  transition: opacity .4s;
}
.actor.alice { left: 24px; }
.actor.bob   { right: 24px; }

.actor .avatar {
  position: relative;
  width: 84px; height: 84px;
  margin: 0 auto 8px;
  border-radius: 50%;
  display: grid; place-items: center;
  border: 2px solid var(--line);
  background: #1c2230;
}
.actor.alice .avatar { box-shadow: 0 0 0 3px rgba(240,136,62,.25); border-color: var(--alice); color: var(--alice); }
.actor.bob   .avatar { box-shadow: 0 0 0 3px rgba(88,166,255,.25); border-color: var(--bob); color: var(--bob); }

/* 棒人間 SVG（#figure-* を <use> で参照。色・線幅は継承で流し込む） */
.figure {
  width: 52px; height: 52px; display: block;
  fill: none; stroke: currentColor;
  stroke-width: 3; stroke-linecap: round; stroke-linejoin: round;
}
.eve .figure { width: 36px; height: 36px; stroke-width: 3.2; }

.actor .name { font-weight: 700; font-size: 16px; }
.actor.alice .name { color: var(--alice); }
.actor.bob   .name { color: var(--bob); }
.actor .role { font-size: 12px; color: var(--text-dim); }

/* 手元の鍵（SVG）。avatar に対して絶対配置。色はインラインで上書き可 */
.held-key {
  position: absolute;
  top: -8px; right: -12px;
  width: 30px; height: 30px;
  color: var(--gold);
  fill: none; stroke: currentColor; stroke-width: 2.4;
  stroke-linecap: round; stroke-linejoin: round;
  filter: drop-shadow(0 2px 3px var(--shadow));
  transition: transform .3s, opacity .3s;
}

/* 通信路 */
.wire {
  position: absolute;
  top: 70px; left: 180px; right: 180px;
  height: 2px;
  background: repeating-linear-gradient(90deg, var(--line) 0 8px, transparent 8px 16px);
}
.wire-label {
  position: absolute;
  top: 44px; left: 50%; transform: translateX(-50%);
  font-size: 12px; color: var(--text-dim);
  background: var(--bg-soft); padding: 2px 10px; border-radius: 99px;
  border: 1px solid var(--line);
}

/* 盗聴者 Eve
   ステージ直下に限定してある。`.eve` は解説文中の色ユーティリティ
   （<b class="eve">）とクラス名が同じで、素の `.eve` にすると本文の
   <b> まで position:absolute / opacity:0 を拾って消えてしまうため。
   Eve のブロックは全デモで `.stage` の直下に置くこと。 */
.stage > .eve {
  position: absolute;
  top: 92px; left: 50%; transform: translateX(-50%);
  text-align: center;
  opacity: 0; transition: opacity .4s;
}
.eve .avatar {
  width: 56px; height: 56px; margin: 0 auto 4px;
  border-radius: 50%; display: grid; place-items: center;
  background: #1c2230; color: var(--eve);
  border: 2px solid var(--eve);
  box-shadow: 0 0 0 3px rgba(248,81,73,.2);
}
.eve .name { font-size: 12px; color: var(--eve); font-weight: 700; }
.stage > .eve.show { opacity: 1; }
.eve .bubble {
  margin-top: 6px; font-size: 11px; color: var(--eve);
  max-width: 170px; min-height: 14px;
}

/* ===== 移動する箱＋南京錠（公開鍵・共通鍵デモで共有） ===== */
.parcel {
  position: absolute;
  left: 60px; bottom: 150px;
  width: 92px; height: 92px;
  transition: left 1.4s cubic-bezier(.55,0,.45,1), bottom .5s, transform .4s, opacity .4s;
  will-change: left;
}
.parcel svg { width: 100%; height: 100%; overflow: visible; }

.box-body { fill: #c98a3a; stroke: #8a5a1d; stroke-width: 2; }
.box-lid  { fill: #e0a24e; stroke: #8a5a1d; stroke-width: 2; }
.note { fill: #fff7e6; }

.shackle {
  fill: none; stroke: var(--gold); stroke-width: 7; stroke-linecap: round;
  transition: transform .45s cubic-bezier(.34,1.56,.64,1);
  transform-box: fill-box; transform-origin: center bottom;
}
.lock-open .shackle { transform: rotate(-32deg) translateX(-3px); }
.lock-body { fill: var(--gold); stroke: #9c7b1e; stroke-width: 2; }
.keyhole   { fill: #6b540f; }

/* メッセージ吹き出し */
.msg-pop {
  position: absolute;
  left: 60px; bottom: 252px;
  transform: translateX(-50%) scale(.6);
  background: var(--green); color: #02220b;
  font-weight: 700; font-size: 13px;
  padding: 6px 12px; border-radius: 10px;
  opacity: 0; transition: all .45s cubic-bezier(.34,1.56,.64,1);
  pointer-events: none; white-space: nowrap;
}
.msg-pop::after {
  content: ""; position: absolute; left: 50%; bottom: -6px;
  transform: translateX(-50%);
  border: 6px solid transparent; border-top-color: var(--green); border-bottom: 0;
}
.msg-pop.danger { background: var(--eve); color: #2a0000; }
.msg-pop.danger::after { border-top-color: var(--eve); }
.msg-pop.show { opacity: 1; transform: translateX(-50%) scale(1); }

/* ===== 判定バッジ（署名検証・改ざん検知などで使用） ===== */
.verdict {
  position: absolute;
  left: 50%; top: 18px; transform: translateX(-50%) scale(.7);
  display: inline-flex; align-items: center; gap: 8px;
  padding: 8px 16px; border-radius: 99px;
  font-weight: 700; font-size: 14px;
  opacity: 0; transition: all .4s cubic-bezier(.34,1.56,.64,1);
}
.verdict .mark {
  width: 18px; height: 18px;
  fill: none; stroke: currentColor; stroke-width: 3;
  stroke-linecap: round; stroke-linejoin: round;
}
.verdict.show { opacity: 1; transform: translateX(-50%) scale(1); }
.verdict.ok { background: rgba(63,185,80,.15); color: var(--green); border: 1px solid var(--green); }
.verdict.ng { background: rgba(248,81,73,.15); color: var(--eve); border: 1px solid var(--eve); }

/* ===== ステップ説明 ===== */
.panel {
  display: flex; gap: 16px; align-items: flex-start;
  background: var(--bg-soft); border: 1px solid var(--line);
  border-radius: 12px; padding: 18px 20px; min-height: 92px;
}
.step-no {
  flex: 0 0 auto;
  width: 40px; height: 40px; border-radius: 50%;
  display: grid; place-items: center;
  font-weight: 800; font-size: 18px;
  background: #11202e; color: var(--bob); border: 1px solid var(--bob);
}
.step-text h2 { margin: 2px 0 6px; font-size: 18px; }
.step-text p  { margin: 0; color: var(--text-dim); font-size: 14px; line-height: 1.7; }
.step-text b.alice { color: var(--alice); }
.step-text b.bob   { color: var(--bob); }
.step-text b.eve   { color: var(--eve); }
.step-text b.gold  { color: var(--gold); }
.step-text b.green { color: var(--green); }

/* ===== コントロール ===== */
.controls {
  display: flex; gap: 12px; align-items: center; margin-top: 18px;
}
button {
  font: inherit; font-weight: 600;
  color: var(--text); background: #21262d;
  border: 1px solid var(--line); border-radius: 8px;
  padding: 10px 18px; cursor: pointer;
  transition: background .15s, border-color .15s, opacity .15s;
}
button:hover:not(:disabled) { background: #2d333b; border-color: #444c56; }
button:disabled { opacity: .4; cursor: not-allowed; }
button.primary { background: var(--bob); color: #03192e; border-color: var(--bob); }
button.primary:hover:not(:disabled) { background: #79b8ff; }

/* 台本順で次のデモへ進む導線（最終ステップで出現） */
.next-demo {
  font: inherit; font-weight: 700; text-decoration: none;
  background: var(--blue); color: #051633;
  border: 1px solid var(--blue); border-radius: 8px;
  padding: 10px 18px;
  display: inline-flex; align-items: center; gap: 6px;
  transition: background .15s;
}
.next-demo:hover { background: #5b92ff; }

/* 前のデモへ戻る導線（最初のステップで出現） */
.prev-demo {
  font: inherit; font-weight: 600; text-decoration: none;
  color: var(--text); background: #21262d;
  border: 1px solid var(--line); border-radius: 8px;
  padding: 10px 16px;
  display: inline-flex; align-items: center; gap: 6px;
  transition: background .15s, border-color .15s;
}
.prev-demo:hover { background: #2d333b; border-color: #444c56; }

.dots { display: flex; gap: 8px; margin-left: auto; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--line); transition: background .2s; }
.dot.active { background: var(--bob); }
.dot.done   { background: var(--green); }

/* ===== 大画面スケーリング（2026-07 追加拡張） =====
   デモは 1080px の設計キャンバスのまま、広い画面では縦横比を維持して等倍拡大する。
   幅と高さの両方を見て小さい方に合わせるので、収録画面から縦にはみ出さない。
   扉絵デッキ（title-cards）は vw/vh 設計で元から画面追従するため .app を持たず対象外。 */
@media (min-width: 1440px) and (min-height: 1150px) { .app { zoom: 1.2; } }
@media (min-width: 1800px) and (min-height: 1350px) { .app { zoom: 1.4; } }
@media (min-width: 2200px) and (min-height: 1700px) { .app { zoom: 1.75; } }
/* 連続スケール：対応ブラウザでは段階指定を上書きして画面にぴったり追従 */
@supports (zoom: min(calc(100vw / 1160px), calc(100vh / 960px))) {
  @media (min-width: 1200px) {
    .app { zoom: max(1, min(calc(100vw / 1160px), calc(100vh / 960px))); }
  }
}
