/* ===== 기본 ===== */
* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --felt-1: #1a5c38;
  --felt-2: #0e3d24;
  --surface: rgba(0, 0, 0, 0.28);
  --surface-2: rgba(0, 0, 0, 0.42);
  --text: #f2f6f0;
  --text-dim: #b9ccbd;
  --accent: #ffd166;
  --good: #6ee7a0;
  --bad: #ff8f8f;
  --man: #b3282d;
  --pin: #1d5fa8;
  --sou: #1e7e45;
  /* 손패 13장 + 쯔모 1장이 화면 폭에 정확히 들어가도록 계산 */
  --tile-w: clamp(19px, calc((100vw - 96px) / 14), 54px);
}

html { -webkit-text-size-adjust: 100%; }

body {
  font-family: "Pretendard", "Apple SD Gothic Neo", "Noto Sans KR", system-ui, sans-serif;
  background: radial-gradient(ellipse at 50% 0%, var(--felt-1), var(--felt-2) 75%);
  min-height: 100vh;
  color: var(--text);
  touch-action: manipulation;
  padding-bottom: env(safe-area-inset-bottom);
}

main { max-width: 860px; margin: 0 auto; padding: 12px 12px 32px; }

/* ===== 헤더 ===== */
.app-header {
  max-width: 860px; margin: 0 auto;
  padding: 14px 12px 6px;
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px 16px;
}
.app-header h1 { font-size: clamp(17px, 4.5vw, 24px); letter-spacing: -0.5px; }

.tabs {
  display: flex; flex-wrap: wrap; gap: 4px;
  background: var(--surface); border-radius: 12px; padding: 4px;
  margin-left: auto;
}
.tab {
  border: 0; background: transparent; color: var(--text-dim);
  font: inherit; font-weight: 600;
  padding: 5px 9px; border-radius: 9px; cursor: pointer;
  white-space: nowrap;
  display: flex; flex-direction: column; align-items: center; gap: 1px;
}
.tab .tab-name { font-size: clamp(12px, 3.1vw, 14px); line-height: 1.2; }
.tab .tab-desc { font-size: clamp(9px, 2.3vw, 10.5px); font-weight: 500; opacity: 0.75; line-height: 1.1; }
.tab.active { background: var(--accent); color: #3a2c00; }
.tab.active .tab-desc { opacity: 0.9; }

/* ===== 툴바 / 통계 ===== */
.toolbar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px;
  background: var(--surface); border-radius: 12px;
  padding: 10px 14px; margin-bottom: 14px;
  font-size: clamp(12px, 3.2vw, 14px);
}
.stats { display: flex; gap: 12px; color: var(--text-dim); flex-wrap: wrap; }
.stats b { color: var(--text); }
.difficulty { margin-left: auto; color: var(--text-dim); display: flex; align-items: center; gap: 6px; }
.difficulty select {
  font: inherit; padding: 4px 6px; border-radius: 8px;
  border: 1px solid rgba(255,255,255,.25); background: var(--surface-2); color: var(--text);
}

/* ===== 상대 버림패 ===== */
.opponents { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.opp-row {
  display: flex; align-items: flex-start; gap: 8px;
  background: var(--surface); border-radius: 10px; padding: 6px 8px;
}
.opp-label {
  flex: 0 0 34px; font-size: 12px; font-weight: 700; color: var(--text-dim);
  padding-top: 6px; text-align: center;
}
.opp-tiles { display: flex; flex-wrap: wrap; gap: 2px; }

/* ===== 안내문 ===== */
.prompt { font-size: clamp(13px, 3.4vw, 15px); color: var(--text-dim); margin: 4px 2px 12px; }

/* ===== 패 (타일) ===== */
.tile {
  --w: var(--tile-w);
  width: var(--w); height: calc(var(--w) * 1.4);
  flex: 0 0 auto;
  background: linear-gradient(178deg, #fffdf4 55%, #efe7d2);
  border: 1px solid #b8ad8f;
  border-bottom-width: calc(var(--w) * 0.1);
  border-radius: calc(var(--w) * 0.15);
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.4);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: calc(var(--w) * 0.02);
  padding: 0; cursor: pointer; user-select: none; -webkit-user-select: none;
  transition: transform 0.12s ease, box-shadow 0.12s ease;
  font-family: inherit;
}
button.tile:disabled { cursor: default; }
.tile img.face {
  width: 92%; height: 94%;
  object-fit: contain;
  pointer-events: none;
  -webkit-user-select: none; user-select: none;
}

.tile.selected {
  transform: translateY(calc(var(--w) * -0.22));
  box-shadow: 0 0 0 3px var(--accent), 0 6px 12px rgba(0, 0, 0, 0.5);
}
.tile.correct-mark { box-shadow: 0 0 0 3px var(--good), 0 2px 5px rgba(0,0,0,.4); }
.tile.wrong-mark { box-shadow: 0 0 0 3px var(--bad), 0 2px 5px rgba(0,0,0,.4); }

.tile.small { --w: clamp(17px, 4.4vw, 32px); border-radius: 4px; box-shadow: 0 1px 2px rgba(0,0,0,.35); }

/* ===== 손패 영역 ===== */
.hand-area {
  display: flex; align-items: flex-end; gap: clamp(8px, 2.5vw, 20px);
  background: var(--surface); border-radius: 14px;
  padding: clamp(14px, 4vw, 22px) clamp(8px, 2.5vw, 16px) clamp(10px, 3vw, 16px);
  margin-bottom: 16px;
  overflow-x: auto;
}
.hand { display: flex; gap: clamp(2px, 0.7vw, 6px); }
.drawn { display: flex; }
.drawn .tile { box-shadow: 0 2px 5px rgba(0,0,0,.4), 0 0 0 2px rgba(255, 209, 102, 0.55); }

/* ===== 피드백 ===== */
.feedback { background: var(--surface); border-radius: 14px; padding: 14px; }
.verdict { font-size: clamp(16px, 4.4vw, 20px); font-weight: 800; margin-bottom: 4px; }
.verdict.good { color: var(--good); }
.verdict.soso { color: var(--accent); }
.verdict.bad { color: var(--bad); }
.verdict-sub { font-size: clamp(12px, 3.3vw, 14px); color: var(--text-dim); font-weight: 500; margin-top: 2px; }
.verdict-sub.why {
  margin-top: 8px; padding: 8px 10px;
  background: var(--surface-2); border-radius: 8px;
  color: var(--text); line-height: 1.55;
}

.analysis-table { display: flex; flex-direction: column; gap: 6px; margin: 12px 0; }
.arow {
  display: grid;
  grid-template-columns: auto auto auto 1fr;
  gap: 10px; align-items: center;
  background: var(--surface-2); border-radius: 10px; padding: 6px 10px;
  font-size: clamp(12px, 3.2vw, 14px);
}
.arow.best { outline: 2px solid var(--good); }
.arow.mine:not(.best) { outline: 2px solid var(--bad); }
.arow .badge {
  font-size: 11px; font-weight: 700; border-radius: 6px; padding: 2px 6px;
  background: rgba(255,255,255,.12); color: var(--text-dim); white-space: nowrap;
}
.arow.best .badge.b-best { background: var(--good); color: #04340f; }
.arow .badge.b-mine { background: var(--accent); color: #3a2c00; }
.arow .meta { color: var(--text-dim); white-space: nowrap; }
.arow .meta b { color: var(--text); }
.ukeire-chips { display: flex; flex-wrap: wrap; gap: 4px 6px; align-items: center; }
.chip { display: flex; align-items: center; gap: 2px; padding: 2px 3px; border-radius: 6px; }
.chip .cnt { font-size: 11px; color: var(--text-dim); white-space: nowrap; }
/* 내 선택에는 없는(놓친) 유효패 강조 */
.chip.missed {
  background: rgba(110, 231, 160, 0.16);
  box-shadow: 0 0 0 2px var(--good);
}
.chip.missed .cnt { color: var(--good); font-weight: 700; }

/* ===== 버튼 ===== */
.btn {
  font: inherit; font-weight: 700; font-size: clamp(14px, 3.6vw, 15px);
  border: 1px solid rgba(255,255,255,.25); border-radius: 10px;
  background: var(--surface-2); color: var(--text);
  padding: 10px 18px; cursor: pointer;
}
.btn.primary { background: var(--accent); border-color: transparent; color: #3a2c00; width: 100%; }
.btn.ghost { background: transparent; }

/* ===== 조건 칩 (장풍/자풍/도라/화료 방식) ===== */
.cond-chips {
  display: flex; flex-wrap: wrap; gap: 6px;
  margin-bottom: 12px;
}
.cond-chip {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--surface); border-radius: 10px;
  padding: 6px 10px; font-size: clamp(12px, 3.2vw, 14px);
}
.cond-chip .cond-label { color: var(--text-dim); font-size: 0.85em; }
.cond-chip b { color: var(--text); }
.cond-tiles { display: inline-flex; align-items: center; gap: 5px; }
.cond-tiles .tile { --w: clamp(17px, 4.4vw, 28px); }
.cond-arrow { color: var(--text-dim); font-size: 12px; }
.cond-tiles .tile.dora-mark { box-shadow: 0 0 0 2px var(--accent), 0 1px 2px rgba(0,0,0,.35); }

/* ===== 점수 계산 모드 ===== */
.win-tile-wrap { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.win-label {
  font-size: 11px; font-weight: 700; color: var(--accent);
  text-align: center; margin-bottom: 3px;
}
.choices {
  display: grid; grid-template-columns: 1fr 1fr;
  gap: 8px; margin-bottom: 16px;
}
.btn.choice { width: 100%; padding: 14px 8px; font-size: clamp(14px, 3.8vw, 17px); }
.btn.choice.reveal-correct { background: var(--good); border-color: transparent; color: #04340f; }
.btn.choice.reveal-wrong { background: var(--bad); border-color: transparent; color: #4a0808; }
.btn.choice:disabled { opacity: 0.85; }

/* 점수 조견표 (접기/펼치기) */
.score-ref {
  background: var(--surface); border-radius: 14px;
  padding: 0; margin-bottom: 16px;
  overflow: hidden;
}
.score-ref summary {
  cursor: pointer; user-select: none; -webkit-user-select: none;
  padding: 12px 14px;
  font-size: clamp(13px, 3.4vw, 15px); font-weight: 700; color: var(--text-dim);
  list-style: none;
}
.score-ref summary::-webkit-details-marker { display: none; }
.score-ref[open] summary { color: var(--text); border-bottom: 1px solid rgba(255,255,255,.1); }
.ref-tables {
  display: flex; flex-wrap: wrap; gap: 12px;
  padding: 12px;
}
.ref-block { flex: 1 1 320px; overflow-x: auto; }
.ref-block table {
  width: 100%; border-collapse: collapse;
  font-size: clamp(10px, 2.8vw, 12.5px); line-height: 1.35;
  text-align: center; white-space: nowrap;
}
.ref-block th, .ref-block td {
  border: 1px solid rgba(255,255,255,.12);
  padding: 4px 6px;
}
.ref-block thead th { background: var(--surface-2); color: var(--accent); }
.ref-block tbody th { background: var(--surface-2); color: var(--text-dim); font-weight: 700; }
.ref-block td { color: var(--text); }
.ref-block .dim { color: var(--text-dim); font-size: 0.9em; }
.ref-block .limit-row th, .ref-block .limit-row td { background: rgba(255, 209, 102, 0.07); }
.ref-note {
  padding: 0 14px 12px;
  font-size: clamp(10px, 2.8vw, 12px); color: var(--text-dim);
}

/* 역 일람 */
.yaku-groups {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 10px; padding: 12px;
}
.yaku-group { background: var(--surface-2); border-radius: 10px; padding: 10px 12px; }
.yaku-group-title {
  font-weight: 800; color: var(--accent);
  font-size: clamp(13px, 3.4vw, 15px); margin-bottom: 6px;
}
.yaku-ref-row {
  display: flex; gap: 8px; align-items: baseline;
  padding: 3px 0; font-size: clamp(11px, 3vw, 13px); line-height: 1.45;
}
.yaku-ref-row b { flex: 0 0 auto; color: var(--text); white-space: nowrap; }
.yaku-ref-row span { color: var(--text-dim); }
.yref-badge {
  flex: 0 0 auto; font-style: normal; font-size: 10px; font-weight: 700;
  padding: 1px 5px; border-radius: 6px; white-space: nowrap;
  background: rgba(255, 209, 102, 0.18); color: var(--accent);
}
.yref-badge.menzen { background: rgba(110, 231, 160, 0.15); color: var(--good); }

/* 후로 몸통 */
.open-meld {
  display: flex; align-items: flex-end; gap: clamp(1px, 0.4vw, 3px);
  margin-left: clamp(8px, 2.4vw, 18px);
  padding: 3px 5px 4px; border-radius: 8px;
  background: rgba(255, 255, 255, 0.08);
  position: relative;
}
.meld-label {
  position: absolute; top: -14px; left: 4px;
  font-size: 10px; font-weight: 800; color: var(--accent);
}

.yaku-list { margin: 12px 0 10px; display: flex; flex-direction: column; gap: 4px; }
.yaku-row {
  display: flex; justify-content: space-between; align-items: center;
  background: var(--surface-2); border-radius: 8px;
  padding: 7px 12px; font-size: clamp(13px, 3.4vw, 15px);
}
.yaku-row b { color: var(--accent); }
.fu-list {
  background: var(--surface-2); border-radius: 10px;
  padding: 10px 12px; margin-bottom: 10px;
  font-size: clamp(12px, 3.2vw, 13px); color: var(--text-dim);
}
.fu-title { font-weight: 700; color: var(--text); margin-bottom: 4px; }
.fu-item { line-height: 1.6; }
.formula {
  font-size: clamp(14px, 3.8vw, 16px);
  padding: 10px 4px 12px; color: var(--text);
}
.formula b { color: var(--accent); }

/* ===== 분석 모드 ===== */
.notation-row { display: flex; gap: 6px; margin-bottom: 12px; }
.notation-row input {
  flex: 1; min-width: 0; font: inherit; font-size: 14px;
  padding: 10px 12px; border-radius: 10px;
  border: 1px solid rgba(255,255,255,.25); background: var(--surface-2); color: var(--text);
}
.notation-row input::placeholder { color: rgba(255,255,255,.35); }

.palette {
  display: flex; flex-direction: column; gap: 5px;
  background: var(--surface); border-radius: 14px; padding: 10px; margin-bottom: 12px;
}
.palette-row { display: flex; gap: clamp(2px, 0.8vw, 6px); justify-content: center; }
.palette .tile { --w: clamp(26px, 8.4vw, 44px); position: relative; }
.palette .tile:disabled { opacity: 0.3; }
.palette .tile .left {
  position: absolute; right: -3px; top: -5px;
  background: var(--accent); color: #3a2c00;
  font-size: 10px; font-weight: 800; border-radius: 8px; padding: 0 4px;
}

.analyze-hand { align-items: center; min-height: calc(var(--tile-w) * 1.4 + 40px); }
.hand-count { margin-left: auto; color: var(--text-dim); font-size: 13px; white-space: nowrap; }

/* ===== 기타 ===== */
.hidden { display: none !important; }
.app-footer {
  max-width: 860px; margin: 0 auto; padding: 0 14px 24px;
  font-size: 11px; color: rgba(255,255,255,.35); text-align: center;
}

@media (min-width: 640px) {
  :root { --tile-w: 50px; }
  .tile.small { --w: 30px; }
}
