:root {
  --bg: #141018;
  --panel: #241c2c;
  --panel-2: #322838;
  --text: #f3e9d7;
  --muted: #a89888;
  --gold: #f0c14a;
  --hp: #e85d5d;
  --accent: #7bc96f;
  --arrow: #d4a574;
  --magic: #9b7ed9;
  --fence: #8b6914;
  --well: #4aa3c8;
  --danger: #ff6b6b;
  --easy: #7bc96f;
  --normal: #f0c14a;
  --hard: #e85d5d;
  --radius: 8px;
  --font: "Segoe UI", "Malgun Gothic", sans-serif;
  --side-w: 280px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  overflow: hidden;
  /* 모바일 주소창 변화 대응 */
  height: 100dvh;
}

body {
  font-family: var(--font);
  background: radial-gradient(ellipse at top, #2a2035 0%, var(--bg) 55%);
  color: var(--text);
  display: flex;
  flex-direction: column;
  user-select: none;
  touch-action: none;
  overscroll-behavior: none;
}

/* 전체 뷰포트 사용 — 스크롤 없음 */
#app {
  width: 100%;
  height: 100vh;
  height: 100dvh;
  max-height: 100dvh;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 6px 8px;
  overflow: hidden;
}

/* 세로로 잡은 폰: 화면 전체를 가로 구도로 강제 회전 */
html.force-landscape,
html.force-landscape body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  position: fixed;
  inset: 0;
  background: #141018;
}
html.force-landscape #app {
  position: fixed;
  top: 50%;
  left: 50%;
  width: 100dvh;
  height: 100dvw;
  max-height: none;
  /* 시계 방향 90° → 세로 폰에서도 PC와 같은 가로 레이아웃 */
  transform: translate(-50%, -50%) rotate(90deg);
  transform-origin: center center;
  padding: 4px 6px;
  box-sizing: border-box;
}
/* 회전 안내 (잠깐 보이거나 잠금 실패 시) */
#rotate-gate {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 99999;
  background: rgba(12, 10, 16, 0.94);
  color: #f3e9d7;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 24px;
  font-size: 1.05rem;
  line-height: 1.5;
}
#rotate-gate .rotate-ico {
  font-size: 3rem;
  display: block;
  margin-bottom: 12px;
  animation: spin-hint 1.6s ease-in-out infinite;
}
@keyframes spin-hint {
  0%, 100% { transform: rotate(0deg); }
  40% { transform: rotate(90deg); }
  60% { transform: rotate(90deg); }
}

header {
  flex: 0 0 auto;
  display: flex;
  align-items: baseline;
  gap: 10px;
  min-height: 0;
}
h1 { font-size: 1.2rem; margin: 0; }
.subtitle {
  color: var(--muted);
  font-size: 0.85rem;
  margin: 0;
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.header-actions {
  display: flex;
  gap: 4px;
  margin-left: auto;
}
.btn-sm {
  padding: 2px 8px !important;
  font-size: 0.85rem !important;
  min-width: 32px;
}

.screen {
  display: none;
  flex: 1 1 auto;
  min-height: 0;
  flex-direction: column;
  gap: 6px;
  overflow: hidden;
}
.screen.active { display: flex; }

/* 메뉴: 가운데 카드 — 글씨 크게·대비 높게 */
#screen-menu {
  align-items: center;
  justify-content: center;
}
.menu-card {
  background: #2e2538;
  border: 1px solid #6a5a78;
  border-radius: 12px;
  padding: 22px 26px;
  width: min(480px, 96vw);
  max-height: min(92vh, 700px);
  text-align: center;
  overflow: hidden;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.45);
}
.menu-card h2 {
  margin-bottom: 10px;
  font-size: 1.45rem;
  color: #fffaf0;
  font-weight: 800;
  letter-spacing: 0.02em;
}
.menu-card > p {
  color: #e8dcc8;
  font-size: 0.95rem;
  line-height: 1.55;
  margin-bottom: 14px;
}
.menu-card > p b {
  color: #fff6d6;
  font-weight: 700;
}
.difficulty { display: flex; flex-direction: column; gap: 8px; margin-bottom: 10px; }
.diff-btn {
  border: 2px solid #7a6a8a;
  background: #3a3048;
  color: #fff8ee;
  padding: 12px 14px;
  border-radius: 10px;
  cursor: pointer;
  text-align: left;
  font-size: 1rem;
}
.diff-btn:hover {
  border-color: #9dce8f;
  background: #453a55;
}
.diff-btn .name {
  font-weight: 800;
  display: block;
  font-size: 1.15rem;
  margin-bottom: 2px;
}
.diff-btn .desc {
  font-size: 0.88rem;
  color: #d4c8b8;
  line-height: 1.35;
}
.diff-btn[data-diff="easy"] .name { color: #8fef7a; }
.diff-btn[data-diff="normal"] .name { color: #ffd666; }
.diff-btn[data-diff="hard"] .name { color: #ff8a8a; }

.menu-card .disease-opt {
  color: #e8dcc8 !important;
  font-size: 0.95rem !important;
  margin: 10px 0 12px !important;
}
.menu-card .hint {
  color: #cfc0b0 !important;
  font-size: 0.85rem !important;
  line-height: 1.4;
}

/* HUD 한 줄 */
.hud {
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  gap: 4px;
}
.hud-item {
  background: var(--panel);
  border: 1px solid #463850;
  border-radius: 6px;
  padding: 3px 6px;
  min-width: 0;
}
.hud-item .label {
  font-size: 0.72rem;
  color: var(--muted);
  text-transform: uppercase;
  white-space: nowrap;
  overflow: hidden;
}
.hud-item .value {
  font-size: 1rem;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.hud-item.gold .value { color: var(--gold); }
.hud-item.hp .value { color: var(--hp); }
.hud-item.wave .value { color: #7ec8e3; }

/* 플레이: 맵 크게 + 사이드 고정, 스크롤 없음 */
.play-layout {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: 1fr var(--side-w);
  gap: 6px;
  overflow: hidden;
}

.canvas-wrap {
  background: #2a5530;
  border: 1px solid #463850;
  border-radius: var(--radius);
  overflow: hidden;
  position: relative;
  min-height: 0;
  height: 100%;
  width: 100%;
}
#game-root {
  width: 100%;
  height: 100%;
  min-height: 0;
  position: relative;
  background: #2a5530;
}
#game-root canvas {
  display: block;
  width: 100% !important;
  height: 100% !important;
  cursor: crosshair;
  touch-action: none;
}

.build-banner {
  position: absolute;
  top: 8px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 4;
  background: rgba(40, 30, 20, 0.88);
  border: 1px solid #c9a227;
  color: #f5e6b8;
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 0.9rem;
  pointer-events: none;
  white-space: nowrap;
}
.build-banner.hidden { display: none; }
.build-confirm {
  position: absolute;
  top: 40px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 5;
  background: rgba(20, 40, 30, 0.95);
  border: 1px solid #7bc96f;
  color: #e8ffe0;
  padding: 10px 14px;
  border-radius: 10px;
  font-size: 0.95rem;
  pointer-events: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  min-width: 220px;
  box-shadow: 0 6px 20px rgba(0,0,0,0.4);
}
.build-confirm.hidden { display: none !important; }
.build-confirm-btns {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
}
.build-confirm-btns .btn {
  font-size: 0.95rem !important;
  padding: 8px 14px !important;
  min-width: 100px;
}
.info-card { text-align: left; }
.info-body {
  margin: 10px 0;
  font-size: 0.95rem;
  line-height: 1.55;
  color: #f3e9d7;
}
.info-body .row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 4px 0;
  border-bottom: 1px solid #463850;
}
.info-body .row .k { color: #a89888; }
.info-body .row .v { color: #fff6d6; font-weight: 700; }
.select-marquee {
  position: absolute;
  border: 2px solid #7bc96f;
  background: rgba(123, 201, 111, 0.12);
  z-index: 7;
  pointer-events: none;
}
.select-marquee.hidden { display: none; }

.side {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-height: 0;
  height: 100%;
  overflow: hidden; /* 스크롤 제거 */
}

.panel {
  background: var(--panel);
  border: 1px solid #463850;
  border-radius: var(--radius);
  padding: 6px 7px;
  flex: 0 0 auto;
  min-height: 0;
}
/* 로그·선택 패널이 남는 공간 흡수 */
.panel.flex-fill {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}
.highlight-panel { border-color: #6dbf62; }
.panel h3 {
  font-size: 0.88rem;
  margin-bottom: 5px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.btn-start {
  width: 100%;
  padding: 9px;
  font-size: 1rem;
}

/* 건설 버튼 2열 */
.tools {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
}
.tool {
  border: 1px solid #564860;
  background: var(--panel-2);
  color: var(--text);
  padding: 6px 6px;
  border-radius: 5px;
  cursor: pointer;
  text-align: left;
  font-size: 0.82rem;
  line-height: 1.3;
  border-left-width: 3px;
}
.tool:hover { border-color: #7a6a80; }
.tool.active { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.tool .cost {
  display: block;
  float: none;
  color: var(--gold);
  font-weight: 700;
  font-size: 0.78rem;
}
.tool.arrow-t { border-left-color: var(--arrow); }
.tool.magic-t { border-left-color: var(--magic); }
.tool.fence-t { border-left-color: var(--fence); }
.tool.well-t { border-left-color: var(--well); }
.tool.egg-t { border-left-color: #f5e6c8; }
.tool.catapult-t { border-left-color: #c9a227; }
.tool.chicken-t { border-left-color: #f5d76e; }
.tool.super-t { border-left-color: #ff8c42; }
.tool.sell-t { border-left-color: var(--danger); }

.egg-actions { display: flex; gap: 3px; flex-wrap: wrap; }

.btn {
  border: 1px solid #564860;
  border-radius: 5px;
  padding: 6px 8px;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.82rem;
  background: var(--panel-2);
  color: var(--text);
}
.btn:hover { filter: brightness(1.08); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn.primary {
  background: linear-gradient(180deg, #6dbf62, #4a9a42);
  border-color: #3d7a38;
  color: #fff;
}
.btn.danger {
  background: linear-gradient(180deg, #e07070, #c04040);
  border-color: #a03030;
  color: #fff;
}
.speed-btn { min-width: 32px; padding: 3px 5px; }
.speed-btn.active {
  border-color: var(--accent);
  background: #3d5a38;
  color: #c8f0c0;
}

.hint {
  font-size: 0.8rem;
  color: var(--muted);
  line-height: 1.4;
}
.tower-title { font-size: 1.05rem !important; }
.stat-grid { font-size: 0.88rem; }
.log { font-size: 0.8rem !important; }
.hidden { display: none !important; }

.tower-title { font-weight: 700; font-size: 0.8rem; margin-bottom: 4px; }
.stat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 3px;
}
.stat-grid > div {
  background: var(--panel-2);
  border-radius: 4px;
  padding: 3px 5px;
  display: flex;
  flex-direction: column;
}
.stat-grid .k { font-size: 0.55rem; color: var(--muted); }
.stat-grid .v { font-size: 0.75rem; font-weight: 700; }

.log {
  font-size: 0.62rem;
  color: var(--muted);
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden; /* 스크롤 대신 최근 몇 줄만 보이게 잘림 */
  line-height: 1.3;
}
.log div { margin-bottom: 1px; }

.overlay {
  position: absolute;
  inset: 0;
  background: rgba(20, 14, 24, 0.88);
  display: none;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 10px;
  z-index: 5;
  text-align: center;
  padding: 16px;
  overflow: hidden;
}
.overlay.active { display: flex; }
.overlay h2 { font-size: 1.35rem; }
.overlay p {
  color: var(--muted);
  white-space: pre-line;
  font-size: 0.8rem;
  max-height: 40vh;
  overflow: hidden;
}

.speed-row { margin-top: 4px !important; }

/* —— 스팀 준비: 메뉴 / 모달 / 튜토리얼 —— */
.menu-home { width: min(440px, 96vw); }
.menu-tagline {
  color: #e8dcc8 !important;
  font-size: 0.92rem !important;
  line-height: 1.5 !important;
  margin-bottom: 16px !important;
}
.menu-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 12px;
}
.btn-lg {
  padding: 12px 16px !important;
  font-size: 1.05rem !important;
  font-weight: 700;
}
.menu-hint { margin-top: 8px; }
.diff-panel {
  text-align: left;
  margin-top: 8px;
  padding-top: 10px;
  border-top: 1px solid #5a4a68;
}
.diff-panel h3 {
  text-align: center;
  margin-bottom: 8px;
  color: #fffaf0;
}
.diff-panel.hidden,
.hidden { display: none !important; }

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(12, 8, 16, 0.78);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 16px;
}
.modal-overlay.active { display: flex; }
#pause-overlay {
  position: absolute;
  z-index: 8;
}
.modal-card {
  background: #2e2538;
  border: 1px solid #6a5a78;
  border-radius: 12px;
  padding: 20px 22px;
  width: min(400px, 94vw);
  max-height: 90vh;
  overflow: auto;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
  text-align: center;
}
.modal-card h2 {
  margin-bottom: 8px;
  color: #fffaf0;
}
.modal-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 14px;
}
.settings-grid {
  display: flex;
  flex-direction: column;
  gap: 12px;
  text-align: left;
  margin-top: 12px;
}
.settings-grid label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.88rem;
  color: #e8dcc8;
}
.settings-grid label.chk {
  flex-direction: row;
  align-items: center;
  gap: 8px;
}
.settings-grid input[type="range"] { width: 100%; }
.settings-grid select {
  background: #1e1828;
  color: #fff8ee;
  border: 1px solid #6a5a78;
  border-radius: 6px;
  padding: 6px 8px;
}
.modal-card { width: min(440px, 94vw); }
.keybind-section {
  margin-top: 16px;
  padding-top: 12px;
  border-top: 1px solid #5a4a68;
  text-align: left;
}
.keybind-section h3 {
  margin: 0 0 6px;
  color: #fffaf0;
  font-size: 1rem;
}
.keybind-hint { margin-bottom: 8px !important; font-size: 0.8rem !important; }
.keybind-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.keybind-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.keybind-row span {
  color: #e8dcc8;
  font-size: 0.88rem;
}
.keybind-row button {
  min-width: 72px;
  font-family: ui-monospace, Consolas, monospace;
  font-weight: 700;
}
.keybind-row button.listening {
  outline: 2px solid #c9a227;
  background: #4a3a20;
}
.tool .hk {
  display: inline-block;
  margin-left: 4px;
  padding: 0 5px;
  border-radius: 4px;
  background: rgba(0, 0, 0, 0.35);
  color: #f0d78c;
  font-size: 0.72em;
  font-weight: 700;
  vertical-align: middle;
}
.credits-body {
  text-align: left;
  color: #d4c8b8;
  font-size: 0.88rem;
  line-height: 1.55;
  white-space: normal;
}

.tutorial-tip {
  position: absolute;
  left: 12px;
  bottom: 12px;
  z-index: 6;
  width: min(340px, calc(100% - 24px));
  background: rgba(30, 22, 40, 0.94);
  border: 1px solid #c9a227;
  border-radius: 10px;
  padding: 12px 14px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.4);
}
.tutorial-tip.hidden { display: none; }
.tutorial-step {
  font-size: 0.72rem;
  color: #c9a227;
  font-weight: 700;
  margin-bottom: 4px;
}
.tutorial-text {
  font-size: 0.88rem;
  color: #f3e9d7;
  line-height: 1.45;
  margin-bottom: 10px;
}
.tutorial-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}
.overlay-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
}

body.is-paused .canvas-wrap #game-root {
  filter: brightness(0.55);
}

/* 터치 카메라 패드 (모바일) */
.touch-cam {
  display: none;
  position: absolute;
  left: 8px;
  bottom: 10px;
  z-index: 5;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  pointer-events: none;
}
.touch-cam .tcam-btn,
.touch-cam .tcam-mid,
.touch-cam .tcam-zoom {
  pointer-events: auto;
}
.tcam-mid,
.tcam-zoom {
  display: flex;
  gap: 4px;
}
.tcam-btn {
  width: 44px;
  height: 44px;
  border: 1px solid #6a5a78;
  border-radius: 10px;
  background: rgba(30, 22, 40, 0.82);
  color: #fff8ee;
  font-size: 1.05rem;
  font-weight: 700;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
.tcam-btn:active {
  background: rgba(90, 70, 40, 0.9);
  border-color: #c9a227;
}
.side-grab {
  display: none;
  width: 100%;
  border: none;
  background: #2a2234;
  color: #e8dcc8;
  padding: 8px 10px 10px;
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
  border-bottom: 1px solid #463850;
  touch-action: manipulation;
}
.side-grab .grab-bar {
  display: block;
  width: 42px;
  height: 4px;
  border-radius: 2px;
  background: #6a5a78;
  margin: 0 auto 6px;
}
.mobile-only { display: none !important; }
.pc-only { display: inline; }

/*
 * 모바일 / 좁은 화면: 세로 스택 금지.
 * PC와 동일하게 좌측 맵 + 우측 패널 가로 구도 유지.
 * (세로 파지시 html.force-landscape 로 #app 을 90° 회전)
 */
@media (max-width: 1100px), (pointer: coarse) {
  :root { --side-w: 220px; }
  .mobile-only { display: block !important; }
  .pc-only { display: none !important; }
  span.mobile-only { display: inline !important; }

  #app {
    padding: 4px 6px;
    height: 100dvh;
    max-height: 100dvh;
  }
  header {
    gap: 6px;
    flex: 0 0 auto;
  }
  h1 { font-size: 0.95rem; }
  .subtitle { display: none; }

  /* HUD: 한 줄 가로 (PC와 동일 구조, 글자만 축소) */
  .hud {
    grid-template-columns: repeat(8, minmax(0, 1fr));
    gap: 3px;
  }
  .hud-item { padding: 2px 4px; }
  .hud-item .label { font-size: 0.58rem; }
  .hud-item .value { font-size: 0.8rem; }

  /* ★ 핵심: 세로 배치 제거 → PC처럼 맵 | 사이드 */
  .play-layout {
    grid-template-columns: minmax(0, 1fr) var(--side-w);
    grid-template-rows: minmax(0, 1fr);
    gap: 4px;
  }

  .canvas-wrap {
    min-height: 0;
    height: 100%;
  }

  .touch-cam {
    display: flex;
  }

  .side {
    width: var(--side-w);
    max-width: var(--side-w);
    min-width: 0;
    height: 100%;
    max-height: none;
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    display: flex;
    flex-direction: column;
    border: 1px solid #463850;
    border-radius: var(--radius);
    background: var(--panel);
  }
  .side-grab {
    display: block;
    flex: 0 0 auto;
    position: sticky;
    top: 0;
    z-index: 2;
  }
  /* 접기 = 사이드 폭만 줄여 맵 확대 (세로 접기 아님) */
  .side.collapsed {
    width: 44px;
    max-width: 44px;
    overflow: hidden;
  }
  .side.collapsed > :not(.side-grab) {
    display: none !important;
  }
  .side.collapsed .side-grab {
    writing-mode: vertical-rl;
    text-orientation: mixed;
    padding: 10px 4px;
    min-height: 100%;
  }
  .side.collapsed .grab-bar {
    display: none;
  }
  .play-layout:has(.side.collapsed) {
    grid-template-columns: minmax(0, 1fr) 44px;
  }

  .panel {
    padding: 6px 8px;
    flex: 0 0 auto;
  }
  .panel.flex-fill {
    flex: 1 1 auto;
    min-height: 60px;
  }
  .tools {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 4px;
  }
  .tool {
    min-height: 40px;
    font-size: 0.78rem;
    padding: 6px 4px;
  }
  .btn {
    min-height: 38px;
    font-size: 0.88rem;
  }
  .btn-start {
    min-height: 44px;
    font-size: 0.95rem;
  }
  .egg-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 4px;
  }
  .egg-actions .btn {
    width: 100%;
  }

  .build-banner {
    font-size: 0.72rem;
    white-space: normal;
    max-width: 55%;
    text-align: left;
    top: 6px;
    left: 8px;
    right: auto;
    transform: none;
    padding: 4px 8px;
  }
  /* 스마트폰: 확정(V)/취소(X) — 맵 가리지 않게 좌상단·작게 */
  .build-confirm {
    top: 6px;
    left: 8px;
    right: auto;
    bottom: auto;
    transform: none;
    width: auto;
    min-width: 0;
    max-width: min(200px, 42vw);
    padding: 5px 7px;
    gap: 4px;
    border-radius: 8px;
    font-size: 0.72rem;
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.35);
    align-items: stretch;
  }
  .build-confirm #build-confirm-text {
    font-size: 0.68rem;
    line-height: 1.25;
    white-space: normal;
    text-align: left;
  }
  .build-confirm-btns {
    gap: 4px;
    flex-wrap: nowrap;
  }
  .build-confirm-btns .btn {
    min-width: 0 !important;
    min-height: 30px !important;
    padding: 4px 8px !important;
    font-size: 0.75rem !important;
    flex: 1 1 auto;
  }

  .tutorial-tip {
    left: 8px;
    right: auto;
    width: min(360px, 70%);
    bottom: 8px;
    font-size: 0.88rem;
  }

  .log {
    max-height: 72px;
  }

  .menu-card {
    width: min(520px, 92%);
    max-height: min(92%, 640px);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 14px 16px;
  }
  .diff-btn {
    min-height: 48px;
  }
  .btn-lg {
    min-height: 46px;
  }

  /* 가로인데 높이가 매우 낮은 폰: HUD/사이드 더 압축 */
  @media (max-height: 420px) {
    :root { --side-w: 190px; }
    header { display: none; }
    .hud-item .label { font-size: 0.52rem; }
    .hud-item .value { font-size: 0.72rem; }
    .tool { min-height: 34px; font-size: 0.72rem; padding: 4px 3px; }
    .panel { padding: 4px 6px; }
    .tcam-btn { width: 36px; height: 36px; font-size: 0.9rem; }
  }
}

/* 아주 작은 논리 폭 (강제 가로 회전 포함) */
@media (max-width: 700px) {
  :root { --side-w: 180px; }
  .hud {
    grid-template-columns: repeat(8, minmax(0, 1fr));
  }
  .hud-item:nth-child(n+7) {
    display: none;
  }
  .hud {
    grid-template-columns: repeat(6, minmax(0, 1fr));
  }
  .tcam-btn {
    width: 40px;
    height: 40px;
  }
}

/* 호버 가능한 환경에서만 호버 스타일 유지 */
@media (hover: none) {
  .diff-btn:hover {
    border-color: #7a6a8a;
    background: #3a3048;
  }
  .tool:hover {
    filter: none;
  }
}
