/* ===== CSS Variables ===== */
:root {
  --color-primary: #B39DDB;
  --color-primary-light: #D1C4E9;
  --color-secondary: #F48FB1;
  --color-mint: #80CBC4;
  --color-bg: #FFF8F0;
  --color-text: #5D4037;
  --color-rare: #FFD54F;
  --color-special: #FF8A65;
  --color-white: #FFFFFF;
  --color-shadow: rgba(93, 64, 55, 0.12);
  --color-correct: #66BB6A;
  --color-wrong: #EF5350;

  --radius-sm: 12px;
  --radius-md: 16px;
  --radius-lg: 20px;
  --radius-round: 50%;

  --shadow-sm: 0 2px 8px var(--color-shadow);
  --shadow-md: 0 4px 16px var(--color-shadow);
  --shadow-lg: 0 8px 32px var(--color-shadow);

  --transition: 0.25s ease;
}

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

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: 'M PLUS Rounded 1c', 'Hiragino Maru Gothic Pro', sans-serif;
  color: var(--color-text);
  background: var(--color-bg);
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  touch-action: manipulation;
}

.hidden {
  display: none !important;
}

/* ===== Screen Management ===== */
.screen {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: none;
  flex-direction: column;
  background: var(--color-bg);
}

.screen.active {
  display: flex;
}

/* ===== Room Header ===== */
.room-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px;
  background: linear-gradient(135deg, var(--color-primary-light), var(--color-primary));
  color: var(--color-white);
  z-index: 10;
}

.room-header-left {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
  min-width: 0;
}

.room-header h1 {
  font-size: 22px;
  font-weight: 900;
  text-shadow: 0 1px 3px rgba(0,0,0,0.15);
}

/* ===== XP Bar ===== */
.xp-bar-container {
  display: flex;
  align-items: center;
  gap: 6px;
}

.xp-level-label {
  font-size: 13px;
  font-weight: 900;
  text-shadow: 0 1px 2px rgba(0,0,0,0.2);
  white-space: nowrap;
}

.xp-bar {
  flex: 1;
  height: 10px;
  background: rgba(255,255,255,0.3);
  border-radius: 100px;
  overflow: hidden;
  min-width: 60px;
}

.xp-fill {
  height: 100%;
  background: linear-gradient(90deg, #FFD54F, #FFC107, #FFB300);
  border-radius: 100px;
  transition: width 0.5s ease;
  box-shadow: 0 0 6px rgba(255, 193, 7, 0.5);
}

.xp-text {
  font-size: 11px;
  font-weight: 700;
  opacity: 0.9;
  white-space: nowrap;
}

.xp-title-label {
  font-size: 11px;
  font-weight: 700;
  opacity: 0.85;
  letter-spacing: 0.5px;
}

.icon-btn {
  width: 44px;
  height: 44px;
  border: none;
  background: rgba(255,255,255,0.25);
  border-radius: var(--radius-round);
  font-size: 22px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform var(--transition), background var(--transition);
}

.icon-btn:active {
  transform: scale(0.9);
  background: rgba(255,255,255,0.4);
}

/* ===== Room Area ===== */
.room-area {
  flex: 1;
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.wall-area {
  flex: 0 0 40%;
  background: linear-gradient(180deg, #E8D5F5 0%, #F3E5F5 100%);
  position: relative;
  transition: background var(--transition);
}

.floor-area {
  flex: 1;
  background: linear-gradient(180deg, #FFE0B2 0%, #FFCC80 100%);
  position: relative;
  transition: background var(--transition);
}

/* Wallpaper themes */
.wall-area.wallpaper-lavender { background: linear-gradient(180deg, #E8D5F5 0%, #F3E5F5 100%); }
.wall-area.wallpaper-pink { background: linear-gradient(180deg, #FCE4EC 0%, #F8BBD0 100%); }
.wall-area.wallpaper-mint { background: linear-gradient(180deg, #E0F2F1 0%, #B2DFDB 100%); }
.wall-area.wallpaper-sky { background: linear-gradient(180deg, #E3F2FD 0%, #BBDEFB 100%); }
.wall-area.wallpaper-peach { background: linear-gradient(180deg, #FFF3E0 0%, #FFE0B2 100%); }
.wall-area.wallpaper-stars {
  background: linear-gradient(180deg, #283593 0%, #5C6BC0 100%);
}
.wall-area.wallpaper-stars::after {
  content: '⭐ ✨ ⭐ ✨ ⭐';
  position: absolute;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 20px;
  letter-spacing: 16px;
  opacity: 0.6;
}

/* Floor themes */
.floor-area.floor-wood { background: linear-gradient(180deg, #FFE0B2 0%, #FFCC80 100%); }
.floor-area.floor-pink { background: linear-gradient(180deg, #FCE4EC 0%, #F48FB1 50%); }
.floor-area.floor-green { background: linear-gradient(180deg, #C8E6C9 0%, #A5D6A7 100%); }
.floor-area.floor-blue { background: linear-gradient(180deg, #BBDEFB 0%, #90CAF9 100%); }
.floor-area.floor-carpet {
  background: linear-gradient(180deg, #D1C4E9 0%, #B39DDB 100%);
}

/* ===== Character ===== */
.character {
  position: absolute;
  bottom: 40%;
  left: 50%;
  transform: translateX(-50%);
  z-index: 5;
  cursor: pointer;
  transition: transform 0.3s ease;
}

.character:active {
  transform: translateX(-50%) scale(1.1);
}

.character-body {
  font-size: 72px;
  animation: float 3s ease-in-out infinite;
  filter: drop-shadow(0 4px 8px rgba(0,0,0,0.15));
}

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

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

.character.happy {
  animation: bounce 0.6s ease;
}

.speech-bubble {
  position: absolute;
  bottom: 110%;
  left: 50%;
  transform: translateX(-50%);
  background: var(--color-white);
  border: 3px solid var(--color-primary);
  border-radius: var(--radius-lg);
  padding: 8px 16px;
  font-size: 16px;
  font-weight: 700;
  white-space: nowrap;
  box-shadow: var(--shadow-sm);
  animation: popIn 0.3s ease;
}

.speech-bubble::after {
  content: '';
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  border: 8px solid transparent;
  border-top-color: var(--color-primary);
}

@keyframes popIn {
  0% { transform: translateX(-50%) scale(0); opacity: 0; }
  50% { transform: translateX(-50%) scale(1.1); }
  100% { transform: translateX(-50%) scale(1); opacity: 1; }
}

/* ===== Room Items (Placed) ===== */
.room-item {
  position: absolute;
  cursor: grab;
  font-size: 48px;
  transition: filter 0.2s ease;
  touch-action: none;
  z-index: 2;
}

.room-item.dragging {
  cursor: grabbing;
  filter: brightness(1.1) drop-shadow(0 8px 16px rgba(0,0,0,0.25));
  z-index: 100 !important;
  transition: none;
}

.room-item .item-emoji {
  display: block;
  line-height: 1;
  filter: drop-shadow(0 2px 4px rgba(0,0,0,0.1));
}

/* ===== Bottom Navigation ===== */
.bottom-nav {
  display: flex;
  align-items: center;
  justify-content: space-around;
  padding: 8px 0;
  background: var(--color-white);
  border-top: 2px solid var(--color-primary-light);
  z-index: 10;
}

.nav-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 8px 16px;
  border: none;
  background: none;
  cursor: pointer;
  border-radius: var(--radius-md);
  transition: background var(--transition), transform var(--transition);
  min-width: 80px;
  min-height: 54px;
}

.nav-btn:active {
  background: var(--color-primary-light);
  transform: scale(0.95);
}

.nav-icon { font-size: 24px; }
.nav-label { font-size: 13px; font-weight: 700; color: var(--color-text); }

/* ===== Screen Header ===== */
.screen-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: linear-gradient(135deg, var(--color-primary-light), var(--color-primary));
  color: var(--color-white);
}

.screen-header h2 {
  font-size: 20px;
  font-weight: 900;
}

.back-btn {
  padding: 8px 16px;
  border: none;
  background: rgba(255,255,255,0.25);
  color: var(--color-white);
  font-family: inherit;
  font-size: 15px;
  font-weight: 700;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background var(--transition);
  min-height: 44px;
}

.back-btn:active { background: rgba(255,255,255,0.4); }

/* ===== Action Buttons ===== */
.action-btn {
  padding: 14px 32px;
  border: none;
  border-radius: var(--radius-lg);
  font-family: inherit;
  font-size: 18px;
  font-weight: 900;
  cursor: pointer;
  transition: transform var(--transition), box-shadow var(--transition);
  min-height: 52px;
  min-width: 140px;
}

.action-btn:active {
  transform: scale(0.95);
}

.action-btn.primary {
  background: linear-gradient(135deg, var(--color-secondary), #EC407A);
  color: var(--color-white);
  box-shadow: 0 4px 12px rgba(244, 143, 177, 0.4);
}

.action-btn.secondary {
  background: var(--color-white);
  color: var(--color-primary);
  border: 3px solid var(--color-primary-light);
}

/* ===== Inventory Grid ===== */
.inventory-grid {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
  gap: 12px;
  padding: 16px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.inventory-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  aspect-ratio: 1;
  padding: 8px;
  background: var(--color-white);
  border: 3px solid var(--color-primary-light);
  border-radius: var(--radius-lg);
  cursor: pointer;
  transition: transform var(--transition), border-color var(--transition), box-shadow var(--transition);
}

.inventory-item:active {
  transform: scale(0.95);
  border-color: var(--color-primary);
  box-shadow: var(--shadow-md);
}

.inventory-item .item-emoji { font-size: 40px; line-height: 1; }
.inventory-item .item-name { font-size: 12px; font-weight: 700; text-align: center; }

.inventory-empty {
  grid-column: 1 / -1;
  text-align: center;
  padding: 40px 20px;
  color: var(--color-primary);
  font-size: 18px;
  font-weight: 700;
}

/* ===== Placeholder ===== */
.placeholder-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  font-size: 20px;
  font-weight: 700;
  color: var(--color-primary);
  text-align: center;
  line-height: 1.6;
}

.placeholder-emoji { font-size: 64px; }

/* ===== Settings ===== */
.settings-content {
  flex: 1;
  padding: 16px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.settings-section { margin-bottom: 24px; }
.settings-section h3 { font-size: 18px; font-weight: 900; color: var(--color-primary); margin-bottom: 12px; }

.option-grid { display: flex; gap: 12px; flex-wrap: wrap; }

.option-swatch {
  width: 64px;
  height: 64px;
  border-radius: var(--radius-md);
  border: 3px solid transparent;
  cursor: pointer;
  transition: transform var(--transition), border-color var(--transition);
  position: relative;
}

.option-swatch:active { transform: scale(0.92); }

.option-swatch.selected {
  border-color: var(--color-secondary);
  box-shadow: var(--shadow-md);
}

.option-swatch.selected::after {
  content: '✓';
  position: absolute;
  top: -6px; right: -6px;
  width: 22px; height: 22px;
  background: var(--color-secondary);
  color: white;
  font-size: 14px; font-weight: 900;
  border-radius: var(--radius-round);
  display: flex; align-items: center; justify-content: center;
}

.option-label { font-size: 11px; font-weight: 700; text-align: center; margin-top: 4px; }

/* ===== Item Context Menu ===== */
.item-menu {
  position: fixed;
  z-index: 200;
  background: var(--color-white);
  border: 3px solid var(--color-primary);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  animation: popIn 0.2s ease;
}

.menu-btn {
  display: block;
  width: 100%;
  padding: 14px 24px;
  border: none;
  background: none;
  font-family: inherit;
  font-size: 16px;
  font-weight: 700;
  color: var(--color-text);
  cursor: pointer;
  text-align: left;
  transition: background var(--transition);
  min-height: 48px;
}

.menu-btn:active { background: var(--color-primary-light); }
.menu-btn.danger { color: #E53935; }
.menu-btn + .menu-btn { border-top: 1px solid var(--color-primary-light); }

/* ===== Toast ===== */
.toast {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%) translateY(-100px);
  background: var(--color-primary);
  color: var(--color-white);
  padding: 12px 24px;
  border-radius: var(--radius-lg);
  font-size: 16px;
  font-weight: 700;
  box-shadow: var(--shadow-md);
  z-index: 300;
  transition: transform 0.4s ease;
  pointer-events: none;
}

.toast.show { transform: translateX(-50%) translateY(0); }

/* ================================================================
   QUEST SCREEN
   ================================================================ */
.quest-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 20px;
  gap: 20px;
  overflow-y: auto;
}

.quest-character-msg {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--color-white);
  padding: 16px;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}

.quest-char-emoji { font-size: 40px; }
.quest-char-text { font-size: 18px; font-weight: 700; }

.quest-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.quest-item {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 16px 20px;
  background: var(--color-white);
  border: 3px solid var(--color-primary-light);
  border-radius: var(--radius-lg);
  font-size: 18px;
  font-weight: 700;
  transition: transform var(--transition), box-shadow var(--transition);
}

.quest-item.current {
  border-color: var(--color-secondary);
  box-shadow: var(--shadow-md);
  cursor: pointer;
}

.quest-item.current:active { transform: scale(0.97); }

.quest-item.done {
  opacity: 0.5;
  border-style: dashed;
}

.quest-number {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--color-primary-light);
  border-radius: var(--radius-round);
  font-size: 16px;
  font-weight: 900;
  flex-shrink: 0;
}

.quest-item.done .quest-number { background: none; }
.quest-label { flex: 1; }

.quest-go {
  color: var(--color-secondary);
  font-size: 24px;
  animation: pulse 1.5s ease infinite;
}

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

.quest-complete-msg {
  text-align: center;
  padding: 24px;
  font-size: 20px;
  font-weight: 900;
  color: var(--color-secondary);
  line-height: 1.6;
}

/* ================================================================
   TRACE (KANA) SCREEN
   ================================================================ */
.trace-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 16px;
}

.canvas-wrapper {
  position: relative;
  width: min(80vw, 400px);
  height: min(80vw, 400px);
  border: 4px solid var(--color-primary-light);
  border-radius: var(--radius-lg);
  background: var(--color-white);
  box-shadow: var(--shadow-md);
  overflow: hidden;
}

.trace-guide-canvas,
.trace-draw-canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
}

.trace-guide-canvas { z-index: 1; }
.trace-draw-canvas { z-index: 2; touch-action: none; }

.trace-hint {
  font-size: 16px;
  font-weight: 700;
  color: var(--color-primary);
}

.trace-message {
  font-size: 18px;
  font-weight: 700;
  color: var(--color-secondary);
  animation: popIn 0.3s ease;
}

.trace-buttons {
  display: flex;
  gap: 16px;
}

/* ================================================================
   CHOICE QUESTION SCREEN
   ================================================================ */
.choice-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 32px;
  padding: 24px;
}

.choice-question-area {
  background: var(--color-white);
  padding: 24px 40px;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  border: 3px solid var(--color-primary-light);
}

.choice-question {
  font-size: 32px;
  font-weight: 900;
  text-align: center;
}

.choice-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  width: 100%;
  max-width: 400px;
}

.choice-btn {
  padding: 20px;
  border: 3px solid var(--color-primary-light);
  background: var(--color-white);
  border-radius: var(--radius-lg);
  font-family: inherit;
  font-size: 22px;
  font-weight: 900;
  color: var(--color-text);
  cursor: pointer;
  transition: transform var(--transition), border-color var(--transition), background var(--transition);
  min-height: 64px;
}

.choice-btn:active { transform: scale(0.95); }

.choice-btn.correct {
  border-color: var(--color-correct);
  background: #E8F5E9;
  animation: correctPop 0.4s ease;
}

.choice-btn.wrong {
  border-color: var(--color-wrong);
  background: #FFEBEE;
  animation: wrongShake 0.4s ease;
}

@keyframes correctPop {
  0% { transform: scale(1); }
  50% { transform: scale(1.08); }
  100% { transform: scale(1); }
}

@keyframes wrongShake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-8px); }
  75% { transform: translateX(8px); }
}

/* ================================================================
   QUEST CLEAR SCREEN
   ================================================================ */
.clear-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  background: linear-gradient(135deg, #FFF8E1, #FFF3E0);
}

.clear-text {
  font-size: 100px;
  animation: clearBounce 0.8s ease;
}

.clear-text-sub {
  font-size: 28px;
  font-weight: 900;
  color: var(--color-secondary);
  animation: fadeInUp 0.5s ease 0.3s both;
}

@keyframes clearBounce {
  0% { transform: scale(0); }
  50% { transform: scale(1.3); }
  70% { transform: scale(0.9); }
  100% { transform: scale(1); }
}

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

/* ================================================================
   GACHA SCREEN
   ================================================================ */
.gacha-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 24px;
  position: relative;
  overflow: hidden;
  background: linear-gradient(180deg, #EDE7F6 0%, #F3E5F5 50%, #FCE4EC 100%);
}

.gacha-overlay {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  z-index: 1;
  pointer-events: none;
}

/* Rarity glow hints (during shake) */
.gacha-overlay.glow-rare {
  animation: glowRare 1.5s ease infinite;
}

.gacha-overlay.glow-special {
  animation: glowSpecial 1.2s ease infinite;
}

@keyframes glowRare {
  0%, 100% { background: transparent; }
  50% { background: rgba(255, 213, 79, 0.2); }
}

@keyframes glowSpecial {
  0% { background: rgba(255, 138, 101, 0.1); }
  33% { background: rgba(255, 213, 79, 0.2); }
  66% { background: rgba(179, 157, 219, 0.2); }
  100% { background: rgba(255, 138, 101, 0.1); }
}

/* Dramatic pause for special */
.gacha-box.dramatic-pause {
  animation: dramaticPause 0.8s ease;
}

@keyframes dramaticPause {
  0% { transform: scale(1.05); }
  50% { transform: scale(1.15); }
  100% { transform: scale(1.1); }
}

.gacha-overlay.flash-rare {
  animation: flashRare 0.8s ease;
}

.gacha-overlay.flash-special {
  animation: flashSpecial 1.2s ease;
}

@keyframes flashRare {
  0% { background: transparent; }
  30% { background: rgba(255, 213, 79, 0.5); }
  100% { background: transparent; }
}

@keyframes flashSpecial {
  0% { background: transparent; }
  20% { background: rgba(255, 138, 101, 0.6); }
  40% { background: rgba(255, 213, 79, 0.4); }
  60% { background: rgba(255, 138, 101, 0.3); }
  100% { background: transparent; }
}

.gacha-sparkles {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  z-index: 3;
  pointer-events: none;
}

.sparkle-particle {
  position: absolute;
  font-size: 24px;
  animation: sparkleFloat 1s ease-out forwards;
}

@keyframes sparkleFloat {
  0% { opacity: 1; transform: scale(0) rotate(0deg); }
  50% { opacity: 1; transform: scale(1.2) rotate(180deg); }
  100% { opacity: 0; transform: scale(0.5) rotate(360deg) translateY(-60px); }
}

.gacha-title {
  font-size: 24px;
  font-weight: 900;
  color: var(--color-text);
  z-index: 2;
}

/* Gacha box */
.gacha-box {
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  font-size: 80px;
  line-height: 1;
}

.gacha-box-lid {
  transition: transform 0.3s ease;
}

.gacha-box-base {
  display: none;
}

.gacha-box.shake {
  animation: gachaShake 0.15s ease infinite;
}

.gacha-box.shake-hard {
  animation: gachaShakeHard 0.1s ease infinite;
}

.gacha-box.open .gacha-box-lid {
  animation: lidOpen 0.6s ease forwards;
}

@keyframes gachaShake {
  0%, 100% { transform: rotate(0deg); }
  25% { transform: rotate(-3deg); }
  75% { transform: rotate(3deg); }
}

@keyframes gachaShakeHard {
  0%, 100% { transform: rotate(0deg) scale(1); }
  25% { transform: rotate(-6deg) scale(1.05); }
  75% { transform: rotate(6deg) scale(1.05); }
}

@keyframes lidOpen {
  0% { transform: translateY(0) rotate(0deg); opacity: 1; }
  60% { transform: translateY(-80px) rotate(20deg); opacity: 1; }
  100% { transform: translateY(-120px) rotate(30deg); opacity: 0; }
}

/* Gacha result */
.gacha-result {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  z-index: 4;
}

.gacha-result.result-reveal {
  animation: resultReveal 0.5s ease;
}

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

.gacha-result-emoji { font-size: 80px; }
.gacha-result-name { font-size: 24px; font-weight: 900; }

.gacha-rarity-label {
  padding: 6px 20px;
  border-radius: 100px;
  font-size: 14px;
  font-weight: 900;
  color: var(--color-white);
}

.rarity-normal { background: var(--color-primary); }
.rarity-rare { background: var(--color-rare); color: var(--color-text); }
.rarity-special { background: linear-gradient(135deg, var(--color-special), #FF6E40); }

.gacha-buttons {
  display: flex;
  gap: 16px;
  z-index: 4;
}

/* ================================================================
   CELEBRATION EFFECTS
   ================================================================ */
.celebration-particle {
  position: fixed;
  z-index: 500;
  pointer-events: none;
  animation: celebrationFall linear forwards;
}

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

.screen-flash {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  z-index: 400;
  pointer-events: none;
  animation: screenFlash ease forwards;
}

@keyframes screenFlash {
  0% { opacity: 0.8; }
  100% { opacity: 0; }
}

/* ================================================================
   RECORD SCREEN
   ================================================================ */
.record-content {
  flex: 1;
  padding: 16px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.record-card {
  background: var(--color-white);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: var(--shadow-sm);
}

.record-card h3 {
  font-size: 16px;
  font-weight: 900;
  color: var(--color-primary);
  margin-bottom: 12px;
}

.record-character {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.record-char-emoji { font-size: 64px; }

.record-char-name {
  font-size: 20px;
  font-weight: 900;
  color: var(--color-secondary);
}

.record-stat {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
  font-size: 16px;
  font-weight: 700;
}

.record-stat + .record-stat {
  border-top: 1px solid var(--color-primary-light);
}

.record-value {
  color: var(--color-secondary);
  font-size: 20px;
  font-weight: 900;
}

.kana-grid {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.kana-cell {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 8px 12px;
  background: var(--color-bg);
  border-radius: var(--radius-sm);
  font-size: 18px;
  font-weight: 700;
}

.kana-cell.learned {
  background: #E8F5E9;
  color: var(--color-correct);
}

.kana-grid-sm {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}

.kana-cell-sm {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--color-bg);
  border-radius: 6px;
  font-size: 15px;
  font-weight: 700;
  color: var(--color-text);
  opacity: 0.4;
}

.kana-cell-sm.learned {
  background: #E8F5E9;
  color: var(--color-correct);
  opacity: 1;
}

.growth-bar {
  height: 16px;
  background: var(--color-primary-light);
  border-radius: 100px;
  overflow: hidden;
  margin-bottom: 8px;
}

.growth-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--color-mint), var(--color-primary), var(--color-secondary));
  border-radius: 100px;
  transition: width 0.5s ease;
}

.growth-labels {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  font-weight: 700;
  color: var(--color-text);
  opacity: 0.7;
}

/* ================================================================
   WEAK QUESTIONS (にがてなもんだい)
   ================================================================ */
.weak-card {
  border: 3px solid #FF8A65;
  background: linear-gradient(135deg, #FFF3E0, #FFECB3);
}

.weak-card h3 {
  color: #E64A19;
}

.weak-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0;
  font-size: 15px;
  font-weight: 700;
}

.weak-item + .weak-item {
  border-top: 1px solid rgba(255, 138, 101, 0.3);
}

.weak-label {
  flex: 1;
}

.weak-stats {
  font-size: 14px;
  color: #E64A19;
}

.weak-card-clear {
  border: 3px solid var(--color-mint);
  background: linear-gradient(135deg, #E8F5E9, #C8E6C9);
  text-align: center;
}

.weak-card-clear h3 {
  color: var(--color-correct);
}

.weak-clear-msg {
  font-size: 16px;
  font-weight: 700;
  color: var(--color-correct);
  margin-top: 4px;
}

/* ================================================================
   REVIEW BUTTON
   ================================================================ */
.review-start-btn {
  display: block;
  width: 100%;
  padding: 18px 24px;
  border: 3px solid #FF8A65;
  background: linear-gradient(135deg, #FF8A65, #FF6E40);
  border-radius: var(--radius-lg);
  font-family: inherit;
  font-size: 20px;
  font-weight: 900;
  color: var(--color-white);
  cursor: pointer;
  transition: transform var(--transition), box-shadow var(--transition);
  box-shadow: 0 4px 16px rgba(255, 138, 101, 0.4);
  animation: pulse 2s ease infinite;
  min-height: 60px;
}

.review-start-btn:active {
  transform: scale(0.95);
}

/* ================================================================
   REVIEW CLEAR SCREEN
   ================================================================ */
.review-clear-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background: linear-gradient(135deg,
    #FF8A65 0%, #FFD54F 20%, #66BB6A 40%,
    #42A5F5 60%, #AB47BC 80%, #FF8A65 100%);
  background-size: 400% 400%;
  animation: rainbowBg 3s ease infinite;
}

@keyframes rainbowBg {
  0% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
  100% { background-position: 0% 50%; }
}

.review-clear-text {
  font-size: 100px;
  animation: clearBounce 0.8s ease;
}

.review-clear-text-sub {
  font-size: 32px;
  font-weight: 900;
  color: var(--color-white);
  text-shadow: 0 2px 8px rgba(0,0,0,0.3);
  animation: fadeInUp 0.5s ease 0.3s both;
}

.review-clear-text-detail {
  font-size: 20px;
  font-weight: 700;
  color: var(--color-white);
  text-shadow: 0 1px 4px rgba(0,0,0,0.2);
  animation: fadeInUp 0.5s ease 0.5s both;
}

/* ================================================================
   OVERCOME SCREEN (苦手克服)
   ================================================================ */
.overcome-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background: linear-gradient(135deg, #FFF8E1, #FFE0B2, #FFCC80);
}

.overcome-text {
  font-size: 100px;
  animation: overcomeBurst 0.8s ease;
}

@keyframes overcomeBurst {
  0% { transform: scale(0) rotate(-30deg); }
  50% { transform: scale(1.4) rotate(10deg); }
  70% { transform: scale(0.9) rotate(-5deg); }
  100% { transform: scale(1) rotate(0deg); }
}

.overcome-text-sub {
  font-size: 32px;
  font-weight: 900;
  color: #E64A19;
  animation: fadeInUp 0.5s ease 0.3s both;
}

.overcome-text-detail {
  font-size: 20px;
  font-weight: 700;
  color: var(--color-special);
  animation: fadeInUp 0.5s ease 0.5s both;
}

/* Overcome particle burst */
.overcome-particle {
  animation: burstOut 1s ease-out forwards !important;
}

@keyframes burstOut {
  0% { transform: translate(0, 0) scale(1); opacity: 1; }
  100% { transform: translate(var(--burst-x), var(--burst-y)) scale(0.3); opacity: 0; }
}

/* Review gacha rarity label */
.rarity-review {
  background: linear-gradient(135deg, #FF8A65, #FF6E40);
}

/* ================================================================
   KANJI WRITING HINT
   ================================================================ */
.trace-hint-kanji {
  font-size: 18px;
  font-weight: 900;
  color: var(--color-special);
  background: rgba(255, 138, 101, 0.1);
  padding: 8px 20px;
  border-radius: var(--radius-sm);
  border: 2px solid rgba(255, 138, 101, 0.3);
}

/* Review particle extra glow */
.review-particle {
  filter: drop-shadow(0 0 8px rgba(255, 213, 79, 0.6));
}

/* Tap-to-advance hint on celebration screens */
.tap-hint {
  font-size: 14px;
  color: rgba(93, 64, 55, 0.4);
  margin-top: 24px;
  animation: tapPulse 2s ease-in-out infinite;
}

@keyframes tapPulse {
  0%, 100% { opacity: 0.3; }
  50% { opacity: 0.7; }
}

/* ================================================================
   EXTRA QUEST (おかわり)
   ================================================================ */
.extra-quest-btn {
  background: linear-gradient(135deg, #66BB6A, #43A047);
  border-color: #43A047;
  box-shadow: 0 4px 16px rgba(67, 160, 71, 0.4);
}

.extra-count-msg {
  font-size: 16px !important;
  color: #43A047 !important;
}

/* Extra progress overlay (between batch problems) */
.extra-progress-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 600;
  animation: extraFadeIn 0.2s ease;
}

.extra-progress-overlay.hidden {
  display: none !important;
}

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

.extra-progress-content {
  background: var(--color-white);
  border-radius: var(--radius-lg);
  padding: 32px 40px;
  text-align: center;
  box-shadow: var(--shadow-lg);
  animation: popIn 0.3s ease;
  min-width: 260px;
}

.extra-progress-emoji {
  font-size: 56px;
  margin-bottom: 8px;
  animation: clearBounce 0.6s ease;
}

.extra-progress-text {
  font-size: 24px;
  font-weight: 900;
  color: var(--color-secondary);
  margin-bottom: 4px;
}

.extra-progress-count {
  font-size: 17px;
  font-weight: 700;
  color: #43A047;
  margin-bottom: 16px;
}

.extra-progress-bar {
  height: 12px;
  background: var(--color-primary-light);
  border-radius: 100px;
  overflow: hidden;
  width: 200px;
  margin: 0 auto;
}

.extra-progress-fill {
  height: 100%;
  background: linear-gradient(90deg, #66BB6A, #43A047);
  border-radius: 100px;
  transition: width 0.3s ease;
}

/* ================================================================
   LEVEL UP SCREEN
   ================================================================ */
.levelup-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background: linear-gradient(135deg, #FFF8E1 0%, #FFE0B2 30%, #FFCC80 60%, #FFB74D 100%);
}

.levelup-emoji {
  font-size: 80px;
  animation: clearBounce 0.8s ease;
}

.levelup-text {
  font-size: 32px;
  font-weight: 900;
  color: #E65100;
  text-shadow: 0 2px 4px rgba(0,0,0,0.1);
  animation: fadeInUp 0.4s ease 0.2s both;
}

.levelup-level {
  font-size: 48px;
  font-weight: 900;
  color: #BF360C;
  text-shadow: 0 2px 8px rgba(191, 54, 12, 0.3);
  animation: fadeInUp 0.4s ease 0.4s both;
}

.levelup-title {
  font-size: 20px;
  font-weight: 900;
  color: #E65100;
  background: rgba(255,255,255,0.5);
  padding: 8px 24px;
  border-radius: 100px;
  animation: fadeInUp 0.4s ease 0.6s both;
}

.levelup-phase-msg {
  font-size: 22px;
  font-weight: 900;
  color: var(--color-secondary);
  animation: fadeInUp 0.4s ease 0.8s both;
}

/* ================================================================
   RECORD LEVEL INFO
   ================================================================ */
.record-level-info {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-top: 8px;
}

.record-level-badge {
  font-size: 18px;
  font-weight: 900;
  color: var(--color-white);
  background: linear-gradient(135deg, #FFB300, #FF8F00);
  padding: 4px 14px;
  border-radius: 100px;
  box-shadow: 0 2px 6px rgba(255, 143, 0, 0.3);
}

.record-title-text {
  font-size: 16px;
  font-weight: 900;
  color: #E65100;
}

/* Kanji trimester sub-labels */
.kanji-trimester-label {
  font-size: 13px;
  font-weight: 700;
  color: var(--color-primary);
  margin: 8px 0 4px;
}

.kanji-trimester-label:first-of-type {
  margin-top: 0;
}

/* ================================================================
   MATH STATS (Record Screen)
   ================================================================ */
.math-stat-item {
  margin-bottom: 12px;
}

.math-stat-item:last-child {
  margin-bottom: 0;
}

.math-stat-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 14px;
  font-weight: 700;
  color: var(--color-text);
  margin-bottom: 4px;
}

.math-stat-stars {
  font-size: 12px;
}

.math-stat-bar {
  height: 10px;
  background: var(--color-primary-light);
  border-radius: 100px;
  overflow: hidden;
  margin-bottom: 2px;
}

.math-stat-fill {
  height: 100%;
  border-radius: 100px;
  transition: width 0.3s ease;
}

.math-stat-detail {
  font-size: 12px;
  color: #999;
  text-align: right;
}

/* ================================================================
   SETTINGS DANGER SECTION
   ================================================================ */
.settings-danger {
  margin-top: 32px;
  padding-top: 20px;
  border-top: 1px dashed #ddd;
}

.danger-btn {
  background: #EF5350 !important;
  border-color: #E53935 !important;
  color: var(--color-white) !important;
  box-shadow: 0 4px 12px rgba(239, 83, 80, 0.3) !important;
}

.danger-btn:active {
  background: #E53935 !important;
}

.settings-danger-note {
  font-size: 12px;
  color: #999;
  margin-top: 8px;
  text-align: center;
}

/* ================================================================
   OKAWARI BANNER (room screen)
   ================================================================ */
.okawari-banner {
  position: absolute;
  bottom: 72px;
  left: 12px;
  right: 12px;
  background: linear-gradient(135deg, #FFB300, #FF8F00);
  color: var(--color-white);
  padding: 12px 16px;
  border-radius: var(--radius-md);
  text-align: center;
  font-weight: 900;
  font-size: 16px;
  box-shadow: 0 4px 16px rgba(255, 143, 0, 0.4);
  cursor: pointer;
  z-index: 10;
  animation: okawariBounce 2s ease infinite;
}

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

.okawari-text {
  display: block;
}

/* Math "not attempted" label */
.math-stat-new {
  font-size: 12px;
  font-weight: 700;
  color: #B0BEC5;
  background: #ECEFF1;
  padding: 2px 10px;
  border-radius: 100px;
}
