/* ===== Reset & Base ===== */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: -apple-system, 'Apple SD Gothic Neo', sans-serif;
  background: #f8f4ff;
  color: #333;
  touch-action: none;
}

/* ===== Screen Management ===== */
.screen {
  display: none;
  width: 100%;
  height: 100%;
  position: absolute;
  top: 0;
  left: 0;
}

.screen.active {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

/* ===== Rotate Notice ===== */
#rotate-notice {
  display: none;
  background: #6c5ce7;
  color: white;
  z-index: 9999;
}

@media (orientation: portrait) {
  #rotate-notice {
    display: flex !important;
  }
  .screen:not(#rotate-notice) {
    display: none !important;
  }
}

.rotate-content {
  text-align: center;
}

.rotate-icon {
  font-size: 80px;
  animation: rotate-hint 2s ease-in-out infinite;
}

@keyframes rotate-hint {
  0%, 100% { transform: rotate(0deg); }
  50% { transform: rotate(90deg); }
}

#rotate-notice p {
  font-size: 24px;
  margin-top: 20px;
  font-weight: 600;
}

/* ===== Buttons ===== */
.btn {
  border: none;
  border-radius: 16px;
  font-size: 20px;
  font-weight: 600;
  cursor: pointer;
  padding: 14px 32px;
  transition: transform 0.1s, opacity 0.1s;
}

.btn:active {
  transform: scale(0.95);
  opacity: 0.8;
}

.btn-primary {
  background: #6c5ce7;
  color: white;
}

.btn-secondary {
  background: #dfe6e9;
  color: #2d3436;
}

.btn-action {
  background: #ffffff;
  color: #6c5ce7;
  border: 2px solid #6c5ce7;
  padding: 10px 20px;
  font-size: 16px;
}

.btn-icon {
  background: transparent;
  font-size: 28px;
  padding: 8px;
}

.btn:disabled {
  opacity: 0.5;
  pointer-events: none;
}

/* ===== Start Screen ===== */
.start-content {
  text-align: center;
}

.game-title {
  font-size: 36px;
  color: #6c5ce7;
  margin-bottom: 16px;
}

.mascot-container {
  margin: 16px 0;
}

.mascot {
  font-size: 80px;
  animation: bounce 2s ease-in-out infinite;
}

@keyframes bounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-10px); }
}

.game-description {
  font-size: 20px;
  color: #636e72;
  margin-bottom: 32px;
  line-height: 1.5;
}

.start-content .btn {
  display: block;
  width: 200px;
  margin: 10px auto;
}

/* ===== Tutorial Screen ===== */
.tutorial-content {
  text-align: center;
  padding: 20px;
}

.tutorial-content h2 {
  font-size: 28px;
  color: #6c5ce7;
  margin-bottom: 24px;
}

.tutorial-steps {
  margin-bottom: 24px;
}

.step {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin: 12px 0;
  font-size: 20px;
}

.step-num {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: #6c5ce7;
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 16px;
}

.demo-canvas-area {
  display: flex;
  gap: 12px;
  justify-content: center;
  margin: 20px 0;
}

.demo-char-box {
  width: 80px;
  height: 80px;
  border: 3px dashed #b2bec3;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 36px;
  color: #b2bec3;
  background: white;
}

/* ===== Game Screen ===== */
#game-screen.active {
  justify-content: space-between;
  padding: 12px 20px;
}

.game-header {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 16px;
}

.coin-display {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 22px;
  font-weight: 700;
}

.coin-icon {
  font-size: 24px;
}

.coin-icon.large {
  font-size: 48px;
}

.round-display {
  font-size: 18px;
  color: #636e72;
  font-weight: 600;
}

.game-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  width: 100%;
}

.insect-image-container {
  width: 200px;
  height: 200px;
  border-radius: 20px;
  overflow: hidden;
  background: white;
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
  display: flex;
  align-items: center;
  justify-content: center;
}

.insect-image-container img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* ===== Canvas Container ===== */
.canvas-container {
  display: flex;
  gap: 12px;
  justify-content: center;
  flex-wrap: wrap;
}

.char-canvas-wrapper {
  position: relative;
}

.char-canvas {
  width: 320px;
  height: 320px;
  border: 3px solid #dfe6e9;
  border-radius: 12px;
  background: white;
  touch-action: none;
}

.char-canvas.active-input {
  border-color: #6c5ce7;
}

.char-canvas.correct {
  border-color: #00b894;
  background: #f0fff4;
}

.char-canvas.incorrect {
  border-color: #fdcb6e;
  background: #fffbf0;
}

.char-canvas.unrecognized {
  border-color: #b2bec3;
  background: #f5f5f5;
}

.char-canvas-guide {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 80%;
  height: 80%;
  pointer-events: none;
}

.char-canvas-guide::before,
.char-canvas-guide::after {
  content: '';
  position: absolute;
  background: #f0f0f0;
}

.char-canvas-guide::before {
  width: 1px;
  height: 100%;
  left: 50%;
}

.char-canvas-guide::after {
  width: 100%;
  height: 1px;
  top: 50%;
}

/* Trace canvas */
.trace-char-canvas {
  width: 140px;
  height: 140px;
  border: 3px solid #6c5ce7;
  border-radius: 12px;
  background: white;
  touch-action: none;
}

/* ===== Feedback Message ===== */
.feedback-message {
  font-size: 18px;
  font-weight: 600;
  padding: 8px 16px;
  border-radius: 8px;
  text-align: center;
  min-height: 36px;
}

.feedback-message.hidden {
  visibility: hidden;
}

.feedback-message.success {
  color: #00b894;
}

.feedback-message.error {
  color: #e17055;
}

.feedback-message.info {
  color: #6c5ce7;
}

/* ===== Game Footer ===== */
.game-footer {
  width: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
}

/* ===== Mascot Feedback ===== */
.mascot-feedback {
  position: fixed;
  bottom: 80px;
  right: 20px;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  transition: opacity 0.3s, transform 0.3s;
}

.mascot-feedback.hidden {
  opacity: 0;
  transform: translateY(20px);
  pointer-events: none;
}

.mascot-bubble {
  background: white;
  border-radius: 16px;
  padding: 12px 16px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
  font-size: 16px;
  max-width: 160px;
}

.mascot-char {
  font-size: 40px;
}

/* ===== Bonus Screen ===== */
#bonus-screen.active {
  background: rgba(0,0,0,0.7);
  z-index: 100;
}

.bonus-content {
  background: white;
  border-radius: 24px;
  padding: 32px;
  text-align: center;
  max-width: 400px;
  width: 90%;
}

.bonus-content h2 {
  color: #00b894;
  font-size: 28px;
  margin-bottom: 16px;
}

.bonus-images {
  margin: 16px 0;
}

.bonus-images img {
  width: 180px;
  height: 180px;
  border-radius: 16px;
  object-fit: cover;
}

.bonus-desc {
  font-size: 18px;
  color: #636e72;
  margin: 12px 0;
}

.bonus-tap {
  font-size: 14px;
  color: #b2bec3;
  margin-top: 16px;
}

/* ===== Trace Screen ===== */
#trace-screen.active {
  background: #f8f4ff;
  z-index: 99;
}

.trace-content {
  text-align: center;
}

.trace-content h2 {
  font-size: 24px;
  color: #6c5ce7;
  margin-bottom: 24px;
}

/* ===== Result Screen ===== */
.result-content {
  text-align: center;
  padding: 20px;
  max-height: 100%;
  overflow-y: auto;
}

.result-content h2 {
  font-size: 28px;
  color: #6c5ce7;
  margin-bottom: 12px;
}

.result-score {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 36px;
  font-weight: 700;
  margin-bottom: 24px;
}

.result-list {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 24px;
  max-width: 400px;
  margin-left: auto;
  margin-right: auto;
}

.result-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: white;
  border-radius: 8px;
  font-size: 16px;
}

.result-item.correct {
  border-left: 4px solid #00b894;
}

.result-item.incorrect {
  border-left: 4px solid #e17055;
}

.result-buttons {
  display: flex;
  gap: 12px;
  justify-content: center;
}

/* ===== Collection Screen ===== */
.collection-content {
  padding: 20px;
  text-align: center;
  max-height: 100%;
  overflow-y: auto;
}

.collection-content h2 {
  font-size: 24px;
  color: #6c5ce7;
  margin-bottom: 20px;
}

.collection-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 12px;
  max-width: 500px;
  margin: 0 auto 24px;
}

.collection-item {
  width: 80px;
  height: 80px;
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  gap: 4px;
}

.collection-item.collected {
  background: white;
  border: 2px solid #00b894;
}

.collection-item.locked {
  background: #dfe6e9;
  border: 2px solid #b2bec3;
}

.collection-item .item-icon {
  font-size: 28px;
}

.collection-item.locked .item-icon {
  filter: brightness(0) opacity(0.3);
}

/* ===== Coin Animation ===== */
.coin-fly {
  position: fixed;
  font-size: 32px;
  pointer-events: none;
  z-index: 1000;
  animation: coin-fly-up 0.8s ease-out forwards;
}

@keyframes coin-fly-up {
  0% {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
  100% {
    opacity: 0;
    transform: translateY(-100px) scale(0.5);
  }
}

/* ===== Loading Spinner ===== */
.spinner {
  display: inline-block;
  width: 20px;
  height: 20px;
  border: 3px solid rgba(255,255,255,0.3);
  border-radius: 50%;
  border-top-color: white;
  animation: spin 0.8s linear infinite;
}

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

/* ===== Hint Display ===== */
.hint-display {
  font-size: 24px;
  letter-spacing: 8px;
  color: #6c5ce7;
  font-weight: 700;
  margin-top: 8px;
}

/* ===== Modal ===== */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9998;
}

.modal {
  background: white;
  border-radius: 20px;
  padding: 32px;
  text-align: center;
  max-width: 320px;
}

.modal p {
  font-size: 18px;
  margin-bottom: 20px;
}

.modal .btn {
  margin: 8px;
}
