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

:root {
  --bg: #FFF8F0;
  --card-bg: #FFFFFF;
  --primary: #F2915A;
  --primary-light: #FDDCBF;
  --secondary: #8BC48A;
  --accent: #F7C948;
  --text: #5D4E37;
  --text-light: #A89880;
  --shadow: rgba(93, 78, 55, 0.12);
  --radius: 20px;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: 'Zen Maru Gothic', 'Hiragino Maru Gothic Pro', sans-serif;
  background-color: var(--bg);
  background-image: url('../assets/images/BG_03.webp');
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  background-attachment: local;
  color: var(--text);
  min-height: 100dvh;
  display: flex;
  justify-content: center;
  overflow-x: hidden;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
}

/* ===== Layout ===== */
.page-wrapper {
  width: 100%;
  max-width: 700px;
  padding: 8px 12px 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

/* ===== Header ===== */
.header { text-align: center; }

.title {
  font-size: 1.4rem;
  font-weight: 900;
  color: var(--primary);
  text-shadow: 2px 2px 0 var(--primary-light);
  letter-spacing: 0.05em;
}

.subtitle {
  font-size: 0.85rem;
  color: var(--text-light);
  font-weight: 700;
  margin-top: 1px;
}

.stage-label {
  font-size: 0.8rem;
  font-weight: 900;
  color: var(--primary);
  background: var(--primary-light);
  border-radius: 20px;
  padding: 2px 14px;
  margin-top: 2px;
  letter-spacing: 0.05em;
}

/* ===== Puzzle Frame ===== */
.puzzle-frame {
  position: relative;
  width: min(calc(100vw - 24px), calc((100dvh - 240px) * 3 / 4));
  aspect-ratio: 3 / 4;
  margin: 0 auto;
  min-width: 240px;
  background:
    linear-gradient(rgba(237, 232, 223, 0.55), rgba(237, 232, 223, 0.55)),
    url('../assets/images/P02.png') center / auto 130% no-repeat;
  border-radius: var(--radius);
  box-shadow: 0 4px 20px var(--shadow), inset 0 0 0 3px var(--primary-light);
  overflow: hidden;
}

@media (min-width: 768px) {
  .page-wrapper { max-width: min(95vw, 960px); }
}

#puzzle-container {
  width: 100%;
  height: 100%;
}

/* ===== Loading ===== */
.loading {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: var(--card-bg);
  z-index: 10;
  gap: 8px;
  transition: opacity 0.4s;
}

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

.loading-emoji {
  font-size: 3rem;
  animation: bounce 1s ease-in-out infinite;
}

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

.loading p {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-light);
}

/* ===== Sidebar (controls + progress wrapper) ===== */
.sidebar {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

/* ===== Controls ===== */
.controls {
  display: flex;
  gap: 12px;
  justify-content: center;
}

.btn {
  font-family: inherit;
  font-size: 1.1rem;
  font-weight: 900;
  border: none;
  border-radius: 50px;
  padding: 12px 28px;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
  box-shadow: 0 3px 10px var(--shadow);
  letter-spacing: 0.05em;
}

.btn:active {
  transform: scale(0.95);
  box-shadow: 0 1px 4px var(--shadow);
}

.btn-shuffle {
  background: var(--secondary);
  color: #fff;
}

.btn-hint {
  background: var(--accent);
  color: var(--text);
}

.btn-primary {
  background: var(--primary);
  color: #fff;
  font-size: 1.2rem;
  padding: 14px 36px;
}

.btn-next {
  background: linear-gradient(135deg, #60A5FA, #818CF8);
  color: #fff;
  font-size: 1.2rem;
  padding: 14px 36px;
  width: 100%;
  max-width: 260px;
}

.btn-play-again {
  background: var(--primary-light);
  color: var(--text);
  font-size: 0.95rem;
  padding: 10px 24px;
}

/* ===== Progress Bar ===== */
.progress-bar {
  position: relative;
  width: 80%;
  max-width: 400px;
  margin: 0 auto;
  height: 28px;
  background: var(--primary-light);
  border-radius: 14px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--secondary), #6DBF6D);
  border-radius: 14px;
  transition: width 0.5s ease;
}

.progress-text {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  font-weight: 900;
  color: var(--text);
}

/* ===== Modal ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(93, 78, 55, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  animation: fadeIn 0.4s;
}

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

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal-content {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 32px 28px;
  text-align: center;
  max-width: 420px;
  width: 100%;
  box-shadow: 0 8px 40px rgba(93, 78, 55, 0.3);
  animation: popIn 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

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

.modal-emoji { font-size: 3.5rem; }

.modal-title {
  font-size: 2rem;
  font-weight: 900;
  color: var(--primary);
}

.modal-stage-info {
  font-size: 1.3rem;
  font-weight: 900;
  color: var(--primary);
  letter-spacing: 0.03em;
}

.modal-daily-acorn {
  margin-top: 4px;
  font-size: 0.95rem;
  font-weight: 700;
  color: #7a5c2a;
}
.modal-daily-acorn.full { color: #C44A2A; }

.modal-message {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-light);
}

/* ===== Confetti ===== */
.confetti-container {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 99;
  overflow: hidden;
}

.confetti {
  position: absolute;
  width: 12px;
  height: 12px;
  border-radius: 3px;
  top: -20px;
  animation: confettiFall 3s ease-in forwards;
}

@keyframes confettiFall {
  0% { transform: translateY(0) rotate(0deg); opacity: 1; }
  100% { transform: translateY(100vh) rotate(720deg); opacity: 0; }
}

/* ===== Responsive ===== */
@media (max-width: 480px) {
  .title { font-size: 1.4rem; }
  .subtitle { font-size: 0.85rem; }
  .btn { font-size: 0.95rem; padding: 10px 22px; }
  .page-wrapper { padding: 8px 10px 16px; gap: 8px; }
}

/* ===== Landscape Notice (portrait-only) ===== */
#landscape-notice {
  display: none;
  position: fixed; inset: 0; z-index: 9980;
  background: #1a3a4a;
  flex-direction: column; align-items: center; justify-content: center; gap: 20px;
  color: white; text-align: center; padding: 40px;
  font-family: 'Zen Maru Gothic', sans-serif;
}
#landscape-notice .rotate-icon { font-size: 64px; animation: rotateHintV 2s ease-in-out infinite; }
@keyframes rotateHintV {
  0%, 100% { transform: rotate(0deg); }
  50% { transform: rotate(-90deg); }
}
#landscape-notice p { font-size: 18px; line-height: 1.6; }

/* ===== Tutorial ===== */
.tut-dim { position:fixed;inset:0;z-index:9995;background:rgba(93,78,55,0.6);pointer-events:auto; }
.tut-dim.hidden { display:none; }
.tut-bubble { position:fixed;z-index:9997;background:#fff;border-radius:16px;padding:12px 12px;max-width:none;box-shadow:0 4px 20px rgba(93,78,55,0.3);font-size:0.95rem;font-weight:700;color:#5D4E37;line-height:1.6;text-align:center;white-space:nowrap;animation:tutPopIn 0.3s cubic-bezier(0.34,1.56,0.64,1); }
.tut-bubble.hidden { display:none; }
@keyframes tutPopIn { from{opacity:0} to{opacity:1} }
.tut-next-btn { display:inline-block;margin-top:10px;padding:8px 24px;border:none;border-radius:50px;background:linear-gradient(135deg,#60A5FA,#818CF8);color:#fff;font-family:inherit;font-size:0.85rem;font-weight:900;cursor:pointer; }
