:root {
  --bg: #0f1117;
  --panel: #171a23;
  --line: #262b38;
  --text: #e8eaf0;
  --muted: #8a90a2;
  --accent: #ffcc33;
  --accent-ink: #1a1400;
  --radius: 12px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Apple SD Gothic Neo", "Noto Sans KR", sans-serif;
}

body {
  display: flex;
  flex-direction: column;
}

/* 상단: 로고 + 게임 제목 탭 */
.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

.logo {
  flex: none;
  font-weight: 800;
  letter-spacing: 0.12em;
  color: var(--accent);
  text-decoration: none;
}

.tabs {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  scrollbar-width: thin;
  min-width: 0;
}

.tab {
  flex: none;
  padding: 8px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--text);
  font-size: 14px;
  text-decoration: none;
  white-space: nowrap;
}

.tab:hover { border-color: var(--muted); }

.tab[aria-current="page"] {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
  font-weight: 700;
}

/* 아래 영역 */
.stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

/* 첫 화면: 썸네일 카드, 한 줄에 4개 (좁은 화면은 2개) */
.home {
  flex: 1;
  overflow-y: auto;
  padding: 24px 16px;
}

.grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 20px;
  max-width: 1280px;
  margin: 0 auto;
}

@media (max-width: 860px) {
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
}

.card {
  display: flex;
  flex-direction: column;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--text);
  text-decoration: none;
  overflow: hidden;
  transition: transform 0.15s ease, border-color 0.15s ease;
}

.card:hover,
.card:focus-visible {
  transform: translateY(-3px);
  border-color: var(--accent);
  outline: none;
}

.card img {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 10;
  object-fit: cover;
  background: #000;
}

.card-body {
  padding: 12px 14px 14px;
}

.card-title {
  display: block;
  font-size: 16px;
  font-weight: 700;
}

.card-desc {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
}

/* 게임 실행 화면 */
.player {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 16px;
  min-height: 0;
}

.stage-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.stage-head h1 {
  margin: 0;
  font-size: 20px;
}

.stage-head p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.stage-actions {
  display: flex;
  gap: 6px;
}

.stage-actions button,
.btn-link {
  padding: 6px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
  font: inherit;
  font-size: 13px;
  text-decoration: none;
  cursor: pointer;
}

.stage-actions button:hover,
.btn-link:hover { border-color: var(--muted); }

.screen {
  position: relative;
  flex: 1;
  min-height: 360px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #000;
  overflow: hidden;
}

.screen iframe {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
  display: block;
}

[hidden] { display: none !important; }

/* ── 공통 버튼/입력 ── */
button.primary,
.stage-actions button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
  font-weight: 700;
}

button:disabled { opacity: 0.6; cursor: default; }

.card-badge {
  display: inline-block;
  margin-top: 8px;
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(255, 204, 51, 0.12);
  color: var(--accent);
  font-size: 12px;
  font-weight: 600;
}

input {
  min-width: 0;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 16px; /* 모바일에서 확대되지 않도록 16px 이상 */
}

input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

.form-error {
  min-height: 1.2em;
  margin: 8px 0 0;
  color: #ff6b7a;
  font-size: 14px;
}

/* ── 방 만들기 창 ── */
.modal {
  width: min(420px, calc(100vw - 32px));
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--panel);
  color: var(--text);
}

.modal::backdrop { background: rgba(0, 0, 0, 0.6); }
.modal h2 { margin: 0; font-size: 20px; }
.modal-sub { margin: 4px 0 20px; color: var(--muted); }

.field { margin-bottom: 18px; }
.field-label { display: block; margin-bottom: 8px; font-weight: 600; }
.field-label small { color: var(--muted); font-weight: 400; }

.stepper {
  display: flex;
  align-items: center;
  gap: 10px;
}

.stepper button {
  width: 40px;
  height: 40px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  font-size: 20px;
  cursor: pointer;
}

.stepper output {
  min-width: 2ch;
  font-size: 22px;
  font-weight: 800;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 12px;
}

.modal-actions button,
.share-row button,
.join-row button,
.wide {
  padding: 10px 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 15px;
  white-space: nowrap;
  cursor: pointer;
}

/* ── 도전 방 페이지 ── */
.room-page { min-height: 100%; height: auto; }

.topbar-note { color: var(--muted); font-size: 14px; }

.room {
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px 16px 40px;
}

.pill {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 12px;
  font-weight: 800;
}

.room-head h1 { margin: 6px 0 4px; font-size: 24px; }
.room-head p { margin: 0; color: var(--muted); font-size: 14px; }

.share {
  margin: 16px 0;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
}

.share.highlight { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(255, 204, 51, 0.15); }
.share-hint { margin: 0 0 10px; font-size: 14px; font-weight: 600; }
.share-row, .join-row { display: flex; gap: 8px; }
.share-row input, .join-row input { flex: 1; }

.room-body {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 16px;
  align-items: start;
}

@media (max-width: 860px) {
  .room-body { grid-template-columns: minmax(0, 1fr); }
}

.join, .notice {
  padding: 28px 20px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  text-align: center;
}

.join h2, .notice h2 { margin: 0 0 6px; font-size: 18px; }
.join-sub, .notice p { margin: 0 0 16px; color: var(--muted); font-size: 14px; }
.join-row { max-width: 380px; margin: 0 auto; }
.notice.center { max-width: 420px; margin: 60px auto; }

.status {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 16px;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 14px;
}

.status b { color: var(--text); }

.room-screen {
  height: min(70vh, 620px);
  min-height: 340px;
}

.toast {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  padding: 8px 14px;
  border-radius: 999px;
  background: rgba(23, 26, 35, 0.92);
  border: 1px solid var(--accent);
  color: var(--accent);
  font-size: 14px;
  font-weight: 700;
  white-space: nowrap;
  pointer-events: none;
}

.cover {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  gap: 6px;
  padding: 16px;
  background: rgba(10, 12, 18, 0.88);
  text-align: center;
}

.cover-title { margin: 0; color: var(--accent); font-size: 28px; font-weight: 800; }
.cover-sub { margin: 0; color: var(--text); }

.board {
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
}

.board-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
}

.board-head h2 { margin: 0; font-size: 17px; }
.board-meta { color: var(--muted); font-size: 13px; }

.ranks { list-style: none; margin: 0 0 12px; padding: 0; }

.rank {
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 10px;
  padding: 9px 8px;
  border-radius: 8px;
  font-size: 15px;
}

.rank + .rank { border-top: 1px solid var(--line); }
.rank.me { background: rgba(255, 204, 51, 0.1); }
.rank.first .rank-no { color: var(--accent); }
.rank.empty { color: var(--muted); font-size: 14px; }
.rank-no { font-weight: 800; text-align: center; }
.rank-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank-tries { color: var(--muted); font-size: 10px; letter-spacing: 1px; }
.rank-best { font-weight: 700; font-variant-numeric: tabular-nums; text-align: right; }

.wide { width: 100%; }

/* 강조 버튼 (위의 공통 버튼 규칙보다 우선) */
.modal-actions .primary,
.share-row .primary,
.join-row .primary,
.wide.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
  font-weight: 700;
}
