/* ==========================================================================
   리치마작 (Riichi Mahjong) - Modern Dark Green Felt Styling
   ========================================================================== */

:root {
  --table-bg: #12402b;
  --table-border: #0a2519;
  --table-felt: radial-gradient(circle at center, #1b5e3d 0%, #113f2a 70%, #0c2b1d 100%);
  --panel-bg: rgba(14, 34, 25, 0.88);
  --panel-border: rgba(255, 255, 255, 0.12);
  --accent-gold: #f59e0b;
  --accent-red: #ef4444;
  --accent-blue: #3b82f6;
  --accent-green: #10b981;
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --tile-ivory: #fffdf7;
  --tile-border: #d4cfbe;
  --tile-shadow: rgba(0, 0, 0, 0.35);
  --tile-back-color: #2e6648;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans KR", "Apple SD Gothic Neo", sans-serif;
  background-color: #08150f;
  color: var(--text-main);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
  user-select: none;
}

/* 상단 헤더 & 네비게이션 바 */
.top-navbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 18px;
  background: rgba(10, 25, 18, 0.95);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--panel-border);
  z-index: 100;
}

.brand-container {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo-icon {
  font-size: 24px;
}

.brand-title {
  font-size: 1.25rem;
  font-weight: 800;
  letter-spacing: -0.5px;
  background: linear-gradient(135deg, #fcd34d, #f59e0b);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.brand-badge {
  font-size: 0.72rem;
  padding: 2px 7px;
  border-radius: 9999px;
  background: rgba(245, 158, 11, 0.2);
  color: #fcd34d;
  border: 1px solid rgba(245, 158, 11, 0.35);
}

.nav-tabs {
  display: flex;
  gap: 6px;
}

.nav-btn {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-muted);
  padding: 7px 14px;
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  gap: 6px;
}

.nav-btn:hover {
  color: var(--text-main);
  background: rgba(255, 255, 255, 0.06);
}

.nav-btn.active {
  background: rgba(16, 185, 129, 0.2);
  color: #34d399;
  border-color: rgba(52, 211, 153, 0.4);
}

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

.action-icon-btn {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--panel-border);
  color: var(--text-main);
  width: 36px;
  height: 36px;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  transition: all 0.2s;
}

.action-icon-btn:hover {
  background: rgba(255, 255, 255, 0.15);
}

/* 탭 컨테이너 */
.tab-pane {
  display: none;
  flex: 1;
}

.tab-pane.active {
  display: flex;
  flex-direction: column;
  flex: 1;
}

/* ==========================================================================
   1. 마작 대국 화면 (Mahjong Table)
   ========================================================================== */
.mahjong-table-wrapper {
  position: relative;
  flex: 1;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 12px;
  min-height: calc(100vh - 55px);
}

.mahjong-table {
  width: 100%;
  max-width: 1100px;
  aspect-ratio: 16 / 10;
  min-height: 650px;
  background: var(--table-felt);
  border-radius: 18px;
  border: 14px solid #1c2b21;
  box-shadow: inset 0 0 50px rgba(0, 0, 0, 0.7), 0 16px 40px rgba(0, 0, 0, 0.6);
  position: relative;
  display: grid;
  grid-template-rows: 110px 1fr 150px;
  grid-template-columns: 140px 1fr 140px;
  overflow: hidden;
}

/* 플레이어 영역 */
.player-seat {
  position: absolute;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
}

/* 상단 대가 (맞은편 AI) */
.seat-toimen {
  top: 8px;
  left: 50%;
  transform: translateX(-50%);
  flex-direction: column;
  gap: 6px;
  width: 75%;
}

.seat-toimen .hand-container {
  display: flex;
  justify-content: center;
  gap: 2px;
}

/* 좌측 상가 (좌측 AI) */
.seat-kamicha {
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  flex-direction: column;
  gap: 8px;
  height: 60%;
}

.seat-kamicha .hand-container {
  display: flex;
  flex-direction: column;
  gap: -8px;
}

/* 우측 하가 (우측 AI) */
.seat-shimocha {
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  flex-direction: column;
  gap: 8px;
  height: 60%;
}

.seat-shimocha .hand-container {
  display: flex;
  flex-direction: column;
  gap: -8px;
}

/* 하단 나 (플레이어) */
.seat-player {
  bottom: 12px;
  left: 50%;
  transform: translateX(-50%);
  flex-direction: column;
  gap: 8px;
  width: 90%;
  max-width: 900px;
}

.player-info-badge {
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(10, 24, 18, 0.85);
  border: 1px solid rgba(255, 255, 255, 0.15);
  padding: 5px 14px;
  border-radius: 9999px;
  backdrop-filter: blur(8px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  font-size: 0.88rem;
}

.wind-badge {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #1e3a8a;
  color: #bfdbfe;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.82rem;
}

.wind-badge.dealer {
  background: #b91c1c;
  color: #fef08a;
  border: 1px solid #facc15;
}

.player-score {
  font-weight: 800;
  font-size: 1rem;
  color: #fcd34d;
  font-variant-numeric: tabular-nums;
}

.riichi-tag {
  background: #ef4444;
  color: white;
  font-size: 0.72rem;
  font-weight: 800;
  padding: 2px 7px;
  border-radius: 4px;
  letter-spacing: 1px;
  box-shadow: 0 0 8px rgba(239, 68, 68, 0.6);
  animation: pulseGlow 1.5s infinite;
}

/* 중앙 게임 정보 대시보드 */
.table-center-board {
  grid-column: 2 / 3;
  grid-row: 2 / 3;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  position: relative;
  z-index: 5;
}

.center-core {
  background: rgba(10, 24, 18, 0.92);
  border: 2px solid rgba(255, 255, 255, 0.15);
  border-radius: 14px;
  padding: 10px 18px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
  min-width: 240px;
}

.round-info-title {
  font-size: 1.15rem;
  font-weight: 800;
  color: #fcd34d;
  display: flex;
  align-items: center;
  gap: 8px;
}

.dora-showcase {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(0, 0, 0, 0.35);
  padding: 4px 10px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.dora-label {
  font-size: 0.8rem;
  font-weight: 700;
  color: #94a3b8;
}

.dora-tiles-row {
  display: flex;
  gap: 4px;
}

.meta-stats-row {
  display: flex;
  gap: 16px;
  font-size: 0.82rem;
  color: #cbd5e1;
}

.stat-item {
  display: flex;
  align-items: center;
  gap: 4px;
}

.stat-item strong {
  color: #38bdf8;
}

/* 버림패 바닥 (Kawa - 각 플레이어별 6개 x 3줄) */
.discards-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 2px;
  background: rgba(0, 0, 0, 0.18);
  padding: 4px;
  border-radius: 6px;
}

.discards-player {
  position: absolute;
  bottom: 110px;
  left: 50%;
  transform: translateX(-50%);
}

.discards-toimen {
  position: absolute;
  top: 95px;
  left: 50%;
  transform: translateX(-50%) rotate(180deg);
}

.discards-kamicha {
  position: absolute;
  left: 120px;
  top: 50%;
  transform: translateY(-50%) rotate(90deg);
}

.discards-shimocha {
  position: absolute;
  right: 120px;
  top: 50%;
  transform: translateY(-50%) rotate(-90deg);
}

/* 플레이어 손패 컨테이너 */
.player-hand-row {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 3px;
  background: rgba(0, 0, 0, 0.25);
  padding: 8px 12px;
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  position: relative;
}

.hand-tiles-group {
  display: flex;
  gap: 2px;
}

.drawn-tile-slot {
  margin-left: 14px;
  position: relative;
}

.drawn-tile-slot::before {
  content: '쯔모';
  position: absolute;
  top: -18px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.68rem;
  color: #fcd34d;
  font-weight: 700;
  letter-spacing: 1px;
}

.melds-group {
  display: flex;
  gap: 6px;
  margin-left: 14px;
}

/* ==========================================================================
   2. 마작 패 (Mahjong Tile) 3D 렌더링 스타일
   ========================================================================== */
.mahjong-tile {
  background: var(--tile-ivory);
  border: 1px solid var(--tile-border);
  border-radius: 5px;
  position: relative;
  cursor: pointer;
  box-shadow: 0 4px 6px var(--tile-shadow), 0 1px 2px rgba(0, 0, 0, 0.2);
  transition: transform 0.15s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.15s ease;
  user-select: none;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

/* 패 옆면/밑면 두께 표현 (실제 마작패의 노란/초록 플라스틱 뒷면) */
.mahjong-tile::after {
  content: '';
  position: absolute;
  bottom: -4px;
  left: 1px;
  right: 1px;
  height: 4px;
  background: linear-gradient(to bottom, #d5c89f, #b39b5e);
  border-bottom-left-radius: 4px;
  border-bottom-right-radius: 4px;
}

.mahjong-tile:hover {
  transform: translateY(-8px);
  box-shadow: 0 10px 14px rgba(0, 0, 0, 0.45);
  border-color: #38bdf8;
}

.mahjong-tile.selected {
  transform: translateY(-12px);
  border-color: #f59e0b;
  box-shadow: 0 0 12px rgba(245, 158, 11, 0.7);
}

.mahjong-tile.rotated {
  transform: rotate(90deg);
  margin: 0 6px;
}

/* 뒷면 패 */
.mahjong-tile.tile-back {
  background: linear-gradient(135deg, #1b5e3d 0%, #113f2a 100%);
  border-color: #0b291c;
  cursor: default;
}

.mahjong-tile.tile-back::after {
  background: #082015;
}

.back-pattern {
  width: 80%;
  height: 85%;
  border: 1px dashed rgba(255, 255, 255, 0.18);
  border-radius: 3px;
}

/* 타일 내부 글자 및 그래픽 */
.tile-face {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  position: relative;
  padding: 2px;
}

.tile-man {
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 0.95;
}

.man-num {
  font-size: 1.15rem;
  font-weight: 900;
  font-family: "KaiTi", "Bikai", "Noto Serif CJK KR", "Batang", serif;
}

.man-kanji {
  font-size: 0.95rem;
  font-weight: 800;
  font-family: "KaiTi", "Noto Serif CJK KR", serif;
}

.tile-honor {
  font-size: 1.45rem;
  font-weight: 900;
  font-family: "KaiTi", "Noto Serif CJK KR", serif;
}

.tile-dragon.haku {
  width: 65%;
  height: 75%;
  border: 2px solid #2563eb;
  border-radius: 3px;
}

.tile-dragon.hatsu {
  font-size: 1.4rem;
  font-weight: 900;
  color: #15803d;
}

.tile-dragon.chun {
  font-size: 1.4rem;
  font-weight: 900;
  color: #dc2626;
}

.pin-grid, .sou-grid, .sou-bird {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.pin-big-svg, .pin-svg, .sou-svg, .bird-svg {
  width: 82%;
  height: 82%;
}

.aka-indicator {
  position: absolute;
  top: 2px;
  right: 2px;
  color: #ef4444;
  font-size: 0.65rem;
  font-weight: 900;
}

/* ==========================================================================
   3. 액션 바 (치/퐁/깡/리치/론/쯔모/패스)
   ========================================================================== */
.player-actions-panel {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  position: absolute;
  bottom: 85px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 50;
  background: rgba(15, 23, 42, 0.95);
  padding: 10px 20px;
  border-radius: 9999px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  backdrop-filter: blur(12px);
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.7);
  animation: slideUp 0.25s ease-out;
}

.action-btn {
  padding: 9px 20px;
  border-radius: 9999px;
  font-size: 1rem;
  font-weight: 800;
  cursor: pointer;
  border: none;
  transition: all 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
  display: flex;
  align-items: center;
  gap: 6px;
}

.action-btn:hover {
  transform: translateY(-3px) scale(1.05);
}

.btn-tsumo {
  background: linear-gradient(135deg, #f59e0b, #d97706);
  color: white;
  box-shadow: 0 0 15px rgba(245, 158, 11, 0.6);
}

.btn-ron {
  background: linear-gradient(135deg, #ef4444, #b91c1c);
  color: white;
  box-shadow: 0 0 18px rgba(239, 68, 68, 0.7);
  animation: pulseGlow 1.2s infinite;
}

.btn-riichi {
  background: linear-gradient(135deg, #3b82f6, #1d4ed8);
  color: white;
  box-shadow: 0 0 15px rgba(59, 130, 246, 0.6);
}

.btn-pon {
  background: linear-gradient(135deg, #10b981, #047857);
  color: white;
}

.btn-chii {
  background: linear-gradient(135deg, #06b6d4, #0e7490);
  color: white;
}

.btn-kan {
  background: linear-gradient(135deg, #8b5cf6, #6d28d9);
  color: white;
}

.btn-pass {
  background: rgba(255, 255, 255, 0.15);
  color: #cbd5e1;
  border: 1px solid rgba(255, 255, 255, 0.25);
}

/* 대기패 및 실시간 힌트 가이드 바 */
.tenpai-guide-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background: rgba(15, 23, 42, 0.85);
  border: 1px solid rgba(255, 255, 255, 0.12);
  padding: 6px 18px;
  border-radius: 8px;
  font-size: 0.86rem;
  color: #e2e8f0;
  margin-top: 4px;
}

.tenpai-guide-bar strong {
  color: #38bdf8;
}

/* ==========================================================================
   4. 모달 팝업 (화료 정산, 결과, 도감 등)
   ========================================================================== */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(8px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  animation: fadeIn 0.2s ease-out;
}

.modal-overlay.active {
  display: flex;
}

.modal-card {
  background: #0f172a;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 18px;
  width: 90%;
  max-width: 650px;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.8);
  padding: 24px;
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.modal-title {
  font-size: 1.5rem;
  font-weight: 800;
  text-align: center;
  background: linear-gradient(135deg, #fcd34d, #f59e0b);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.yaku-breakdown-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: rgba(255, 255, 255, 0.04);
  padding: 14px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.yaku-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 1rem;
}

.yaku-item .han-badge {
  font-weight: 800;
  color: #f59e0b;
}

.score-summary-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 16px;
  background: linear-gradient(135deg, rgba(245, 158, 11, 0.15), rgba(239, 68, 68, 0.1));
  border: 1px solid rgba(245, 158, 11, 0.3);
  border-radius: 14px;
}

.score-summary-title {
  font-size: 1.6rem;
  font-weight: 900;
  color: #fcd34d;
}

.score-summary-points {
  font-size: 2.2rem;
  font-weight: 900;
  color: #ffffff;
  font-variant-numeric: tabular-nums;
}

.score-payment-desc {
  font-size: 0.95rem;
  color: #94a3b8;
}

.modal-confirm-btn {
  background: linear-gradient(135deg, #10b981, #059669);
  color: white;
  border: none;
  padding: 12px 24px;
  border-radius: 10px;
  font-size: 1.1rem;
  font-weight: 800;
  cursor: pointer;
  transition: transform 0.15s;
}

.modal-confirm-btn:hover {
  transform: translateY(-2px);
}

/* ==========================================================================
   5. 트레이너 & 계산기 탭 전용 레이아웃
   ========================================================================== */
.trainer-container, .calculator-container, .guide-container {
  max-width: 950px;
  margin: 20px auto;
  width: 95%;
  background: rgba(15, 23, 42, 0.85);
  border: 1px solid var(--panel-border);
  border-radius: 16px;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  backdrop-filter: blur(10px);
}

.section-header {
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  padding-bottom: 12px;
}

.section-title {
  font-size: 1.35rem;
  font-weight: 800;
  color: #f8fafc;
}

.section-desc {
  font-size: 0.88rem;
  color: var(--text-muted);
  margin-top: 4px;
}

/* 타일 팔레트 (계산기/퀴즈용) */
.tile-palette {
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: rgba(0, 0, 0, 0.25);
  padding: 14px;
  border-radius: 12px;
}

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

.palette-label {
  width: 50px;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text-muted);
}

/* 애니메이션 */
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes slideUp {
  from { opacity: 0; transform: translate(-50%, 20px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

@keyframes pulseGlow {
  0%, 100% { box-shadow: 0 0 10px rgba(239, 68, 68, 0.5); }
  50% { box-shadow: 0 0 20px rgba(239, 68, 68, 0.9); }
}

/* 모바일 반응형 처리 */
@media (max-width: 768px) {
  .top-navbar {
    padding: 6px 10px;
  }
  .brand-title {
    font-size: 1rem;
  }
  .nav-btn span {
    display: none;
  }
  .mahjong-table {
    min-height: 520px;
    border-width: 8px;
  }
  .center-core {
    min-width: 180px;
    padding: 6px 10px;
  }
  .mahjong-tile {
    width: 32px !important;
    height: 46px !important;
  }
  .man-num { font-size: 0.85rem; }
  .man-kanji { font-size: 0.72rem; }
  .tile-honor { font-size: 1rem; }
  .player-actions-panel {
    bottom: 60px;
    padding: 6px 12px;
    gap: 8px;
  }
  .action-btn {
    padding: 6px 14px;
    font-size: 0.85rem;
  }
}
