:root {
  --bg: #f4f7f0;
  --paper: #fffef8;
  --green-dark: #2d5a27;
  --green: #4a8f3c;
  --green-light: #8bc34a;
  --brown: #8b6f47;
  --text: #2c3e2c;
  --text-muted: #6b7c6b;
  --accent: #ff9800;
  --error: #c62828;
  --success: #2e7d32;
  --shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

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

html,
body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #87ceeb;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--text);
  touch-action: none;
}

#app {
  position: relative;
  width: 100%;
  height: 100%;
}

#game-canvas {
  display: block;
  width: 100%;
  height: 100%;
  outline: none;
}

/* Top bar */
.top-bar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  background: linear-gradient(to bottom, rgba(255, 255, 255, 0.95), rgba(255, 255, 255, 0.75));
  backdrop-filter: blur(4px);
  box-shadow: var(--shadow);
  z-index: 10;
}

.top-bar h1 {
  font-size: 16px;
  font-weight: 700;
  color: var(--green-dark);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.top-actions {
  display: flex;
  gap: 6px;
}

.icon-btn {
  width: 38px;
  height: 38px;
  border: none;
  border-radius: 50%;
  background: var(--paper);
  box-shadow: var(--shadow);
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.1s, background 0.15s;
}

.icon-btn:active {
  transform: scale(0.92);
  background: #f0f0e8;
}

/* Interaction hint */
.interaction-hint {
  position: absolute;
  bottom: 140px;
  left: 50%;
  transform: translateX(-50%);
  padding: 10px 18px;
  background: rgba(255, 255, 255, 0.95);
  border: none;
  border-radius: 20px;
  box-shadow: var(--shadow);
  font-size: 14px;
  color: var(--text);
  z-index: 10;
  transition: opacity 0.2s;
  cursor: pointer;
}

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

/* Joystick */
.joystick-zone {
  position: absolute;
  bottom: 24px;
  left: 24px;
  z-index: 20;
}

.joystick-base {
  width: 110px;
  height: 110px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.35);
  border: 2px solid rgba(255, 255, 255, 0.5);
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: none;
}

.joystick-knob {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.9);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.25);
  position: absolute;
  transition: transform 0.05s linear;
}

/* Modal */
.modal {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.5);
  z-index: 50;
  padding: 16px;
  opacity: 1;
  transition: opacity 0.2s;
}

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

.modal-content {
  position: relative;
  width: 100%;
  max-width: 520px;
  max-height: 80vh;
  overflow-y: auto;
  background: var(--paper);
  border-radius: 16px;
  padding: 24px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25);
}

.modal-close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 50%;
  background: #f0f0e8;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-body h2,
.modal-body h3 {
  color: var(--green-dark);
  margin-bottom: 12px;
}

.modal-body p {
  margin-bottom: 10px;
  line-height: 1.5;
}

.modal-body .fact {
  padding: 10px;
  background: #f1f8e9;
  border-radius: 8px;
  margin-bottom: 8px;
}

.btn-primary {
  display: inline-block;
  width: 100%;
  padding: 12px 20px;
  margin-top: 12px;
  border: none;
  border-radius: 10px;
  background: var(--green);
  color: white;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}

.btn-primary:active {
  background: var(--green-dark);
}

.quiz-options {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 16px 0;
}

.quiz-option {
  padding: 12px 16px;
  border: 2px solid #e0e0d8;
  border-radius: 10px;
  background: white;
  text-align: left;
  font-size: 15px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.quiz-option:active {
  background: #f1f8e9;
  border-color: var(--green);
}

.lifecycle-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 16px 0;
}

.lifecycle-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  background: white;
  border: 2px solid #e0e0d8;
  border-radius: 10px;
}

.lifecycle-emoji {
  font-size: 24px;
}

.lifecycle-name {
  flex: 1;
  font-size: 15px;
}

.lifecycle-controls {
  display: flex;
  gap: 4px;
}

.lifecycle-controls button {
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 6px;
  background: var(--green-light);
  color: white;
  font-size: 16px;
  cursor: pointer;
}

.lifecycle-controls button:disabled {
  background: #ccc;
  cursor: not-allowed;
}

.feedback {
  margin-top: 10px;
  font-weight: 600;
  min-height: 24px;
}

.feedback.success {
  color: var(--success);
}

.feedback.error {
  color: var(--error);
}

/* Diary */
.diary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 12px;
  margin: 16px 0;
}

.diary-card {
  padding: 12px;
  background: white;
  border: 2px solid #e0e0d8;
  border-radius: 10px;
  text-align: center;
}

.diary-card.locked {
  opacity: 0.6;
  background: #f5f5f0;
}

.diary-emoji {
  font-size: 36px;
  margin-bottom: 8px;
}

.diary-info strong {
  display: block;
  color: var(--green-dark);
  margin-bottom: 4px;
}

.diary-info p {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.btn-color {
  padding: 6px 12px;
  border: none;
  border-radius: 6px;
  background: var(--accent);
  color: white;
  font-size: 13px;
  cursor: pointer;
}

/* Loading screen */
.loading-screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  background: var(--bg);
  z-index: 100;
  transition: opacity 0.3s;
}

.loading-screen.hidden {
  opacity: 0;
  pointer-events: none;
}

.loading-spinner {
  width: 48px;
  height: 48px;
  border: 4px solid rgba(74, 143, 60, 0.2);
  border-top-color: var(--green);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

.loading-screen p {
  color: var(--text-muted);
  font-size: 16px;
}

/* Responsive */
@media (max-width: 480px) {
  .top-bar h1 {
    font-size: 13px;
  }

  .icon-btn {
    width: 34px;
    height: 34px;
    font-size: 16px;
  }

  .joystick-zone {
    bottom: 16px;
    left: 16px;
  }

  .joystick-base {
    width: 96px;
    height: 96px;
  }

  .joystick-knob {
    width: 40px;
    height: 40px;
  }

  .interaction-hint {
    bottom: 120px;
    font-size: 13px;
  }

  .modal-content {
    padding: 18px;
    max-height: 85vh;
  }

  .diary-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (min-width: 1024px) {
  .joystick-zone {
    display: none;
  }
}
