/* ============================================================
   물리 놀이터 3D · style.css   (밝은 톤 / 프로페셔널 디자인)
   ------------------------------------------------------------
   색을 바꾸고 싶으면 아래 :root 부분의 값만 고치면 전체가 함께 바뀝니다.
   ============================================================ */

@import url('https://cdn.jsdelivr.net/gh/orioncactus/pretendard@v1.3.9/dist/web/variable/pretendardvariable-dynamic-subset.css');

:root {
  /* 배경 · 면 */
  --bg:         #eef3fa;   /* 페이지 바탕 */
  --bg-soft:    #e3ecf8;
  --surface:    #ffffff;   /* 카드 · 패널 */
  --surface-2:  #f6f9fd;   /* 안쪽 박스 */
  --surface-3:  #eef3fb;

  /* 선 */
  --line:       #dde5f1;
  --line-2:     #c6d3e6;

  /* 글자 */
  --text:       #12203c;   /* 제목 */
  --text-2:     #3d5478;   /* 본문 */
  --muted:      #7387a6;   /* 보조 설명 */

  /* 포인트 색 */
  --primary:    #2563eb;   /* 메인 파랑 */
  --primary-d:  #1b4fd0;
  --primary-l:  #e8f0ff;
  --cyan:       #0891b2;
  --cyan-l:     #e0f5fa;
  --gold:       #f59e0b;
  --gold-l:     #fff4de;
  --green:      #10b981;
  --green-l:    #e4f8f1;
  --red:        #ef4444;
  --red-l:      #fdecec;
  --blue:       #3b82f6;
  --gray:       #94a3b8;

  --radius:     18px;
  --radius-sm:  12px;
  --shadow-sm:  0 1px 2px rgba(16,34,63,.05), 0 2px 8px rgba(16,34,63,.05);
  --shadow:     0 1px 2px rgba(16,34,63,.05), 0 10px 26px rgba(16,34,63,.09);
  --shadow-lg:  0 20px 50px rgba(16,34,63,.16);
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0; height: 100%;
  background: var(--bg);
  color: var(--text-2);
  font-family: 'Pretendard Variable', Pretendard, 'Apple SD Gothic Neo', 'Malgun Gothic', system-ui, sans-serif;
  font-size: 17px;
  line-height: 1.6;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

button { font-family: inherit; cursor: pointer; }
h1, h2, h3, h4 { color: var(--text); }

/* 화면 전환 */
.screen { display: none; height: 100%; }
.screen.is-active { display: block; }


/* ============================================================
   홈 화면
   ============================================================ */
.home-wrap {
  height: 100%; overflow-y: auto;
  padding: 40px 44px 56px;
  background:
    radial-gradient(900px 480px at 8% -12%, #dbe9ff 0%, transparent 62%),
    radial-gradient(760px 420px at 96% -6%, #d9f4fb 0%, transparent 58%),
    var(--bg);
}

.home-head {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 16px; margin: 0 auto 30px; max-width: 1240px;
}
.home-head h1 {
  font-size: 44px; margin: 0 0 8px; letter-spacing: -1.4px; font-weight: 800;
}
.home-sub { margin: 0; color: var(--muted); font-size: 17.5px; }

.card-grid {
  display: grid; gap: 22px;
  grid-template-columns: repeat(auto-fit, minmax(310px, 1fr));
  max-width: 1240px; margin: 0 auto;
}

/* 카드마다 다른 포인트 색 */
.card[data-sim="projectile"] { --tint: #2563eb; --tint-l: #e8f0ff; }
.card[data-sim="collision"]  { --tint: #db2777; --tint-l: #fde9f3; }
.card[data-sim="coaster"]    { --tint: #0891b2; --tint-l: #e0f5fa; }
.card[data-sim="orbit"]      { --tint: #7c3aed; --tint-l: #f0e9fe; }
.card[data-sim="racing"]     { --tint: #ea580c; --tint-l: #ffeee2; }
.card[data-sim="spaceship"]  { --tint: #0d9488; --tint-l: #dff5f2; }
.card[data-sim="train"]      { --tint: #4f46e5; --tint-l: #eaeaff; }

.card {
  position: relative; overflow: hidden;
  display: flex; flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 26px 24px 24px;
  box-shadow: var(--shadow-sm);
  transition: transform .18s ease, box-shadow .18s ease, border-color .18s ease;
}
.card::before {                       /* 카드 위쪽 색 띠 */
  content: ''; position: absolute; inset: 0 0 auto 0; height: 5px;
  background: var(--tint);
}
.card:hover {
  transform: translateY(-5px);
  box-shadow: var(--shadow);
  border-color: var(--tint);
}
.card-icon {
  width: 66px; height: 66px; margin: 6px 0 14px;
  display: flex; align-items: center; justify-content: center;
  font-size: 36px; line-height: 1;
  background: var(--tint-l); border-radius: 20px;
}
.card h2 { font-size: 24px; margin: 0 0 6px; font-weight: 800; letter-spacing: -.4px; }
.card p { margin: 0 0 20px; color: var(--muted); font-size: 15.5px; flex: 1 0 auto; }

.card-star {
  position: absolute; top: 22px; right: 20px;
  background: var(--gold-l); border: 1px solid #f5d9a4;
  border-radius: 999px; padding: 4px 12px;
  font-size: 14px; font-weight: 800; color: #b45309;
}
.card-tag {
  position: absolute; top: 22px; left: 24px;
  background: var(--tint); color: #fff;
  border-radius: 999px; padding: 3px 11px;
  font-size: 12.5px; font-weight: 800; letter-spacing: .3px;
}
.card.is-game .card-icon { margin-top: 26px; }

.go-btn {
  width: 100%; min-height: 52px;
  border: none; border-radius: var(--radius-sm);
  background: var(--tint); color: #fff;
  font-size: 17px; font-weight: 800; letter-spacing: -.2px;
  box-shadow: 0 6px 16px rgba(16,34,63,.14);
  transition: filter .15s ease, transform .1s ease;
}
.go-btn:hover { filter: brightness(1.08); }
.go-btn:active { transform: translateY(1px); }

/* Three.js 소개 배너 */
.tech-banner {
  display: flex; align-items: center; justify-content: space-between;
  gap: 22px; flex-wrap: wrap;
  max-width: 1240px; margin: 26px auto 0; padding: 24px 28px;
  background: linear-gradient(115deg, #ffffff 0%, #f0f6ff 60%, #eaf7fb 100%);
  border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}
.tech-text h3 { margin: 0 0 6px; font-size: 20px; font-weight: 800; }
.tech-text h3 b { color: var(--primary); }
.tech-text p { margin: 0; color: var(--muted); font-size: 15.5px; max-width: 800px; }
.tech-text p b { color: var(--text-2); font-weight: 700; }
.tech-btn {
  min-height: 52px; padding: 0 24px; flex: 0 0 auto;
  background: var(--surface); color: var(--primary);
  border: 1.5px solid var(--primary); border-radius: var(--radius-sm);
  font-size: 16.5px; font-weight: 800;
  transition: background .15s ease, color .15s ease;
}
.tech-btn:hover { background: var(--primary); color: #fff; }

.home-foot { max-width: 1240px; margin: 28px auto 0; color: var(--muted); font-size: 15.5px; }
.key-tip b { color: var(--primary); }


/* ============================================================
   시뮬레이션 화면
   ============================================================ */
#screen-sim { display: none; }
#screen-sim.is-active { display: flex; flex-direction: column; }

.sim-top {
  display: flex; align-items: center; gap: 16px;
  padding: 11px 18px; flex: 0 0 auto;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  box-shadow: 0 1px 3px rgba(16,34,63,.05);
  z-index: 10;
}
.sim-top h2 { font-size: 21px; margin: 0; flex: 1; font-weight: 800; letter-spacing: -.4px; }

.ghost-btn {
  min-height: 48px; padding: 0 18px;
  background: var(--surface-2); color: var(--text-2);
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  font-size: 16px; font-weight: 700;
  transition: border-color .15s ease, color .15s ease;
}
.ghost-btn:hover { border-color: var(--primary); color: var(--primary); }

.icon-btn {
  min-width: 52px; min-height: 48px; font-size: 22px;
  background: var(--surface-2); color: var(--text-2);
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  transition: border-color .15s ease;
}
.icon-btn.small { min-width: 40px; min-height: 40px; font-size: 17px; }
.icon-btn:hover { border-color: var(--primary); }

.sim-body { flex: 1 1 auto; display: flex; min-height: 0; }

#canvas-wrap {
  position: relative; flex: 7 1 0; min-width: 0;
  background: #dce7f5; overflow: hidden;
}
/* 3D 렌더러 캔버스만 꽉 채우기 (미니맵 캔버스는 제외) */
#canvas-wrap > canvas:not(.hud-map) { display: block; width: 100%; height: 100%; }

#panel {
  flex: 3 1 0; min-width: 340px; max-width: 470px;
  background: var(--surface);
  border-left: 1px solid var(--line);
  overflow-y: auto; padding: 20px 20px 44px;
}

/* ---------- 컨트롤 ---------- */
.sim-panel { display: none; }
.sim-panel.is-active { display: block; }

.ctrl { margin-bottom: 20px; }
.ctrl label {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; font-size: 15px; color: var(--muted); font-weight: 600; margin-bottom: 8px;
}
.ctrl .val {
  font-size: 26px; font-weight: 800; color: var(--text);
  font-variant-numeric: tabular-nums; letter-spacing: -.5px;
}
.ctrl-note { font-size: 13.5px; color: var(--muted); margin-top: 6px; }
.ctrl-note b { color: var(--primary); font-weight: 700; }

/* 슬라이더 : 지나온 부분이 파랗게 차오릅니다 (--fill 값은 js/main.js가 갱신) */
input[type=range] {
  -webkit-appearance: none; appearance: none;
  width: 100%; height: 8px; border-radius: 999px; outline: none;
  background: linear-gradient(90deg, var(--primary) var(--fill, 50%), var(--line-2) var(--fill, 50%));
}
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 28px; height: 28px; border-radius: 50%;
  background: #fff; border: 3px solid var(--primary); cursor: pointer;
  box-shadow: 0 2px 6px rgba(16,34,63,.22);
}
input[type=range]::-moz-range-thumb {
  width: 24px; height: 24px; border-radius: 50%;
  background: #fff; border: 3px solid var(--primary); cursor: pointer;
  box-shadow: 0 2px 6px rgba(16,34,63,.22);
}

/* 3단 선택 버튼 */
.seg { display: flex; gap: 8px; }
.seg-btn {
  flex: 1; min-height: 48px;
  background: var(--surface-2); color: var(--text-2);
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  font-size: 15.5px; font-weight: 700;
  transition: all .14s ease;
}
.seg-btn:hover { border-color: var(--primary); color: var(--primary); }
.seg-btn.is-on {
  background: var(--primary); color: #fff; border-color: var(--primary);
  box-shadow: 0 4px 12px rgba(37,99,235,.28);
}

/* 실행 / 초기화 */
.btn-row { display: flex; gap: 10px; margin: 22px 0 10px; }
.btn-run, .btn-reset, .btn-sub {
  min-height: 52px; border-radius: var(--radius-sm); border: none;
  font-size: 17px; font-weight: 800; flex: 1;
  transition: filter .15s ease, transform .1s ease;
}
.btn-run {
  background: var(--green); color: #fff;
  box-shadow: 0 6px 16px rgba(16,185,129,.3);
}
.btn-reset {
  background: var(--surface-2); color: var(--text-2); border: 1px solid var(--line-2);
}
.btn-sub {
  width: 100%; min-height: 48px; margin-bottom: 8px;
  background: var(--surface-2); color: var(--text-2); border: 1px solid var(--line);
  font-size: 15.5px;
}
.btn-run:hover, .btn-reset:hover, .btn-sub:hover { filter: brightness(.97); }
.btn-run:hover { filter: brightness(1.06); }
.btn-run:active, .btn-reset:active { transform: translateY(1px); }
.btn-run:disabled { opacity: .45; cursor: not-allowed; }

/* ---------- 측정값 박스 ---------- */
.readout {
  background: var(--surface-2); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 16px 18px; margin: 20px 0;
}
.readout h4 {
  margin: 0 0 12px; font-size: 13px; font-weight: 800;
  color: var(--muted); letter-spacing: .6px; text-transform: uppercase;
}
.ro {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: 10px; padding: 7px 0; border-bottom: 1px dashed var(--line);
}
.ro:last-child { border-bottom: none; }
.ro span { font-size: 14.5px; color: var(--muted); }
.ro b {
  font-size: 25px; font-weight: 800; color: var(--text);
  font-variant-numeric: tabular-nums; letter-spacing: -.6px;
}

/* ---------- 미션 ---------- */
.missions h4 {
  margin: 0 0 12px; font-size: 13px; font-weight: 800;
  color: var(--muted); letter-spacing: .6px; text-transform: uppercase;
}
.mission-list { list-style: none; margin: 0; padding: 0; }
.mission-list li {
  display: flex; gap: 10px; align-items: flex-start;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius-sm); padding: 13px 15px; margin-bottom: 8px;
  font-size: 15px; color: var(--text-2);
  transition: all .16s ease;
}
.mission-list li.done {
  background: var(--gold-l); border-color: #f3d191; color: #92600b; font-weight: 600;
}
.mission-list .mk { font-size: 17px; line-height: 1.4; }

/* ---------- 게임용 조작 버튼 / 상태 ---------- */
.game-warn {
  border-radius: var(--radius-sm); padding: 12px 14px; margin-bottom: 16px;
  font-size: 15px; font-weight: 700; text-align: center;
}
.game-warn.ok   { background: var(--green-l); border: 1px solid #a9e6d1; color: #0a7256; }
.game-warn.warn { background: var(--gold-l);  border: 1px solid #f3d191; color: #92600b; }
.game-warn.bad  { background: var(--red-l);   border: 1px solid #f5b7b7; color: #b91c1c; }

.game-pad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 10px; }
.game-pad button {
  min-height: 62px; border-radius: var(--radius-sm);
  background: var(--surface-2); color: var(--text);
  border: 1px solid var(--line-2);
  font-size: 19px; font-weight: 800; line-height: 1.15;
  touch-action: none; user-select: none;
  transition: all .1s ease;
}
.game-pad button span { font-size: 12.5px; font-weight: 600; color: var(--muted); }
.game-pad button:active {
  background: var(--primary); color: #fff; border-color: var(--primary);
}
.game-pad button:active span { color: rgba(255,255,255,.85); }
.game-pad.two { grid-template-columns: repeat(2, 1fr); }
.game-pad.two button { grid-column: auto; grid-row: auto; min-height: 72px; }
.pad-up   { grid-column: 2; grid-row: 1; }
.pad-left { grid-column: 1; grid-row: 2; }
.pad-down { grid-column: 2; grid-row: 2; }
.pad-right{ grid-column: 3; grid-row: 2; }

.fuel-wrap { display: flex; align-items: center; gap: 10px; margin: 16px 0 6px; }
.fuel-wrap span { font-size: 14.5px; color: var(--muted); font-weight: 600; }
.fuel-bar {
  flex: 1; height: 14px; background: var(--surface-3);
  border-radius: 999px; overflow: hidden; border: 1px solid var(--line);
}
.fuel-bar > div {
  height: 100%; width: 100%;
  background: linear-gradient(90deg, #fbbf24, var(--gold));
  transition: width .1s linear;
}


/* ============================================================
   캔버스 위 오버레이
   ============================================================ */
.hint-box {
  position: absolute; top: 16px; left: 50%; transform: translateX(-50%);
  background: rgba(255,255,255,.94); border: 1px solid var(--line-2);
  color: var(--text); padding: 12px 22px; border-radius: 999px;
  font-size: 16px; font-weight: 700; display: none; z-index: 8;
  max-width: 84%; text-align: center;
  box-shadow: var(--shadow); backdrop-filter: blur(6px);
}
.hint-box.show { display: block; }

.canvas-overlay { position: absolute; display: none; z-index: 4; }
.canvas-overlay.show { display: block; }

/* 공통 유리판 느낌 */
.energy-overlay, .chart-overlay, .hud-info, .hud-map, .hud-compare, .hud-speedo-box {
  background: rgba(255,255,255,.9);
  border: 1px solid rgba(180,200,225,.7);
  box-shadow: 0 6px 20px rgba(16,34,63,.14);
  backdrop-filter: blur(8px);
}

/* ③ 에너지 막대 (좌측 세로) */
.energy-overlay {
  left: 14px; top: 14px; bottom: 88px; width: 188px;
  border-radius: var(--radius); padding: 13px;
}
.energy-title { font-size: 13px; color: var(--muted); margin-bottom: 2px; font-weight: 800; letter-spacing: .5px; text-transform: uppercase; }
.energy-total { font-size: 12.5px; color: #92600b; font-weight: 700; margin-bottom: 10px; }
.energy-total b { font-size: 14px; }
.energy-bars { position: relative; height: calc(100% - 100px); display: flex; gap: 10px; align-items: flex-end; }
.ebar {
  position: relative; flex: 1; height: 100%;
  background: var(--surface-3); border-radius: 10px;
  display: flex; flex-direction: column; justify-content: flex-end;
}
.ebar-fill { width: 100%; height: 0%; border-radius: 10px; transition: height .06s linear; }
#e-pe   { background: linear-gradient(180deg, #60a5fa, #2563eb); }
#e-ke   { background: linear-gradient(180deg, #fb7185, #e11d48); }
#e-heat { background: linear-gradient(180deg, #cbd5e1, #94a3b8); }
.ebar-label {
  position: absolute; bottom: -44px; left: -3px; right: -3px;
  text-align: center; font-size: 12px; color: var(--muted); line-height: 1.4;
}
.ebar-label b { font-size: 16px; color: var(--text); font-variant-numeric: tabular-nums; }
.total-line { position: absolute; left: 0; right: 0; top: 0; border-top: 2px dashed var(--gold); }

/* ② 충돌 막대그래프 (하단 가로) */
.chart-overlay {
  left: 16px; right: 16px; bottom: 84px;
  border-radius: var(--radius); padding: 12px 18px; display: none;
}
.chart-overlay.show { display: flex; gap: 30px; justify-content: center; }
.chart-group { flex: 0 1 340px; }
.chart-name { font-size: 13px; color: var(--muted); text-align: center; margin-bottom: 8px; font-weight: 700; }
.chart-pair { display: flex; gap: 18px; align-items: flex-end; height: 106px; }
.bar-col { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; height: 100%; }
.bar-col > span { font-size: 12px; color: var(--muted); text-align: center; margin-top: 5px; }
.bar-col b { font-size: 15px; color: var(--text); font-variant-numeric: tabular-nums; }
.bar { width: 62px; border-radius: 8px 8px 0 0; height: 0px; transition: height .18s ease; }
.bar.mom  { background: linear-gradient(180deg, #fbbf24, #f59e0b); }
.bar.eng  { background: linear-gradient(180deg, #fb7185, #e11d48); }
.bar.lost { background: repeating-linear-gradient(45deg, #cbd5e1 0 6px, #b8c5d6 6px 12px); }
.bar-stack { display: flex; flex-direction: column; justify-content: flex-end; }
.bar-stack .bar { border-radius: 0; }
.bar-stack .lost { border-radius: 8px 8px 0 0; }

/* AI 열기 버튼 */
.ai-open-btn {
  position: absolute; bottom: 16px; left: 50%; transform: translateX(-50%);
  min-height: 52px; padding: 0 26px; z-index: 6;
  background: var(--surface); color: var(--primary);
  border: 1.5px solid var(--primary); border-radius: 999px;
  font-size: 16.5px; font-weight: 800;
  box-shadow: var(--shadow);
  transition: background .15s ease, color .15s ease;
}
.ai-open-btn:hover { background: var(--primary); color: #fff; }


/* ============================================================
   게임 HUD (레이싱 / 우주선 / 기차)
   ============================================================ */
.game-hud { inset: 0; pointer-events: none; }
.game-hud.show { display: block; }

.hud-info { position: absolute; top: 14px; left: 14px; border-radius: var(--radius); padding: 11px 17px; }
.hud-row { display: flex; align-items: baseline; gap: 14px; justify-content: space-between; }
.hud-row span { font-size: 11.5px; letter-spacing: 1.2px; color: var(--muted); font-weight: 800; text-transform: uppercase; }
.hud-row b { font-size: 21px; font-weight: 900; color: var(--text); font-variant-numeric: tabular-nums; }

.hud-map {
  position: absolute; top: 14px; right: 14px;
  width: 190px; height: 190px; border-radius: var(--radius);
}

.hud-speedo {
  position: absolute; right: 16px; bottom: 74px; text-align: right;
  background: rgba(255,255,255,.9); border: 1px solid rgba(180,200,225,.7);
  border-radius: var(--radius); padding: 12px 20px 14px;
  box-shadow: 0 6px 20px rgba(16,34,63,.14); backdrop-filter: blur(8px);
}
.hud-speedo b {
  display: block; font-size: 62px; line-height: .95; font-weight: 900;
  color: var(--text); font-variant-numeric: tabular-nums; letter-spacing: -2px;
}
.hud-speedo > span { font-size: 15px; color: var(--muted); font-weight: 700; }
.hud-sub { margin-top: 4px; font-size: 14px; font-weight: 900; letter-spacing: 2px; color: var(--muted); }
.hud-sub.ok  { color: var(--green); }
.hud-sub.bad { color: var(--red); }
.hud-fuelbar {
  width: 150px; height: 10px; margin: 9px 0 3px auto;
  background: var(--surface-3); border: 1px solid var(--line); border-radius: 999px; overflow: hidden;
}
.hud-fuelbar i { display: block; height: 100%; width: 100%; background: linear-gradient(90deg, #fbbf24, var(--gold)); }

/* 기차 : 가속·제동 손잡이 */
.hud-levers { position: absolute; left: 14px; bottom: 84px; display: flex; gap: 12px; align-items: flex-end; }
.lever {
  position: relative; width: 42px; height: 128px;
  background: rgba(255,255,255,.9); border: 1px solid rgba(180,200,225,.7);
  border-radius: 12px; display: flex; align-items: flex-end;
  box-shadow: 0 6px 20px rgba(16,34,63,.14); backdrop-filter: blur(8px);
}
.lever-fill { width: 100%; height: 0%; border-radius: 11px; transition: height .08s linear; }
.lever-fill.throttle { background: linear-gradient(0deg, #059669, #34d399); }
.lever-fill.brake    { background: linear-gradient(0deg, #dc2626, #f87171); }
.lever span {
  position: absolute; bottom: -25px; left: -6px; right: -6px; text-align: center;
  font-size: 12.5px; font-weight: 800; color: var(--text);
  text-shadow: 0 1px 4px rgba(255,255,255,.9);
}

/* 기차 : 남은 거리 vs 제동거리 비교 */
.hud-compare {
  position: absolute; left: 50%; transform: translateX(-50%); top: 76px;
  width: min(470px, 62%); border-radius: var(--radius); padding: 11px 16px;
}
.cmp-row { display: flex; align-items: center; gap: 10px; margin: 5px 0; }
.cmp-row span { flex: 0 0 128px; font-size: 12.5px; color: var(--muted); font-weight: 700; }
.cmp-track { flex: 1; height: 13px; background: var(--surface-3); border-radius: 999px; overflow: hidden; }
.cmp-track i { display: block; height: 100%; width: 0%; border-radius: 999px; background: var(--blue); transition: width .1s linear; }
#hud-bar-brake { background: var(--gold); }
#hud-bar-brake.danger { background: var(--red); }


/* ============================================================
   AI 물리 선생님 패널
   ============================================================ */
.ai-panel {
  position: fixed; top: 0; right: 0; bottom: 0; width: 410px; max-width: 92vw;
  background: var(--surface); border-left: 1px solid var(--line);
  transform: translateX(105%); transition: transform .26s cubic-bezier(.4,0,.2,1);
  display: flex; flex-direction: column; z-index: 40;
  box-shadow: -12px 0 40px rgba(16,34,63,.16);
}
.ai-panel.open { transform: translateX(0); }
.ai-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px; border-bottom: 1px solid var(--line);
  background: linear-gradient(100deg, #f3f8ff, #eef7fb);
}
.ai-head h3 { margin: 0; font-size: 19px; font-weight: 800; }

.grade-toggle { display: flex; gap: 8px; padding: 14px 18px 6px; }
.ai-quick { display: flex; flex-wrap: wrap; gap: 8px; padding: 10px 18px 14px; }
.ai-quick button {
  min-height: 42px; padding: 0 15px;
  background: var(--primary-l); color: var(--primary-d);
  border: 1px solid #cfe0ff; border-radius: 999px; font-size: 14.5px; font-weight: 700;
}
.ai-quick button:hover { background: var(--primary); color: #fff; border-color: var(--primary); }

.ai-msgs { flex: 1 1 auto; overflow-y: auto; padding: 12px 18px; background: var(--surface-2); }
.msg { margin-bottom: 12px; display: flex; }
.msg .bubble {
  padding: 12px 15px; border-radius: 16px; font-size: 15.5px; line-height: 1.6;
  max-width: 88%; white-space: pre-wrap; word-break: break-word;
  box-shadow: var(--shadow-sm);
}
.msg.user { justify-content: flex-end; }
.msg.user .bubble { background: var(--primary); color: #fff; border-bottom-right-radius: 5px; }
.msg.bot .bubble { background: var(--surface); border: 1px solid var(--line); color: var(--text-2); border-bottom-left-radius: 5px; }
.msg.sys .bubble { background: var(--gold-l); border: 1px solid #f3d191; color: #92600b; font-size: 14.5px; }

.ai-input { display: flex; gap: 8px; padding: 14px 18px 18px; border-top: 1px solid var(--line); }
.ai-input textarea {
  flex: 1; resize: none; border-radius: var(--radius-sm); padding: 11px 13px;
  background: var(--surface-2); border: 1px solid var(--line-2); color: var(--text);
  font-size: 15.5px; font-family: inherit;
}
.ai-input textarea:focus { outline: 2px solid var(--primary); outline-offset: -1px; border-color: transparent; }
.ai-input .btn-run { flex: 0 0 82px; min-height: 48px; font-size: 16px; }


/* ============================================================
   모달 / 토스트
   ============================================================ */
.modal {
  position: fixed; inset: 0; background: rgba(18,32,60,.42);
  display: none; align-items: center; justify-content: center; z-index: 60; padding: 22px;
  backdrop-filter: blur(3px);
}
.modal.open { display: flex; }
.modal-box {
  width: 560px; max-width: 100%; max-height: 88vh; overflow-y: auto;
  background: var(--surface); border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
}
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid var(--line);
  position: sticky; top: 0; background: var(--surface); border-radius: var(--radius) var(--radius) 0 0;
}
.modal-head h3 { margin: 0; font-size: 20px; font-weight: 800; }
.modal-body { padding: 22px; }
.modal-body h4 { margin: 0 0 8px; font-size: 17px; font-weight: 800; }
.note { color: var(--muted); font-size: 14.5px; margin: 0 0 14px; }
.key-row { display: flex; gap: 8px; flex-wrap: wrap; }
.key-row input {
  flex: 1 1 240px; min-height: 48px; padding: 0 14px;
  background: var(--surface-2); border: 1px solid var(--line-2);
  border-radius: var(--radius-sm); color: var(--text); font-size: 15.5px;
}
.key-row input:focus { outline: 2px solid var(--primary); outline-offset: -1px; }
.small-btn { flex: 0 0 auto !important; padding: 0 20px; }
.key-status { margin-top: 12px; font-size: 14.5px; color: var(--muted); }
.key-status.ok { color: #0a7256; font-weight: 700; }
.modal-body hr { border: none; border-top: 1px solid var(--line); margin: 24px 0 20px; }

/* Three.js 소개 모달 */
.modal-box.wide { width: 880px; }
.tech-body h4 { margin: 26px 0 8px; font-size: 18.5px; }
.tech-body h4:first-child { margin-top: 0; }
.tech-body p { font-size: 15.5px; margin: 0 0 10px; color: var(--text-2); }
.tech-body p b { color: var(--text); font-weight: 700; }
.tech-flow {
  background: var(--primary-l); border: 1px solid #cfe0ff; border-radius: var(--radius-sm);
  padding: 13px 15px; text-align: center; font-size: 15px !important; color: var(--text-2) !important;
  font-weight: 600;
}
.tech-flow b { color: var(--primary-d) !important; }
.tech-list { margin: 0 0 10px; padding-left: 20px; }
.tech-list li { font-size: 15px; color: var(--text-2); margin-bottom: 8px; }
.tech-list li b { color: var(--primary-d); }
.tech-list code {
  background: var(--surface-3); border: 1px solid var(--line);
  border-radius: 6px; padding: 1px 7px; font-size: 13.5px; color: #0e7490;
}
.tech-list.two-col { columns: 2; column-gap: 28px; }
.tech-code {
  background: #0f1e38; border-radius: var(--radius-sm);
  padding: 16px 18px; overflow-x: auto; font-size: 13.5px; line-height: 1.75;
  color: #a5e8f5; margin: 14px 0 6px;
}
@media (max-width: 700px) { .tech-list.two-col { columns: 1; } }

.toast {
  position: fixed; left: 50%; bottom: 92px; transform: translateX(-50%) translateY(18px);
  background: var(--text); color: #fff; font-weight: 700; font-size: 16px;
  padding: 13px 24px; border-radius: 999px; opacity: 0; pointer-events: none;
  transition: opacity .2s ease, transform .2s ease; z-index: 80;
  box-shadow: var(--shadow-lg);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }


/* ---------- 좁은 화면 대응 ---------- */
@media (max-width: 900px) {
  .sim-body { flex-direction: column; }
  #canvas-wrap { flex: 1 1 55%; }
  #panel { flex: 1 1 45%; max-width: none; border-left: none; border-top: 1px solid var(--line); }
  .home-wrap { padding: 26px 20px 40px; }
  .home-head h1 { font-size: 32px; }
  .hud-map { width: 130px; height: 130px; }
  .hud-speedo b { font-size: 44px; }
}
