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

:root {
  --bg-warm: #f5f0e8;
  --bg-toolbar: #2c2c2c;
  --accent-red: #e74c3c;
  --accent-blue: #3498db;
  --accent-yellow: #f1c40f;
  --accent-green: #2ecc71;
  --accent-purple: #9b59b6;
  --accent-orange: #e67e22;
  --text-dark: #2c3e50;
  --text-light: #ecf0f1;
  --grid-line: rgba(100, 130, 180, 0.12);
  --panel-bg: #faf8f4;
  --control-bg: #363636;
  --shadow: 0 2px 12px rgba(0,0,0,0.15);
}

body {
  font-family: 'Baloo 2', cursive, sans-serif;
  background: var(--bg-warm);
  color: var(--text-dark);
  overflow: hidden;
  height: 100vh;
  width: 100vw;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  width: 100vw;
}

/* TOOLBAR */
#toolbar {
  background: var(--bg-toolbar);
  display: flex;
  align-items: center;
  padding: 4px 12px;
  gap: 8px;
  min-height: 56px;
  overflow-x: auto;
  z-index: 10;
  box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}

#toolbar-label {
  color: var(--accent-yellow);
  font-weight: 700;
  font-size: 13px;
  white-space: nowrap;
  letter-spacing: 1px;
}

#palette {
  display: flex;
  gap: 6px;
  align-items: center;
}

.palette-item {
  background: rgba(255,255,255,0.08);
  border: 2px solid rgba(255,255,255,0.15);
  border-radius: 10px;
  padding: 4px 10px;
  cursor: grab;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  transition: all 0.15s;
  user-select: none;
  min-width: 64px;
  position: relative;
}

.palette-item:hover {
  background: rgba(255,255,255,0.18);
  border-color: var(--accent-yellow);
  transform: translateY(-2px);
}

.palette-item:active {
  cursor: grabbing;
}

.palette-item .emoji {
  font-size: 22px;
  line-height: 1;
}

.palette-item .label {
  font-size: 10px;
  color: var(--text-light);
  white-space: nowrap;
  font-weight: 600;
}

.palette-item .tooltip {
  display: none;
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  background: #222;
  color: #fff;
  padding: 4px 8px;
  border-radius: 6px;
  font-size: 11px;
  white-space: nowrap;
  z-index: 100;
  margin-top: 4px;
  pointer-events: none;
}

.palette-item:hover .tooltip { display: block; }

/* MAIN AREA */
#main-area {
  flex: 1;
  position: relative;
  overflow: hidden;
}

#canvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: crosshair;
}

/* SIDE PANEL */
#side-panel {
  position: absolute;
  top: 0;
  right: 0;
  width: 240px;
  height: 100%;
  background: var(--panel-bg);
  box-shadow: -2px 0 12px rgba(0,0,0,0.1);
  transition: transform 0.3s ease;
  z-index: 5;
  display: flex;
  flex-direction: column;
}

#side-panel.collapsed {
  transform: translateX(200px);
}

#panel-toggle {
  position: absolute;
  left: -28px;
  top: 12px;
  width: 28px;
  height: 36px;
  background: var(--panel-bg);
  border: 1px solid #ddd;
  border-right: none;
  border-radius: 6px 0 0 6px;
  cursor: pointer;
  font-size: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: -2px 0 6px rgba(0,0,0,0.08);
}

#panel-content {
  padding: 12px;
  overflow-y: auto;
  flex: 1;
  font-size: 13px;
}

#panel-content h3 {
  font-size: 14px;
  margin: 10px 0 6px 0;
  color: var(--text-dark);
  border-bottom: 2px solid var(--accent-yellow);
  padding-bottom: 3px;
}

#panel-content h3:first-child { margin-top: 0; }

#props-body, #stats-body, #tips-body {
  margin-bottom: 8px;
  line-height: 1.6;
}

.prop-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: 4px 0;
}

.prop-row label { font-size: 12px; font-weight: 600; }
.prop-row select, .prop-row input { font-size: 12px; padding: 2px 4px; border-radius: 4px; border: 1px solid #ccc; }

.stat-line {
  font-size: 13px;
  padding: 2px 0;
}

.milestone {
  color: var(--accent-orange);
  font-weight: 700;
  font-size: 12px;
  margin-top: 6px;
  animation: pulse 1.5s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}

/* CONTROLS */
#controls {
  background: var(--control-bg);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 12px;
  gap: 8px;
  min-height: 48px;
  z-index: 10;
  flex-wrap: wrap;
}

#controls-left, #controls-center, #controls-right {
  display: flex;
  align-items: center;
  gap: 6px;
}

.ctrl-btn {
  font-family: 'Baloo 2', cursive;
  font-size: 13px;
  font-weight: 600;
  padding: 5px 12px;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  background: rgba(255,255,255,0.12);
  color: var(--text-light);
  transition: all 0.15s;
  white-space: nowrap;
}

.ctrl-btn:hover:not(:disabled) {
  background: rgba(255,255,255,0.25);
  transform: translateY(-1px);
}

.ctrl-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.play-btn {
  background: var(--accent-green) !important;
  color: #fff !important;
}

.play-btn:hover:not(:disabled) {
  background: #27ae60 !important;
}

.danger-btn {
  background: rgba(231, 76, 60, 0.3) !important;
}

.danger-btn:hover {
  background: var(--accent-red) !important;
}

#speed-slider {
  width: 80px;
  accent-color: var(--accent-yellow);
}

#speed-label, #snap-label {
  color: var(--text-light);
  font-size: 12px;
  white-space: nowrap;
}

#snap-label { cursor: pointer; }
#snap-toggle { cursor: pointer; }

#preset-select {
  font-family: 'Baloo 2', cursive;
  font-size: 12px;
  padding: 4px 8px;
  border-radius: 6px;
  border: 1px solid rgba(255,255,255,0.2);
  background: rgba(255,255,255,0.1);
  color: var(--text-light);
  cursor: pointer;
}

#preset-select option { background: #333; color: #fff; }

/* FOOTER */
#footer {
  background: var(--bg-toolbar);
  color: rgba(255,255,255,0.5);
  text-align: center;
  font-size: 11px;
  padding: 4px;
}

#footer a { color: var(--accent-yellow); text-decoration: none; }
#footer a:hover { text-decoration: underline; }

/* MODAL */
#modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

#modal-overlay.hidden { display: none; }

#modal {
  background: var(--panel-bg);
  border-radius: 16px;
  padding: 24px;
  min-width: 320px;
  max-width: 90vw;
  box-shadow: var(--shadow);
}

#modal h3 {
  margin-bottom: 16px;
  font-size: 18px;
}

#modal-slots {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 16px;
}

.save-slot {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  border: 2px solid #ddd;
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.15s;
}

.save-slot:hover {
  border-color: var(--accent-blue);
  background: rgba(52,152,219,0.05);
}

.save-slot .slot-info {
  flex: 1;
  font-size: 13px;
}

.save-slot .slot-name { font-weight: 700; }
.save-slot .slot-date { font-size: 11px; color: #888; }
.save-slot .slot-count { font-size: 11px; color: var(--accent-blue); }
.save-slot .slot-empty { color: #aaa; font-style: italic; }

.save-slot .slot-delete {
  background: none;
  border: none;
  font-size: 16px;
  cursor: pointer;
  opacity: 0.5;
  padding: 4px;
}
.save-slot .slot-delete:hover { opacity: 1; }

/* CELEBRATION */
#celebration {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  z-index: 90;
}

#celebration.hidden { display: none; }

#cele-text {
  font-size: 48px;
  font-weight: 800;
  color: var(--accent-green);
  text-shadow: 3px 3px 0 var(--accent-yellow), -1px -1px 0 #fff;
  animation: celeBounce 0.6s ease;
}

@keyframes celeBounce {
  0% { transform: scale(0); opacity: 0; }
  60% { transform: scale(1.2); opacity: 1; }
  100% { transform: scale(1); }
}

/* Onomatopoeia */
.onomatopoeia {
  position: absolute;
  font-family: 'Baloo 2', cursive;
  font-weight: 800;
  font-size: 24px;
  pointer-events: none;
  animation: onomFade 0.8s ease forwards;
  z-index: 20;
  text-shadow: 1px 1px 0 #fff, -1px -1px 0 #fff;
}

@keyframes onomFade {
  0% { transform: scale(0.5) translateY(0); opacity: 0; }
  20% { transform: scale(1.3) translateY(-10px); opacity: 1; }
  100% { transform: scale(0.8) translateY(-40px); opacity: 0; }
}

/* Ghost preview */
.ghost-preview {
  position: fixed;
  pointer-events: none;
  opacity: 0.6;
  z-index: 50;
}

/* Mobile */
@media (max-width: 768px) {
  #toolbar { min-height: 48px; padding: 3px 8px; }
  #toolbar-label { display: none; }
  .palette-item { min-width: 48px; padding: 3px 6px; }
  .palette-item .label { display: none; }
  .palette-item .emoji { font-size: 20px; }
  
  #side-panel { width: 200px; }
  #side-panel.collapsed { transform: translateX(160px); }
  
  #controls { flex-wrap: wrap; gap: 4px; padding: 4px 8px; }
  .ctrl-btn { font-size: 11px; padding: 4px 8px; }
  #speed-slider { width: 60px; }
  #controls-center { order: 3; width: 100%; justify-content: center; }
}

@media (max-width: 480px) {
  .palette-item { min-width: 40px; padding: 2px 4px; }
  .palette-item .emoji { font-size: 18px; }
  #side-panel { display: none; }
  #controls-right { flex-wrap: wrap; }
}