* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: 'Apple SD Gothic Neo', 'Malgun Gothic', sans-serif;
  background: linear-gradient(170deg, #1a1a2e 0%, #16213e 40%, #0f172a 100%);
  color: #eee;
  height: 100dvh;
  overflow: hidden;
  display: flex;
  justify-content: center;
  align-items: center;
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}

.screen {
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
  max-width: 500px;
  height: 100%;
  padding: 20px;
}

.screen.active {
  display: flex;
}

/* 로고 영역 */
.logo-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-bottom: 40px;
  animation: fadeInDown 0.6s ease-out;
}

.logo-area.small {
  margin-bottom: 16px;
}

.logo-area.small .logo-title {
  font-size: 2.2rem;
}

.logo-area.small .logo-stones span {
  width: 14px;
  height: 14px;
}

.logo-stones {
  display: flex;
  gap: 6px;
  margin-bottom: 12px;
}

.logo-stones span {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  display: inline-block;
  animation: stoneDrop 0.5s ease-out both;
}

.logo-stones span:nth-child(1) { animation-delay: 0.1s; }
.logo-stones span:nth-child(2) { animation-delay: 0.2s; }
.logo-stones span:nth-child(3) { animation-delay: 0.3s; }
.logo-stones span:nth-child(4) { animation-delay: 0.4s; }
.logo-stones span:nth-child(5) { animation-delay: 0.5s; }

.stone-black {
  background: radial-gradient(circle at 35% 35%, #555, #111);
  box-shadow: 1px 1px 3px rgba(0,0,0,0.5);
}

.stone-white {
  background: radial-gradient(circle at 35% 35%, #fff, #bbb);
  box-shadow: 1px 1px 3px rgba(0,0,0,0.3);
}

@keyframes stoneDrop {
  0% { opacity: 0; transform: translateY(-20px) scale(0.5); }
  100% { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes fadeInDown {
  0% { opacity: 0; transform: translateY(-15px); }
  100% { opacity: 1; transform: translateY(0); }
}

@keyframes fadeInUp {
  0% { opacity: 0; transform: translateY(15px); }
  100% { opacity: 1; transform: translateY(0); }
}

.logo-title {
  font-size: 3.2rem;
  font-weight: 800;
  color: #e0c068;
  text-shadow: 0 2px 12px rgba(224, 192, 104, 0.35);
  letter-spacing: 4px;
}

.logo-subtitle {
  font-size: 1rem;
  color: #8a8a9a;
  letter-spacing: 6px;
  margin-top: 4px;
}

/* 닉네임 입력 */
.nickname-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
  width: 100%;
  max-width: 300px;
  animation: fadeInUp 0.6s ease-out 0.3s both;
}

.nickname-form input {
  padding: 16px 18px;
  font-size: 1.05rem;
  border: 2px solid rgba(255,255,255,0.08);
  border-radius: 14px;
  background: rgba(255,255,255,0.05);
  color: #eee;
  text-align: center;
  outline: none;
  transition: border-color 0.3s, background 0.3s;
  backdrop-filter: blur(4px);
}

.nickname-form input:focus {
  border-color: #e0c068;
  background: rgba(224, 192, 104, 0.06);
}

.nickname-form button {
  padding: 16px;
  font-size: 1.1rem;
  font-weight: 700;
  background: linear-gradient(135deg, #e0c068, #c49b30);
  color: #1a1a2e;
  border: none;
  border-radius: 14px;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.2s;
  box-shadow: 0 4px 15px rgba(224, 192, 104, 0.25);
}

.nickname-form button:active {
  transform: scale(0.97);
}

/* 환영 메시지 */
#welcome-msg {
  font-size: 0.9rem;
  color: #8a8a9a;
  margin-bottom: 20px;
}

/* 메뉴 섹션 */
.menu-section {
  width: 100%;
  max-width: 340px;
  margin-bottom: 16px;
  animation: fadeInUp 0.5s ease-out both;
}

.menu-section:nth-child(3) { animation-delay: 0.1s; }
.menu-section:nth-child(4) { animation-delay: 0.2s; }

.menu-label {
  font-size: 0.75rem;
  color: #666;
  text-transform: uppercase;
  letter-spacing: 3px;
  margin-bottom: 8px;
  padding-left: 4px;
}

.menu-row {
  display: flex;
  gap: 10px;
}

.menu-card {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 18px 8px;
  border: none;
  border-radius: 16px;
  cursor: pointer;
  font-size: 0.95rem;
  font-weight: 700;
  color: white;
  transition: transform 0.15s, box-shadow 0.2s;
}

.menu-card .card-icon {
  font-size: 1.4rem;
}

.menu-card:active {
  transform: scale(0.95);
}

.menu-card.easy {
  background: linear-gradient(160deg, #43a047, #2e7d32);
  box-shadow: 0 4px 12px rgba(67, 160, 71, 0.3);
}
.menu-card.medium {
  background: linear-gradient(160deg, #fb8c00, #e65100);
  box-shadow: 0 4px 12px rgba(251, 140, 0, 0.3);
}
.menu-card.hard {
  background: linear-gradient(160deg, #e53935, #b71c1c);
  box-shadow: 0 4px 12px rgba(229, 57, 53, 0.3);
}
.menu-card.online {
  background: linear-gradient(160deg, #1e88e5, #0d47a1);
  box-shadow: 0 4px 12px rgba(30, 136, 229, 0.3);
}
.menu-card.friend {
  background: linear-gradient(160deg, #8e24aa, #4a148c);
  box-shadow: 0 4px 12px rgba(142, 36, 170, 0.3);
}

/* 하단 버튼 (전적/랭킹) */
.menu-bottom-row {
  display: flex;
  gap: 10px;
  width: 100%;
  max-width: 340px;
  animation: fadeInUp 0.5s ease-out 0.3s both;
}

.menu-bottom-btn {
  flex: 1;
  padding: 14px 8px;
  font-size: 0.9rem;
  font-weight: 600;
  background: rgba(255,255,255,0.05);
  color: #aaa;
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 12px;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}

.menu-bottom-btn:active {
  background: rgba(255,255,255,0.1);
  color: #eee;
}

/* 전적 화면 */
#stats-screen,
#ranking-screen {
  justify-content: flex-start;
  padding-top: 40px;
  gap: 16px;
  overflow-y: auto;
}

#stats-screen h2,
#ranking-screen h2 {
  font-size: 1.6rem;
  color: #e0c068;
}

#stats-content {
  width: 100%;
  max-width: 350px;
}

.stats-section {
  background: #16213e;
  border-radius: 12px;
  padding: 16px 20px;
  margin-bottom: 12px;
}

.stats-section h3 {
  font-size: 1rem;
  color: #e0c068;
  margin-bottom: 10px;
  padding-bottom: 8px;
  border-bottom: 1px solid #333;
}

.stats-row {
  display: flex;
  justify-content: space-between;
  padding: 6px 0;
  font-size: 0.95rem;
}

.stats-row .label {
  color: #aaa;
}

.stats-row .value {
  font-weight: 700;
}

.stats-row .value.win { color: #4caf50; }
.stats-row .value.loss { color: #f44336; }

/* 랭킹 탭 */
.ranking-tabs {
  display: flex;
  gap: 0;
  width: 100%;
  max-width: 300px;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid #444;
}

.ranking-tabs .tab {
  flex: 1;
  padding: 10px 0;
  font-size: 0.95rem;
  font-weight: 600;
  border: none;
  cursor: pointer;
  background: #16213e;
  color: #888;
  transition: background 0.2s, color 0.2s;
}

.ranking-tabs .tab.active {
  background: #e0c068;
  color: #1a1a2e;
}

/* 랭킹 화면 */
#ranking-date {
  font-size: 0.9rem;
  color: #888;
}

#ranking-content {
  width: 100%;
  max-width: 400px;
}

.ranking-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 8px;
}

.ranking-table th {
  font-size: 0.8rem;
  color: #888;
  padding: 8px 4px;
  text-align: center;
  border-bottom: 1px solid #333;
}

.ranking-table td {
  font-size: 0.9rem;
  padding: 10px 4px;
  text-align: center;
  border-bottom: 1px solid #222;
}

.ranking-table tr:nth-child(-n+3) td:first-child {
  font-weight: 700;
}

.rank-1 { color: #ffd700; }
.rank-2 { color: #c0c0c0; }
.rank-3 { color: #cd7f32; }

.ranking-empty {
  text-align: center;
  color: #666;
  padding: 40px 0;
  font-size: 0.95rem;
}

.btn-back-menu {
  margin-top: 20px;
  padding: 12px 32px;
  font-size: 1rem;
  background: #444;
  color: white;
  border: none;
  border-radius: 8px;
  cursor: pointer;
}

/* 친구 대전 화면 */
#friend-screen {
  justify-content: center;
  gap: 16px;
}

#friend-screen h2 {
  font-size: 1.6rem;
  color: #e0c068;
}

.friend-menu {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
  max-width: 300px;
  align-items: center;
}

.friend-menu button {
  width: 100%;
  padding: 14px;
  font-size: 1.05rem;
  font-weight: 600;
  border: none;
  border-radius: 12px;
  cursor: pointer;
  background: linear-gradient(135deg, #9c27b0, #6a1b9a);
  color: white;
}

.friend-menu input {
  width: 100%;
  padding: 14px;
  font-size: 1.2rem;
  text-align: center;
  letter-spacing: 6px;
  text-transform: uppercase;
  border: 2px solid #444;
  border-radius: 12px;
  background: #16213e;
  color: #eee;
  outline: none;
}

.friend-menu input:focus {
  border-color: #9c27b0;
}

.friend-divider {
  color: #666;
  font-size: 0.9rem;
  padding: 4px 0;
}

/* 친구방 대기 */
#friend-waiting-screen {
  justify-content: center;
  gap: 12px;
}

#friend-waiting-screen h2 {
  margin-bottom: 8px;
}

#friend-room-code {
  font-size: 2.5rem;
  font-weight: 700;
  letter-spacing: 8px;
  color: #e0c068;
  background: #16213e;
  padding: 16px 32px;
  border-radius: 12px;
}

.friend-hint {
  color: #888;
  font-size: 0.9rem;
}

#friend-waiting-screen button {
  padding: 12px 32px;
  font-size: 1rem;
  background: #555;
  color: white;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  margin-top: 10px;
}

/* 무르기/힌트 버튼 */
#header-buttons {
  display: flex;
  gap: 6px;
  align-items: center;
}

.icon-btn {
  padding: 6px 10px;
  font-size: 0.85rem;
  background: #333;
  color: #eee;
  border: 1px solid #555;
  border-radius: 8px;
  cursor: pointer;
}

.icon-btn:disabled {
  opacity: 0.3;
  cursor: default;
}

/* 이모지 채팅 바 */
#emoji-bar {
  display: flex;
  justify-content: center;
  gap: 8px;
  padding: 6px 0;
  width: 100%;
}

#emoji-bar.hidden {
  display: none;
}

#emoji-bar button {
  font-size: 1.5rem;
  background: #2a2a4a;
  border: 1px solid #444;
  border-radius: 10px;
  padding: 6px 12px;
  cursor: pointer;
  transition: transform 0.1s;
}

#emoji-bar button:active {
  transform: scale(1.2);
}

/* 이모지 표시 */
#emoji-display {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 4rem;
  pointer-events: none;
  z-index: 20;
  animation: emojiPop 1.5s ease-out forwards;
}

#emoji-display.hidden {
  display: none;
}

@keyframes emojiPop {
  0% { opacity: 1; transform: translate(-50%, -50%) scale(0.5); }
  20% { opacity: 1; transform: translate(-50%, -50%) scale(1.2); }
  40% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -80%) scale(1); }
}

/* 힌트 마커 */
.hint-marker {
  position: absolute;
  pointer-events: none;
}

/* 대기 화면 */
#waiting-screen h2 {
  margin-bottom: 30px;
}

.spinner {
  width: 50px;
  height: 50px;
  border: 5px solid rgba(255,255,255,0.2);
  border-top-color: #2196f3;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-bottom: 30px;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

#waiting-screen button {
  padding: 12px 32px;
  font-size: 1rem;
  background: #555;
  color: white;
  border: none;
  border-radius: 8px;
  cursor: pointer;
}

/* 게임 화면 */
#game-screen {
  justify-content: flex-start;
  padding-top: 10px;
  gap: 8px;
}

#game-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
}

#game-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

#game-mode-label {
  font-size: 0.85rem;
  color: #aaa;
}

#turn-indicator {
  font-size: 1.1rem;
  font-weight: 700;
}

#btn-back {
  padding: 8px 16px;
  font-size: 0.9rem;
  background: #444;
  color: #eee;
  border: none;
  border-radius: 8px;
  cursor: pointer;
}

#board-container {
  width: 100%;
  aspect-ratio: 1;
  max-width: 500px;
  max-height: 500px;
  display: flex;
  justify-content: center;
  align-items: center;
}

#board-canvas {
  width: 100%;
  height: 100%;
  border-radius: 8px;
  cursor: pointer;
  touch-action: none;
}

#game-controls {
  width: 100%;
  display: flex;
  justify-content: center;
  padding: 8px 0;
}

#btn-place {
  padding: 14px 60px;
  font-size: 1.2rem;
  font-weight: 700;
  background: linear-gradient(135deg, #e0c068, #c49b30);
  color: #1a1a2e;
  border: none;
  border-radius: 12px;
  cursor: pointer;
  transition: opacity 0.2s, transform 0.15s;
}

#btn-place:disabled {
  opacity: 0.35;
  cursor: default;
}

#btn-place:not(:disabled):active {
  transform: scale(0.96);
}

/* 결과 */
#game-result {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0,0,0,0.75);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 16px;
  z-index: 10;
}

#game-result.hidden {
  display: none;
}

#result-text {
  font-size: 2rem;
  font-weight: 700;
  text-align: center;
}

#result-record {
  font-size: 1rem;
  color: #ccc;
  text-align: center;
}

#game-result button {
  padding: 14px 40px;
  font-size: 1.1rem;
  background: #e0c068;
  color: #1a1a2e;
  border: none;
  border-radius: 10px;
  font-weight: 700;
  cursor: pointer;
}
