/* 대결 모드 화면(js/game/duel.js) — 16:9 전자칠판 기준. 색·크기 값은 css/base.css의 토큰을 쓴다.
 * 화면은 창(또는 transform이 걸린 상자)을 가득 채운다: .duel { position: fixed; inset: 0 }.
 * 팀 색(--blue/--red)은 팀 표시(팀명·4px 띠·소유 영역)에만. 발사 단추는 두 팀 모두 청록. 신호 색은 판의 결과에만.
 * 두 팀 자리의 안쪽 배치는 똑같다: [쏘는 바다 | 단면도(보여 주기)] / 조작부(① 자리 · ② 방법 · ③ 세기 + 발사, 폭에 따라 두세 줄).
 * 글씨·단추 크기는 이 화면의 크기로 정한다(container duel): 칠판(높이 900 이상)은 카드 28px·단추 68px. */
.duel {
  position: fixed;
  inset: 0;
  z-index: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  container: duel / size; /* 아래 크기 조건은 창이 아니라 이 화면의 크기로 판단(점검 상자에서도 같게) */
}
.duel-stage { position: relative; flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; }

/* 공통 단추: 주 단추(청록 채움) · 보조 단추(흰 바탕 + 경계선) */
.duel-btn {
  min-width: calc(var(--touch) * 2);
  min-height: var(--touch);
  padding: 6px 28px;
  border: 2px solid var(--control-line);
  border-radius: var(--r-btn);
  background: var(--surface);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 24px;
  font-weight: 700;
  line-height: 1.2;
  cursor: pointer;
  touch-action: manipulation;
  transition: background-color var(--t-pick);
}
.duel-btn:hover:not(:disabled) { background: var(--accent-soft); }
.duel-btn--main { background: var(--accent); border-color: var(--accent); color: #fff; }
.duel-btn--main:hover:not(:disabled) { background: var(--accent-2); }
.duel-btn:disabled { opacity: 0.45; cursor: default; }
.duel-home {
  min-height: var(--touch);
  padding: 4px 18px;
  border: 2px solid var(--control-line);
  border-radius: var(--r-btn);
  background: var(--surface);
  color: var(--ink);
  font-size: 18px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  touch-action: manipulation;
}
.duel-home:hover { background: var(--accent-soft); }

/* ── 세로 화면 · 낮은 가로 화면: 대결 안내 한 줄 ── */
.duel-phone {
  display: none;
  position: absolute;
  inset: 0;
  z-index: 50;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--s5);
  padding: var(--s5) var(--s4);
  background: var(--bg);
  text-align: center;
}
.duel.is-phone .duel-phone { display: flex; }
.duel.is-phone .duel-stage { visibility: hidden; }
.duel-phone-text { margin: 0; max-width: 32em; font-size: 18px; font-weight: 600; line-height: 1.45; word-break: keep-all; }
.duel-phone .duel-btn { font-size: 20px; }

/* ── 준비 화면 ── */
.duel-setup {
  margin: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--s6);
  padding: var(--s6) var(--s7);
  max-width: 100%;
  background: var(--surface);
  border: 1px solid var(--divider);
  border-radius: var(--r-panel);
}
.duel-h { margin: 0; font-size: 44px; font-weight: 700; color: var(--ink); }
.duel-h-game { font-family: var(--font-title); font-weight: 800; color: var(--sea); }
.duel-setup-groups { display: grid; grid-template-columns: auto auto; align-items: center; gap: var(--s4) var(--s5); }
.duel-seg { display: contents; }
.duel-seg-label { justify-self: end; font-size: 24px; font-weight: 600; color: var(--ink-2); }
.duel-seg-opts { display: flex; flex-wrap: wrap; gap: var(--s3); }
.duel-opt {
  position: relative;
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-width: calc(var(--touch) * 1.8);
  min-height: var(--touch);
  padding: 4px 18px;
  border: 2px solid var(--control-line);
  border-radius: var(--r-btn);
  background: var(--surface);
  color: var(--ink);
  font-size: 22px;
  font-weight: 600;
  line-height: 1.2;
  cursor: pointer;
  touch-action: manipulation;
}
.duel-opt:hover { background: var(--accent-soft); }
.duel-opt-sub { font-size: 15px; font-weight: 500; color: var(--ink-2); }
.duel-opt.is-on { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); background: var(--accent-soft); color: var(--accent-2); font-weight: 700; }
.duel-opt.is-on::after {
  content: ''; position: absolute; top: 6px; right: 6px; width: 16px; height: 16px; border-radius: 50%;
  background: var(--accent) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'%3E%3Cpath d='M24 52l17 17 36-38' fill='none' stroke='%23fff' stroke-width='14' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center / 100% no-repeat;
}
.duel-actions { display: flex; gap: var(--s5); }

/* ── 가림 화면: 그 팀 색 바탕(팀 표시) ── */
.duel-stage.is-gate { background: var(--sea); color: #fff; }
.duel-stage.gate-blue { background: var(--blue); }
.duel-stage.gate-red { background: var(--red); }
.duel-gate { margin: auto; display: flex; flex-direction: column; align-items: center; gap: var(--s6); padding: var(--s5); text-align: center; }
.duel-gate-text { margin: 0; font-size: 48px; font-weight: 700; line-height: 1.35; word-break: keep-all; }
.duel-gate .duel-btn { border-color: #fff; background: #fff; color: var(--ink); font-size: 30px; padding: 10px 40px; }
.duel-corner { position: absolute; right: var(--s4); top: var(--s3); }

/* ── 숨기기 시간: 한 팀의 배치 ── */
.duel-placing { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; gap: var(--s3); padding: var(--s3) var(--s5) var(--s4); border-top: 4px solid var(--team, var(--accent)); }
.duel-stage.team-blue { --team: var(--blue); }
.duel-stage.team-red { --team: var(--red); }
.duel-place-head { display: flex; align-items: center; justify-content: center; gap: var(--s5); }
.duel-place-title { margin: 0; font-size: 38px; font-weight: 700; color: var(--team); }
.duel-timer {
  min-width: 8em;
  padding: 6px 18px;
  border: 2px solid var(--control-line);
  border-radius: var(--r-btn);
  background: var(--surface);
  font-size: 28px;
  font-weight: 700;
  text-align: center;
  font-variant-numeric: tabular-nums;
}
.duel-timer.is-low { border-color: var(--ink); background: var(--ink); color: #fff; }
.duel-place-head .duel-home { margin-left: auto; }
.duel-place-head .duel-place-title { margin-left: auto; }
.duel-place-sea { flex: 1 1 auto; min-height: 0; width: 100%; max-width: 1200px; margin: 0 auto; padding: var(--s2); }
.duel-place-foot { display: flex; align-items: center; justify-content: center; gap: var(--s5); }
.duel-line { margin: 0; min-height: 1.4em; font-size: 26px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ── 대결 화면(16:9, 실시간 — 차례 없음) ──
 * 위 띠 = 청팀(팀명 · 남은 배 · 남은 발 · 배 그림) | 제목 | 홍팀(같은 순서). 그 아래 좌우 절반 = 팀 자리(같은 배치).
 * 두 팀이 동시에 누르므로 자리마다 터치를 따로 받는다(touch-action: manipulation, 문서 전체를 막지 않음). */
.duel-play {
  --ctl-card-fs: 22px; --ctl-msg-fs: 24px; --ctl-label-fs: 18px; --ctl-combo-fs: 20px; --ctl-log-fs: 18px;
  --duel-team-fs: 30px; --duel-stat-fs: 20px;
  position: relative; flex: 1 1 auto; min-height: 0; display: grid; grid-template-rows: auto minmax(0, 1fr);
}
@container duel (min-height: 900px) {
  .duel-play { --ctl-card-fs: 28px; --ctl-msg-fs: 30px; --ctl-label-fs: 22px; --ctl-combo-fs: 24px; --ctl-log-fs: 22px; --duel-team-fs: 40px; --duel-stat-fs: 24px; --touch: 68px; }
}
.duel-top {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: stretch;
  background: var(--surface);
  border-bottom: 1px solid var(--divider);
}
.duel-side {
  display: flex;
  align-items: center;
  gap: var(--s5);
  min-width: 0;
  padding: 6px var(--s5);
  border-top: 4px solid var(--team); /* 4px 팀색 띠 */
}
.side-blue { --team: var(--blue); }
.side-red { --team: var(--red); }
.duel-side-head { display: flex; flex-direction: column; align-items: flex-start; line-height: 1.2; min-width: 0; }
.duel-team { font-size: var(--duel-team-fs); font-weight: 700; color: var(--team); }
.duel-side-sub { display: flex; align-items: center; gap: var(--s3); white-space: nowrap; }
.duel-stat { font-size: var(--duel-stat-fs); font-weight: 600; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.duel-shots { font-weight: 700; color: var(--ink); }
.duel-side.is-out .duel-shots { color: var(--ink-2); } /* 발을 다 씀(글씨로도 '남은 발 0') */
.duel-ships { min-width: 0; margin-left: auto; }
.duel-ships .sb-ships { flex-wrap: nowrap; }
.duel-ships .sb-ships-title { display: none; } /* 머리글은 팀 이름이 대신한다 */
.duel-ships .sb-pic { height: 40px; }
.duel-ships .sb-ship-name { font-size: 15px; }

/* 가운데 칸: 양옆 팀 칸과 같은 4px 윗줄(중립 회색)과 같은 위아래 여백을 두어, 제목·'처음으로'가 팀 이름 줄과 같은 높이 가운데에 온다.
   승패 줄(.duel-status)은 판이 끝났을 때만 자리를 차지한다(비어 있으면 숨김 — 빈 줄이 제목을 위로 밀어 올리지 않게). */
.duel-center { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: var(--s1); padding: 6px var(--s5); border-top: 4px solid var(--divider); border-left: 1px solid var(--divider); border-right: 1px solid var(--divider); }
.duel-titlerow { display: flex; align-items: center; gap: var(--s4); }
.duel-title { margin: 0; font-family: var(--font-title); font-size: 30px; font-weight: 800; color: var(--sea); line-height: 1.2; }
.duel-titlerow .duel-home { font-size: 16px; padding: 2px 14px; } /* 글씨는 작게(눈에 덜 띄게), 누르는 크기는 64px 그대로 */
.duel-status:empty { display: none; }
.duel-status { font-size: 28px; font-weight: 700; line-height: 1.3; white-space: nowrap; color: var(--ink); }
.duel-status[data-team="blue"] { color: var(--blue); }
.duel-status[data-team="red"] { color: var(--red); }
.duel-status[data-team="draw"] { color: var(--ink); }

/* 좌우 절반: 팀 자리(같은 배치). 가운데에 분명한 구분선 */
.duel-halves { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); min-height: 0; }
.duel-station {
  --team: var(--accent);
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  padding: var(--s2) var(--s4) 0;
  border-top: 4px solid var(--team);
  touch-action: manipulation;
  transition: background-color var(--t-result);
}
.station-blue { --team: var(--blue); --team-soft: var(--blue-soft); border-right: 4px solid var(--ink-2); }
.station-red { --team: var(--red); --team-soft: var(--red-soft); } /* 발사는 두 팀 모두 공통 행동색(청록) — 팀색은 팀명·띠·소유 표시에만(2차 검수) */
.duel-station.is-busy { background: var(--team-soft); } /* 그 팀이 쏘는 중(공기 흐름) — 그 자리만 잠김 */
.duel-st-body { flex: 1 1 auto; min-height: 0; display: grid; gap: var(--s4); grid-template-columns: minmax(0, 2.7fr) minmax(0, 1fr); } /* [바다 | 단면도] — 단면도가 보여 주기 전용이 되어 쏘는 바다에 폭을 준다(칠판 1920에서 소리 40px·축 이름 24px 이상) */
.duel-sea { position: relative; display: flex; flex-direction: column; gap: 4px; min-height: 0; min-width: 0; }
.duel-sea-name { position: absolute; left: 0; right: 0; bottom: 100%; margin-bottom: 8px; font-size: calc(var(--ctl-label-fs) + 2px); font-weight: 700; text-align: center; line-height: 1.25; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--team); }
.duel-board {
  flex: 1 1 auto; min-height: 0; padding: 40px 4px 4px; display: flex; align-items: center; justify-content: center;
  --touch: 44px; /* 쏘는 바다의 칸은 누르는 곳이 아니다(board.js play 모드) — 두 자리가 너비를 나누므로 칸이 더 작아질 수 있게 */
}
.duel-board > .sb.sb-fit { height: auto; } /* 높이 맞추기는 board.js가 이 상자 높이로 한다 */
.duel-mouthcol { min-height: 0; min-width: 0; display: flex; flex-direction: column; overflow: hidden; }
.duel-mouth { position: relative; flex: 1 1 auto; min-height: 0; min-width: 0; --mouth-label: 20px; }
.duel-mouth .mouth-svg { position: absolute; inset: 0; } /* 상자 크기에 맞춤(그림 비율대로 가운데) */

/* 팀 자리 아래: 조작부(기록 띠 · 한 줄 문구 · 요약 줄 · 방법 카드 / 세기 카드 + 발사) */
.duel-st-dock { flex: 0 0 auto; min-width: 0; }
.duel-st-dock .ctl { padding: 2px 4px var(--s2); gap: 6px; }
.duel-st-dock .ctl-bar { row-gap: 6px; column-gap: var(--s4); } /* 묶음 단위로 줄이 넘어간다: ① / ② ③+발사 또는 ① / ② / ③+발사 */
.duel-st-dock .ctl-fire { white-space: nowrap; }
.duel-st-dock .ctl-log--strip .ctl-log-item:nth-last-child(n+3) { display: none; } /* 대결: 최근 두 발 */
/* 발을 다 쓴 팀: 카드·발사가 잠기고(조작부가 disabled) 한 줄이 '상대를 기다려요' */
.duel-station.is-out .ctl-cards, .duel-station.is-out .ctl-fire { opacity: 0.45; }
.duel-station.is-out .ctl-msg { color: var(--ink-2); }

/* 1366×768·1280×800처럼 낮은 가로 화면: 기록 띠를 접고 위 띠를 줄인다 */
@container duel (max-height: 860px) {
  .duel-play { --duel-team-fs: 26px; --duel-stat-fs: 18px; }
  .duel-title { font-size: 26px; }
  .duel-status { font-size: 22px; }
  .duel-ships .sb-pic { height: 30px; }
  .duel-ships .sb-ship-name { display: none; }
  .duel-st-dock .ctl-log--strip { display: none; } /* 판 위 흔적이 기록을 대신한다 — 단면도·판에 자리를 준다 */
  .duel-st-dock .ctl-group-label { font-size: 15px; }
  .duel-gate-text { font-size: 38px; }
}
