:root {
  color-scheme: dark;
}

* {
  box-sizing: border-box;
  touch-action: manipulation;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100dvh;
  overflow: hidden;
  background: #0a0a0a;
  color: #f5f5f5;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Apple SD Gothic Neo", "Noto Sans KR", sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
  overscroll-behavior: none;
}

main {
  height: 100%;
  max-width: 480px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  padding:
    max(60px, env(safe-area-inset-top))
    16px
    max(20px, env(safe-area-inset-bottom));
  gap: 8px;
}

/* 점수바: SCORE | BEST | New 버튼 */
.score-bar {
  display: flex;
  gap: 8px;
  align-items: stretch;
}

.score-box {
  flex: 1;
  background: #161616;
  border: 1px solid #2a2a2a;
  border-radius: 12px;
  padding: 8px 12px;
  text-align: center;
  min-width: 0;
}

.score-label {
  display: block;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #a0a0a0;
}

.score-val,
.best-val {
  display: block;
  font-size: 22px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
  color: #f5f5f5;
  margin-top: 2px;
  line-height: 1.1;
}

.new-btn {
  flex: 0 0 auto;
  font: inherit;
  color: #fff;
  background: #4f9eff;
  border: none;
  border-radius: 12px;
  padding: 0 14px;
  min-height: 52px;
  cursor: pointer;
  font-weight: 700;
  font-size: 14px;
  -webkit-tap-highlight-color: transparent;
}

.new-btn:active { background: #3d8ae8; }

/* 게임 영역 — 보드/캠버스/그리드 등을 여기에 */
#game {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;   /* 작은 폰에서 아래 조작 요소가 화면 밖으로 밀리지 않게 */
}

/* 좌상단 ← 홈, 우상단 🏆 명예의 전당 — 모든 게임 공통 chrome */
.home-link,
.hof-link {
  position: fixed;
  top: max(12px, env(safe-area-inset-top));
  z-index: 10;
  width: 40px;
  height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.35);
  color: #fff;
  text-decoration: none;
  font-size: 20px;
  font-weight: 600;
  line-height: 1;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  transition: background 0.15s ease;
  border: none;
  cursor: pointer;
  font-family: inherit;
}

.home-link { left:  max(12px, env(safe-area-inset-left)); }
.hof-link  { right: max(12px, env(safe-area-inset-right)); }

@media (hover: hover) {
  .home-link:hover,
  .hof-link:hover {
    background: rgba(0, 0, 0, 0.55);
  }
}

/* 오버레이 (게임 종료 / 완료 시 점수 + 저장 버튼) */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 20;
  padding: 20px;
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
}

.overlay[hidden] { display: none; }

.overlay-card {
  background: #161616;
  border: 1px solid #2a2a2a;
  border-radius: 18px;
  padding: 24px 22px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: center;
  text-align: center;
  min-width: 240px;
  max-width: 320px;
  width: 100%;
}

.overlay-card h2 {
  margin: 0;
  font-size: 22px;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.overlay-score {
  margin: 0;
  font-size: 56px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.04em;
  line-height: 1;
}

.overlay-card button {
  font: inherit;
  color: #fff;
  background: rgba(255, 255, 255, 0.10);
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 999px;
  padding: 12px 20px;
  min-height: 44px;
  cursor: pointer;
  font-weight: 600;
  font-size: 14px;
  width: 100%;
  -webkit-tap-highlight-color: transparent;
}

.overlay-card button:active {
  background: rgba(255, 255, 255, 0.18);
}

.overlay-card .save-btn {
  background: #4f9eff;
  border-color: #4f9eff;
}

.overlay-card .save-btn:active {
  background: #3d8ae8;
}


/* ─── Truss Builder ───────────────────────────────────────── */
.score-box { padding: 6px 8px; }
.time-val {
  display: block; font-size: 22px; font-weight: 800; font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em; color: #f5f5f5; margin-top: 2px; line-height: 1.1;
}
.time-box[data-low="1"] { border-color: #b5443a; background: #2a1513; }
.time-box[data-low="1"] .time-val { color: #ff8a7a; animation: tr-pulse 0.8s ease-in-out infinite; }
@keyframes tr-pulse { 50% { opacity: 0.55; } }

.info-bar {
  display: flex; align-items: center; gap: 10px;
  font-size: 13px; color: #c9ced6; padding: 0 2px; min-height: 22px;
}
.info-item { white-space: nowrap; }
.info-label { color: #8f96a1; font-weight: 700; font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; }
.info-item b { color: #f5f5f5; font-variant-numeric: tabular-nums; }
.budget-bar {
  flex: 1; height: 6px; border-radius: 3px; background: #262a30; overflow: hidden; min-width: 30px;
}
.budget-bar i { display: block; height: 100%; width: 0; background: #5fc27e; border-radius: 3px; transition: width 0.15s ease; }
.budget-bar[data-warn="1"] i { background: #f0a23a; }

#game { position: relative; border-radius: 12px; overflow: hidden; background: #bfe0f0; }
.board { display: block; touch-action: none; }

.status {
  margin: 0; text-align: center; font-size: 13px; line-height: 1.3; color: #c9ced6;
  min-height: 2.6em; display: flex; align-items: center; justify-content: center; padding: 0 4px;
}
.status[data-kind="warn"] { color: #ffc46b; }
.status[data-kind="bad"] { color: #ff8a7a; font-weight: 700; }

.tools { display: flex; gap: 6px; align-items: stretch; }
.mat-group { display: flex; gap: 0; border-radius: 12px; overflow: hidden; border: 1px solid #2f343b; }
.mat-btn, .tool-btn, .test-btn {
  font: inherit; color: #f5f5f5; cursor: pointer; border: none; min-height: 48px;
  -webkit-tap-highlight-color: transparent;
}
.mat-btn {
  background: #16191e; padding: 4px 8px; min-width: 58px;
  display: grid; grid-template-columns: auto auto; grid-template-rows: auto auto;
  column-gap: 6px; align-items: center; justify-items: start;
}
.mat-btn + .mat-btn { border-left: 1px solid #2f343b; }
.mat-btn .sw { grid-row: 1 / 3; width: 6px; height: 26px; border-radius: 3px; }
.sw-road { background: linear-gradient(90deg, #23272d 0 25%, #f2c94c 25% 45%, #4d545e 45%); width: 9px !important; }
.sw-beam { background: #d39a5c; box-shadow: inset 0 0 0 1.5px #4a2d14; }
.mat-name { font-weight: 700; font-size: 13px; line-height: 1.1; }
.mat-price { font-size: 11px; color: #9aa1ab; line-height: 1.1; }
.mat-btn[aria-pressed="true"] { background: #2b3a52; box-shadow: inset 0 -3px 0 #7ab8ff; }
.mat-btn[aria-pressed="true"] .mat-price { color: #cfe3ff; }
.tool-btn {
  background: #1d2026; border: 1px solid #2f343b; border-radius: 12px; min-width: 44px;
  font-size: 20px; font-weight: 700; padding: 0 6px;
}
.tool-btn:disabled, .test-btn:disabled { opacity: 0.4; cursor: default; }
.test-btn {
  flex: 1; background: #2f9e5b; border-radius: 12px; font-weight: 800; font-size: 15px; padding: 0 8px;
  color: #fff; min-width: 64px;
}
.test-btn:not(:disabled):active { background: #278a4e; }
.tool-btn:not(:disabled):active { background: #2a2e36; }

/* start / result card */
.start-card .intro {
  list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px;
  text-align: left; font-size: 14px; line-height: 1.4; color: #d7dbe1;
}
.start-card .intro li { display: flex; gap: 10px; align-items: flex-start; }
.ico { flex: 0 0 auto; width: 30px; height: 30px; border-radius: 8px; background: #22262d; position: relative; margin-top: 1px; }
.ico-drag::before { content: ""; position: absolute; left: 6px; top: 6px; width: 7px; height: 7px; border-radius: 2px; background: #e4502f; }
.ico-drag::after { content: ""; position: absolute; left: 11px; top: 14px; width: 15px; height: 4px; background: #d39a5c; border-radius: 2px; transform: rotate(35deg); transform-origin: left center; }
.ico-tri::before { content: ""; position: absolute; left: 6px; top: 7px; border-left: 9px solid transparent; border-right: 9px solid transparent; border-bottom: 15px solid #d39a5c; }
.ico-tri::after { content: ""; position: absolute; left: 4px; right: 4px; bottom: 6px; height: 4px; background: #f2c94c; border-radius: 2px; }
.ico-clock::before { content: ""; position: absolute; inset: 6px; border-radius: 50%; border: 2.5px solid #7ab8ff; }
.ico-clock::after { content: ""; position: absolute; left: 14px; top: 9px; width: 2.5px; height: 7px; background: #7ab8ff; border-radius: 1px; }
.start-card .start-btn { background: #2f9e5b; border-color: #2f9e5b; font-weight: 800; font-size: 16px; min-height: 48px; }
.overlay-sub { margin: -4px 0 0; color: #b6bcc6; font-size: 14px; }
.sol-box { display: flex; flex-direction: column; gap: 6px; align-items: center; width: 100%; }
.sol-label { font-size: 12px; color: #9aa1ab; }
.sol-thumb { border-radius: 10px; max-width: 100%; height: auto; }
.overlay { overflow-y: auto; }
.overlay-card { margin: auto; }
@media (max-height: 640px) {
  .overlay { padding: 12px; }
  .overlay-card { padding: 16px 16px; gap: 8px; }
  .overlay-card h2 { font-size: 19px; }
  .overlay-score { font-size: 40px; }
  .overlay-card button { min-height: 40px; padding: 8px 16px; }
  .sol-thumb { width: 168px !important; height: 105px !important; }
  .start-card .intro { gap: 7px; font-size: 13px; }
}

@media (max-width: 340px) {
  .mat-btn { min-width: 52px; padding: 4px 6px; column-gap: 5px; }
  .mat-price { font-size: 10px; }
  .tool-btn { min-width: 40px; }
  .info-bar { font-size: 12px; gap: 6px; }
  .test-btn { font-size: 14px; }
}
@media (max-height: 600px) {
  .status { min-height: 2.4em; font-size: 12px; }
}
