:root {
  --bg: #1b1e25;
  --stage: #333842;
  --panel: #232731;
  --line: #343a47;
  --text: #eef1f6;
  --muted: #9aa3b2;
  --accent: #4d9eff;
  --gold: #ffd23f;
  --good: #47c26a;
  --bad: #ff7a7a;
  --bar-h: 46px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "Pretendard", "Apple SD Gothic Neo", "Malgun Gothic", "맑은 고딕", "Noto Sans KR", sans-serif;
  font-size: 15px;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}

button { font: inherit; color: inherit; cursor: pointer; }

/* ── 윗줄 ── */
#bar {
  height: var(--bar-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 0 12px;
  background: #262a33;
  border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-right { display: flex; gap: 8px; flex: none; }
.chip {
  height: 32px;
  padding: 0 12px;
  border-radius: 16px;
  border: 1px solid var(--line);
  background: #2e333f;
  max-width: 46vw;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chip.strong { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 700; }

/* ── 게임 화면 + 순위표 ── */
main {
  height: calc(100dvh - var(--bar-h));
  display: flex;
  justify-content: center;
  align-items: stretch;
}
#stage {
  position: relative;
  flex: none;
  /* 게임 화면은 세로 9:16 을 지킨다(더 길쭉하면 화면 아래 단추들이 잘린다). */
  height: min(calc(100dvh - var(--bar-h)), calc(100vw * 16 / 9));
  aspect-ratio: 9 / 16;
  align-self: center;
  background: var(--stage);
}
#unity-canvas {
  width: 100%;
  height: 100%;
  display: block;
  background: var(--stage);
  touch-action: none;
  outline: none;
}
#loading {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 24px;
  text-align: center;
  background: var(--stage);
}
.loading-title { font-size: 17px; font-weight: 700; }
.loading-note { color: var(--muted); font-size: 13px; min-height: 18px; white-space: pre-line; }
.progress { width: min(260px, 70%); height: 8px; border-radius: 4px; background: #23262e; overflow: hidden; }
#progressFill { width: 0; height: 100%; background: var(--accent); transition: width .15s; }

#panel {
  width: 340px;
  flex: none;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border-left: 1px solid var(--line);
  min-height: 0;
}
.panel-head { display: flex; align-items: center; gap: 8px; padding: 10px 12px 0; }
.tabs { display: flex; flex: 1; background: #1c2028; border-radius: 10px; padding: 3px; }
.tab { flex: 1; height: 34px; border: 0; border-radius: 8px; background: transparent; color: var(--muted); font-weight: 700; }
.tab.on { background: #3a4150; color: var(--text); }
.icon { width: 34px; height: 34px; border: 0; border-radius: 8px; background: transparent; color: var(--muted); font-size: 16px; display: none; }
.board-title { padding: 12px 14px 2px; font-weight: 700; font-size: 16px; }
.mine { margin: 8px 12px 4px; padding: 10px 12px; border-radius: 10px; background: #1c2028; color: var(--muted); font-size: 14px; line-height: 1.5; }
.mine b { color: var(--text); }
.board { list-style: none; margin: 4px 0 0; padding: 0 8px; overflow-y: auto; flex: 1; min-height: 0; }
.board li {
  display: grid;
  grid-template-columns: 34px 1fr auto;
  align-items: center;
  gap: 6px;
  padding: 8px 6px;
  border-bottom: 1px solid #2b303b;
}
.board li.me { background: rgba(77, 158, 255, .14); border-radius: 8px; border-bottom-color: transparent; }
.rank { text-align: center; font-weight: 700; color: var(--muted); font-variant-numeric: tabular-nums; }
.rank.top1 { color: var(--gold); }
.rank.top2 { color: #cfd6e3; }
.rank.top3 { color: #d99a5b; }
.who { min-width: 0; }
.who .name { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.who .sub { color: var(--muted); font-size: 12.5px; }
.points { text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; }
.points .sub { display: block; color: var(--muted); font-size: 12.5px; font-weight: 400; }
.stars { color: var(--gold); letter-spacing: 1px; }
.stars .off { color: #4a5160; }
.board-note { padding: 14px; color: var(--muted); text-align: center; font-size: 14px; }
.board-note:empty { display: none; }
/* 기록이 없을 때는 안내 글이 바로 위에 붙어 보이게(빈 목록이 자리를 차지하지 않게) */
.board:empty { flex: 0 0 auto; }
.panel-foot { margin-top: auto; padding: 10px 14px 12px; color: var(--muted); font-size: 12px; line-height: 1.5; border-top: 1px solid var(--line); }

/* 좁은 화면(휴대폰): 순위표는 「순위」를 눌렀을 때 화면 위로 덮인다 */
@media (max-width: 859px) {
  #panel {
    position: fixed;
    inset: var(--bar-h) 0 0 0;
    width: auto;
    border-left: 0;
    z-index: 20;
    display: none;
  }
  body.panel-open #panel { display: flex; }
  .icon { display: block; }
}
@media (min-width: 860px) {
  #rankButton { display: none; }
}

/* ── 이름 창 ── */
.dialog[hidden], .toast[hidden] { display: none; }
.dialog {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(0, 0, 0, .6);
}
.dialog-box { width: min(360px, 100%); padding: 20px; border-radius: 16px; background: var(--panel); border: 1px solid var(--line); }
.dialog-title { font-size: 18px; font-weight: 700; }
.dialog-text { margin: 8px 0 14px; color: var(--muted); line-height: 1.5; }
#nameInput {
  width: 100%;
  height: 46px;
  padding: 0 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #1c2028;
  color: var(--text);
  font: inherit;
  font-size: 16px;   /* 16px 보다 작으면 아이폰이 화면을 확대한다 */
}
#nameInput:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.dialog-error { min-height: 20px; margin-top: 8px; color: var(--bad); font-size: 13.5px; }
.dialog-buttons { display: flex; gap: 8px; margin-top: 6px; }
.btn { flex: 1; height: 44px; border-radius: 10px; border: 1px solid var(--line); font-weight: 700; }
.btn.ghost { background: transparent; color: var(--muted); }
.btn.primary { background: var(--good); border-color: var(--good); color: #fff; }
.btn:disabled { opacity: .5; cursor: default; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%);
  z-index: 50;
  max-width: 90vw;
  padding: 10px 16px;
  border-radius: 20px;
  background: rgba(15, 17, 22, .92);
  border: 1px solid var(--line);
  font-size: 14px;
  text-align: center;
}
