:root {
  --bg-primary: #fff0f5;
  --bg-secondary: #ffeef8;
  --card-bg: rgba(255, 255, 255, 0.85);
  --accent-color: #ff8ebb;
  --accent-hover: #ff75ab;
  --text-dark: #4a2a38;
  --text-muted: #8c6a78;
  --border-color: #ffd6e8;
  --shadow-color: rgba(255, 142, 187, 0.15);
  --success-color: #4cd964;
  --font-fancy: 'Outfit', 'Gowun Dodum', sans-serif;
  --font-title: 'Outfit', 'Nanum Pen Script', sans-serif;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: var(--font-fancy);
}

body {
  background: radial-gradient(circle at center, #fff9fb 0%, #ffeaf2 100%);
  color: var(--text-dark);
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  overflow-x: hidden;
  padding: 10px;
}

#app {
  width: 100%;
  max-width: 900px;
  background: var(--card-bg);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 4px solid var(--border-color);
  border-radius: 32px;
  box-shadow: 0 20px 50px var(--shadow-color);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
  animation: popIn 0.6s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes popIn {
  from { transform: scale(0.9) translateY(20px); opacity: 0; }
  to { transform: scale(1) translateY(0); opacity: 1; }
}

/* Header */
.game-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 24px;
  border-bottom: 2px dashed var(--border-color);
  background: rgba(255, 255, 255, 0.5);
}

.header-logo {
  display: flex;
  align-items: center;
  gap: 10px;
}

.logo-emoji {
  font-size: 2rem;
  animation: wave 2s infinite ease-in-out;
}

@keyframes wave {
  0%, 100% { transform: rotate(0deg); }
  50% { transform: rotate(15deg) scale(1.1); }
}

.header-logo h1 {
  font-size: 1.8rem;
  font-weight: 800;
  color: var(--text-dark);
  letter-spacing: -0.5px;
}

.header-controls {
  display: flex;
  gap: 10px;
}

.control-btn {
  background: white;
  border: 2px solid var(--border-color);
  border-radius: 16px;
  padding: 8px 14px;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-dark);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  box-shadow: 0 4px 6px rgba(255, 142, 187, 0.05);
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.control-btn:hover {
  transform: translateY(-2px);
  border-color: var(--accent-color);
  box-shadow: 0 6px 12px var(--shadow-color);
}

.control-btn:active {
  transform: translateY(0);
}

/* Main Container Layout */
.game-container {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  padding: 24px;
  align-items: stretch;
}

@media (max-width: 768px) {
  .game-container {
    grid-template-columns: 1fr;
  }
  #app {
    border-radius: 20px;
    border-width: 2px;
  }
  .header-logo h1 {
    font-size: 1.4rem;
  }
}

/* Target Card */
.target-card-container {
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.target-card {
  background: white;
  border: 3px solid var(--border-color);
  border-radius: 24px;
  padding: 20px;
  box-shadow: inset 0 0 10px rgba(255, 142, 187, 0.05);
  position: relative;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.card-header {
  display: flex;
  justify-content: center;
  margin-bottom: 15px;
}

.card-badge {
  background: var(--accent-color);
  color: white;
  font-size: 0.9rem;
  font-weight: 800;
  padding: 6px 16px;
  border-radius: 20px;
  box-shadow: 0 4px 10px rgba(255, 142, 187, 0.3);
}

.target-nails-preview {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin: 15px 0;
  background: var(--bg-secondary);
  padding: 12px;
  border-radius: 20px;
}

.target-nail-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  flex: 1;
}

.finger-label {
  font-size: 0.75rem;
  font-weight: bold;
  color: var(--text-muted);
  margin-bottom: 6px;
}

/* Nail Base Design */
.nail-display, .nail-slot {
  width: 32px;
  height: 46px;
  background: #f7cbd5; /* Default bare nail skin tone */
  border-radius: 12px 12px 6px 6px;
  border: 2.5px solid #d4a5b1;
  position: relative;
  overflow: hidden;
  box-shadow: inset 0 4px 6px rgba(0,0,0,0.1), 0 2px 4px rgba(0,0,0,0.05);
  cursor: pointer;
  transition: all 0.2s ease;
}

/* Active Highlight for Hand Editor */
.nail-slot.active {
  border-color: var(--accent-color);
  box-shadow: 0 0 0 4px rgba(255, 142, 187, 0.4), inset 0 4px 6px rgba(0,0,0,0.1);
  transform: scale(1.08);
}

/* Rendering Polish, Patterns, Parts */
.nail-polish {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  border-radius: 9px 9px 4px 4px;
}

/* Nail Polish Highlights */
.nail-polish::after {
  content: '';
  position: absolute;
  top: 10%;
  left: 15%;
  width: 25%;
  height: 60%;
  background: rgba(255, 255, 255, 0.4);
  border-radius: 10px;
  filter: blur(1px);
}

.nail-pattern {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  background-size: cover;
}

/* Pattern CSS Styles */
.pattern-dots {
  background-image: radial-gradient(rgba(255,255,255,0.7) 15%, transparent 16%);
  background-size: 8px 8px;
}
.pattern-stripes {
  background: repeating-linear-gradient(45deg, rgba(255,255,255,0.4), rgba(255,255,255,0.4) 4px, transparent 4px, transparent 8px);
}
.pattern-check {
  background: linear-gradient(45deg, rgba(255,255,255,0.3) 25%, transparent 25%, transparent 75%, rgba(255,255,255,0.3) 75%),
              linear-gradient(45deg, rgba(255,255,255,0.3) 25%, transparent 25%, transparent 75%, rgba(255,255,255,0.3) 75%);
  background-size: 10px 10px;
  background-position: 0 0, 5px 5px;
}
.pattern-hearts {
  background-image: radial-gradient(rgba(255,255,255,0.85) 20%, transparent 20%),
                    radial-gradient(rgba(255,255,255,0.85) 20%, transparent 20%);
  background-size: 12px 12px;
  background-position: 0 0, 6px 6px;
}

.nail-part {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 18px;
  line-height: 1;
  pointer-events: none;
  filter: drop-shadow(0 2px 4px rgba(0,0,0,0.25));
  animation: partAttach 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes partAttach {
  from { transform: translate(-50%, -50%) scale(0.2); opacity: 0; }
  to { transform: translate(-50%, -50%) scale(1); opacity: 1; }
}

.instructions {
  font-size: 0.95rem;
  font-weight: 600;
  text-align: center;
  color: var(--text-muted);
  margin-top: 12px;
}

/* Game Board Column */
.game-board {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  background: white;
  border: 3px solid var(--border-color);
  border-radius: 24px;
  padding: 20px;
}

.timer-display {
  font-size: 1.4rem;
  font-weight: 800;
  color: var(--text-dark);
  background: var(--bg-secondary);
  padding: 8px 20px;
  border-radius: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
  border: 2px solid var(--border-color);
}

#gameTimer {
  font-variant-numeric: tabular-nums;
  color: var(--accent-color);
  font-weight: 800;
}

/* Cute Hand Drawing */
.hand-wrapper {
  margin: 25px 0;
  display: flex;
  justify-content: center;
  width: 100%;
}

.cute-hand {
  position: relative;
  width: 260px;
  height: 200px;
  background: #ffecf0;
  border-radius: 100px 100px 30px 30px;
  border: 5px solid #ffd6e0;
  box-shadow: 0 10px 15px rgba(255, 142, 187, 0.1);
}

.wrist {
  position: absolute;
  bottom: -40px;
  left: 50%;
  transform: translateX(-50%);
  width: 120px;
  height: 40px;
  background: #ffecf0;
  border-left: 5px solid #ffd6e0;
  border-right: 5px solid #ffd6e0;
}

.finger {
  position: absolute;
  width: 38px;
  background: #ffecf0;
  border: 5px solid #ffd6e0;
  border-bottom: none;
  border-radius: 20px 20px 0 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  cursor: pointer;
}

.finger-hint {
  font-size: 0.7rem;
  font-weight: bold;
  color: #ff9fb4;
  margin-top: 4px;
  background: white;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  display: flex;
  justify-content: center;
  align-items: center;
}

/* Finger Positions and Heights */
.finger-thumb {
  height: 70px;
  left: -25px;
  top: 90px;
  transform: rotate(-35deg);
  border-radius: 20px;
  border-bottom: 5px solid #ffd6e0;
}
.finger-thumb .nail-slot {
  margin-top: 6px;
  transform: rotate(0deg);
}

.finger-index {
  height: 110px;
  left: 20px;
  top: -70px;
  border-radius: 20px 20px 0 0;
}
.finger-index .nail-slot {
  margin-top: 8px;
}

.finger-middle {
  height: 125px;
  left: 85px;
  top: -90px;
}
.finger-middle .nail-slot {
  margin-top: 8px;
}

.finger-ring {
  height: 115px;
  left: 150px;
  top: -75px;
}
.finger-ring .nail-slot {
  margin-top: 8px;
}

.finger-pinky {
  height: 85px;
  left: 215px;
  top: -25px;
  transform: rotate(15deg);
  border-radius: 20px;
  border-bottom: 5px solid #ffd6e0;
}
.finger-pinky .nail-slot {
  margin-top: 6px;
}

/* Selected indicator text */
.finger-focus-indicator {
  margin-bottom: 15px;
  font-size: 0.95rem;
  color: var(--text-dark);
  font-weight: 600;
  background: var(--bg-primary);
  padding: 6px 16px;
  border-radius: 12px;
  border: 1px solid var(--border-color);
}
.finger-focus-indicator strong {
  color: var(--accent-color);
}

/* Submit & Reset Button Panel */
.submit-panel {
  display: flex;
  gap: 12px;
  width: 100%;
}

.action-btn {
  flex: 1;
  border: none;
  border-radius: 16px;
  padding: 12px 20px;
  font-size: 1rem;
  font-weight: 800;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.submit-btn {
  background: var(--accent-color);
  color: white;
  box-shadow: 0 6px 12px rgba(255, 142, 187, 0.3);
}

.submit-btn:hover {
  background: var(--accent-hover);
  transform: translateY(-2px);
  box-shadow: 0 8px 20px rgba(255, 142, 187, 0.4);
}

.reset-btn {
  background: #f0f0f0;
  color: var(--text-dark);
  border: 2px solid var(--border-color);
}

.reset-btn:hover {
  background: #e4e4e4;
  transform: translateY(-2px);
}

.action-btn:active {
  transform: translateY(0);
}

/* Toolbox Styles */
.toolbox-section {
  grid-column: 1 / span 2;
  background: white;
  border: 3px solid var(--border-color);
  border-radius: 24px;
  overflow: hidden;
}

@media (max-width: 768px) {
  .toolbox-section {
    grid-column: 1;
  }
}

.toolbox-tabs {
  display: flex;
  background: var(--bg-secondary);
  border-bottom: 2px solid var(--border-color);
}

.tab-btn {
  flex: 1;
  background: none;
  border: none;
  padding: 14px;
  font-size: 1rem;
  font-weight: 800;
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: all 0.2s ease;
}

.tab-btn:hover {
  color: var(--text-dark);
  background: rgba(255, 255, 255, 0.4);
}

.tab-btn.active {
  color: var(--accent-color);
  background: white;
  box-shadow: 0 -4px 10px rgba(255, 142, 187, 0.05);
}

.eraser-tab {
  background: rgba(255, 230, 230, 0.4);
}
.eraser-tab.active {
  color: #ff5c5c;
  background: white;
}

.toolbox-contents {
  padding: 20px;
  background: white;
  min-height: 120px;
}

.tab-pane {
  display: none;
}

.tab-pane.active {
  display: block;
}

/* Grids for Items */
.polish-grid, .pattern-grid, .part-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  justify-content: center;
}

.polish-bottle {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 3px solid var(--border-color);
  cursor: pointer;
  position: relative;
  transition: all 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.polish-bottle:hover, .pattern-item:hover, .part-item:hover {
  transform: scale(1.15) rotate(5deg);
  border-color: var(--accent-color);
  box-shadow: 0 4px 10px var(--shadow-color);
}

.polish-bottle.active, .pattern-item.active, .part-item.active {
  border-color: var(--accent-color);
  box-shadow: 0 0 0 4px rgba(255, 142, 187, 0.4);
}

.pattern-item {
  width: 44px;
  height: 44px;
  border-radius: 8px;
  border: 3px solid var(--border-color);
  cursor: pointer;
  transition: all 0.2s ease;
}

.part-item {
  width: 44px;
  height: 44px;
  border-radius: 8px;
  border: 3px solid var(--border-color);
  background: var(--bg-secondary);
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 24px;
  cursor: pointer;
  transition: all 0.2s ease;
}

/* Custom glitters and colors */
.color-clear { background: #f7cbd5; }

/* Leaderboard Sidebar */
.leaderboard-sidebar {
  position: fixed;
  top: 0;
  right: 0;
  width: 320px;
  height: 100%;
  background: white;
  border-left: 4px solid var(--border-color);
  box-shadow: -10px 0 30px rgba(0,0,0,0.1);
  display: flex;
  flex-direction: column;
  z-index: 110; /* Set to 110 to slide above the modal overlay (z-index 100) */
  animation: slideIn 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes slideIn {
  from { transform: translateX(100%); }
  to { transform: translateX(0); }
}

.sidebar-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px;
  background: var(--bg-secondary);
  border-bottom: 2px solid var(--border-color);
}

.sidebar-header h2 {
  font-size: 1.3rem;
  font-weight: 800;
  color: var(--text-dark);
  display: flex;
  align-items: center;
  gap: 8px;
}

.close-sidebar-btn {
  background: none;
  border: none;
  font-size: 1.8rem;
  color: var(--text-muted);
  cursor: pointer;
}

.leaderboard-content {
  flex: 1;
  overflow-y: auto;
  padding: 15px;
}

.leaderboard-table-container {
  width: 100%;
}

.leaderboard-table {
  width: 100%;
  border-collapse: collapse;
}

.leaderboard-table th, .leaderboard-table td {
  padding: 10px;
  text-align: left;
  font-size: 0.9rem;
}

.leaderboard-table th {
  border-bottom: 2px solid var(--border-color);
  font-weight: bold;
  color: var(--text-muted);
}

.leaderboard-table td {
  border-bottom: 1px solid #fbf0f4;
}

.leaderboard-table tr:nth-child(even) {
  background-color: var(--bg-secondary);
}

.rank-col { width: 15%; text-align: center; }
.name-col { width: 55%; font-weight: 600; }
.time-col { width: 30%; font-weight: bold; color: var(--accent-color); text-align: right; }

.leaderboard-toggle-btn {
  position: fixed;
  bottom: 20px;
  right: 20px;
  width: 56px;
  height: 56px;
  background: var(--accent-color);
  border: none;
  border-radius: 50%;
  font-size: 24px;
  color: white;
  cursor: pointer;
  box-shadow: 0 4px 15px rgba(255, 142, 187, 0.4);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 105; /* Above modal overlay (100) but below sidebar (110) */
  transition: all 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.leaderboard-toggle-btn:hover {
  transform: scale(1.1);
  background: var(--accent-hover);
}

/* Modal Overlay & Card (z-index: 100) */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(74, 42, 56, 0.5);
  backdrop-filter: blur(8px);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 100; /* Set to 100 as specified */
}

.modal-card {
  width: 90%;
  max-width: 440px;
  background: white;
  border: 4px solid var(--border-color);
  border-radius: 28px;
  padding: 30px;
  text-align: center;
  box-shadow: 0 15px 35px rgba(0,0,0,0.15);
  animation: modalPop 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes modalPop {
  from { transform: scale(0.85); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.modal-logo {
  font-size: 3rem;
  margin-bottom: 10px;
  animation: bounce 1.5s infinite alternate ease-in-out;
}

@keyframes bounce {
  from { transform: translateY(0); }
  to { transform: translateY(-10px); }
}

.modal-card h2 {
  font-size: 2rem;
  font-weight: 800;
  color: var(--accent-color);
  margin-bottom: 15px;
}

.result-text {
  font-size: 1.05rem;
  color: var(--text-muted);
  margin-bottom: 15px;
  line-height: 1.5;
}

.final-score {
  font-size: 1.6rem;
  font-weight: 800;
  margin: 15px 0 25px 0;
  color: var(--text-dark);
}
.final-score strong {
  color: var(--accent-color);
}

/* Name Entry Input and button */
.input-group {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 15px;
}

#playerNameInput {
  width: 100%;
  padding: 12px;
  border-radius: 12px;
  border: 2px solid var(--border-color);
  font-size: 1rem;
  text-align: center;
  font-weight: 600;
  outline: none;
  transition: all 0.2s ease;
}

#playerNameInput:focus {
  border-color: var(--accent-color);
  box-shadow: 0 0 0 3px rgba(255, 142, 187, 0.2);
}

.modal-action-btn {
  width: 100%;
  border: none;
  border-radius: 14px;
  padding: 12px;
  font-size: 1rem;
  font-weight: 800;
  cursor: pointer;
  transition: all 0.2s ease;
}

.submit-score-btn {
  background: var(--accent-color);
  color: white;
}
.submit-score-btn:hover {
  background: var(--accent-hover);
}

.replay-btn {
  background: var(--accent-color);
  color: white;
  margin-top: 10px;
  box-shadow: 0 4px 10px rgba(255, 142, 187, 0.2);
}
.replay-btn:hover {
  background: var(--accent-hover);
}

.text-highlight {
  font-weight: 600;
  color: var(--accent-color);
  margin-bottom: 5px;
}

.text-success {
  font-weight: 600;
  color: var(--success-color);
  margin-bottom: 10px;
}

.text-muted {
  color: var(--text-muted);
}

/* Footer elements */
.game-footer {
  border-top: 2px dashed var(--border-color);
  padding: 15px 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  background: rgba(255, 255, 255, 0.3);
}

.shortcuts-cheat-sheet {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  justify-content: center;
}

.cheat-title {
  color: var(--text-dark);
  font-weight: bold;
}

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

kbd {
  background: white;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  padding: 1px 5px;
  font-size: 0.75rem;
  box-shadow: 0 1px 0 rgba(0,0,0,0.1);
  font-family: monospace;
}

.copyright {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-weight: bold;
}
