:root {
  --ink: 15, 23, 42;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }

html, body {
  height: 100%;
  overflow: hidden;
  background: #8f7a60;
  color: #fff;
  font-family: Pretendard, 'Noto Sans KR', 'Malgun Gothic', system-ui, sans-serif;
  user-select: none;
}

#stage {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

/* 사진처럼 가장자리를 살짝 어둡게 */
#vignette {
  position: fixed;
  inset: 0;
  background: radial-gradient(ellipse at center, transparent 55%, rgba(0, 0, 0, 0.3) 100%);
  pointer-events: none;
}

/* 위쪽 점수판 */
#hud {
  position: fixed;
  top: 1.6vh;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 1.4vw;
  padding: 1vh 1vw;
  background: rgba(var(--ink), 0.8);
  border-radius: 18px;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.22);
  pointer-events: none;
}

.card {
  display: flex;
  align-items: center;
  gap: 0.8vw;
  min-width: 15vw;
  padding: 0.9vh 1.2vw;
  border-radius: 12px;
  border: 2px solid transparent;
  font-size: clamp(18px, 1.9vw, 36px);
  font-weight: 600;
  opacity: 0.6;
  transition: opacity 0.2s, background 0.2s, border-color 0.2s;
}
.card .dot { flex: none; width: 1em; height: 1em; border-radius: 50%; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.5); }
.card .name { white-space: nowrap; }
/* 온라인에서 어느 쪽이 나인지 */
.card.me .name::after { content: ' (나)'; font-weight: 500; opacity: 0.7; }
.card .pct { margin-left: auto; font-variant-numeric: tabular-nums; font-weight: 700; }
.card.p1 .dot { background: radial-gradient(circle at 35% 30%, #5a5a60, #0c0c0e 60%); }
.card.p2 .dot { background: radial-gradient(circle at 35% 30%, #fff, #d9d4c6 75%); }
.card.active { opacity: 1; background: rgba(255, 255, 255, 0.14); border-color: rgba(255, 255, 255, 0.85); }

.status { text-align: center; min-width: 9vw; }
.round { font-size: clamp(14px, 1.3vw, 24px); font-weight: 500; opacity: 0.85; }
.pips { display: flex; justify-content: center; gap: 0.5vw; margin-top: 0.6vh; }
.pips i {
  width: clamp(12px, 1.1vw, 20px);
  height: clamp(12px, 1.1vw, 20px);
  border-radius: 50%;
  background: #fff;
  transition: opacity 0.2s;
}
.pips i.used { opacity: 0.22; }

/* 아래 안내 문구 */
#hint {
  position: fixed;
  bottom: 2.4vh;
  left: 50%;
  transform: translateX(-50%);
  padding: 1vh 1.6vw;
  background: rgba(var(--ink), 0.72);
  border-radius: 999px;
  font-size: clamp(15px, 1.4vw, 26px);
  font-weight: 500;
  white-space: nowrap;
  pointer-events: none;
}

/* 가운데 결과 알림 */
#toast {
  position: fixed;
  top: 44%;
  left: 50%;
  transform: translate(-50%, -50%);
  padding: 1.8vh 2.6vw;
  background: rgba(var(--ink), 0.86);
  border-radius: 16px;
  font-size: clamp(24px, 3vw, 56px);
  font-weight: 700;
  white-space: nowrap;
  pointer-events: none;
  animation: pop 0.18s ease-out;
}
#toast.good { color: #7ee2a8; }
#toast.bad { color: #ff9d8a; }
@keyframes pop {
  from { opacity: 0; transform: translate(-50%, -42%); }
  to { opacity: 1; transform: translate(-50%, -50%); }
}

/* 시작·결과 화면 */
#overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(var(--ink), 0.45);
}
/* 놀이 방법(왼쪽)과 고르기(오른쪽)를 나란히 놓아 낮은 화면에서도 넘치지 않게 한다. */
.panel {
  display: grid;
  grid-template-columns: minmax(0, 0.8fr) minmax(0, 1.2fr);
  column-gap: 2.4vw;
  align-items: center;
  width: min(96vw, 1240px);
  max-height: 96vh;
  overflow-y: auto;
  padding: 3vh 2.6vw;
  background: rgba(var(--ink), 0.92);
  position: relative;
  border-radius: 24px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.35);
  text-align: center;
}
.panel h1, .panel .sub, #panelBtn { grid-column: 1 / -1; }
/* 시작·결과 창에서 놀이 고르는 첫 화면으로 돌아가기(창의 왼쪽 위). 자리를 차지하지 않아 창 크기는 그대로다. */
.panel .back {
  position: absolute;
  top: 2.2vh;
  left: 1.6vw;
  padding: 0.9vh 1.1vw;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  font-size: clamp(14px, 1.25vw, 22px);
  font-weight: 600;
  text-decoration: none;
}
.panel .back::before { content: '‹ '; }
.panel .back:hover { background: rgba(255, 255, 255, 0.24); }
.panel h1 { font-size: clamp(30px, 3.6vw, 64px); font-weight: 800; letter-spacing: -0.02em; line-height: 1.2; }
.panel .sub { margin-top: 0.4vh; font-size: clamp(16px, 1.6vw, 28px); opacity: 0.85; }
.rules {
  grid-column: 1;
  margin-top: 2.4vh;
  padding-left: 1.4em;
  text-align: left;
  font-size: clamp(15px, 1.3vw, 23px);
  line-height: 1.5;
  word-break: keep-all;
  opacity: 0.92;
}
.rules li + li { margin-top: 0.6em; }

/* 상대와 말 고르기 */
.opts { grid-column: 2; margin-top: 2.4vh; display: grid; grid-template-columns: minmax(0, 1fr); gap: 1.2vh; }
/* 결과 화면에는 놀이 방법이 없으니 고르기가 한가운데에 온다. */
.rules[hidden] + .opts { grid-column: 1 / -1; width: min(100%, 860px); justify-self: center; }
.opt { display: flex; align-items: center; gap: 1vw; }
.opt .label {
  flex: 0 0 5em;
  text-align: right;
  font-size: clamp(15px, 1.35vw, 23px);
  font-weight: 600;
  opacity: 0.8;
}
.seg { flex: 1; display: flex; gap: 6px; padding: 5px; border-radius: 14px; background: rgba(255, 255, 255, 0.1); }
.seg button {
  flex: 1;
  padding: 1vh 0.4vw;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: #fff;
  font: inherit;
  font-size: clamp(15px, 1.4vw, 24px);
  font-weight: 600;
  cursor: pointer;
}
.seg button:hover { background: rgba(255, 255, 255, 0.12); }
.seg button.on { background: #fff; color: rgb(var(--ink)); }
/* 이름 길이가 서로 많이 다른 줄: 긴 이름이 두 줄로 접히지 않게 글자 수만큼 너비를 나눈다. */
.seg.fit button { flex: 1 1 auto; word-break: keep-all; }
/* 고르는 것에 따라 내용이 바뀌는 자리. 후보를 모두 같은 칸에 겹쳐 놓고 하나만 보이게 한다.
   가장 큰 것만큼 자리를 잡아 두므로 무엇을 골라도 창 크기가 변하지 않는다. */
.swap { flex: 1; display: grid; align-items: center; min-width: 0; }
.swap > * { grid-area: 1 / 1; min-width: 0; }
.swap > .off { visibility: hidden; }
.swap > p { font-size: clamp(14px, 1.25vw, 21px); word-break: keep-all; opacity: 0.8; }
.pieceDesc { flex: none; min-height: 1.5em; }

/* 온라인 방 이름과 비밀번호 */
.fields { flex: 1; display: flex; gap: 6px; min-width: 0; }
/* 입력 칸은 글자 수만큼의 제 너비를 갖는다. 그 너비가 줄을 밀어내지 않게 0에서 늘린다. */
.fields input {
  flex: 1;
  width: 0;
  min-width: 0;
  padding: 1vh 0.9vw;
  border: 2px solid rgba(255, 255, 255, 0.28);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
  font: inherit;
  font-size: clamp(15px, 1.4vw, 24px);
  font-weight: 600;
  user-select: text;
}
.fields input::placeholder { color: rgba(255, 255, 255, 0.55); font-weight: 500; }
.fields input:focus { outline: none; border-color: #fff; background: rgba(255, 255, 255, 0.16); }
/* 방에 들어갈 때의 안내와 오류 */
.note {
  grid-column: 1 / -1;
  display: grid;
  margin-top: 1.8vh;
  font-size: clamp(15px, 1.35vw, 23px);
  word-break: keep-all;
  opacity: 0.85;
}
.note.warn { color: #ffcf8a; opacity: 1; font-weight: 600; }
/* 고르는 동안에는 가장 긴 안내만큼 자리를 잡아 둔다. */
.note > * { grid-area: 1 / 1; }
.note > .off { visibility: hidden; }

#panelLeave {
  grid-column: 1 / -1;
  justify-self: center;
  margin-top: 1.6vh;
  padding: 1vh 2vw;
  border: 2px solid rgba(255, 255, 255, 0.4);
  border-radius: 12px;
  background: transparent;
  color: #fff;
  font: inherit;
  font-size: clamp(16px, 1.5vw, 26px);
  font-weight: 600;
  cursor: pointer;
}
#panelLeave:hover { background: rgba(255, 255, 255, 0.12); }
/* 시작 단추와 나가기 단추를 한 줄에 놓는 놀이: 방에 들어가 있어도 창 크기가 변하지 않는다. */
.btns { grid-column: 1 / -1; display: flex; justify-content: center; align-items: center; gap: 1.2vw; margin-top: 2.4vh; }
.btns #panelBtn, .btns #panelLeave { margin-top: 0; }
/* 상대를 기다리는 동안에는 시작 단추가 보이지 않게 자리(높이)만 지킨다. */
.btns.waiting #panelBtn { visibility: hidden; width: 0; min-width: 0; padding-left: 0; padding-right: 0; margin-right: -1.2vw; overflow: hidden; white-space: nowrap; }
/* 방에 들어가 있는 동안에는 고른 것을 바꿀 수 없다. */
.opts.locked { opacity: 0.5; pointer-events: none; }

#panelBtn {
  justify-self: center;
  margin-top: 2.4vh;
  padding: 1.4vh 3vw;
  border: 0;
  border-radius: 14px;
  background: #fff;
  color: rgb(var(--ink));
  font: inherit;
  font-size: clamp(20px, 2vw, 34px);
  font-weight: 700;
  cursor: pointer;
}
#panelBtn:hover { background: #e8edf5; }
#panelBtn:disabled { opacity: 0.5; cursor: default; }
kbd {
  margin-left: 0.5em;
  padding: 0.1em 0.5em;
  border-radius: 6px;
  background: rgba(var(--ink), 0.1);
  font: inherit;
  font-size: 0.7em;
  font-weight: 600;
}

/* 내 시점에서 쓰는 단추: 둘러보기(왼쪽 아래), 시선·전체 보기(오른쪽 아래) */
#look, #views { position: fixed; bottom: 2.4vh; }
#views { right: 1.6vw; display: flex; flex-direction: column; align-items: flex-end; gap: 1vh; }
#look, #views button {
  display: flex;
  align-items: center;
  gap: 0.8vw;
  background: rgba(var(--ink), 0.72);
  border-radius: 999px;
  color: #fff;
  font: inherit;
  font-size: clamp(15px, 1.4vw, 26px);
  font-weight: 600;
}
#look { left: 1.6vw; padding: 0.6vh 0.5vw; }
#look span { opacity: 0.85; }
#look button {
  width: clamp(44px, 4vw, 72px);
  height: clamp(44px, 4vw, 72px);
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.16);
  cursor: pointer;
  touch-action: none;
}
#look button:hover, #look button.held { background: rgba(255, 255, 255, 0.34); }
#look svg { width: 56%; height: 56%; fill: none; stroke: #fff; stroke-width: 2.6; stroke-linecap: round; stroke-linejoin: round; }
#views button { padding: 1.4vh 1.6vw; border: 0; cursor: pointer; }
#views button:hover { background: rgba(var(--ink), 0.88); }
#views kbd { background: rgba(255, 255, 255, 0.18); }

/* 놀이 고르는 첫 화면으로 돌아가기(왼쪽 위) */
#home {
  position: fixed;
  top: 1.6vh;
  left: 1.2vw;
  padding: 1vh 1.2vw;
  border-radius: 999px;
  background: rgba(var(--ink), 0.72);
  color: #fff;
  font-size: clamp(14px, 1.25vw, 22px);
  font-weight: 600;
  text-decoration: none;
}
#home::before { content: '‹ '; }
#home:hover { background: rgba(var(--ink), 0.9); }
/* 시작·결과 창이 떠 있을 때는 창 안의 단추를 쓴다. */
body:has(#overlay:not([hidden])) #home { visibility: hidden; }

/* 좁거나 세로로 긴 화면에서는 한 줄로 쌓는다. */
@media (max-width: 860px), (orientation: portrait) {
  .panel { grid-template-columns: minmax(0, 1fr); }
  .rules, .opts { grid-column: 1; }
  /* 제목과 겹치지 않게 맨 위에 한 줄로 놓는다. */
  .panel .back { position: static; justify-self: start; margin-bottom: 1vh; }
}
