/* =====================================================================
   プログラミングコンテスト -THE JUDGE-  css/judges.css
   審査員（CSS アート）：顔・髪型・服、表情バリエーション、振り向き・拍手・大暴れ・退避などのアニメ（§3, §10）

   役割分担（設計書 §1.3 / §14）:
     - レイアウト・配色・タイポグラフィ … Tailwind（index.html 内の class）
     - CSS アート・複合 @keyframes・Tailwind 不達時のフォールバック … css/ 配下
   読み込み順（index.html）: base → judges → effects → responsive
   ===================================================================== */

/* =====================================================================
   審査員（CSS アート）
   ===================================================================== */
.judge {
  position: relative;
  width: 30%;
  max-width: 170px;
  text-align: center;
  transition: opacity 0.3s, filter 0.3s, transform 0.3s;
}
.judge .avatar {
  position: relative;
  width: 92px; height: 118px;
  margin: 0 auto -14px;
  transition: transform 0.3s;
}

/* 頭・顔 */
.judge .head {
  position: absolute; left: 50%; top: 0; transform: translateX(-50%);
  width: 68px; height: 68px; z-index: 2;
  transition: transform 0.25s;
}
.judge .face {
  position: absolute; inset: 4px 6px 2px;
  background: #f5d6b8;
  border-radius: 46% 46% 42% 42%;
  box-shadow: inset 0 -6px 8px rgba(0, 0, 0, 0.08);
}
.judge .eye {
  position: absolute; top: 30px; width: 8px; height: 9px;
  background: #26202a; border-radius: 50%;
  transition: transform 0.15s, height 0.15s;
}
.judge .eye.l { left: 13px; }
.judge .eye.r { right: 13px; }
.judge .brow {
  position: absolute; top: 22px; width: 13px; height: 3px;
  background: #4a3524; border-radius: 2px;
  transition: transform 0.15s, top 0.15s;
}
.judge .brow.l { left: 11px; }
.judge .brow.r { right: 11px; }
.judge .mouth {
  position: absolute; left: 50%; bottom: 12px; transform: translateX(-50%);
  width: 16px; height: 3px; background: #b0605c; border-radius: 3px;
  transition: all 0.15s;
}
.judge .sweat {
  position: absolute; right: 2px; top: 14px; width: 8px; height: 11px;
  background: #9ed8ff; border-radius: 50% 50% 60% 60%; opacity: 0;
  transition: opacity 0.2s;
}

/* 髪型（キャラ別） */
.judge .hair { position: absolute; z-index: 3; pointer-events: none; }
#judge-dragon  { --hair: #6b4a2f; }
#judge-tsuchy  { --hair: #26202a; }
#judge-akkina  { --hair: #4a2f23; }

/* ドラゴン: ロングヘア */
#judge-dragon .hair {
  left: 2px; right: 2px; top: -3px; height: 26px;
  background: var(--hair); border-radius: 32px 32px 10px 10px;
}
#judge-dragon .hair::before, #judge-dragon .hair::after {
  content: ""; position: absolute; top: 12px; width: 15px; height: 66px;
  background: var(--hair); border-radius: 8px 8px 12px 12px;
}
#judge-dragon .hair::before { left: -4px; transform: rotate(3deg); }
#judge-dragon .hair::after  { right: -4px; transform: rotate(-3deg); }

/* つっちー: 黒髪短髪 + メガネ */
#judge-tsuchy .hair {
  left: 3px; right: 3px; top: -3px; height: 24px;
  background: var(--hair); border-radius: 34px 34px 14px 14px;
}
#judge-tsuchy .glasses {
  position: absolute; left: 8px; top: 27px; width: 20px; height: 14px;
  border: 2.5px solid #2b3a55; border-radius: 5px; background: rgba(255,255,255,0.14);
  box-shadow: 26px 0 0 -2.5px rgba(255,255,255,0.14), 26px 0 0 0 #2b3a55;
}
#judge-tsuchy .glasses::before {
  content: ""; position: absolute; left: 18px; top: 4px; width: 10px; height: 3px;
  background: #2b3a55;
}
#judge-tsuchy .eye { top: 32px; }

/* あっきーな: ボブヘア */
#judge-akkina .hair {
  left: -3px; right: -3px; top: -4px; height: 30px;
  background: var(--hair); border-radius: 36px 36px 16px 16px;
}
#judge-akkina .hair::before, #judge-akkina .hair::after {
  content: ""; position: absolute; top: 14px; width: 13px; height: 46px;
  background: var(--hair);
}
#judge-akkina .hair::before { left: 0; border-radius: 4px 0 10px 12px; }
#judge-akkina .hair::after  { right: 0; border-radius: 0 4px 12px 10px; }

/* 胴体（スーツ） */
.judge .torso {
  position: absolute; left: 50%; bottom: 0; transform: translateX(-50%);
  width: 88px; height: 52px; z-index: 1;
  border-radius: 26px 26px 6px 6px;
  transition: transform 0.3s;
}
#judge-dragon .torso { background: #2b2b3a; }
#judge-tsuchy .torso { background: #33415c; }
#judge-akkina .torso { background: #7a3b52; }
.judge .torso::before { /* シャツ */
  content: ""; position: absolute; left: 50%; top: 0; transform: translateX(-50%);
  width: 26px; height: 30px; background: #f4f2ec;
  clip-path: polygon(0 0, 100% 0, 50% 100%);
}
#judge-tsuchy .torso::after { /* 胸の「酒」プリント */
  content: "酒";
  position: absolute; left: 50%; top: 4px; transform: translateX(-50%);
  font-size: 15px; font-weight: 900; line-height: 1;
  color: #b3251e;
  text-shadow: 0 0 2px rgba(255, 255, 255, 0.55);
}
#judge-tsuchy .laptop {
  position: absolute; left: 50%; bottom: -8px; transform: translateX(-50%);
  width: 54px; height: 10px; background: #a9b3c2; border-radius: 2px 2px 0 0;
  box-shadow: inset 0 2px 0 #7f8b9d;
}

/* 手（拍手用・通常は非表示） */
.judge .hand {
  position: absolute; bottom: 30px; width: 15px; height: 15px;
  background: #f5d6b8; border-radius: 50%; z-index: 4; opacity: 0;
}
.judge .hand.l { left: 12px; }
.judge .hand.r { right: 12px; }
.judge.clap .hand { opacity: 1; }
.judge.clap .hand.l { animation: clapL 0.28s infinite alternate; }
.judge.clap .hand.r { animation: clapR 0.28s infinite alternate; }
@keyframes clapL { from { transform: translateX(0) rotate(0); } to { transform: translateX(11px) rotate(14deg); } }
@keyframes clapR { from { transform: translateX(0) rotate(0); } to { transform: translateX(-11px) rotate(-14deg); } }

/* ---------- 表情バリエーション ---------- */
.judge[data-face="smile"] .mouth {
  width: 18px; height: 8px; background: none;
  border: 3px solid #b0605c; border-top: none; border-radius: 0 0 16px 16px;
}
.judge[data-face="happy"] .eye { height: 4px; border-radius: 0 0 8px 8px; }
.judge[data-face="happy"] .mouth {
  width: 16px; height: 10px; background: #c0392b; border-radius: 0 0 12px 12px;
}
.judge[data-face="excited"] .eye { transform: scale(1.35); }
.judge[data-face="excited"] .mouth {
  width: 12px; height: 12px; background: #c0392b; border-radius: 50%;
}
.judge[data-face="scared"] .eye {
  transform: scale(1.55); background: #fff; border: 2px solid #26202a;
}
.judge[data-face="scared"] .brow { top: 17px; }
.judge[data-face="scared"] .mouth {
  width: 12px; height: 15px; background: #8e2b2b; border-radius: 46%;
}
.judge[data-face="scared"] .sweat,
.judge[data-face="worry"] .sweat { opacity: 1; }
.judge[data-face="frown"] .brow.l { transform: rotate(16deg); }
.judge[data-face="frown"] .brow.r { transform: rotate(-16deg); }
.judge[data-face="frown"] .mouth {
  width: 16px; height: 7px; background: none;
  border: 3px solid #b0605c; border-bottom: none; border-radius: 14px 14px 0 0;
}
.judge[data-face="think"] .eye { height: 4px; }
.judge[data-face="think"] .mouth { width: 9px; }
.judge[data-face="worry"] .brow.l { transform: rotate(-12deg); }
.judge[data-face="worry"] .brow.r { transform: rotate(12deg); }
.judge[data-face="worry"] .mouth { width: 12px; transform: translateX(-50%) rotate(-6deg); }
.judge[data-face="fire"] .mouth {
  width: 17px; height: 17px; background: #ff5a2a; border-radius: 50%;
  box-shadow: 0 0 10px #ffb347;
}
.judge[data-face="fire"] .eye { height: 4px; }
/* ドラゴンの基本顔は常にキリッと */
#judge-dragon[data-face="neutral"] .brow.l { transform: rotate(10deg); }
#judge-dragon[data-face="neutral"] .brow.r { transform: rotate(-10deg); }

/* ---------- 後ろ姿（上映中 A3） ---------- */
.judge .backhead {
  position: absolute; inset: 0; z-index: 5; opacity: 0; pointer-events: none;
  background: var(--hair); border-radius: 46%;
  box-shadow: inset 0 -10px 10px rgba(0, 0, 0, 0.25);
  transition: opacity 0.1s;
}
.judge.back .backhead { opacity: 1; }
.judge.turning .head { animation: turnHead 0.4s ease-in-out; }
@keyframes turnHead {
  0%   { transform: translateX(-50%) scaleX(1); }
  50%  { transform: translateX(-50%) scaleX(0.12); }
  100% { transform: translateX(-50%) scaleX(1); }
}

/* ---------- 審査員のリアクション動作 ---------- */
.judge.sway .avatar { animation: sway 0.9s ease-in-out infinite alternate; }
@keyframes sway { from { transform: rotate(-4deg); } to { transform: rotate(4deg); } }

.judge.stand .avatar { transform: translateY(-10px); }
.judge.delight .avatar { transform: translateY(-6px); }
.judge.stand.delight .avatar { transform: translateY(-12px); }

.judge.headshake .head { animation: headshake 0.4s ease-in-out 3; }
@keyframes headshake {
  0%, 100% { transform: translateX(-50%) rotate(0); }
  25% { transform: translateX(-50%) rotate(-8deg); }
  75% { transform: translateX(-50%) rotate(8deg); }
}

/* あっきーな大暴れ（A10）: 隠れる前に両手を振り回して跳ね回る。回数が増えるほど激しく */
.judge.panic .avatar {
  transform-origin: 50% 100%;
  animation: panicJump var(--panic-speed, 0.18s) ease-in-out infinite alternate;
  transition: none;
}
.judge.panic .head { animation: panicHead calc(var(--panic-speed, 0.18s) * 1.4) ease-in-out infinite alternate; }
.judge.panic .hand { opacity: 1; }
.judge.panic .hand.l { animation: flailL calc(var(--panic-speed, 0.18s) * 0.7) ease-in-out infinite alternate; }
.judge.panic .hand.r { animation: flailR calc(var(--panic-speed, 0.18s) * 0.7) ease-in-out infinite alternate -0.06s; }
.judge.panic-1 { --panic-speed: 0.18s; --panic-x: 7px;  --panic-y: -12px; --panic-rot: 7deg; }
.judge.panic-2 { --panic-speed: 0.13s; --panic-x: 11px; --panic-y: -20px; --panic-rot: 11deg; }
.judge.panic-3 { --panic-speed: 0.10s; --panic-x: 15px; --panic-y: -28px; --panic-rot: 16deg; }
@keyframes panicJump {
  0%   { transform: translate(calc(var(--panic-x, 7px) * -1), 0) rotate(calc(var(--panic-rot, 7deg) * -1)); }
  50%  { transform: translate(0, var(--panic-y, -12px)) rotate(0); }
  100% { transform: translate(var(--panic-x, 7px), 0) rotate(var(--panic-rot, 7deg)); }
}
@keyframes panicHead {
  from { transform: translateX(-50%) rotate(-9deg); }
  to   { transform: translateX(-50%) rotate(9deg); }
}
@keyframes flailL {
  from { transform: translate(-8px, -26px) rotate(-45deg); }
  to   { transform: translate(4px, 6px) rotate(30deg); }
}
@keyframes flailR {
  from { transform: translate(8px, 6px) rotate(45deg); }
  to   { transform: translate(-4px, -26px) rotate(-30deg); }
}

/* あっきーな退避（A10）: 机の下へ飛び込む → 頭だけ出して震える / deep は潜ったままガタガタ */
.judge.hiding .avatar { transform: translateY(36px); }
.judge.hiding:not(.deep) .avatar { animation: peek 2.2s ease-in-out infinite; }
.judge.hiding.deep .avatar { transform: translateY(52px); animation: tremble 0.09s linear infinite alternate; }
.judge.hiding .head { animation: shiver 0.08s linear infinite alternate; }
@keyframes peek {
  0%, 55%, 100% { transform: translateY(36px); }
  58% { transform: translateY(36px) translateX(-2px); }
  62% { transform: translateY(30px) translateX(2px); }
  70%, 85% { transform: translateY(24px); }
  74% { transform: translateY(24px) translateX(-2px); }
  78% { transform: translateY(24px) translateX(2px); }
  90% { transform: translateY(36px) translateX(2px); }
}
@keyframes tremble {
  from { transform: translateY(52px) translateX(-3px); }
  to   { transform: translateY(52px) translateX(3px); }
}
@keyframes shiver {
  from { transform: translateX(-50%) rotate(-3deg); }
  to   { transform: translateX(-50%) rotate(3deg); }
}

/* つっちー暴走（§6.1 / A16）: 身を乗り出す・飛んでいく手・焦げ */
.judge.reach .avatar { transform: translate(18px, -4px) rotate(10deg); transition: transform 0.5s ease-in; }
.judge.reach .hand.r { opacity: 1; transform: translate(14px, -18px) rotate(-30deg); transition: transform 0.5s; }
.fx-hand {
  position: fixed; width: 18px; height: 18px; border-radius: 50%;
  background: #f5d6b8; box-shadow: 0 2px 4px rgba(0, 0, 0, 0.4); z-index: 60;
  animation: handFly 0.65s cubic-bezier(0.3, 0, 0.7, 1) forwards;
}
@keyframes handFly {
  from { transform: translate(-50%, -50%) scale(0.8); opacity: 0; }
  20%  { opacity: 1; }
  to   { transform: translate(calc(var(--tx) - 50%), calc(var(--ty) - 50%)) scale(1.2); opacity: 1; }
}
.judge.burnt .avatar { filter: brightness(0.35) sepia(0.6); transition: filter 0.4s; }
.judge.burnt .hair { filter: brightness(0.6); }

/* つっちーのメガネ光り（A11/A14） */
.judge.flash .glasses { animation: glassFlash 0.5s ease-out 2; }
@keyframes glassFlash {
  0%   { background: rgba(255, 255, 255, 0.14); box-shadow: 26px 0 0 -2.5px rgba(255,255,255,0.14), 26px 0 0 0 #2b3a55; }
  50%  { background: rgba(255, 255, 255, 0.95); box-shadow: 26px 0 0 -2.5px rgba(255,255,255,0.95), 26px 0 0 0 #2b3a55; }
  100% { background: rgba(255, 255, 255, 0.14); box-shadow: 26px 0 0 -2.5px rgba(255,255,255,0.14), 26px 0 0 0 #2b3a55; }
}

/* 火吹き前の吸い込み（§9.4） */
.judge.inhale .torso { transform: translateX(-50%) scale(1.14); }
.judge.inhale .head { transform: translateX(-50%) translateY(-3px); }

/* フォーカス演出（QA / 得点発表） */
#judgesRow[data-focus="dragon"] .judge:not(#judge-dragon),
#judgesRow[data-focus="tsuchy"] .judge:not(#judge-tsuchy),
#judgesRow[data-focus="akkina"] .judge:not(#judge-akkina) {
  opacity: 0.3; filter: brightness(0.55);
}
#judgesRow[data-focus="dragon"] #judge-dragon,
#judgesRow[data-focus="tsuchy"] #judge-tsuchy,
#judgesRow[data-focus="akkina"] #judge-akkina {
  transform: scale(1.06);
}

/* ---------- 吹き出し（A4） ---------- */
.judge .bubble {
  position: absolute; bottom: calc(100% + 2px); left: 50%;
  transform: translateX(-50%);
  min-width: 130px; max-width: 230px; z-index: 20;
  background: #fffdf6; color: #241a10;
  border-radius: 12px; padding: 8px 10px;
  font-size: 12px; font-weight: 700; line-height: 1.5; text-align: left;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.4);
}
.judge .bubble::after {
  content: ""; position: absolute; top: 100%; left: 50%;
  transform: translateX(-50%);
  border: 7px solid transparent; border-top-color: #fffdf6;
}
.judge .bubble.pop { animation: bubblePop 0.25s cubic-bezier(0.2, 1.6, 0.4, 1); }
@keyframes bubblePop { from { transform: translateX(-50%) scale(0); } to { transform: translateX(-50%) scale(1); } }

/* ---------- 机・名札・得点札 ---------- */
.judge .desk {
  position: relative; z-index: 6;
  height: 52px; border-radius: 8px 8px 0 0;
  background: linear-gradient(#3b2a55, #2a1d3e);
  box-shadow: inset 0 3px 0 rgba(255, 255, 255, 0.12);
}
.judge .nameplate {
  position: absolute; top: -11px; left: 50%; transform: translateX(-50%);
  background: #ffd75e; color: #241a10;
  font-size: 11px; font-weight: 900; letter-spacing: 0.08em;
  padding: 2px 10px; border-radius: 4px; white-space: nowrap;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.4);
}
.scorecard {
  position: absolute; left: 50%; top: 8px; transform: translateX(-50%);
  width: 44px; height: 58px; perspective: 500px;
}
.card-inner {
  position: relative; width: 100%; height: 100%;
  transform-style: preserve-3d;
  transition: transform 0.6s cubic-bezier(0.3, 1.2, 0.4, 1);
}
.scorecard.open .card-inner { transform: rotateY(180deg); }
.scorecard.rolling .card-inner { animation: cardShiver 0.08s infinite alternate; }
@keyframes cardShiver { from { transform: rotate(-2deg); } to { transform: rotate(2deg); } }
.card-front, .card-back {
  position: absolute; inset: 0; backface-visibility: hidden;
  display: grid; place-items: center;
  border-radius: 6px; font-weight: 900;
}
.card-front {
  background: repeating-linear-gradient(45deg, #5a4f8a 0 6px, #4a3f78 6px 12px);
  color: #ffd75e; font-size: 20px;
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.5);
}
.card-back {
  transform: rotateY(180deg);
  background: #fffdf6; color: #c1121f; font-size: 30px;
  text-shadow: 0 2px 0 rgba(193, 18, 31, 0.25);
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.5);
}

/* ---------- 質疑応答の選択肢 ---------- */
.choice-btn {
  display: block; width: 100%; text-align: left;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 215, 94, 0.35);
  border-radius: 10px; padding: 10px 14px;
  font-size: 13px; font-weight: 700; color: #fff;
  transition: background 0.15s, transform 0.1s;
}
.choice-btn:hover { background: rgba(255, 215, 94, 0.2); }
.choice-btn:active { transform: scale(0.98); }
.choice-btn:disabled { opacity: 0.4; pointer-events: none; }
