/* style.css — 끝말잇기 모바일 우선 반응형 + 다크모드 */

:root {
  --bg: #f1f5f9;
  --card: #ffffff;
  --ink: #1e293b;
  --muted: #64748b;
  --line: #e2e8f0;
  --brand: #4f46e5;
  --brand-ink: #ffffff;
  --player: #4f46e5;
  --ai: #0d9488;
  --p2: #db2777;
  --danger: #dc2626;
  --ok: #16a34a;
  --shadow: 0 8px 30px rgba(15, 23, 42, 0.12);
  --radius: 16px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f172a;
    --card: #1e293b;
    --ink: #f1f5f9;
    --muted: #94a3b8;
    --line: #334155;
    --brand: #6366f1;
    --player: #818cf8;
    --ai: #2dd4bf;
    --p2: #f472b6;
    --shadow: 0 8px 30px rgba(0, 0, 0, 0.4);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  font-family: "Malgun Gothic", "맑은 고딕", "Apple SD Gothic Neo", system-ui, sans-serif;
  background: var(--bg);
  color: var(--ink);
  overscroll-behavior: none;
}

#app {
  height: 100dvh;
  max-width: 480px;
  margin: 0 auto;
  position: relative;
  overflow: hidden;
}

/* ---- 화면 전환 ---- */
.screen {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  padding: env(safe-area-inset-top) 16px calc(16px + env(safe-area-inset-bottom));
}
.screen.active { display: flex; }

/* ---- 시작 화면 ---- */
#screen-start { justify-content: center; align-items: center; }
.start-card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 32px 24px;
  width: 100%;
  text-align: center;
}
.logo {
  font-size: 44px;
  font-weight: 800;
  letter-spacing: 2px;
  color: var(--brand);
}
.logo span { color: var(--ai); }
.subtitle { color: var(--muted); margin: 8px 0 28px; font-size: 15px; }

.field { text-align: left; margin-bottom: 22px; }
.field > label {
  display: block;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 8px;
  font-weight: 600;
}

.segmented {
  display: flex;
  gap: 8px;
  background: var(--bg);
  padding: 4px;
  border-radius: 12px;
}
.seg {
  flex: 1;
  border: 0;
  padding: 12px;
  border-radius: 9px;
  background: transparent;
  color: var(--muted);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}
.seg.active {
  background: var(--card);
  color: var(--brand);
  box-shadow: 0 2px 6px rgba(0,0,0,0.08);
}
/* 최강 난이도: 선택했을 때 경고색으로 티를 낸다 */
.seg-danger.active { color: var(--danger); }

.check-row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin-top: 10px;
  font-size: 13px;
  color: var(--ink);
  cursor: pointer;
  line-height: 1.45;
}
.check-row input { margin-top: 2px; accent-color: var(--brand); flex-shrink: 0; }
.check-row em { font-style: normal; color: var(--muted); font-size: 12px; }

.field-note {
  font-size: 12px;
  line-height: 1.5;
  color: var(--muted);
  margin: 8px 2px 0;
}

input[type="range"] { width: 100%; accent-color: var(--brand); }
#time-label { color: var(--brand); font-weight: 700; }

.btn-primary {
  width: 100%;
  border: 0;
  padding: 16px;
  border-radius: 14px;
  background: var(--brand);
  color: var(--brand-ink);
  font-size: 17px;
  font-weight: 700;
  cursor: pointer;
  margin-top: 4px;
}
.btn-primary:active { transform: scale(0.98); }
.rules-hint { color: var(--muted); font-size: 12px; margin: 16px 0 0; }

.btn-secondary {
  width: 100%;
  border: 0;
  padding: 13px;
  border-radius: 14px;
  background: transparent;
  color: var(--muted);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  margin-top: 8px;
}

/* ---- 랭킹 ---- */
.rank-save {
  display: flex;
  gap: 8px;
  margin: 0 0 8px;
}
.rank-save[hidden] { display: none; }
#rank-name {
  flex: 1;
  min-width: 0;
  border: 2px solid var(--line);
  background: var(--bg);
  color: var(--ink);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 14px;
  outline: none;
}
#rank-name:focus { border-color: var(--brand); }
.btn-rank-save {
  border: 0;
  background: var(--ai);
  color: #fff;
  border-radius: 10px;
  padding: 0 18px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  flex-shrink: 0;
}
.rank-saved-msg {
  font-size: 13px;
  font-weight: 700;
  color: var(--ai);
  margin: 0 0 12px;
}
.rank-saved-msg:empty { display: none; }

.ranking-title { margin: 0 0 12px; font-size: 24px; }
.ranking-tabs { margin-bottom: 10px; }
.ranking-sub { color: var(--muted); font-size: 12px; margin: 0 0 14px; }
.ranking-list {
  list-style: none;
  margin: 0 0 20px;
  padding: 0;
  text-align: left;
  max-height: 55dvh;
  overflow-y: auto;
}
.ranking-list li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: 10px;
  font-size: 14px;
}
.ranking-list li:nth-child(odd) { background: var(--bg); }
.ranking-list li.mine {
  background: color-mix(in srgb, var(--brand) 14%, transparent);
  font-weight: 700;
}
.ranking-list .rank-no { width: 26px; font-weight: 800; color: var(--brand); flex-shrink: 0; }
.ranking-list .rank-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ranking-list .rank-turns { font-weight: 700; flex-shrink: 0; }
.ranking-list .rank-tag { font-size: 11px; color: var(--muted); flex-shrink: 0; }

.start-record, .result-record {
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  margin: 12px 0 0;
}
.start-record:empty, .result-record:empty { display: none; }
.result-record { margin: 0 0 18px; }

/* ---- 게임 화면 ---- */
.game-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 2px 12px;
}
.icon-btn {
  border: 0;
  background: var(--card);
  color: var(--muted);
  width: 38px;
  height: 38px;
  border-radius: 10px;
  font-size: 16px;
  cursor: pointer;
  flex-shrink: 0;
}
.header-info { display: flex; align-items: center; gap: 8px; }
.turn-count { font-weight: 700; font-size: 14px; }
.badge {
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 999px;
  background: #f59e0b;
  color: #fff;
  font-weight: 700;
}
.badge.hidden { display: none; }

.timer-wrap {
  flex: 1;
  height: 8px;
  background: var(--line);
  border-radius: 999px;
  overflow: hidden;
}
.timer-bar {
  height: 100%;
  width: 100%;
  background: var(--ok);
  transform-origin: left;
  transition: width 0.2s linear, background 0.3s;
}

.chain {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 8px 2px 12px;
}
.bubble {
  max-width: 78%;
  padding: 12px 16px;
  border-radius: 18px;
  font-size: 18px;
  font-weight: 600;
  line-height: 1.2;
  box-shadow: var(--shadow);
  animation: pop 0.2s ease;
}
.bubble .who { display: block; font-size: 11px; font-weight: 700; opacity: 0.8; margin-bottom: 2px; }
/* 로마자 표기 (누르면 다시 읽어준다) */
.bubble .roman {
  display: block;
  margin-top: 3px;
  padding: 0;
  border: 0;
  background: none;
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.2px;
  color: inherit;
  opacity: 0.7;
  cursor: pointer;
  text-align: left;
}
.bubble .roman:hover { opacity: 1; }
.bubble .roman:active { transform: scale(0.97); }

/* 단어 아래 붙는 짧은 뜻풀이 */
.bubble .meaning {
  display: block;
  margin-top: 4px;
  font-size: 12px;
  font-weight: 500;
  line-height: 1.45;
  opacity: 0.88;
  word-break: keep-all;
}
.bubble .meaning:empty { display: none; }
.bubble.ai {
  align-self: flex-start;
  background: var(--card);
  color: var(--ink);
  border-bottom-left-radius: 6px;
}
.bubble.ai .who { color: var(--ai); }
.bubble.player,
.bubble.p1 {
  align-self: flex-end;
  background: var(--player);
  color: #fff;
  border-bottom-right-radius: 6px;
}
.bubble.player .who,
.bubble.p1 .who { color: rgba(255,255,255,0.85); }

/* 로컬 2인전: P2 는 반대쪽에 다른 색으로 */
.bubble.p2 {
  align-self: flex-start;
  background: var(--p2);
  color: #fff;
  border-bottom-left-radius: 6px;
}
.bubble.p2 .who { color: rgba(255,255,255,0.85); }

/* 제시어: 가운데 중립 표시 */
.bubble.system {
  align-self: center;
  background: transparent;
  color: var(--muted);
  box-shadow: none;
  border: 1px dashed var(--line);
  font-size: 16px;
  text-align: center;
}
.bubble.system .who { color: var(--muted); }

@keyframes pop {
  from { transform: translateY(6px) scale(0.96); opacity: 0; }
  to { transform: none; opacity: 1; }
}

.play-area {
  padding-top: 8px;
  border-top: 1px solid var(--line);
}
/* 로컬 2인전에서 지금 누구 차례인지 크게 알린다 */
.turn-label {
  text-align: center;
  font-size: 15px;
  font-weight: 800;
  padding: 8px;
  border-radius: 10px;
  margin-bottom: 8px;
  background: color-mix(in srgb, var(--player) 14%, transparent);
  color: var(--player);
}
.turn-label.p2 {
  background: color-mix(in srgb, var(--p2) 14%, transparent);
  color: var(--p2);
}

.need-hint { font-size: 14px; color: var(--muted); text-align: center; margin-bottom: 6px; }
.need-hint strong {
  display: inline-block;
  min-width: 28px;
  font-size: 20px;
  color: var(--brand);
}
.status-msg {
  min-height: 20px;
  text-align: center;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 8px;
  color: var(--danger);
}
.status-msg.thinking { color: var(--muted); }

.input-row { display: flex; gap: 8px; }
#word-input {
  flex: 1;
  border: 2px solid var(--line);
  background: var(--card);
  color: var(--ink);
  border-radius: 12px;
  padding: 14px 16px;
  font-size: 17px;
  outline: none;
}
#word-input:focus { border-color: var(--brand); }
#word-input:disabled { opacity: 0.6; }
.btn-submit {
  border: 0;
  background: var(--brand);
  color: #fff;
  border-radius: 12px;
  padding: 0 22px;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
}
.btn-submit:disabled { opacity: 0.5; }

/* ---- 결과 화면 ---- */
#screen-result { justify-content: center; align-items: center; }
.result-card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 40px 28px;
  text-align: center;
  width: 100%;
}
.result-emoji { font-size: 64px; }
#result-title { font-size: 28px; margin: 12px 0 8px; }
.result-detail { color: var(--muted); margin: 0 0 12px; font-size: 15px; }

/* 진 쪽이 낼 수 있었던 단어들 */
.result-words {
  font-size: 13px;
  line-height: 1.6;
  color: var(--muted);
  background: var(--bg);
  border-radius: 10px;
  padding: 10px 12px;
  margin: 0 0 24px;
  word-break: keep-all;
}
.result-words:empty { display: none; }
/* 애초에 이을 단어가 없었던 경우 */
.result-words.kill {
  color: var(--danger);
  font-weight: 700;
  background: color-mix(in srgb, var(--danger) 12%, transparent);
}

.time-left {
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  min-width: 42px;
  text-align: right;
  flex-shrink: 0;
}
