/* =============================================================
   星星超市大冒險 — style.css
   設計原則：圓潤、繽紛、大按鈕，適合 7-12 歲兒童
   調色盤：
     奶油黃  #FFF8E7  (背景)
     珊瑚紅  #FF6B6B  (主色/CTA)
     薄荷綠  #4ECDC4  (次要色)
     檸檬黃  #FFE66D  (亮點)
     深藍紫  #2C2C54  (文字)
     淡紫    #A8A8D8  (說明文)
   字型：Nunito (display) + Noto Sans TC (body)
   ============================================================= */

/* ── Reset & Base ── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg:         #FFF8E7;
  --primary:    #FF6B6B;
  --primary-dk: #E05555;
  --secondary:  #4ECDC4;
  --accent:     #FFE66D;
  --text:       #2C2C54;
  --muted:      #8888AA;
  --card-bg:    #FFFFFF;
  --shadow:     0 4px 16px rgba(44,44,84,0.10);
  --radius-lg:  20px;
  --radius-md:  14px;
  --radius-sm:  8px;

  /* danger states */
  --danger:     #FF4444;
  --warn:       #FF9900;
  --success:    #4ECDC4;

  --font-display: 'Nunito', 'Noto Sans TC', sans-serif;
  --font-body:    'Noto Sans TC', 'Nunito', sans-serif;
}

html {
  font-size: 16px;
  scroll-behavior: smooth;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  min-height: 100dvh;
  overflow-x: hidden;
}

/* ── Screen System ── */
.screen {
  display: none;
  flex-direction: column;
  min-height: 100dvh;
  animation: fadeIn 0.35s ease;
}
.screen.active,
.screen:not([hidden]) {
  display: flex;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── Buttons ── */
.btn-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: var(--primary);
  color: #fff;
  font-family: var(--font-display);
  font-size: 1.1rem;
  font-weight: 700;
  padding: 14px 28px;
  border: none;
  border-radius: 50px;
  cursor: pointer;
  box-shadow: 0 4px 0 var(--primary-dk);
  transition: transform 0.1s, box-shadow 0.1s, background 0.2s;
  min-height: 52px;
  min-width: 44px;
  text-decoration: none;
  -webkit-tap-highlight-color: transparent;
}
.btn-primary:hover:not(:disabled) {
  background: #ff8080;
  transform: translateY(-2px);
  box-shadow: 0 6px 0 var(--primary-dk);
}
.btn-primary:active:not(:disabled) {
  transform: translateY(2px);
  box-shadow: 0 2px 0 var(--primary-dk);
}
.btn-primary:disabled {
  background: #ccc;
  box-shadow: 0 4px 0 #aaa;
  cursor: not-allowed;
  opacity: 0.7;
}

.btn-secondary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: var(--card-bg);
  color: var(--text);
  font-family: var(--font-display);
  font-size: 1rem;
  font-weight: 700;
  padding: 12px 24px;
  border: 2.5px solid var(--text);
  border-radius: 50px;
  cursor: pointer;
  transition: transform 0.1s, background 0.2s;
  min-height: 48px;
  -webkit-tap-highlight-color: transparent;
}
.btn-secondary:hover {
  background: var(--bg);
  transform: translateY(-1px);
}

.btn-icon {
  background: var(--card-bg);
  border: 2px solid #e0d8cc;
  border-radius: 50%;
  width: 44px;
  height: 44px;
  font-size: 1.3rem;
  cursor: pointer;
  transition: transform 0.15s;
  flex-shrink: 0;
}
.btn-icon:hover { transform: scale(1.1); }

/* ── Intro Screen ── */
#screen-intro {
  align-items: center;
  justify-content: center;
  background: linear-gradient(160deg, #FFF8E7 0%, #FFE8D0 60%, #FFD6D6 100%);
  position: relative;
  overflow: hidden;
  text-align: center;
  padding: 32px 24px;
}

.intro-stars {
  position: absolute;
  inset: 0;
  pointer-events: none;
}
.star {
  position: absolute;
  font-size: 1.4rem;
  color: var(--accent);
  opacity: 0.6;
  animation: twinkle 2.5s infinite ease-in-out;
}
.s1 { top: 8%;  left: 12%; animation-delay: 0s;   font-size: 1.8rem; }
.s2 { top: 15%; right: 10%; animation-delay: 0.6s; }
.s3 { top: 65%; left: 5%;  animation-delay: 1.2s; font-size: 1rem; }
.s4 { bottom: 20%; right: 8%; animation-delay: 0.9s; font-size: 2rem; }
.s5 { bottom: 35%; left: 20%; animation-delay: 0.3s; }

@keyframes twinkle {
  0%, 100% { opacity: 0.3; transform: scale(1) rotate(0deg); }
  50%       { opacity: 0.9; transform: scale(1.2) rotate(20deg); }
}

.intro-content {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  max-width: 480px;
  width: 100%;
}

.mascot-big {
  font-size: 5rem;
  animation: float 3s infinite ease-in-out;
  filter: drop-shadow(0 8px 16px rgba(255,107,107,0.3));
}

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

.game-title {
  font-family: var(--font-display);
  font-size: clamp(2.2rem, 8vw, 3.2rem);
  font-weight: 900;
  line-height: 1.1;
  color: var(--text);
  letter-spacing: -0.5px;
  /* text shadow gives the "sticker" look */
  text-shadow:
    3px 3px 0 #fff,
    -1px -1px 0 #fff,
    1px -1px 0 #fff,
    -1px 1px 0 #fff;
}

.intro-desc {
  font-size: 1rem;
  color: var(--muted);
  line-height: 1.6;
}

.intro-hint {
  font-size: 0.85rem;
  color: var(--muted);
  margin-top: 4px;
  line-height: 1.5;
}

/* ── Game Header ── */
.game-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--card-bg);
  border-bottom: 2px solid #EDE5D8;
  position: sticky;
  top: 0;
  z-index: 100;
  gap: 8px;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 6px;
}

.mascot-small {
  font-size: 1.5rem;
}

.stage-label {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--muted);
}

.budget-display {
  display: flex;
  align-items: center;
  gap: 4px;
  background: var(--accent);
  padding: 6px 14px;
  border-radius: 50px;
  border: 2px solid #E8D42A;
  transition: background 0.3s;
}
.budget-display.warn  { background: #FFD0A0; border-color: var(--warn); }
.budget-display.danger { background: #FFB0B0; border-color: var(--danger); animation: shake 0.4s; }

@keyframes shake {
  0%,100% { transform: translateX(0); }
  20% { transform: translateX(-6px); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(4px); }
}

.budget-icon { font-size: 1.2rem; }
.budget-text { font-size: 0.8rem; color: var(--text); white-space: nowrap; }
.budget-amount {
  font-family: var(--font-display);
  font-size: 1.3rem;
  font-weight: 900;
  color: var(--text);
  transition: color 0.3s;
  min-width: 2.5ch;
  text-align: right;
}
.budget-amount.danger { color: var(--danger); }
.budget-unit { font-size: 0.85rem; color: var(--muted); }

/* ── Budget Progress Bar ── */
.budget-bar-wrap {
  padding: 6px 16px 2px;
  background: var(--card-bg);
}

.budget-bar-track {
  height: 10px;
  background: #EDE5D8;
  border-radius: 10px;
  overflow: hidden;
}

.budget-bar-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--secondary), var(--accent));
  border-radius: 10px;
  transition: width 0.4s cubic-bezier(0.34, 1.56, 0.64, 1), background 0.4s;
}
.budget-bar-fill.warn   { background: linear-gradient(90deg, var(--accent), var(--warn)); }
.budget-bar-fill.danger { background: linear-gradient(90deg, var(--warn), var(--danger)); }

.budget-bar-label {
  display: block;
  font-size: 0.72rem;
  color: var(--muted);
  text-align: right;
  margin-top: 2px;
}

/* ── Dialog Box ── */
.dialog-box {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin: 12px 16px 0;
  animation: slideDown 0.3s ease;
}

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

.dialog-bubble {
  flex: 1;
  background: var(--card-bg);
  border: 2.5px solid var(--secondary);
  border-radius: 0 var(--radius-lg) var(--radius-lg) var(--radius-lg);
  padding: 10px 14px;
  position: relative;
  box-shadow: var(--shadow);
}
.dialog-bubble::before {
  content: '';
  position: absolute;
  top: 4px;
  left: -12px;
  border: 6px solid transparent;
  border-right-color: var(--secondary);
}

.dialog-bubble p {
  font-size: 0.92rem;
  line-height: 1.5;
  color: var(--text);
}

.dialog-close {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1rem;
  color: var(--muted);
  padding: 4px;
  flex-shrink: 0;
  margin-top: 8px;
}

/* ── Mission Panel ── */
.mission-panel {
  margin: 10px 16px 0;
  background: linear-gradient(135deg, #E8F9F8, #D0F0EE);
  border-radius: var(--radius-md);
  padding: 12px 16px;
  border: 2px solid #A8E8E4;
}

.mission-title {
  font-family: var(--font-display);
  font-size: 0.95rem;
  font-weight: 800;
  color: #2A8A85;
  margin-bottom: 4px;
}

.mission-desc {
  font-size: 0.9rem;
  line-height: 1.5;
  color: var(--text);
}

/* ── Shop Area / Items Grid ── */
.shop-area {
  flex: 1;
  padding: 12px 16px;
}

.shelf-label {
  font-family: var(--font-display);
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 10px;
}

.items-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 12px;
}

/* ── Item Card ── */
.item-card {
  background: var(--card-bg);
  border-radius: var(--radius-lg);
  padding: 14px 10px;
  text-align: center;
  box-shadow: var(--shadow);
  border: 3px solid transparent;
  cursor: pointer;
  transition: transform 0.15s, border-color 0.2s, box-shadow 0.2s;
  position: relative;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.item-card:hover:not(.sold-out) {
  transform: translateY(-3px);
  box-shadow: 0 8px 24px rgba(44,44,84,0.14);
}

.item-card.selected {
  border-color: var(--secondary);
  background: #E8FFFE;
}

.item-card.sold-out {
  opacity: 0.5;
  cursor: not-allowed;
  filter: grayscale(0.3);
}

.item-card.bounce {
  animation: bounce 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes bounce {
  0%   { transform: scale(1); }
  40%  { transform: scale(1.2); }
  70%  { transform: scale(0.9); }
  100% { transform: scale(1); }
}

/* Ripple effect on add */
.item-card.ripple::after {
  content: '';
  position: absolute;
  inset: -4px;
  border-radius: calc(var(--radius-lg) + 4px);
  border: 3px solid var(--secondary);
  animation: rippleOut 0.5s ease forwards;
  pointer-events: none;
}

@keyframes rippleOut {
  from { opacity: 1; transform: scale(1); }
  to   { opacity: 0; transform: scale(1.2); }
}

.item-emoji { font-size: 2.6rem; line-height: 1; }

.item-name {
  font-family: var(--font-display);
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1.2;
}

.item-price {
  font-family: var(--font-display);
  font-size: 1rem;
  font-weight: 900;
  color: var(--primary);
}

.item-qty-badge {
  position: absolute;
  top: -6px;
  right: -6px;
  background: var(--secondary);
  color: #fff;
  font-family: var(--font-display);
  font-size: 0.75rem;
  font-weight: 900;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 6px rgba(0,0,0,0.15);
}

.sale-badge {
  position: absolute;
  top: 6px;
  left: 6px;
  background: var(--primary);
  color: #fff;
  font-family: var(--font-display);
  font-size: 0.62rem;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 50px;
}

/* ── Cart Panel ── */
.cart-panel {
  background: var(--card-bg);
  border-top: 3px solid #EDE5D8;
  padding: 14px 16px;
  position: sticky;
  bottom: 0;
  z-index: 90;
  box-shadow: 0 -4px 20px rgba(44,44,84,0.08);
}

.cart-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.cart-title {
  font-family: var(--font-display);
  font-size: 1rem;
  font-weight: 800;
}

.cart-count {
  background: var(--primary);
  color: #fff;
  font-family: var(--font-display);
  font-size: 0.75rem;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 50px;
}

.cart-items {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  min-height: 36px;
  margin-bottom: 10px;
  max-height: 100px;
  overflow-y: auto;
}

.cart-empty {
  color: var(--muted);
  font-size: 0.85rem;
  align-self: center;
}

.cart-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: #F0FAF9;
  border: 2px solid var(--secondary);
  border-radius: 50px;
  padding: 4px 10px;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
  animation: popIn 0.25s ease;
}
.cart-chip:hover { background: #D0EEEC; transform: scale(1.05); }

@keyframes popIn {
  from { transform: scale(0.7); opacity: 0; }
  to   { transform: scale(1);   opacity: 1; }
}

.cart-chip-remove {
  color: var(--primary);
  font-size: 1rem;
  font-weight: 900;
}

.cart-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-top: 6px;
  border-top: 1.5px solid #EDE5D8;
}

.cart-total {
  font-family: var(--font-display);
  font-size: 1rem;
  color: var(--muted);
}
.cart-total strong {
  font-size: 1.4rem;
  color: var(--text);
  font-weight: 900;
}

/* ── Result Screen ── */
#screen-result {
  align-items: center;
  justify-content: center;
  background: linear-gradient(160deg, #FFF8E7 0%, #E8FFFE 100%);
  padding: 32px 24px;
  text-align: center;
}

.result-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  max-width: 480px;
  width: 100%;
}

.result-mascot {
  font-size: 5rem;
  animation: float 3s infinite ease-in-out;
}

.result-title {
  font-family: var(--font-display);
  font-size: 2rem;
  font-weight: 900;
  color: var(--text);
}

.result-summary {
  background: var(--card-bg);
  border-radius: var(--radius-lg);
  padding: 16px 24px;
  box-shadow: var(--shadow);
  width: 100%;
  font-size: 0.95rem;
  line-height: 1.8;
  color: var(--text);
  text-align: left;
}

.result-ai-feedback {
  background: linear-gradient(135deg, #E8F9F8, #F0E8FF);
  border: 2.5px solid var(--secondary);
  border-radius: var(--radius-lg);
  padding: 14px 18px;
  width: 100%;
  text-align: left;
}

.result-ai-feedback p {
  font-size: 0.95rem;
  line-height: 1.6;
  color: var(--text);
}

/* Loading dots */
.ai-loading {
  display: flex;
  gap: 6px;
  align-items: center;
  justify-content: center;
  padding: 8px 0;
}
.dot {
  width: 10px;
  height: 10px;
  background: var(--secondary);
  border-radius: 50%;
  animation: dotBounce 1.2s infinite ease-in-out;
}
.dot:nth-child(2) { animation-delay: 0.2s; }
.dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes dotBounce {
  0%, 80%, 100% { transform: scale(0.8); opacity: 0.5; }
  40%           { transform: scale(1.2); opacity: 1; }
}

.result-stars {
  font-size: 2.5rem;
  letter-spacing: 6px;
}

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

/* ── Modals ── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(44,44,84,0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 999;
  padding: 24px;
  backdrop-filter: blur(4px);
  animation: fadeIn 0.2s ease;
}

.modal-box {
  background: var(--card-bg);
  border-radius: var(--radius-lg);
  padding: 28px 24px;
  max-width: 380px;
  width: 100%;
  box-shadow: 0 20px 60px rgba(44,44,84,0.25);
  text-align: center;
  animation: popIn 0.25s ease;
}

.modal-box h2 {
  font-family: var(--font-display);
  font-size: 1.4rem;
  font-weight: 900;
  margin-bottom: 16px;
  color: var(--text);
}

.rules-list {
  list-style: none;
  text-align: left;
  margin-bottom: 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.rules-list li {
  font-size: 0.95rem;
  line-height: 1.5;
  background: #F8F4EE;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
}

.modal-event-box .event-icon {
  font-size: 4rem;
  margin-bottom: 8px;
  animation: bounce 0.5s ease;
}

#event-desc {
  font-size: 1rem;
  line-height: 1.6;
  color: var(--text);
  margin: 12px 0 20px;
}

/* ── Utility ── */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  clip: rect(0,0,0,0);
  overflow: hidden;
}

/* ── Responsive ── */
@media (max-width: 480px) {
  .items-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .budget-display {
    padding: 5px 10px;
  }

  .budget-text { display: none; }
}

@media (min-width: 768px) {
  #screen-game {
    max-width: 600px;
    margin: 0 auto;
    box-shadow: 0 0 40px rgba(44,44,84,0.1);
  }

  .items-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

@media (min-width: 1024px) {
  body {
    background: linear-gradient(135deg, #FFE8D0 0%, #FFF8E7 40%, #E8FFFE 100%);
  }

  #screen-intro,
  #screen-result {
    min-height: 100vh;
  }
}

/* ── Reduced Motion ── */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
