/* index.css — 학교 설립 시뮬레이터 */
:root {
  --bg: #0e1726;
  --panel: #16233a;
  --line: #2a3b5c;
  --ink: #e8eef7;
  --muted: #9fb2d0;
  --accent: #5aa9ff;
  --gold: #ffd166;
  --green: #4ade80;
  --red: #f87171;
  --ascii: #cfe3ff;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body {
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Noto Sans KR", sans-serif;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-text-size-adjust: 100%;
}

/* 상단 상태바 */
#statusbar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 20;
  display: flex; gap: 6px; align-items: center;
  padding: 8px 10px;
  padding-top: calc(8px + env(safe-area-inset-top));
  background: linear-gradient(180deg, rgba(14,23,38,.97), rgba(14,23,38,.82));
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}
.stat { display: flex; align-items: center; gap: 5px; font-size: 13px;
  background: var(--panel); border: 1px solid var(--line);
  padding: 4px 9px; border-radius: 999px; }
.stat .k { color: var(--muted); font-size: 11px; }
.stat .v { font-weight: 700; font-variant-numeric: tabular-nums; }
#s-money { color: var(--gold); }
#s-fame { color: var(--accent); }
.stat.sat .bar { width: 54px; height: 8px; background: #24314d; border-radius: 6px; overflow: hidden; }
.stat.sat .fill { display: block; height: 100%; width: 100%; background: var(--green); transition: width .3s, background .3s; }

/* 캠퍼스 뷰 */
#viewport {
  position: fixed; inset: 0;
  top: 0; bottom: 0;
  overflow: hidden;
  cursor: grab;
  touch-action: none;
  background:
    radial-gradient(1200px 800px at 60% 40%, #16304f 0%, #0e1726 70%);
}
#viewport.drag { cursor: grabbing; }
#world { position: absolute; left: 0; top: 0; transform-origin: 0 0; }
#campus {
  font-family: "Courier New", Consolas, Menlo, monospace;
  font-size: 11px;
  line-height: 1.0;
  letter-spacing: 0;
  color: var(--ascii);
  white-space: pre;
  margin: 0;
  text-shadow: 0 0 1px rgba(90,169,255,.25);
}
/* 건물별 색상 조각 */
.bpiece {
  position: absolute;
  font-family: "Courier New", Consolas, Menlo, monospace;
  font-size: 11px;
  line-height: 1.0;
  letter-spacing: 0;
  white-space: pre;
  margin: 0;
  cursor: pointer;
  transition: filter .15s;
}
.bpiece:hover { filter: brightness(1.4) drop-shadow(0 0 4px currentColor); }
.bpiece.cat-basic    { color: #cdd8ea; }
.bpiece.cat-advanced { color: #cdd8ea; }
.bpiece.cat-special  { color: #cdd8ea; }
.bpiece.cat-kpop     { color: #cdd8ea; }

/* 건물 부위별 색 (한 건물 안에 여러 색) */
/* 벽·지붕 구조선 — 건물 종류마다 지붕/벽 톤이 다르게 */
.c-wall-basic    { color: #e8edf5; }   /* 기본: 밝은 회백 벽 */
.c-wall-advanced { color: #d8e6f2; }   /* 고급: 희끗한 벽 */
.c-wall-special  { color: #efe3c6; }   /* 특수: 아이보리 벽 */
.c-wall-kpop     { color: #efe0ee; }   /* K-pop: 밝은 벽 */
/* 공통 부위색 */
.c-glass  { color: #8fd0ef; }  /* 유리·창문 하늘색 */
.c-brick  { color: #e8795a; }  /* 붉은 벽돌 */
.c-tree   { color: #5fc27e; }  /* 나무 초록 */
.c-flower { color: #a0e0a8; }  /* 화단 연두 */
.c-path   { color: #9a9488; }  /* 길 회갈색 */
.c-light  { color: #ffd54a; }  /* 조명·장식 노랑 */
.c-sign   { color: #ff9ebd; }  /* 간판 글자 핑크 */
/* 종류별 지붕 포인트색(윗변 강조는 JS 미세조정 대신 톤으로) */
.bpiece.cat-special .c-wall-special { color: #f3dca0; }
.bpiece.cat-kpop .c-light { color: #ff86e0; }
/* 이름표 라벨 — 배경 없이 그림 위에 얹는 글자 */
#labels { position: absolute; left: 0; top: 0; }
.label {
  position: absolute;
  transform: translate(-50%, -100%);
  color: #eaf2ff;
  font-size: 11px; font-weight: 800;
  white-space: nowrap;
  text-shadow: 0 0 3px #06101f, 0 0 3px #06101f, 0 1px 2px #000;
  pointer-events: auto;
  cursor: pointer;
  font-family: "Courier New", monospace;
}
.label .lv { opacity: .85; font-weight: 700; }
.label.basic { color: #cfe3ff; }
.label.advanced { color: #7dd3fc; }
.label.special { color: var(--gold); }
.label.kpop { color: #f0abfc; }

/* 하단 컨트롤 */
#controls {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 20;
  display: flex; gap: 8px; justify-content: center;
  padding: 10px;
  background: linear-gradient(0deg, rgba(14,23,38,.97), rgba(14,23,38,.6));
  border-top: 1px solid var(--line);
}
.ctl {
  background: var(--panel); color: var(--ink);
  border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 14px; font-size: 14px; font-weight: 600;
  cursor: pointer; min-width: 72px;
}
.ctl:hover { border-color: var(--accent); }
.ctl:active { transform: translateY(1px); }

/* 모달 공통 */
.modal {
  position: fixed; inset: 0; z-index: 40;
  display: flex; align-items: center; justify-content: center;
  background: rgba(4,8,16,.72);
  padding: 16px;
}
.modal.hidden, .hidden { display: none !important; }
.modal-box {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 16px; padding: 20px;
  width: 100%; max-width: 460px;
  max-height: 92vh; overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,.5);
}
.modal-box h2 { font-size: 18px; margin-bottom: 6px; }
.modal-box p { color: var(--muted); font-size: 13px; margin-bottom: 14px; }

/* 선택지 카드 */
/* 넓은 모달 (선택지용) — 한 줄에 3개 유지. 6개면 3×2로 세로 확장(팝업 높이 92vh로 충분). */
.modal-box.wide { max-width: 720px; }

/* 상황 진단 팁 (증축 선택지 모달 안) */
#choice-tips {
  margin: 8px 0 12px;
  display: flex; flex-direction: column; gap: 6px;
}
#choice-tips .tip-line {
  background: rgba(125, 211, 252, .1);
  border-left: 3px solid #7dd3fc;
  border-radius: 6px;
  padding: 7px 10px;
  font-size: 13px; line-height: 1.45;
  color: var(--ink, #e8eefc);
}
#choice-tips .tip-line span { color: var(--muted, #9fb0cc); }

/* 선택지 가로 그리드 */
.choice-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);  /* 항상 한 줄에 3개, 4개 이상이면 다음 줄로(3×2 등) */
  gap: 10px;
  margin-bottom: 12px;
}
.choice {
  display: flex; flex-direction: column; gap: 3px;
  background: #1b2b47; border: 1px solid var(--line);
  border-top: 4px solid #5b6b8c;
  border-radius: 12px; padding: 10px; cursor: pointer;
  transition: border-color .15s, background .15s, transform .1s;
}
.choice:hover { background: #213451; transform: translateY(-2px); }
.choice.cat-advanced { border-top-color: #7dd3fc; }
.choice.cat-special { border-top-color: var(--gold); }
.choice.cat-kpop { border-top-color: #f0abfc; }
.choice.cat-basic { border-top-color: #5b6b8c; }
.ch-head { display: flex; justify-content: space-between; align-items: baseline; }
.choice .name { font-weight: 800; font-size: 15px; }
.choice .cost { color: var(--gold); font-weight: 700; font-variant-numeric: tabular-nums; font-size: 14px; }
.ch-action { font-size: 12px; color: var(--accent); font-weight: 700; }
.ch-action b { color: var(--gold); }
.ch-desc { font-size: 12px; color: var(--muted); line-height: 1.35; }
.ch-eff { font-size: 12px; color: #bfe3b0; }
.ch-fame { font-size: 11px; color: #7dd3fc; }
.ch-warn { font-size: 11px; color: var(--red); font-weight: 700; }
.choice.disabled { opacity: .5; cursor: not-allowed; }
.choice.disabled:hover { transform: none; }
.choice.disabled .cost { color: var(--red); }

.choice-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.ghost {
  flex: 1; min-width: 140px;
  background: transparent; color: var(--muted);
  border: 1px dashed var(--line); border-radius: 10px;
  padding: 10px; font-size: 13px; cursor: pointer;
}
.ghost:hover { color: var(--ink); border-color: var(--accent); }

/* info 모달 버튼들 */
#info-actions { display: flex; gap: 8px; margin-top: 14px; }
#info-actions .ctl { flex: 1; }
#info-body { color: var(--ink); font-size: 14px; line-height: 1.5; }
/* 경제 내역 모달(수입/지출) 표 */
#info-body .lead { color: var(--muted); font-size: 13px; margin: 0 0 10px; }
#info-body .row { display: flex; justify-content: space-between; padding: 3px 0; border-bottom: 1px dashed var(--line); }
#info-body .row .k { color: var(--muted); }
#info-body .row .v { font-weight: 700; }
#info-body .row.total .k, #info-body .row.total .v { font-weight: 800; }
#info-body .eco-sec { margin: 12px 0 4px; color: var(--accent); font-size: 13px; }

/* 엔딩 */
#ending {
  position: fixed; inset: 0; z-index: 50;
  background: #06101f;
  display: flex; align-items: center; justify-content: center;
  flex-direction: column;
  padding: 16px; overflow: auto;
}
#ending-stage { text-align: center; display: flex; flex-direction: column; align-items: center; }
#ending-title { color: var(--gold); font-size: 26px; margin-bottom: 10px; }
/* 엔딩 캠퍼스 뷰포트: 고정 박스 안에서 드래그/줌 */
#ending-viewport {
  position: relative;
  width: 70vw; height: 62vh;
  max-width: 900px;
  border: 1px solid var(--line, #26324a);
  border-radius: 12px;
  background: #081423;
  overflow: hidden;
  cursor: grab;
}
#ending-viewport.drag { cursor: grabbing; }
#ending-world {
  position: absolute; left: 0; top: 0;
  transform-origin: 0 0;
  will-change: transform;
}
#ending-campus {
  font-family: "Courier New", monospace; font-size: 7px; line-height: 1.0;
  color: var(--ascii); white-space: pre; display: inline-block; text-align: left;
  margin: 0;
}
#ending-zoom {
  position: absolute; right: 10px; bottom: 10px;
  display: flex; flex-direction: column; gap: 6px; z-index: 2;
}
#ending-zoom button {
  width: 34px; height: 34px; border-radius: 8px;
  background: rgba(20,32,54,.9); color: var(--ink, #e8eefc);
  border: 1px solid var(--line, #26324a); font-size: 18px; cursor: pointer;
}
#ending-zoom button:hover { background: rgba(40,56,84,.95); }
#ending-caption { color: var(--accent); font-size: 16px; margin-top: 14px; min-height: 24px; }
#ending-credits { max-width: 520px; text-align: left; display: flex; flex-direction: column; }
#ending-credits h2 { color: var(--gold); margin: 0 0 12px; text-align: left; font-size: 20px; border-bottom: 2px solid var(--line, #26324a); padding-bottom: 8px; }
#credits-body { font-size: 15px; line-height: 1.8; color: var(--ink); margin-bottom: 20px; }
/* 타임랩스 타이밍에 맞춰 쌓이는 업적 로그 (오른쪽 패널) */
#credits-body { text-align: left; overflow-y: auto; }
#credits-body .credit-line {
  padding: 5px 8px; margin: 3px 0; font-size: 13px; line-height: 1.4;
  background: rgba(125,211,252,.08); border-left: 3px solid #7dd3fc; border-radius: 5px;
  animation: creditIn .35s ease;
}
#credits-body .credit-line .cl-year { color: var(--gold); font-weight: 700; margin-right: 4px; }
#credits-body .credits-summary { margin-top: 14px; padding-top: 10px; border-top: 1px solid var(--line, #26324a); }
#credits-body .credits-summary h3 { color: var(--gold); font-size: 15px; margin: 0 0 8px; }
#credits-body .credits-summary .summary-lines div { padding: 2px 0; font-size: 13px; }
@keyframes creditIn { from { opacity: 0; transform: translateX(10px); } to { opacity: 1; transform: none; } }

/* 크레딧 화면: 왼쪽 캠퍼스(드래그/줌) + 오른쪽 업적/통계 동시 표시 */
#ending.with-credits {
  flex-direction: row;
  align-items: center;
  justify-content: center;
  gap: 24px;
  flex-wrap: wrap;
  padding: 16px 32px; /* 좌우 여백을 넉넉히 — 크레딧이 화면 끝에 박히지 않게 */
}
#ending.with-credits #ending-stage { flex: 0 1 auto; }
#ending.with-credits #ending-viewport { width: 52vw; height: 72vh; }
#ending.with-credits #ending-credits {
  flex: 0 0 auto; width: 32vw; max-width: 420px; max-height: 76vh; overflow: auto;
  background: rgba(13,22,38,.6);
  border: 1px solid var(--line, #26324a);
  border-radius: 14px;
  padding: 18px 20px;          /* 안쪽 여백 — 글자가 박스에 붙지 않게 */
  box-sizing: border-box;
}
/* 좁은 화면(모바일·태블릿): 그림 위, 크레딧 아래로 쌓는다 */
@media (max-width: 860px) {
  #ending.with-credits { flex-direction: column; gap: 10px; }
  #ending-viewport { width: 92vw; height: 46vh; }
  #ending.with-credits #ending-viewport { width: 92vw; height: 44vh; }
  #ending.with-credits #ending-credits { max-width: 92vw; max-height: 34vh; }
  .choice-grid { grid-template-columns: repeat(2, 1fr); } /* 좁은 화면: 2열 */
}

/* 토스트 */
#toast {
  position: fixed; left: 50%; bottom: 70px; transform: translateX(-50%);
  z-index: 30; display: flex; flex-direction: column; gap: 6px; align-items: center;
  pointer-events: none;
}
.toast-msg {
  background: rgba(20,32,54,.95); border: 1px solid var(--line);
  color: var(--ink); font-size: 13px; padding: 8px 14px; border-radius: 999px;
  animation: toastIn .3s ease, toastOut .4s ease 2.2s forwards;
}
@keyframes toastIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; } }
@keyframes toastOut { to { opacity: 0; transform: translateY(-8px); } }

/* 업데이트 알림 배너 */
#update-banner {
  position: fixed; left: 50%; top: 0; transform: translateX(-50%);
  z-index: 70; margin-top: calc(8px + env(safe-area-inset-top));
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap; justify-content: center;
  background: #143a2a; color: #d6ffe8;
  border: 1px solid #3fae73; border-radius: 12px;
  padding: 10px 14px; font-size: 13px;
  box-shadow: 0 6px 24px rgba(0,0,0,.5);
  max-width: 92vw;
}
#update-banner button {
  background: #3fae73; color: #04140b; border: none; border-radius: 8px;
  padding: 6px 12px; font-size: 13px; font-weight: 700; cursor: pointer;
}
#update-banner #update-dismiss { background: transparent; color: #9fd9b8; border: 1px solid #3fae73; }

/* 시간 진행 게이지 — 짧게(요청): flex 대신 고정 너비 */
#time-gauge {
  flex: 0 0 auto; width: 120px; max-width: 32vw; height: 8px;
  background: #24314d; border-radius: 6px; overflow: hidden;
  margin-left: 4px;
}
#time-fill {
  display: block; height: 100%; width: 0%;
  background: linear-gradient(90deg, var(--accent), #7dd3fc);
  /* rAF로 매 프레임 갱신하므로 CSS transition은 끄다(이중 갱신이 끊김을 유발) */
}

/* 코너 버튼 (일시정지 / 선택지 열기) */
.corner-btn {
  position: fixed; z-index: 25;
  background: var(--panel); color: var(--ink);
  border: 1px solid var(--line); border-radius: 12px;
  padding: 10px 14px; font-size: 16px; font-weight: 700; cursor: pointer;
  box-shadow: 0 2px 8px rgba(0,0,0,.4);
}
.corner-btn:hover { border-color: var(--accent); }
#btn-pause { right: 14px; bottom: 70px; }
#btn-pause.paused { background: var(--gold); color: #06101f; }
#btn-reopen { left: 50%; transform: translateX(-50%); bottom: 70px; font-size: 14px; background: var(--accent); color: #06101f; }

/* 줌 컨트롤 (왼쪽 아래) */
#zoom-ctl {
  position: fixed; left: 14px; bottom: 70px; z-index: 25;
  display: flex; flex-direction: column; gap: 6px;
}
#zoom-ctl button {
  width: 42px; height: 42px;
  background: var(--panel); color: var(--ink);
  border: 1px solid var(--line); border-radius: 10px;
  font-size: 18px; font-weight: 700; cursor: pointer;
  box-shadow: 0 2px 8px rgba(0,0,0,.4);
}
#zoom-ctl button:hover { border-color: var(--accent); }
#zoom-ctl button:active { transform: translateY(1px); }

/* 커스텀 툴팁 */
#tooltip {
  position: fixed; z-index: 60;
  max-width: 260px;
  background: #0b1424; color: var(--ink);
  border: 1px solid var(--accent); border-radius: 8px;
  padding: 8px 10px; font-size: 12px; line-height: 1.45;
  pointer-events: none;
  box-shadow: 0 4px 16px rgba(0,0,0,.5);
}

/* 건물 스탯 팝업 */
#bm-body { font-size: 14px; line-height: 1.6; margin-bottom: 14px; }
#bm-body .row { display: flex; justify-content: space-between; padding: 3px 0; border-bottom: 1px dashed var(--line); }
#bm-body .row .k { color: var(--muted); }
#bm-body .row .v { font-weight: 700; }
#bm-body .lead { color: var(--muted); margin-bottom: 8px; }
#bm-close { width: 100%; }

/* 불러오기 목록 */
#load-list { margin-bottom: 12px; }
.load-slot {
  display: flex; justify-content: space-between; align-items: center;
  background: #1b2b47; border: 1px solid var(--line);
  border-radius: 10px; padding: 12px 14px; margin-bottom: 8px; cursor: pointer;
  transition: border-color .15s, background .15s;
}
.load-slot:hover { border-color: var(--accent); background: #213451; }
.load-slot .ls-year { font-weight: 800; font-size: 15px; }
.load-slot .ls-info { font-size: 12px; color: var(--muted); }
.load-slot .ls-time { font-size: 11px; color: var(--muted); }
#load-empty { color: var(--muted); text-align: center; padding: 20px 0; }
#load-cancel { width: 100%; }

@media (max-width: 520px) {
  #statusbar { gap: 4px; padding: 6px 6px; }
  .stat { font-size: 11px; padding: 3px 6px; gap: 3px; }
  .stat .k { font-size: 10px; }
  .stat.sat .bar { width: 38px; }
  #campus { font-size: 8px; }
  .ctl { padding: 9px 8px; font-size: 13px; min-width: 0; flex: 1; }
  #controls { gap: 6px; padding: 8px 6px calc(8px + env(safe-area-inset-bottom)); }
  .modal-box { padding: 16px; border-radius: 14px; }
  .modal-box h2 { font-size: 16px; }
  #ending-campus { font-size: 5px; }
  #ending-title { font-size: 20px; }
  .label { font-size: 9px; padding: 1px 4px; }
}

/* 아주 작은 화면(초소형 폰) */
@media (max-width: 360px) {
  .stat .k { display: none; } /* 아이콘 없이 값만 */
  #campus { font-size: 7px; }
}

/* 가로 모드(낮은 높이) */
@media (max-height: 480px) {
  #statusbar { padding: 4px 8px; }
  #controls { padding: 5px 8px; }
  .ctl { padding: 6px 10px; }
}
