/* BubbleTD 스타일 — 레이아웃: 맵(왼쪽·위) / 오른쪽 패널(HUD·상점·선택 타워) / 하단 바(컨트롤).
   hover 를 쓰지 않는 터치 친화 UI. 색·간격은 :root 변수로 관리. */

/* ---------- 토큰 ---------- */
:root {
  --bg: #10151c;
  --stage: #0b0f14;
  --panel: #18212c;
  --panel-deep: #0f1620;
  --panel-pop: #111a24;
  --line: #2b3a4b;
  --line-2: #34495e;
  --btn: #243447;
  --btn-on: #33445a;
  --text: #e8eef5;
  --text-soft: #cfe0f1;
  --muted: #8ea3b8;
  --muted-2: #7f93a8;
  --soft: #9fb3c8;
  --gold: #ffd54f;
  --green: #2e7d32;
  --green-line: #43a047;
  --red: #e53935;
  --purple: #5e35b1;
  --touch: 44px;
  --font: 'Segoe UI', 'Malgun Gothic', sans-serif;
}

/* ---------- 기본 ---------- */
* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%; background: var(--bg); color: var(--text); font-family: var(--font);
  overflow: hidden; user-select: none;
  touch-action: manipulation; -webkit-touch-callout: none; -webkit-tap-highlight-color: transparent; overscroll-behavior: none;
}
.hidden { display: none !important; }

/* ---------- 레이아웃 뼈대 ---------- */
#app { display: flex; height: 100vh; height: 100dvh; padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left); }
#main { flex: 1; min-width: 0; display: flex; flex-direction: column; position: relative; }
#top { flex: 1; min-height: 0; display: flex; }
#stage { flex: 1; min-width: 0; min-height: 0; display: block; position: relative; overflow: hidden; background: var(--stage); }
#cv { display: block; cursor: crosshair; touch-action: none; }
#rightbar { flex: 0 0 300px; width: 300px; display: flex; flex-direction: column; padding: 6px 8px; overflow: hidden; background: var(--panel); border-left: 1px solid var(--line); }
#shopview, #selview { display: flex; flex-direction: column; gap: 5px; min-height: 0; }

/* ---------- HUD (목숨·돈·라운드) ---------- */
#hud { flex: 0 0 auto; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); align-items: baseline; overflow: hidden; background: linear-gradient(180deg, #1d2b3d, var(--panel-deep)); border: 2px solid #3d556f; border-radius: 10px; }
#hud > div { display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: 56px; padding: 5px 2px 6px; white-space: nowrap; }
#hud > div + div { border-left: 1px solid var(--line-2); }
#hud .lbl { font-size: 11px; color: var(--muted); letter-spacing: .5px; }
#hud b { font-size: 26px; line-height: 1.1; }
#hud .h-lives b { color: #ff6b6b; }
#hud .h-cash b { color: var(--gold); font-size: 22px; }
#hud .h-round b { color: #fff; }
#hud .of { font-size: 13px; color: var(--muted-2); font-weight: 400; }
#hud .h-lives.danger { background: rgba(229, 57, 53, .28); box-shadow: inset 0 0 0 2px #ff5252; }
#hud .h-lives.danger .lbl { color: #ffcdd2; }
#hud .h-lives.danger b { color: #fff; }
.hud-sep { flex: 0 0 auto; height: 2px; margin: 6px 0 4px; background: linear-gradient(90deg, transparent, #4a6785, transparent); }

/* ---------- 상점 ---------- */
#tip { min-height: 32px; max-height: 32px; overflow: hidden; font-size: 12px; line-height: 1.35; color: var(--soft); }
#shop { display: flex; flex-direction: column; gap: 6px; }
#shop .grpbox { display: flex; flex-direction: column; gap: 3px; }
#shop .grp { margin: 0; padding: 0 2px 1px; font-size: 11px; font-weight: 700; color: var(--gold); border-bottom: 1px solid var(--line-2); letter-spacing: 1px; }
#shop .tiles { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 5px; }
.tw { min-width: 0; min-height: 50px; overflow: hidden; padding: 4px 7px; text-align: left; font: inherit; color: inherit; cursor: pointer; background: var(--btn); border: 2px solid var(--line-2); border-radius: 7px; }
.tw:active:not(:disabled) { background: #3c5573; }
.tw.active { border-color: var(--gold); background: var(--btn-on); }
.tw:disabled { opacity: .45; cursor: not-allowed; }
.tw .n { display: flex; align-items: center; font-weight: 600; font-size: 12px; white-space: nowrap; }
.tw .c { display: flex; justify-content: space-between; color: var(--gold); font-size: 12.5px; }
.tw .d { font-size: 10px; line-height: 1.25; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tw .k { font-size: 10px; color: var(--muted-2); }
.tw .chip { display: inline-flex; flex: 0 0 auto; align-items: center; justify-content: center; width: 20px; height: 20px; margin-right: 5px; border: 2px solid #1c1c1c; border-radius: 50%; color: #fff; font: 700 12px sans-serif; text-shadow: 0 0 2px #000, 0 0 2px #000; }
#help { margin-top: 2px; font-size: 11.5px; color: var(--muted); }
#help summary { display: flex; align-items: center; min-height: 32px; cursor: pointer; }
#helpBody { line-height: 1.5; }

/* ---------- 선택 타워 패널 ---------- */
#btnBack { min-height: var(--touch); font: inherit; font-size: 14px; color: inherit; cursor: pointer; background: var(--btn); border: 1px solid var(--line-2); border-radius: 8px; }
#sel { min-height: 0; overflow: hidden; padding: 6px 8px; font-size: 13px; background: var(--panel-deep); border-radius: 8px; }
#sel h3 { margin: 0 0 4px; font-size: 15px; }
#sel .pips { color: var(--gold); letter-spacing: 2px; }
.up { display: block; width: 100%; min-height: var(--touch); margin: 3px 0; padding: 4px 9px; text-align: left; font: inherit; font-size: 13px; color: inherit; cursor: pointer; background: var(--btn); border: 2px solid var(--line-2); border-radius: 6px; }
.up:disabled { opacity: .45; cursor: not-allowed; }
.up.done { opacity: .6; border-color: var(--green); }
.up.next:not(:disabled) { border-color: var(--gold); }
.up .d { font-size: 10.5px; color: var(--soft); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pathhd { margin: 5px 0 1px; font-size: 11.5px; font-weight: 700; color: var(--gold); }
.pathhd.dim { font-weight: 400; color: var(--muted); }
.pathname { margin-top: 3px; font-size: 11.5px; font-weight: 600; color: #b8c7d6; }
.ability { display: block; width: 100%; min-height: 46px; margin: 5px 0 3px; padding: 4px 9px; text-align: left; font: inherit; font-size: 13px; font-weight: 600; color: #fff; cursor: pointer; background: #3b2f6b; border: 2px solid #b39ddb; border-radius: 6px; }
.ability:disabled { opacity: .55; cursor: not-allowed; }
.ability:not(:disabled) { background: var(--purple); box-shadow: 0 0 8px rgba(179, 157, 219, .7); }
.ability .d { font-size: 11px; font-weight: 400; color: #d1c4e9; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.modes { display: grid; grid-template-columns: repeat(4, 1fr); gap: 5px; margin: 4px 0; }
.modes button { min-height: var(--touch); padding: 2px; font: inherit; font-size: 13px; color: inherit; cursor: pointer; background: var(--btn); border: 1px solid var(--line-2); border-radius: 6px; }
.modes button.on { border-color: var(--gold); background: var(--btn-on); }
.sell { width: 100%; min-height: 46px; margin-top: 5px; padding: 6px; font: inherit; font-size: 14px; font-weight: 700; color: #fff; cursor: pointer; background: var(--red); border: 2px solid #ffcdd2; border-radius: 6px; box-shadow: 0 0 8px rgba(255, 82, 82, .6); }
.up:active:not(:disabled), .ability:active:not(:disabled), .sell:active { filter: brightness(1.25); }

/* ---------- 하단 바 ---------- */
#bottombar { flex: 0 0 auto; height: 60px; display: flex; align-items: center; gap: 8px; padding: 0 8px; overflow: hidden; background: var(--panel); border-top: 1px solid var(--line); }
#bottombar button { flex: 0 0 auto; min-width: var(--touch); min-height: var(--touch); padding: 0 12px; font: inherit; font-size: 14px; color: inherit; cursor: pointer; background: var(--btn); border: 1px solid var(--line-2); border-radius: 8px; }
#bottombar button:active:not(:disabled) { filter: brightness(1.3); }
#bottombar button:disabled { opacity: .5; cursor: not-allowed; }
#bottombar button.on { border-color: var(--gold); background: var(--btn-on); }
#bottombar #btnStart { flex: 1 1 200px; min-width: 120px; max-width: 360px; font-size: 16px; font-weight: 700; background: var(--green); border-color: var(--green-line); }
#bottombar #btnAuto { white-space: nowrap; }
#bottombar #btnAuto b { margin-left: 2px; font-size: 12px; color: var(--muted); }
#bottombar #btnAuto.on { border-color: var(--gold); background: #4a4020; color: #fff3c4; }
#bottombar #btnAuto.on b { color: var(--gold); }

/* ---------- 도구 팝오버 · 배치 바 · 정보 패널 ---------- */
#toolsPop { position: absolute; right: 8px; bottom: 66px; z-index: 20; width: 250px; display: flex; flex-direction: column; gap: 6px; padding: 8px; background: var(--panel-pop); border: 1px solid var(--line-2); border-radius: 10px; box-shadow: 0 6px 20px rgba(0, 0, 0, .5); }
#toolsPop button { min-height: var(--touch); padding: 0 12px; text-align: left; font: inherit; font-size: 14px; color: inherit; cursor: pointer; background: var(--btn); border: 1px solid var(--line-2); border-radius: 8px; }
#toolsPop button.on { border-color: var(--gold); background: var(--btn-on); }
#info { margin-top: 4px; padding-top: 4px; font-size: 12px; line-height: 1.5; color: var(--muted); white-space: pre-line; border-top: 1px solid var(--line); }
#placebar { position: absolute; left: 50%; bottom: 10px; z-index: 8; display: flex; align-items: center; gap: 8px; max-width: calc(100% - 20px); padding: 6px 10px; transform: translateX(-50%); background: rgba(8, 12, 18, .88); border: 1px solid var(--gold); border-radius: 12px; }
#placeText { max-width: 360px; overflow: hidden; font-size: 13px; color: #ffe082; white-space: nowrap; text-overflow: ellipsis; }
#placebar button { min-width: 88px; min-height: var(--touch); font: inherit; font-size: 15px; font-weight: 600; color: #fff; cursor: pointer; background: #37474f; border: 1px solid #607d8b; border-radius: 8px; }
#placebar button.ok { background: var(--green); border-color: #66bb6a; }
#placebar .chk { display: flex; align-items: center; gap: 6px; min-height: var(--touch); font-size: 13px; color: var(--text-soft); }
#placebar input { width: 22px; height: 22px; }
#panels { position: absolute; inset: 0; z-index: 5; pointer-events: none; }
.dp { position: absolute; left: 6px; top: 6px; width: 330px; padding: 5px 8px; font: 11px/1.45 var(--font); color: var(--text-soft); background: rgba(8, 12, 18, .72); border: 1px solid rgba(111, 168, 220, .4); border-radius: 6px; }
.dp h4 { margin: 0 0 2px; font-size: 11px; color: var(--gold); }
.dp .dh { display: flex; align-items: center; justify-content: space-between; min-height: 32px; cursor: grab; user-select: none; pointer-events: auto; touch-action: none; }
.dp .dh:active { cursor: grabbing; }
.dp .grip { padding: 0 4px; font-size: 16px; color: var(--muted); }
.dp .r { display: flex; gap: 6px; justify-content: space-between; }
.dp .r span:first-child { color: var(--muted); white-space: nowrap; }
.dp .r span:last-child { text-align: right; }

/* ---------- 메뉴 · 종료 화면 ---------- */
.overlay { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; padding: 16px; overflow: auto; text-align: center; background: rgba(8, 12, 18, .88); }
.overlay h1 { display: flex; align-items: center; justify-content: center; gap: 10px; margin: 0; font-size: 42px; }
.overlay h1 .logo { flex: 0 0 auto; }
.overlay button.big { min-height: var(--touch); padding: 10px 24px; font-size: 18px; color: #fff; cursor: pointer; background: var(--green); border: 2px solid var(--green-line); border-radius: 8px; }
.sub { margin: 0; color: #a9bdd1; }
.small { font-size: 12px; }
#diff { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
#diff button { min-height: var(--touch); padding: 8px 18px; font: inherit; font-size: 15px; color: inherit; cursor: pointer; background: var(--btn); border: 2px solid var(--line-2); border-radius: 8px; }
#diff button.on { font-weight: 700; border-color: var(--gold); background: #3a4d66; }
#diffdesc { width: 100%; min-height: 16px; font-size: 12px; color: #a9bdd1; }
#maps { display: flex; gap: 14px; flex-wrap: wrap; justify-content: center; }
.card { width: 224px; min-height: var(--touch); padding: 8px; cursor: pointer; background: #1b2735; border: 2px solid var(--line-2); border-radius: 10px; }
.card canvas { display: block; width: 208px; height: 130px; border-radius: 6px; }
.card b { display: block; margin-top: 6px; }
.card span { font-size: 12px; color: var(--soft); }
.card .stars { display: block; color: #ffb74d; letter-spacing: 1px; }
.card .best { display: block; margin-top: 2px; color: var(--gold); }

/* ---------- 시작 버튼 강조 ---------- */
#bottombar #btnStart:not(:disabled) { animation: pulse 1.6s ease-in-out infinite; box-shadow: 0 0 0 0 rgba(102, 187, 106, .7); }
@keyframes pulse { 70% { box-shadow: 0 0 0 10px rgba(102, 187, 106, 0); } 100% { box-shadow: 0 0 0 0 rgba(102, 187, 106, 0); } }
@media (prefers-reduced-motion: reduce) { #bottombar #btnStart:not(:disabled) { animation: none; } }

/* ---------- 반응형 ---------- */
@media (max-width: 1100px) { #bottombar { gap: 6px; } }
@media (max-width: 900px) { #bottombar .tx { display: none; } }
@media (max-height: 800px) {
  .overlay { gap: 4px; padding: 8px; }
  .overlay h1 { font-size: 26px; }
  .overlay h1 .logo { width: 30px; height: 30px; }
  .card { width: 216px; padding: 5px; }
  .card canvas { width: 204px; height: 100px; }
  .card b { margin-top: 3px; }
  .card span { font-size: 11px; }
  #maps { gap: 8px; }
  #rightbar { padding: 5px 8px; }
  #hud > div { min-height: 44px; padding: 2px 2px 3px; }
  #hud b { font-size: 22px; }
  #hud .h-cash b { font-size: 19px; }
  .hud-sep { margin: 3px 0 2px; }
  #tip { min-height: 28px; max-height: 28px; font-size: 11.5px; }
  #shop { gap: 3px; }
  #shop .grpbox { gap: 2px; }
  .tw { min-height: var(--touch); }
  .tw .d { display: none; }
  #help summary { min-height: 28px; }
}
@media (max-height: 760px) {
  #selview, #shopview { gap: 3px; }
  #sel h3 { margin: 0 0 2px; }
  .up { margin: 2px 0; }
  .pathhd, .pathhd.dim { margin: 3px 0 0; }
  .pathhd.dim { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .modes { margin: 2px 0; }
  .sell { min-height: var(--touch); margin-top: 3px; }
}
