/*
 * 햄버거 쟁탈전 조작 패널 스타일.
 * OBS 사용자 지정 브라우저 도크(폭 300px 안팎)와 일반 브라우저(넓은 화면) 둘 다에서 쓰므로
 * 카드는 자동 줄바꿈 그리드로 놓는다. 색은 오버레이와 같은 남색 계열에 참가자 색만 얹는다.
 * OBS 옛 브라우저 엔진 호환을 위해 color-mix()·:has()·CSS 중첩은 쓰지 않는다.
 */
:root {
  --bg: #0A0E19;
  --panel: #141A2A;
  --panel-2: #1C2438;
  --line: rgba(255, 255, 255, 0.09);
  --ink: #F4F6FB;
  --ink-2: rgba(244, 246, 251, 0.64);
  --ink-3: rgba(244, 246, 251, 0.38);
  --gold: #FFD46B;
  --danger: #FF5A6E;
  --radius: 10px;
}

* {
  box-sizing: border-box;
}

html {
  background: var(--bg);
}

body {
  margin: 0;
  padding: 12px;
  font-family: 'Pretendard', system-ui, sans-serif;
  color: var(--ink);
  background: var(--bg);
  word-break: keep-all; /* 한글 낱말이 중간에서 끊겨 줄바꿈되지 않게 한다 */
  -webkit-font-smoothing: antialiased;
}

button,
input {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.35;
}

:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

kbd {
  padding: 1px 5px;
  border: 1px solid var(--line);
  border-radius: 4px;
  font: 600 11px/1.4 'Outfit', sans-serif;
  color: var(--ink-2);
  background: rgba(255, 255, 255, 0.04);
}

/* ───────── 상단 요약 ───────── */

.top {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 8px 16px;
  margin-bottom: 12px;
  padding: 12px 14px;
  border-top: 3px solid var(--ink);
  border-radius: 4px 4px var(--radius) var(--radius);
  background: linear-gradient(180deg, #232C42, #121828);
}

.top__row {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.top__title {
  margin: 0;
  font-size: 16px;
  font-weight: 800;
  letter-spacing: 0.02em;
}

.conn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--ink-2);
}

.conn::before {
  content: '';
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #3DDC84;
  box-shadow: 0 0 8px #3DDC84;
}

body.is-offline .conn {
  color: var(--danger);
}

body.is-offline .conn::before {
  background: var(--danger);
  box-shadow: 0 0 8px var(--danger);
}

.top__remain {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.top__label {
  font-size: 12px;
  font-weight: 700;
  color: var(--ink-2);
}

.top__num {
  font: 800 40px/1 'Outfit', sans-serif;
  font-variant-numeric: tabular-nums;
}

.top__of {
  font: 600 16px/1 'Outfit', sans-serif;
  color: var(--ink-3);
}

/* ───────── 참가자 카드 ───────── */

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(270px, 1fr));
  gap: 10px;
}

.card {
  --c: #FFFFFF;
  --c-rgb: 255, 255, 255;
  --chip-ink: #0B1020;
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px 12px 12px 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: linear-gradient(100deg, rgba(var(--c-rgb), 0.2) 0%, rgba(var(--c-rgb), 0.04) 45%, var(--panel) 80%);
  overflow: hidden;
}

/* 왼쪽 참가자 색 띠 */
.card::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 4px;
  background: var(--c);
}

.card.is-flash {
  animation: card-flash 0.6s ease-out;
}

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

.avatar {
  position: relative;
  flex: 0 0 40px;
  width: 40px;
  height: 40px;
}

.avatar__clip {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  overflow: hidden;
  background: radial-gradient(circle at 50% 30%, rgba(var(--c-rgb), 0.6), #0B0F19 100%);
  box-shadow: 0 0 0 2px var(--c);
}

.avatar__clip img {
  position: absolute;
  max-width: none;
}

.card__name {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.card__name b {
  overflow: hidden;
  font-size: 16px;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.card__key {
  font: 600 11px/1 'Outfit', sans-serif;
  letter-spacing: 0.12em;
  color: var(--ink-3);
}

.card.is-leader .card__key {
  color: var(--gold);
}

/* 개수: 직접 입력 가능한 큰 숫자 */
.card__count {
  width: 76px;
  padding: 2px 4px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  font: 800 38px/1 'Outfit', sans-serif;
  font-variant-numeric: tabular-nums;
  text-align: right;
  -moz-appearance: textfield;
}

.card__count:hover,
.card__count:focus {
  border-color: var(--line);
  background: rgba(0, 0, 0, 0.3);
}

.card__count::-webkit-outer-spin-button,
.card__count::-webkit-inner-spin-button {
  margin: 0;
  -webkit-appearance: none;
}

.card__actions {
  display: grid;
  grid-template-columns: 64px 1fr;
  gap: 8px;
}

.btn-step {
  height: 48px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font: 800 20px/1 'Outfit', sans-serif;
  background: rgba(255, 255, 255, 0.05);
  transition: transform 0.08s ease, filter 0.15s ease;
}

.btn-step:active:not(:disabled) {
  transform: scale(0.97);
}

.btn-step--plus {
  border-color: transparent;
  background: var(--c);
  color: var(--chip-ink);
  box-shadow: 0 4px 14px rgba(var(--c-rgb), 0.35);
}

.btn-step--plus:hover:not(:disabled) {
  filter: brightness(1.08);
}

.card__steal {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

.card__steal-label {
  margin-right: 2px;
  font-size: 12px;
  font-weight: 700;
  color: var(--ink-2);
}

/* 뺏기 칩: "누구에게서" 뺏을지. 칩 색은 뺏기는 사람 색 */
.steal-chip {
  --c: #FFFFFF;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 28px;
  padding: 0 10px 0 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.04);
  font-size: 12px;
  font-weight: 600;
}

.steal-chip::before {
  content: '';
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--c);
}

.steal-chip:hover:not(:disabled) {
  border-color: var(--c);
}

/* ───────── 도구 ───────── */

.tools {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
}

.tools__row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin: 0;
}

.tools__label {
  min-width: 44px;
  font-size: 12px;
  font-weight: 700;
  color: var(--ink-2);
}

.btn {
  height: 34px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--panel-2);
  font-size: 13px;
  font-weight: 700;
}

.btn--ghost:hover:not(:disabled) {
  border-color: rgba(255, 255, 255, 0.24);
}

.btn--danger {
  margin-left: auto;
  color: var(--danger);
}

.btn--danger.is-armed {
  border-color: var(--danger);
  background: var(--danger);
  color: #FFFFFF;
}

.seg {
  display: inline-flex;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
}

.seg button {
  height: 28px;
  padding: 0 10px;
  border: 0;
  border-radius: 5px;
  background: transparent;
  font-size: 12px;
  font-weight: 700;
  color: var(--ink-2);
}

.seg button[aria-pressed='true'] {
  background: var(--ink);
  color: #0B1020;
}

.num-input {
  width: 68px;
  height: 34px;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--bg);
  font: 700 16px/1 'Outfit', sans-serif;
}

.last {
  font-size: 12px;
  color: var(--ink-2);
}

.hint {
  margin: 0;
  font-size: 11px;
  line-height: 1.7;
  color: var(--ink-3);
}

/* 연결이 끊기면 조작을 막는다 (서버가 없으면 눌러도 반영되지 않으므로) */
body.is-offline .cards,
body.is-offline .tools {
  opacity: 0.45;
  pointer-events: none;
}

/* ───────── 알림 ───────── */

.toast {
  position: fixed;
  left: 50%;
  bottom: 16px;
  max-width: calc(100% - 24px);
  padding: 10px 14px;
  border-radius: 8px;
  background: var(--danger);
  color: #FFFFFF;
  font-size: 13px;
  font-weight: 700;
  opacity: 0;
  transform: translate(-50%, 10px);
  transition: opacity 0.2s ease, transform 0.2s ease;
  pointer-events: none;
}

.toast.is-shown {
  opacity: 1;
  transform: translate(-50%, 0);
}

@keyframes card-flash {
  0% { box-shadow: inset 0 0 0 2px var(--c), 0 0 18px rgba(var(--c-rgb), 0.5); }
  100% { box-shadow: inset 0 0 0 0 var(--c), 0 0 0 rgba(var(--c-rgb), 0); }
}

/* ───────── 로그인 ───────── */

.gate {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 12px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
}

.gate[hidden] {
  display: none;
}

.gate__title {
  margin: 0;
  font-size: 16px;
  font-weight: 800;
}

.gate__desc {
  margin: 0;
  font-size: 12px;
  line-height: 1.6;
  color: var(--ink-2);
}

.gate__field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 12px;
  font-weight: 700;
  color: var(--ink-2);
}

.gate__field input {
  height: 40px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  font-size: 15px;
}

.btn--primary {
  height: 40px;
  border-color: transparent;
  background: var(--ink);
  color: #0B1020;
}

.gate__error {
  min-height: 1em;
  margin: 0;
  font-size: 12px;
  font-weight: 700;
  color: var(--danger);
}

/* 로그인 전에는 조작 영역을 숨긴다 */
body.is-locked .cards,
body.is-locked .tools {
  display: none;
}
