/* ===== RESET & BASE ===== */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg:            #e8e0d0;
  --primary:       #4a7fe0;
  --primary-hover: #3668c8;
  --danger:        #e05050;
  --success:       #50c878;
  --text:          #2c2c2c;
  --text-light:    #6c6c6c;
  --card-bg:       #ffffff;
  --hud-bg:        #2c2c2c;
}

body {
  font-family: 'Segoe UI', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg);
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ===== SCREENS ===== */
.screen {
  display: none;
  width: 100%;
  max-width: 820px;
  padding: 0 16px;
  flex-direction: column;
  align-items: center;
  gap: 20px;
}

.screen.active {
  display: flex;
}

/* ===== NICKNAME SCREEN ===== */
.brand {
  text-align: center;
  margin-top: 24px;
}

.brand-icon {
  font-size: 60px;
  margin-bottom: 8px;
}

.brand h1 {
  font-size: 2rem;
  font-weight: 800;
  color: var(--text);
}

.tagline {
  margin-top: 8px;
  color: var(--text-light);
  font-size: 0.95rem;
}

.nickname-card {
  background: var(--card-bg);
  border-radius: 16px;
  padding: 24px;
  width: 100%;
  max-width: 400px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.1);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.nickname-card label {
  font-weight: 600;
  color: var(--text);
  font-size: 0.9rem;
}

#nickname-input {
  padding: 12px 16px;
  border: 2px solid #e0e0e0;
  border-radius: 8px;
  font-size: 1rem;
  outline: none;
  transition: border-color 0.2s;
}

#nickname-input:focus {
  border-color: var(--primary);
}

.theme-selector {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.theme-selector label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-light);
}

.theme-options {
  display: flex;
  gap: 8px;
}

.theme-btn {
  flex: 1;
  padding: 8px 4px;
  border: 2px solid #e0e0e0;
  border-radius: 8px;
  background: white;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  color: var(--text);
  transition: border-color 0.15s, background 0.15s, color 0.15s;
}

.theme-btn:hover { border-color: var(--primary); }

.theme-btn.active {
  border-color: var(--primary);
  background: var(--primary);
  color: white;
}

.btn-primary {
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 8px;
  padding: 12px 24px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
}

.btn-primary:hover  { background: var(--primary-hover); }
.btn-primary:active { transform: scale(0.97); }

.btn-secondary {
  background: transparent;
  color: var(--text-light);
  border: 2px solid #ddd;
  border-radius: 8px;
  padding: 12px 24px;
  font-size: 1rem;
  cursor: pointer;
  transition: border-color 0.2s, color 0.2s;
}

.btn-secondary:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.nickname-leaderboard {
  background: var(--card-bg);
  border-radius: 16px;
  padding: 20px 24px;
  width: 100%;
  max-width: 400px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.07);
  margin-bottom: 24px;
}

.nickname-leaderboard h3 {
  margin-bottom: 12px;
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--text);
}

.how-to {
  background: var(--card-bg);
  border-radius: 16px;
  padding: 20px 24px;
  width: 100%;
  max-width: 400px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.07);
  margin-bottom: 24px;
}

.how-to h3 {
  margin-bottom: 12px;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-light);
}

.rules-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.rule {
  font-size: 0.9rem;
  color: var(--text);
}

/* ===== GAME SCREEN ===== */
#screen-game {
  padding: 0;
  gap: 0;
  align-items: stretch;
}

/* ===== HUD ===== */
#hud {
  background: var(--hud-bg);
  color: #f0f0f0;
  display: flex;
  align-items: center;
  justify-content: space-around;
  padding: 12px 20px;
  border-radius: 12px 12px 0 0;
}

.hud-block {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.hud-label {
  font-size: 0.65rem;
  opacity: 0.55;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.hud-value {
  font-size: 1.4rem;
  font-weight: 700;
}

.combo-value { color: #ffd700; }

.hud-timer .hud-value { color: #7ecfff; }
.hud-timer.danger .hud-value {
  color: #ff6b6b;
  animation: blink 0.5s infinite;
}

#hud-combo-block { display: none; }

@keyframes blink {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.3; }
}

/* ===== GAME AREA ===== */
#game-area {
  background: var(--card-bg);
  border-radius: 0 0 12px 12px;
  overflow: hidden;
  box-shadow: 0 8px 30px rgba(0,0,0,0.15);
}

/* ===== HINT BAR ===== */
.hint-bar {
  text-align: center;
  font-size: 0.8rem;
  color: var(--text-light);
  padding: 6px 12px;
  background: #f9f6f0;
  border-bottom: 1px solid #ede8e0;
  transition: opacity 0.5s;
}

.hint-bar.hidden { opacity: 0; pointer-events: none; }

/* ===== DESK ===== */
#desk {
  position: relative;
  width: 100%;
  height: 320px;
  background:
    repeating-linear-gradient(
      90deg,
      transparent,
      transparent 48px,
      rgba(0,0,0,0.025) 48px,
      rgba(0,0,0,0.025) 49px
    ),
    linear-gradient(175deg, #d4a55a 0%, #c49040 55%, #b07828 100%);
  border-bottom: 4px solid #9a6820;
  cursor: default;
  overflow: visible;
  touch-action: none;
}

/* ===== ITEMS ===== */
.desk-item {
  position: absolute;
  width: 64px;
  height: 64px;
  background: white;
  border-radius: 10px;
  border: 2px solid #e8e8e8;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  cursor: pointer;
  touch-action: none;
  box-shadow: 0 2px 8px rgba(0,0,0,0.18);
  transition: transform 0.15s, box-shadow 0.15s, border-color 0.15s, opacity 0.2s;
  user-select: none;
  z-index: 1;
}

.desk-item:hover {
  transform: translateY(-3px) scale(1.06);
  box-shadow: 0 6px 16px rgba(0,0,0,0.22);
}

.desk-item.selected {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(74,127,224,0.35), 0 6px 16px rgba(0,0,0,0.2);
  transform: translateY(-5px) scale(1.1);
  z-index: 10;
}

.desk-item.placed {
  opacity: 0;
  transform: scale(0.4);
  pointer-events: none;
}

/* ===== PRIORITY ITEM ===== */
.desk-item.priority {
  border-color: var(--danger);
  box-shadow: 0 0 0 3px rgba(224,80,80,0.3), 0 4px 12px rgba(0,0,0,0.2);
  animation: priority-pulse 0.8s ease-in-out infinite;
  z-index: 5;
}

@keyframes priority-pulse {
  0%, 100% { border-color: #e05050; }
  50%       { border-color: #ff9090; }
}

.priority-badge {
  position: absolute;
  top: -10px;
  right: -10px;
  background: var(--danger);
  color: white;
  border-radius: 50%;
  width: 22px;
  height: 22px;
  font-size: 11px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid white;
  pointer-events: none;
  z-index: 6;
}

.priority-badge.urgent {
  background: #c00;
  animation: badge-flash 0.35s ease infinite;
}

@keyframes badge-flash {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%       { opacity: 0.6; transform: scale(1.15); }
}

.score-popup.penalty { color: var(--danger); }

/* ===== DISTURBANCE TOASTS ===== */
.disturb-toast,
.disturb-announce {
  position: absolute;
  top: 12px;
  left: 50%;
  border-radius: 20px;
  font-size: 0.82rem;
  font-weight: 600;
  pointer-events: none;
  white-space: nowrap;
  z-index: 50;
}

.disturb-toast {
  color: white;
  padding: 6px 18px;
  animation: disturb-in 2.2s ease forwards;
}
.disturb-toast.disturb-priority { background: var(--danger); }
.disturb-toast.disturb-mail     { background: #e07820; }

.disturb-announce {
  background: white;
  color: var(--text);
  padding: 7px 18px;
  animation: disturb-in 3.2s ease forwards;
}
.disturb-announce.disturb-priority { border: 2px solid var(--danger); }
.disturb-announce.disturb-mail     { border: 2px solid #e07820; }

.disturb-announce span { font-weight: 700; }
.disturb-announce.disturb-priority span { color: var(--danger); }
.disturb-announce.disturb-mail span     { color: #e07820; }
.disturb-toast.disturb-wind             { background: #2a9fd0; }
.disturb-toast.disturb-zoneswap         { background: #8a4af0; }
.disturb-announce.disturb-wind          { border: 2px solid #2a9fd0; }
.disturb-announce.disturb-zoneswap      { border: 2px solid #8a4af0; }
.disturb-announce.disturb-wind span     { color: #2a9fd0; }
.disturb-announce.disturb-zoneswap span { color: #8a4af0; }

/* 바람에 날리는 아이템 */
.desk-item.wind-moving {
  z-index: 15;
  transform: rotate(14deg) scale(1.1) !important;
  opacity: 0.82;
}

/* 구역 변경 표시 — 점선 테두리가 복구될 때까지 유지 */
.game-zone.zone-swapped {
  outline: 2px dashed #8a4af0;
  outline-offset: 2px;
  animation: zone-swap-flash 0.55s ease forwards;
}

@keyframes zone-swap-flash {
  0%   { background: rgba(138,74,240,0.22); transform: scale(1.06); }
  100% { background: transparent;           transform: scale(1); }
}

/* 메일 아이템 낙하 애니메이션 */
.desk-item.mail-drop {
  animation: mail-drop-in 0.45s cubic-bezier(0.22, 1, 0.36, 1) forwards;
}

@keyframes mail-drop-in {
  0%   { transform: translateY(-72px) scale(0.8); opacity: 0; }
  70%  { transform: translateY(6px) scale(1.05); opacity: 1; }
  100% { transform: translateY(0) scale(1); opacity: 1; }
}

@keyframes disturb-in {
  0%   { opacity: 0; transform: translateX(-50%) translateY(-8px); }
  12%  { opacity: 1; transform: translateX(-50%) translateY(0); }
  75%  { opacity: 1; }
  100% { opacity: 0; }
}

.desk-item.dragging {
  opacity: 0.88;
  cursor: grabbing;
  z-index: 20;
  transition: none !important;
  box-shadow: 0 10px 28px rgba(0,0,0,0.28);
}

.desk-item.shake {
  animation: shake 0.4s ease;
}

@keyframes shake {
  0%   { transform: translateX(0); }
  20%  { transform: translateX(-8px) rotate(-3deg); }
  40%  { transform: translateX(8px) rotate(3deg); }
  60%  { transform: translateX(-5px); }
  80%  { transform: translateX(5px); }
  100% { transform: translateX(0); }
}

/* ===== ZONES ===== */
#zones {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 8px;
  padding: 12px 10px;
  background: #f5f0e8;
}

.game-zone {
  flex: 1;
  min-width: 80px;
  max-width: 140px;
  height: 76px;
  background: white;
  border: 2px dashed #ccc;
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  font-size: 22px;
  cursor: default;
  transition: border-color 0.2s, background 0.2s, transform 0.15s, box-shadow 0.2s;
  user-select: none;
}

.game-zone .zone-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-light);
}

/* 아이템 선택 중 → 구역 활성화 */
body.item-selected .game-zone {
  border-color: var(--primary);
  border-style: solid;
  cursor: pointer;
  animation: zone-pulse 1.6s ease-in-out infinite;
}

body.item-selected .game-zone:hover {
  background: #eef4ff;
  transform: scale(1.06);
  box-shadow: 0 4px 12px rgba(74,127,224,0.25);
  border-color: var(--primary-hover);
}

@keyframes zone-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(74,127,224,0.25); }
  50%       { box-shadow: 0 0 0 5px rgba(74,127,224,0.1); }
}

.game-zone.correct-flash {
  animation: correct-flash 0.45s ease forwards;
}

@keyframes correct-flash {
  0%   { background: #50c878; border-color: #3aaa60; }
  100% { background: white;   border-color: #ccc; }
}

.game-zone.wrong-flash {
  animation: wrong-flash 0.3s ease forwards;
}

.game-zone.drag-over {
  background: #eef4ff;
  border-color: var(--primary);
  border-style: solid;
  transform: scale(1.06);
  box-shadow: 0 4px 12px rgba(74,127,224,0.25);
}

@keyframes wrong-flash {
  0%   { background: #ffcccc; border-color: var(--danger); }
  100% { background: white;   border-color: #ccc; }
}

/* ===== SCORE POPUP ===== */
.score-popup {
  position: fixed;
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--primary);
  pointer-events: none;
  z-index: 999;
  animation: float-up 0.8s ease forwards;
  white-space: nowrap;
}

.score-popup.combo { color: #e09a00; font-size: 1.3rem; }

@keyframes float-up {
  0%   { opacity: 1; transform: translateY(0) scale(1); }
  100% { opacity: 0; transform: translateY(-56px) scale(0.9); }
}

/* ===== LEVEL CLEAR OVERLAY ===== */
.level-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  pointer-events: none;
  background: rgba(80,200,120,0.12);
  animation: overlay-fade 1.5s ease forwards;
}

@keyframes overlay-fade {
  0%   { opacity: 0; }
  15%  { opacity: 1; }
  80%  { opacity: 1; }
  100% { opacity: 0; }
}

.level-overlay-card {
  background: white;
  padding: 28px 44px;
  border-radius: 18px;
  text-align: center;
  box-shadow: 0 8px 30px rgba(0,0,0,0.18);
}

.level-overlay-card .lo-icon  { font-size: 42px; }
.level-overlay-card .lo-title { font-size: 1.4rem; font-weight: 700; color: #2c7a4b; margin-top: 8px; }
.level-overlay-card .lo-bonus { color: var(--text-light); margin-top: 6px; font-size: 0.95rem; }

/* ===== RESULT SCREEN ===== */
#screen-result { padding: 24px 16px; }

.result-card {
  background: white;
  border-radius: 20px;
  padding: 36px;
  width: 100%;
  max-width: 420px;
  box-shadow: 0 8px 30px rgba(0,0,0,0.12);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  text-align: center;
}

#result-icon  { font-size: 52px; }
.result-card h2 { font-size: 1.5rem; color: var(--text); }

.result-stats {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.stat-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 16px;
  background: #f8f8f8;
  border-radius: 8px;
}

.stat-row.highlight { background: #eef4ff; }
.stat-label { color: var(--text-light); font-size: 0.88rem; }
.stat-value { font-weight: 700; color: var(--text); }
.stat-row.highlight .stat-value { color: var(--primary); font-size: 1.25rem; }

.result-actions {
  display: flex;
  gap: 10px;
  width: 100%;
}

.result-actions button { flex: 1; }

/* ===== LEADERBOARD ===== */
.leaderboard-section {
  width: 100%;
  border-top: 1px solid #eee;
  padding-top: 16px;
}

.leaderboard-section h3 {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 10px;
  text-align: left;
}

.lb-row {
  display: grid;
  grid-template-columns: 32px 1fr auto auto;
  align-items: center;
  gap: 6px;
  padding: 7px 10px;
  border-radius: 8px;
  font-size: 0.88rem;
  margin-bottom: 4px;
  background: #f8f8f8;
}

.lb-row.lb-me {
  background: #eef4ff;
  font-weight: 700;
  outline: 2px solid var(--primary);
}

.lb-rank  { font-size: 1rem; text-align: center; }
.lb-name  { color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lb-score { color: var(--primary); font-weight: 700; white-space: nowrap; }
.lb-level { color: var(--text-light); font-size: 0.78rem; white-space: nowrap; }

.lb-status {
  text-align: center;
  color: var(--text-light);
  font-size: 0.85rem;
  padding: 12px 0;
}
.lb-error { color: var(--danger); }

/* ===== RESPONSIVE ===== */
@media (max-width: 600px) {
  #desk { height: 260px; }

  .desk-item {
    width: 54px;
    height: 54px;
    font-size: 24px;
  }

  .game-zone {
    min-width: 64px;
    height: 68px;
    font-size: 18px;
  }
}
