﻿/* style.css — 러미게임 UI */
:root {
  --felt: #15568c; --felt2: #0c3457; --ivory: #f4ecd6;
  --gold: #d9b44a; --ink: #1c2b22; --warn: #c0392b; --ok: #2e7d32;
  --tile-w: 46px; --tile-h: 64px;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; font-family: "Segoe UI", "Malgun Gothic", sans-serif; color: #fff;
  display: flex; flex-direction: column; min-height: 100vh; }
#app { flex: 1 1 auto; display: flex; flex-direction: column; min-height: 0; }

.screen { display: none; }
.screen.active { display: flex; flex: 1 1 auto; min-height: 0; }

/* ── 시작 화면 ── */
#screen-start {
  align-items: center; justify-content: center;
  background: radial-gradient(circle at 50% 30%, #1f6cb0, #082742);
}
.start-box { text-align: center; background: rgba(0,0,0,.28); padding: 38px 46px; border-radius: 18px; box-shadow: 0 12px 40px rgba(0,0,0,.4); }
.start-box h1 { font-size: 2.4rem; margin: 0 0 4px; }
.start-box h1 small { font-size: 1rem; color: var(--gold); }
.subtitle { color: #cfe2f4; margin: 0 0 18px; }
.count-pick { margin: 14px 0; display: flex; gap: 8px; align-items: center; justify-content: center; }
.count-pick > span { color: #cfe2f4; white-space: nowrap; flex-shrink: 0; }
.ver { margin-top: 16px; font-size: .8rem; color: #9ec2e0; }

.btn { display: inline-block; padding: 10px 18px; margin: 5px; border: 0; border-radius: 9px;
  background: var(--gold); color: var(--ink); font-weight: 700; cursor: pointer; font-size: .95rem; }
.btn:hover { filter: brightness(1.07); }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn.big { font-size: 1.15rem; padding: 13px 30px; display: block; width: 100%; margin: 14px 0 6px; }
.btn.ghost { background: transparent; color: #fff; border: 1px solid rgba(255,255,255,.4); }
.btn.small { padding: 6px 12px; font-size: .85rem; }
.btn.ok { background: var(--ok); color: #fff; }
.btn.warn { background: var(--warn); color: #fff; }
.btn.on { outline: none; }   /* 선택 시 두꺼운 흰색 아웃라인 미적용(얇은 테두리·글로우로만 구분) */

/* 인원/난이도 선택 버튼: 비선택=외곽선, 선택=골드 채움+글로우+확대로 명확히 구분 */
.count-btn, .diff-btn { background: transparent; color: #fff; border: 2px solid rgba(255,255,255,.5);
  padding: 9px 22px; white-space: nowrap; transition: transform .12s, background .12s, box-shadow .12s; }
.count-btn:hover, .diff-btn:hover { background: rgba(255,255,255,.14); }
.count-btn.on, .diff-btn.on { background: var(--gold); color: var(--ink); border-color: #fff;
  box-shadow: 0 0 0 3px rgba(217,180,74,.45), 0 4px 14px rgba(0,0,0,.35); transform: scale(1.12); }
.diff-btn { padding: 8px 16px; }
/* 정렬 토글: '그룹'(2자)이 줄바꿈 없이 들어가는 최소 폭으로만 고정(공간 절약).
   단일 토글이라 .on 의 확대(scale)·글로우는 해제해 컴팩트하게 유지. */
#sort-mode { min-width: 3.7em; text-align: center; transform: none; box-shadow: none; border-color: transparent; outline: none; }

/* ── 게임 화면 ── */
#screen-game { flex-direction: column; background: linear-gradient(160deg, var(--felt), var(--felt2)); }

#opponents { position: relative; height: 78px; }
.opp { position: absolute; background: rgba(0,0,0,.3); border-radius: 10px; padding: 6px 10px; min-width: 120px; }
.opp.active { outline: 2px solid var(--gold); box-shadow: 0 0 12px rgba(217,180,74,.6); }
.opp.seat-top { top: 6px; left: 50%; transform: translateX(-50%); }
.opp.seat-left { top: 6px; left: 8px; }
.opp.seat-right { top: 6px; right: 8px; }
.opp.seat-top-left { top: 6px; left: 25%; transform: translateX(-50%); }
.opp.seat-top-right { top: 6px; left: 75%; transform: translateX(-50%); }
.opp-name { font-weight: 700; }
.badge-meld { font-size: .65rem; background: var(--ok); padding: 1px 5px; border-radius: 6px; }
.opp-meta { font-size: .75rem; color: #bcd6ef; margin: 2px 0; }
.opp-tiles { display: flex; flex-wrap: wrap; gap: 1px; }
.mini-tile { width: 14px; height: 20px; display: inline-block; }
.mini-tile .tile-svg { width: 14px; height: 20px; }

/* 테이블 */
#table { flex: 1; display: flex; flex-direction: column; padding: 6px 12px 8px; min-height: 0; }
.deck-info { font-size: .82rem; color: #cfe2f4; white-space: nowrap; }
.deck-info b { color: #fff; }

.board { flex: 1; background: rgba(0,0,0,.18); border-radius: 12px; margin: 4px 0;
  padding: 12px; display: flex; flex-wrap: wrap; align-content: flex-start; gap: 12px; overflow-y: auto; min-height: 120px; }
.set { display: flex; gap: 2px; background: rgba(255,255,255,.07); padding: 6px; border-radius: 9px; border: 2px solid transparent; }
.set.invalid { border-color: var(--warn); box-shadow: 0 0 8px rgba(192,57,43,.6); }
.set.is-new { background: rgba(217,180,74,.16); }
.new-set-zone { min-width: 70px; min-height: calc(var(--tile-h) + 16px); border: 2px dashed rgba(255,255,255,.35);
  border-radius: 9px; display: flex; align-items: center; justify-content: center; color: #bcd6ef; font-size: .8rem; padding: 6px; }

.turn-indicator { font-weight: 700; color: var(--gold); font-size: .9rem; white-space: nowrap; }
.turn-indicator.mine { color: #fff; }

/* 타일 */
.tile { width: var(--tile-w); height: var(--tile-h); display: inline-block; cursor: grab; touch-action: none; user-select: none; }
.tile .tile-svg { width: var(--tile-w); height: var(--tile-h); display: block; }
.tile.dragging-src { opacity: .3; }
.tile-bg { fill: var(--ivory); stroke: #cbb98a; stroke-width: 1.5; }
.tile-num { font-size: 30px; font-weight: 800; }
.tile-joker { font-size: 26px; fill: #b8860b; font-weight: 800; }
.tile-joker-label { font-size: 9px; fill: #8a6d10; font-weight: 700; letter-spacing: 1px; }
.tile-back-bg { fill: var(--ivory); stroke: #cbb98a; stroke-width: 1.5; }
.tile-back-inner { fill: #e7dcb8; }
.tile-back-mark { font-size: 22px; fill: #b08d2e; font-weight: 800; }

.tile.selected { transform: translateY(-10px); }
.tile.selected .tile-bg { stroke: var(--gold); stroke-width: 3.5; }
.drag-ghost { position: fixed; z-index: 999; pointer-events: none; opacity: .92; transform: scale(1.06); filter: drop-shadow(0 6px 8px rgba(0,0,0,.5)); }

/* 내 패널 */
#my-panel { background: rgba(0,0,0,.25); padding: 8px 12px 12px; }
.controls { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 6px; flex-wrap: wrap; }
.sort-toggle { display: flex; align-items: center; gap: 6px; }
.sort-toggle > span { font-size: .85rem; color: #cfe2f4; }
.timer { font-weight: 800; font-size: 1.1rem; color: #fff; min-width: 4em; text-align: center; }
.timer.warn { color: #ffb3b3; animation: blink .6s steps(2) infinite; }
@keyframes blink { 50% { opacity: .35; } }
.action-btns { display: flex; gap: 4px; flex-shrink: 0; }
/* 긴 라벨('턴 종료(가져오기)') 줄바꿈 방지 + .btn 기본 margin 제거(버튼 간 과한 간격·우측 여백 문제 해소) */
.action-btns .btn { white-space: nowrap; margin: 0; }
/* 한 줄 3분할: 잔여(좌) · 시간(중앙, flex 확장) · 취소/턴종료(우) */
.turn-actions { display: flex; align-items: center; gap: 8px; flex-wrap: nowrap; width: 100%; }
.turn-actions .deck-info { flex-shrink: 0; }                        /* 좌측 */
.turn-actions .timer { flex: 1; text-align: center; min-width: 0; } /* 중앙(남는 공간 확장) */

.hand { background: rgba(0,0,0,.22); border-radius: 10px; padding: 8px; min-height: calc(var(--tile-h) * 2 + 18px); }
.rack-row { display: flex; flex-wrap: wrap; gap: 3px; min-height: var(--tile-h); padding: 2px 0; align-items: center; }
.rack-row.melds { border-bottom: 1px dashed rgba(255,255,255,.18); margin-bottom: 4px; padding-bottom: 6px; }
.meld-gap { width: 16px; display: inline-block; }

.info-bar { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.chip { background: rgba(255,255,255,.14); padding: 3px 9px; border-radius: 20px; font-size: .78rem; }
.chip.warn { background: var(--warn); }
.chip.ok-chip { background: var(--ok); }

/* 토스트 */
.toast { position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%) scale(.96);
  background: rgba(0,0,0,.88); color: #fff; padding: 18px 32px; border-radius: 14px;
  font-size: 1.25rem; font-weight: 700; text-align: center; max-width: min(92vw, 620px); white-space: pre;
  border: 1px solid rgba(255,255,255,.18); box-shadow: 0 10px 40px rgba(0,0,0,.5);
  opacity: 0; transition: opacity .2s, transform .2s; pointer-events: none; z-index: 950; }
.toast.show { opacity: 1; transform: translate(-50%, -50%) scale(1); }

/* 모달 */
.modal-root { position: fixed; inset: 0; display: none; align-items: center; justify-content: center;
  background: rgba(0,0,0,.55); z-index: 900; }
.modal-root.show { display: flex; }
.rk-modal { background: #103a5e; border: 2px solid var(--gold); border-radius: 16px; padding: 22px 26px;
  max-width: 92vw; max-height: 88vh; overflow-y: auto; text-align: center; box-shadow: 0 14px 50px rgba(0,0,0,.5); }
.rk-modal h2 { margin: 0 0 10px; color: var(--gold); }
.rules { text-align: left; line-height: 1.7; }
.pick-list { display: flex; flex-direction: column; gap: 8px; margin: 10px 0; }
.pick-row { display: flex; align-items: center; justify-content: space-between; gap: 18px; }
.pick-tile .tile-svg, .res-tiles .tile-svg, .mini .tile-svg { width: 30px; height: 42px; }
.res-list { display: flex; flex-direction: column; gap: 10px; margin: 12px 0; }
.res-row { background: rgba(255,255,255,.08); border-radius: 10px; padding: 8px 12px; text-align: left; }
.res-name { font-weight: 700; }
.res-score { color: var(--gold); }
.res-tiles { display: flex; flex-wrap: wrap; gap: 2px; margin-top: 4px; }
.res-tiles .mini { width: 30px; height: 42px; }
.win-line { color: var(--gold); font-weight: 700; }
.rank-list { display: flex; flex-direction: column; gap: 8px; margin: 14px 0; }
.rank-row { display: flex; align-items: center; gap: 12px; background: rgba(255,255,255,.08); border-radius: 10px; padding: 10px 14px; }
.rank-row.rank-1 { background: rgba(217,180,74,.28); }
.rank-pos { font-weight: 800; min-width: 60px; }
.rank-name { flex: 1; text-align: left; font-weight: 700; }
.rank-score { color: var(--gold); font-weight: 700; }

/* ── 모바일: 타일 축소(보드=랙 동일), 상대패널 가로 스크롤, 버튼 축소 ── */
@media (max-width: 640px) {
  :root { --tile-w: 34px; --tile-h: 48px; }   /* 보드·랙 타일 함께 축소(동일 크기) */
  /* 바닥패 세트 간 여백 축소로 화면 활용 극대화 */
  .board { gap: 5px; padding: 8px; }
  /* 세트 내부 패딩 축소(새 셋트 존도 함께 줄여 높이 일치 유지: 패딩3+테두리2 = 상하 10px) */
  .set { padding: 3px; }
  .new-set-zone { padding: 3px; min-height: calc(var(--tile-h) + 10px); }
  .hand { padding: 6px; }
  .rack-row { gap: 2px; }
  .meld-gap { width: 10px; }
  /* 상대 패널: 절대배치 해제 → 가로 한 줄 스크롤(4인 겹침 방지) */
  #opponents { display: flex; height: auto; overflow-x: auto; overflow-y: hidden; gap: 6px; padding: 4px 6px; }
  .opp, .opp.seat-top, .opp.seat-left, .opp.seat-right, .opp.seat-top-left, .opp.seat-top-right {
    position: static; left: auto; right: auto; top: auto; transform: none; flex: 0 0 auto; min-width: auto; }
  .opp-tiles { display: none; }   /* 모바일: 상대 미니 타일 숨겨 패널 컴팩트하게 */
  /* 상대 이름/정보 폰트 축소(모바일 패널 컴팩트) */
  .opp-name { font-size: .85rem; }
  .opp-meta { font-size: .68rem; }
  /* 취소/완료·정렬 버튼 축소로 공간 확보 */
  .action-btns .btn { padding: 6px 11px; font-size: .82rem; }
  .btn.small { padding: 5px 10px; font-size: .8rem; }
  .sort-toggle .diff-btn { padding: 5px 9px; font-size: .8rem; }
  /* 타이머 폭 축소: 잔여·시간·취소·턴종료 한 줄이 화면을 넘지 않도록 */
  .turn-actions .timer { min-width: 2.4em; font-size: 1rem; }
  .chip-draw-hint { display: none; }   /* 모바일: 안내 문구 숨겨 공간 확보 */
  .chip.ok-chip { display: none; }     /* 모바일: '완료 가능' 칩 숨김 */
  /* 토스트: 폰트·패딩 축소로 각 줄이 좁은 뷰포트에 여유롭게 들어오도록 */
  .toast { font-size: 1.05rem; padding: 14px 20px; }
}
@media (max-width: 430px) {
  :root { --tile-w: 28px; --tile-h: 40px; }
  /* 좁은 화면: 시작박스 여백·버튼 축소로 인원/난이도가 한 줄에 들어오도록 */
  .start-box { padding: 26px 16px; }
  .count-pick { gap: 6px; }
  .count-btn, .diff-btn { padding: 7px 13px; font-size: .9rem; }
}
