/* ============================================
   じゅんじゅく - Style System
   iPad-optimized learning app for 小学3年生
   ============================================ */

/* --- Custom Properties / Theme --- */
:root {
  --primary: #e87fbf;
  --primary-light: #f5b8dc;
  --primary-dark: #c9549a;
  --secondary: #9b7fe8;
  --secondary-light: #c4b8f5;
  --accent-mint: #7fe8c4;
  --accent-yellow: #f5e87f;
  --accent-orange: #f5a87f;
  --bg: #fef6fb;
  --bg-card: #ffffff;
  --bg-nav: #ffffffee;
  --text: #3d2c4e;
  --text-light: #7a6b8a;
  --text-hint: #b0a3be;
  --border: #ecdff5;
  --shadow: 0 2px 12px rgba(155, 127, 232, 0.12);
  --shadow-lg: 0 6px 24px rgba(155, 127, 232, 0.18);
  --radius: 16px;
  --radius-sm: 10px;
  --radius-lg: 24px;
  --nav-height: 72px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);

  /* Frieza theme overrides (applied via .theme-frieza) */
  --frieza-primary: #8b5cf6;
  --frieza-bg: #f3f0ff;
  --frieza-accent: #c084fc;
}

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

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Hiragino Sans', 'Hiragino Kaku Gothic ProN', 'Noto Sans JP', sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
  padding-top: var(--safe-top);
  padding-bottom: calc(var(--nav-height) + var(--safe-bottom) + 8px);
  padding-left: var(--safe-left);
  padding-right: var(--safe-right);
}

/* Prevent accidental text selection while using Apple Pencil on canvas view */
#view-problem {
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}
/* But allow selection in the actual keyboard textarea */
#view-problem textarea,
#view-problem input {
  -webkit-user-select: text;
  user-select: text;
}
/* Canvas containers: full touch ownership */
#pencil-mode .canvas-container,
#canvas-fullscreen .canvas-container {
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

/* --- Typography --- */
h1, h2, h3, h4 {
  font-weight: 700;
  line-height: 1.3;
}
h1 { font-size: 1.75rem; }
h2 { font-size: 1.4rem; }
h3 { font-size: 1.15rem; }
p { margin-bottom: 0.5em; }

/* --- Utility --- */
.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  border: 0;
}

.hidden { display: none !important; }

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

/* --- App Shell --- */
#app {
  max-width: 1200px;
  margin: 0 auto;
  padding: 16px;
}

.view {
  display: none;
  animation: fadeIn 0.3s ease;
}
.view.active {
  display: block;
}

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

/* --- Bottom Navigation --- */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: calc(var(--nav-height) + var(--safe-bottom));
  background: var(--bg-nav);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-around;
  align-items: flex-start;
  padding-top: 6px;
  padding-bottom: var(--safe-bottom);
  z-index: 1000;
}

.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 6px 12px;
  min-width: 64px;
  min-height: 56px;
  border: none;
  background: none;
  color: var(--text-light);
  font-size: 0.65rem;
  font-weight: 600;
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: color 0.2s, transform 0.15s;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.nav-item:active {
  transform: scale(0.92);
}
.nav-item.active {
  color: var(--primary);
}
.nav-item .nav-icon {
  font-size: 1.5rem;
  line-height: 1;
}

/* --- Cards --- */
.card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  transition: transform 0.2s, box-shadow 0.2s;
}
.card:active {
  transform: scale(0.97);
}
.card-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 14px;
  margin: 16px 0;
}

/* --- Subject Cards --- */
.subject-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 20px 14px;
  cursor: pointer;
  min-height: 120px;
  justify-content: center;
}
.subject-card .subject-icon {
  font-size: 2.5rem;
}
.subject-card .subject-name {
  font-size: 1.1rem;
  font-weight: 700;
}
.subject-card.math { border-left: 4px solid #f472b6; }
.subject-card.japanese { border-left: 4px solid #818cf8; }
.subject-card.science { border-left: 4px solid #34d399; }
.subject-card.social { border-left: 4px solid #fbbf24; }
.subject-card.english { border-left: 4px solid #06b6d4; }
.subject-card.programming { border-left: 4px solid #f97316; }

/* --- Buttons --- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 12px 24px;
  border: none;
  border-radius: var(--radius);
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  min-height: 48px;
  min-width: 48px;
  transition: transform 0.15s, box-shadow 0.15s, background 0.2s;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  font-family: inherit;
}
.btn:active {
  transform: scale(0.95);
}
.btn-primary {
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  color: white;
  box-shadow: 0 3px 12px rgba(232, 127, 191, 0.35);
}
.btn-primary:hover {
  box-shadow: 0 5px 18px rgba(232, 127, 191, 0.45);
}
.btn-secondary {
  background: var(--bg-card);
  color: var(--primary);
  border: 2px solid var(--primary-light);
}
.btn-danger {
  background: #fee2e2;
  color: #dc2626;
  border: 2px solid #fecaca;
}
.btn-sm {
  padding: 8px 14px;
  font-size: 0.85rem;
  min-height: 40px;
  border-radius: var(--radius-sm);
}
.btn-lg {
  padding: 16px 32px;
  font-size: 1.15rem;
  border-radius: var(--radius-lg);
}
.btn-icon {
  padding: 10px;
  border-radius: 50%;
  width: 48px;
  height: 48px;
}
.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none !important;
}

.btn-bonus {
  background: linear-gradient(135deg, #fbbf24, #f59e0b);
  color: #78350f;
  box-shadow: 0 3px 12px rgba(251, 191, 36, 0.4);
  font-size: 1.1rem;
  width: 100%;
}

/* --- Difficulty Selector --- */
.difficulty-selector {
  display: flex;
  gap: 12px;
  margin: 16px 0;
}
.difficulty-btn {
  flex: 1;
  padding: 14px;
  border-radius: var(--radius);
  text-align: center;
  cursor: pointer;
  border: 2px solid var(--border);
  background: var(--bg-card);
  font-weight: 700;
  font-size: 1rem;
  transition: all 0.2s;
  font-family: inherit;
}
.difficulty-btn.active {
  border-color: var(--primary);
  background: var(--primary-light);
  color: var(--primary-dark);
}

/* --- Home View --- */
.greeting-section {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 20px;
  padding: 16px;
}
.greeting-section .mascot-small {
  width: 80px;
  height: 80px;
  flex-shrink: 0;
}
.greeting-text h1 {
  color: var(--primary-dark);
}
.greeting-text p {
  color: var(--text-light);
  font-size: 0.95rem;
}

.stats-summary {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin: 16px 0;
}
.stat-box-points .stat-value {
  color: #f59e0b;
}
.stat-box {
  background: var(--bg-card);
  border-radius: var(--radius-sm);
  padding: 14px 10px;
  text-align: center;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}
.stat-value {
  font-size: 1.6rem;
  font-weight: 800;
  color: var(--primary);
}
.stat-label {
  font-size: 0.7rem;
  color: var(--text-light);
  margin-top: 2px;
}

/* --- Problem View --- */
.problem-layout {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding-bottom: 16px;
}

.problem-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.problem-subject-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 0.8rem;
  font-weight: 700;
  background: var(--primary-light);
  color: var(--primary-dark);
}

.problem-text-area {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  font-size: 1.15rem;
  line-height: 1.8;
}
.problem-text-area .problem-number {
  color: var(--primary);
  font-weight: 800;
  margin-right: 4px;
}
.question-highlight {
  margin-top: 16px;
  padding: 10px 14px;
  background: linear-gradient(135deg, #fef3c7, #fde68a);
  border-radius: var(--radius-sm);
  border-left: 4px solid #f59e0b;
  font-weight: 700;
  color: #92400e;
}

/* Answer + Actions Area */
.canvas-section {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.canvas-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: var(--bg-card);
  border-radius: var(--radius) var(--radius) 0 0;
  border: 1px solid var(--border);
  border-bottom: none;
  flex-wrap: wrap;
  flex-shrink: 0;
}
.canvas-toolbar .separator {
  width: 1px;
  height: 28px;
  background: var(--border);
  margin: 0 4px;
}
.color-btn {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 3px solid transparent;
  cursor: pointer;
  transition: transform 0.15s, border-color 0.15s;
  min-height: 32px;
}
.color-btn:active { transform: scale(0.9); }
.color-btn.active { border-color: var(--text); }
.color-btn.black { background: #1a1a1a; }
.color-btn.blue { background: #3b82f6; }
.color-btn.red { background: #ef4444; }

.pen-size-slider {
  width: 80px;
  accent-color: var(--primary);
  height: 28px;
}

.canvas-container {
  flex: 1;
  position: relative;
  border: 2px solid var(--border);
  border-radius: 0 0 var(--radius) var(--radius);
  overflow: hidden;
  background: white;
  min-height: 200px;
  touch-action: none;
}
.canvas-container canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  cursor: crosshair;
}

.canvas-actions {
  display: flex;
  gap: 10px;
  margin-top: 10px;
  flex-shrink: 0;
}
.canvas-actions .btn {
  flex: 1;
}

/* Input Mode Toggle */
.input-mode-toggle {
  display: flex;
  gap: 6px;
  margin-bottom: 8px;
}
.mode-btn {
  flex: 1;
  padding: 10px 14px;
  border: 2px solid var(--border);
  background: var(--bg-card);
  border-radius: var(--radius);
  font-weight: 700;
  font-size: 0.9rem;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.15s;
  min-height: 44px;
}
.mode-btn.active {
  border-color: var(--primary);
  background: var(--primary-light);
  color: var(--primary-dark);
}
.input-mode {
  display: none;
}
.input-mode.active {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
#pencil-mode .canvas-container {
  min-height: 480px;
  aspect-ratio: 16/10;
  background: white;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  position: relative;
  touch-action: none;
}
#pencil-mode .canvas-container canvas {
  width: 100%;
  height: 100%;
  display: block;
  border-radius: var(--radius);
}
@media (min-width: 768px) {
  #pencil-mode .canvas-container {
    min-height: 560px;
  }
}

/* Mermaid diagram rendering */
.mermaid-diagram {
  margin: 12px 0;
  padding: 12px;
  background: var(--bg-card);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  overflow-x: auto;
  text-align: center;
}
.mermaid-diagram svg {
  max-width: 100%;
  height: auto;
}
.mermaid-error {
  background: #fee2e2;
  color: #991b1b;
  padding: 8px;
  border-radius: 6px;
  font-size: 0.8rem;
  white-space: pre-wrap;
}
.feedback-text {
  margin: 8px 0;
  line-height: 1.7;
  white-space: pre-wrap;
}

/* Stock summary bars */
.stock-bar-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 6px;
}
.stock-bar-label {
  font-size: 0.85rem;
  font-weight: 700;
  width: 36px;
}
.stock-bar-track {
  flex: 1;
  height: 14px;
  background: var(--border);
  border-radius: 7px;
  overflow: hidden;
}
.stock-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), var(--secondary));
  border-radius: 7px;
  transition: width 0.4s;
}
.stock-bar-count {
  font-size: 0.85rem;
  font-weight: 700;
  width: 32px;
  text-align: right;
}

/* Photo upload mode */
.photo-upload-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}
.photo-upload-label {
  display: block;
  width: 100%;
  cursor: pointer;
}
.photo-preview {
  min-height: 320px;
  border: 3px dashed var(--primary-light);
  border-radius: var(--radius);
  background: var(--bg-card);
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--primary-dark);
  padding: 24px;
  transition: border-color 0.2s, background 0.2s;
}
.photo-preview:hover {
  border-color: var(--primary);
  background: #fff;
}
.photo-preview.has-image {
  padding: 8px;
  border-style: solid;
}
.photo-preview img {
  max-width: 100%;
  max-height: 500px;
  border-radius: var(--radius-sm);
  object-fit: contain;
}
.photo-placeholder {
  line-height: 1.8;
}
.photo-placeholder small {
  font-size: 0.8rem;
  color: var(--text-light);
  font-weight: 400;
}

/* Fullscreen canvas overlay */
#canvas-fullscreen {
  position: fixed;
  inset: 0;
  background: #fef6fb;
  z-index: 9000;
  display: none;
  flex-direction: column;
  padding: 12px;
  gap: 8px;
}
#canvas-fullscreen.active {
  display: flex;
}
#canvas-fullscreen .canvas-toolbar {
  flex-shrink: 0;
}
#canvas-fullscreen .canvas-container {
  flex: 1;
  min-height: 0;
  background: white;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  position: relative;
  touch-action: none;
  overflow: hidden;
}
#canvas-fullscreen .canvas-container canvas {
  width: 100%;
  height: 100%;
  display: block;
}
#canvas-fullscreen .fullscreen-actions {
  display: flex;
  gap: 10px;
  flex-shrink: 0;
}

/* Input Toolbar (for Apple Pencil) */
.input-toolbar {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px 8px;
  background: var(--bg-card);
  border: 2px solid var(--border);
  border-bottom: none;
  border-radius: var(--radius) var(--radius) 0 0;
  flex-wrap: wrap;
}
.toolbar-btn {
  min-width: 40px;
  min-height: 40px;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  font-size: 1rem;
  font-family: inherit;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, transform 0.1s;
  -webkit-tap-highlight-color: transparent;
}
.toolbar-btn:active {
  background: var(--primary-light);
  transform: scale(0.92);
}
.toolbar-btn-danger {
  color: #dc2626;
}
.toolbar-btn-danger:active {
  background: #fee2e2;
}
.toolbar-sep {
  width: 1px;
  height: 24px;
  background: var(--border);
  margin: 0 2px;
}
/* textarea connects to toolbar */
.input-toolbar + .answer-textarea {
  border-top-left-radius: 0;
  border-top-right-radius: 0;
}

/* Answer Text Input */
.answer-input-area {
  display: flex;
  flex-direction: column;
}
.answer-label {
  font-weight: 700;
  font-size: 1rem;
  margin-bottom: 6px;
  color: var(--text);
}
.answer-textarea {
  width: 100%;
  min-height: 180px;
  padding: 16px;
  font-size: 1.15rem;
  line-height: 1.8;
  font-family: inherit;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-card);
  color: var(--text);
  resize: vertical;
  box-sizing: border-box;
}
.answer-textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(232, 127, 191, 0.15);
}
.answer-textarea::placeholder {
  color: var(--text-hint);
}

/* --- Chat Panel --- */
.chat-panel {
  background: var(--bg-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  max-height: 360px;
  overflow: hidden;
}
.chat-panel.collapsed {
  max-height: 56px;
}
.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  flex-shrink: 0;
  min-height: 48px;
}
.chat-header .character-name {
  font-weight: 700;
  font-size: 0.95rem;
  display: flex;
  align-items: center;
  gap: 6px;
}
.chat-header .toggle-icon {
  font-size: 1.2rem;
  transition: transform 0.3s;
}
.chat-panel.collapsed .toggle-icon {
  transform: rotate(180deg);
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  -webkit-overflow-scrolling: touch;
}

.chat-bubble {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 0.95rem;
  line-height: 1.5;
  word-break: break-word;
  animation: bubbleIn 0.3s ease;
}
@keyframes bubbleIn {
  from { opacity: 0; transform: translateY(6px) scale(0.95); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
.chat-bubble.character {
  align-self: flex-start;
  background: #f0e6ff;
  color: var(--text);
  border-bottom-left-radius: 4px;
}
.chat-bubble.user {
  align-self: flex-end;
  background: var(--primary);
  color: white;
  border-bottom-right-radius: 4px;
}

.chat-bubble .bubble-avatar {
  width: 28px;
  height: 28px;
  display: inline-block;
  vertical-align: middle;
  margin-right: 4px;
}

.chat-input-row {
  display: flex;
  gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}
.chat-input-row input {
  flex: 1;
  padding: 10px 14px;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.95rem;
  font-family: inherit;
  outline: none;
  min-height: 44px;
}
.chat-input-row input:focus {
  border-color: var(--primary-light);
}

/* Typing indicator */
.typing-indicator {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 10px 14px;
  align-self: flex-start;
}
.typing-indicator span {
  width: 8px;
  height: 8px;
  background: var(--secondary-light);
  border-radius: 50%;
  animation: typingBounce 1.2s infinite;
}
.typing-indicator span:nth-child(2) { animation-delay: 0.15s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.3s; }
@keyframes typingBounce {
  0%, 60%, 100% { transform: translateY(0); }
  30% { transform: translateY(-6px); }
}

/* --- History View --- */
.filter-bar {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.filter-btn {
  padding: 8px 16px;
  border-radius: 20px;
  border: 2px solid var(--border);
  background: var(--bg-card);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  min-height: 40px;
  transition: all 0.2s;
}
.filter-btn.active {
  background: var(--primary-light);
  border-color: var(--primary);
  color: var(--primary-dark);
}

.history-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.history-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  cursor: pointer;
}
.history-item .subject-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  flex-shrink: 0;
}
.history-item .subject-dot.math { background: #f472b6; }
.history-item .subject-dot.japanese { background: #818cf8; }
.history-item .subject-dot.science { background: #34d399; }
.history-item .subject-dot.social { background: #fbbf24; }

.history-item .item-info {
  flex: 1;
  min-width: 0;
}
.history-item .item-title {
  font-weight: 600;
  font-size: 0.95rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.history-item .item-date {
  font-size: 0.75rem;
  color: var(--text-light);
}
.history-item .item-score {
  font-weight: 800;
  font-size: 1.2rem;
  min-width: 50px;
  text-align: right;
}

/* History date grouping */
.history-date-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    background: var(--bg);
    border-radius: var(--radius-sm);
    cursor: pointer;
    margin-top: 8px;
    transition: background 0.15s;
    -webkit-tap-highlight-color: transparent;
}
.history-date-header:active {
    background: var(--primary-light);
}
.date-label {
    font-weight: 700;
    font-size: 0.9rem;
}
.date-stats {
    flex: 1;
    font-size: 0.75rem;
    color: var(--text-light);
    text-align: right;
}
.date-toggle {
    font-size: 0.8rem;
    color: var(--text-hint);
    min-width: 16px;
    text-align: center;
}
.history-date-items {
    transition: max-height 0.3s ease;
    overflow: hidden;
}
.history-date-items.collapsed {
    max-height: 0 !important;
    overflow: hidden;
}

/* Score colors */
.score-low { color: #dc2626; }
.score-mid { color: #d97706; }
.score-high { color: #16a34a; }

/* --- Analysis View --- */
.chart-section {
  margin-bottom: 24px;
}
.chart-section h3 {
  margin-bottom: 12px;
}

.bar-chart {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.bar-row {
  display: flex;
  align-items: center;
  gap: 10px;
}
.bar-label {
  width: 60px;
  font-size: 0.85rem;
  font-weight: 600;
  text-align: right;
  flex-shrink: 0;
}
.bar-track {
  flex: 1;
  height: 28px;
  background: #f3e8ff;
  border-radius: 14px;
  overflow: hidden;
  position: relative;
}
.bar-fill {
  height: 100%;
  border-radius: 14px;
  transition: width 0.8s cubic-bezier(0.34, 1.56, 0.64, 1);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding-right: 10px;
  font-size: 0.75rem;
  font-weight: 700;
  color: white;
  min-width: 40px;
}
.bar-fill.math { background: linear-gradient(90deg, #f472b6, #ec4899); }
.bar-fill.japanese { background: linear-gradient(90deg, #818cf8, #6366f1); }
.bar-fill.science { background: linear-gradient(90deg, #34d399, #10b981); }
.bar-fill.social { background: linear-gradient(90deg, #fbbf24, #f59e0b); }

.streak-display {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 20px;
  background: linear-gradient(135deg, #fef3c7, #fde68a);
  border-radius: var(--radius);
  margin-bottom: 20px;
}
.streak-number {
  font-size: 2.5rem;
  font-weight: 900;
  color: #92400e;
}
.streak-label {
  font-size: 1rem;
  color: #92400e;
  font-weight: 600;
}
.streak-fire {
  font-size: 2rem;
}

.weak-areas {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.weak-tag {
  padding: 6px 14px;
  background: #fee2e2;
  color: #b91c1c;
  border-radius: 20px;
  font-size: 0.8rem;
  font-weight: 600;
}

/* --- Settings View --- */
.character-select-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
  margin: 20px 0;
}
.character-option {
  padding: 20px;
  text-align: center;
  cursor: pointer;
  border: 3px solid transparent;
  transition: all 0.25s;
}
.character-option.selected {
  border-color: var(--primary);
  background: linear-gradient(135deg, #fef6fb, #f3e8ff);
}
.character-option .char-preview {
  width: 100px;
  height: 100px;
  margin: 0 auto 10px;
}
.character-option .char-name {
  font-weight: 700;
  font-size: 1.05rem;
  margin-bottom: 4px;
}
.character-option .char-desc {
  font-size: 0.8rem;
  color: var(--text-light);
}

/* --- Problem Detail Modal --- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(61, 44, 78, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
  padding: 20px;
  animation: fadeIn 0.2s ease;
}
.modal-content {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  max-width: 600px;
  width: 100%;
  max-height: 85vh;
  overflow-y: auto;
  padding: 24px;
  box-shadow: var(--shadow-lg);
  position: relative;
}
.modal-close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: var(--border);
  font-size: 1.2rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.modal-content .answer-image {
  width: 100%;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  margin: 12px 0;
}
.modal-content .feedback-box {
  background: #f0fdf4;
  border-radius: var(--radius-sm);
  padding: 14px;
  border-left: 4px solid #22c55e;
  margin-top: 12px;
}

/* --- Loading States --- */
.loading-spinner {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px;
  gap: 12px;
}
.spinner {
  width: 40px;
  height: 40px;
  border: 4px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}
.loading-text {
  font-size: 0.9rem;
  color: var(--text-light);
  animation: pulse 1.5s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

/* Skeleton */
.skeleton {
  background: linear-gradient(90deg, #f0e6ff 25%, #e8d5f5 50%, #f0e6ff 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: var(--radius-sm);
}
@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}
.skeleton-line {
  height: 16px;
  margin-bottom: 8px;
  border-radius: 8px;
}
.skeleton-line:last-child { width: 60%; }

/* --- Mascot Animations --- */
.mascot-bounce {
  animation: mascotBounce 2s ease-in-out infinite;
}
@keyframes mascotBounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}

.mascot-wave {
  animation: mascotWave 1.5s ease-in-out infinite;
  transform-origin: 70% 80%;
}
@keyframes mascotWave {
  0%, 100% { transform: rotate(0deg); }
  25% { transform: rotate(12deg); }
  75% { transform: rotate(-8deg); }
}

.mascot-happy {
  animation: mascotHappy 0.5s ease;
}
@keyframes mascotHappy {
  0% { transform: scale(1); }
  50% { transform: scale(1.15); }
  100% { transform: scale(1); }
}

/* --- Difficulty Modal --- */
.difficulty-modal {
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.difficulty-modal h2 {
  text-align: center;
  color: var(--primary-dark);
}

/* --- Score Feedback --- */
.score-feedback {
  text-align: center;
  padding: 20px;
}
.score-feedback .score-big {
  font-size: 3rem;
  font-weight: 900;
}
.score-feedback .score-msg {
  font-size: 1.1rem;
  margin-top: 8px;
}

/* --- Empty State --- */
.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-light);
}
.empty-state .empty-icon {
  font-size: 3rem;
  margin-bottom: 12px;
}

/* --- Toast Notification --- */
.toast {
  position: fixed;
  top: calc(var(--safe-top) + 16px);
  left: 50%;
  transform: translateX(-50%) translateY(-100px);
  background: var(--text);
  color: white;
  padding: 12px 24px;
  border-radius: var(--radius);
  font-weight: 600;
  font-size: 0.9rem;
  z-index: 3000;
  transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  pointer-events: none;
}
.toast.show {
  transform: translateX(-50%) translateY(0);
}

/* --- Wide screens (PC + iPad landscape) --- */
@media (min-width: 768px) {
  .problem-layout {
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-template-rows: auto 1fr;
    gap: 16px;
  }
  .problem-header {
    grid-column: 1 / -1;
  }
  .problem-text-area {
    grid-column: 1 / -1;
  }
  .canvas-section {
    grid-column: 1;
  }
  .chat-panel {
    grid-column: 2;
    max-height: 400px;
  }
  .card-grid {
    grid-template-columns: repeat(4, 1fr);
  }
  .stats-summary {
    grid-template-columns: repeat(4, 1fr);
  }
  .character-select-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

/* --- Desktop (wider) --- */
@media (min-width: 1024px) {
  #app {
    padding: 24px 32px;
  }
  .problem-text-area {
    font-size: 1.25rem;
  }
  .answer-textarea {
    min-height: 220px;
  }
  .chat-panel {
    max-height: 450px;
  }
}

/* --- Print Styles --- */
@media print {
  .bottom-nav,
  .canvas-toolbar,
  .canvas-actions,
  .chat-panel,
  .btn { display: none !important; }
  body {
    padding: 0;
    background: white;
  }
  .problem-text-area {
    box-shadow: none;
    border: 1px solid #ccc;
    max-height: none;
  }
}

/* --- Theme: Frieza --- */
body.theme-frieza {
  --primary: #8b5cf6;
  --primary-light: #c4b5fd;
  --primary-dark: #6d28d9;
  --secondary: #a78bfa;
  --bg: #f5f3ff;
  --border: #e0d4fc;
}
body.theme-frieza .chat-bubble.character {
  background: #ede9fe;
}

/* --- Theme: カピちゅう --- */
body.theme-pekachu {
  --primary: #FFD93D;
  --primary-light: #FFF3B0;
  --primary-dark: #E6A800;
  --secondary: #FF6B6B;
  --bg: #FFFBEB;
  --border: #FFE4A0;
}
body.theme-pekachu .chat-bubble.character {
  background: #FFF8DC;
}
body.theme-pekachu .btn-primary {
  background: linear-gradient(135deg, #FFD93D, #FF6B6B);
  color: #5D4037;
}
body.theme-pekachu .stat-value {
  color: #E6A800;
}
body.theme-pekachu .nav-item.active {
  color: #E6A800;
}

/* --- Theme: スネェク --- */
body.theme-snake {
    --primary: #4ade80;
    --primary-light: #bbf7d0;
    --primary-dark: #166534;
    --secondary: #6b7280;
    --bg: #f0fdf4;
    --border: #d1fae5;
}
body.theme-snake .chat-bubble.character {
    background: #ecfdf5;
}
body.theme-snake .btn-primary {
    background: linear-gradient(135deg, #4ade80, #6b7280);
    color: white;
}
body.theme-snake .stat-value {
    color: #166534;
}
body.theme-snake .nav-item.active {
    color: #166534;
}

/* --- Subject Modal --- */
.subject-modal-content {
  padding: 20px;
}
.subject-modal-content h2 {
  text-align: center;
  margin-bottom: 20px;
  color: var(--primary-dark);
}
.type-select {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin: 16px 0;
}
.type-option {
  padding: 14px 18px;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 1rem;
  font-weight: 600;
  text-align: center;
  background: var(--bg-card);
  font-family: inherit;
  transition: all 0.2s;
  min-height: 48px;
}
.type-option:active,
.type-option.active {
  border-color: var(--primary);
  background: var(--primary-light);
}

/* ====== Session Badge (floating) ====== */
.session-badge {
  position: fixed;
  top: calc(var(--safe-top) + 12px);
  right: 16px;
  background: var(--bg-card);
  border: 2px solid var(--primary-light);
  border-radius: var(--radius);
  padding: 8px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.8rem;
  font-weight: 600;
  box-shadow: var(--shadow-lg);
  cursor: pointer;
  z-index: 1500;
  transition: transform 0.2s;
}
.session-badge:active {
  transform: scale(0.95);
}
.session-badge.hidden {
  display: none;
}
.badge-pending {
  color: var(--accent-orange);
}
.badge-done {
  color: #16a34a;
}
.badge-done-all {
  color: var(--primary-dark);
  font-weight: 800;
}
.badge-action {
  color: var(--primary);
  font-size: 0.75rem;
}
.session-badge.badge-pulse {
  animation: badgePulse 0.6s ease 3;
  border-color: var(--primary);
  box-shadow: 0 0 0 4px rgba(232, 127, 191, 0.3), var(--shadow-lg);
}
@keyframes badgePulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.08); }
}

/* ====== Session Results Modal ====== */
.results-modal {
  max-width: 550px;
}
.results-summary {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin: 16px 0;
}
.results-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 50vh;
  overflow-y: auto;
}
.result-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  background: var(--bg);
  border-radius: var(--radius-sm);
}
.result-q {
  font-weight: 800;
  color: var(--primary);
  min-width: 32px;
}
.result-subject {
  font-size: 1.2rem;
  min-width: 28px;
}
.result-text {
  flex: 1;
  font-size: 0.85rem;
  color: var(--text-light);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.result-score {
  font-weight: 800;
  font-size: 1rem;
  min-width: 70px;
  text-align: right;
}
.result-feedback {
  padding: 6px 12px 6px 52px;
  font-size: 0.8rem;
  color: var(--text-light);
  line-height: 1.5;
}

/* ====== Grade Selector ====== */
.grade-select-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 8px;
  margin: 12px 0 20px;
}
.grade-btn {
  min-height: 44px;
  font-size: 1rem;
}
.grade-btn.selected {
  background: var(--primary-light);
  border-color: var(--primary);
  color: var(--primary-dark);
}

/* ====== Login Overlay ====== */
.login-overlay {
    position: fixed;
    inset: 0;
    z-index: 8000;
    background: var(--bg);
    display: flex;
    align-items: center;
    justify-content: center;
}
.login-overlay.hidden {
    display: none;
}
.login-content {
    max-width: 360px;
    width: 100%;
    padding: 32px 24px;
}
.login-form {
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.login-input {
    width: 100%;
    padding: 14px 16px;
    border: 2px solid var(--border);
    border-radius: var(--radius);
    font-size: 1.1rem;
    font-family: inherit;
    background: var(--bg-card);
    color: var(--text);
    min-height: 48px;
    box-sizing: border-box;
}
.login-input:focus {
    outline: none;
    border-color: var(--primary);
}

/* ====== Character Affinity ====== */
.affinity-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    margin: 12px 0;
}
.affinity-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 14px;
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
    text-align: center;
    cursor: pointer;
    transition: transform 0.2s;
}
.affinity-card:active {
    transform: scale(0.97);
}
.affinity-card .aff-avatar {
    width: 50px;
    height: 50px;
    margin: 0 auto 6px;
}
.affinity-card .aff-name {
    font-weight: 700;
    font-size: 0.9rem;
    margin-bottom: 4px;
}
.affinity-card .aff-level {
    font-size: 1.2rem;
    font-weight: 800;
    color: var(--primary);
}
.aff-bar {
    height: 6px;
    background: var(--border);
    border-radius: 3px;
    margin-top: 6px;
    overflow: hidden;
}
.aff-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--primary), var(--secondary));
    border-radius: 3px;
    transition: width 0.5s ease;
}
.aff-secrets-count {
    font-size: 0.7rem;
    color: var(--text-light);
    margin-top: 4px;
}
/* Secret conversation modal */
.secret-item {
    padding: 12px;
    margin-bottom: 8px;
    border-radius: var(--radius-sm);
    background: var(--bg);
    border-left: 3px solid var(--primary);
}
.secret-item.locked {
    opacity: 0.4;
    border-left-color: var(--border);
}
.secret-item .secret-title {
    font-weight: 700;
    font-size: 0.9rem;
    margin-bottom: 4px;
}
.secret-item .secret-level {
    font-size: 0.7rem;
    color: var(--text-hint);
}
.secret-item .secret-text {
    font-size: 0.9rem;
    line-height: 1.6;
    margin-top: 6px;
}

/* ====== Lesson Over Overlay ====== */
.lesson-over-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: linear-gradient(135deg, #1a1a3e 0%, #2d1b69 40%, #4a1a6b 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  animation: lessonOverFadeIn 0.6s ease;
}
.lesson-over-overlay.hidden {
  display: none;
}
.lesson-over-content {
  text-align: center;
  padding: 32px;
  max-width: 400px;
}
.lesson-over-icon {
  font-size: 4rem;
  margin-bottom: 12px;
  animation: lessonOverFloat 3s ease-in-out infinite;
}
.lesson-over-content h1 {
  color: #f8e8ff;
  font-size: 1.8rem;
  margin-bottom: 12px;
}
.lesson-over-content p {
  color: #d4b8e8;
  font-size: 1.1rem;
  line-height: 1.6;
}
.lesson-over-sub {
  margin-top: 8px;
  font-size: 0.95rem !important;
  color: #b899d4 !important;
}
@keyframes lessonOverFadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}
@keyframes lessonOverFloat {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-10px); }
}

/* ====== Learn Mode ====== */
.learn-topics {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 12px;
}
.learn-topic-card {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 18px;
    cursor: pointer;
}
.learn-topic-name {
    font-weight: 600;
    font-size: 1rem;
}
.learn-topic-arrow {
    color: var(--primary);
    font-weight: 700;
    font-size: 1.2rem;
}
.topic-info {
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.topic-timing {
    font-size: 0.8rem;
    color: var(--text-light);
}
.topic-right {
    display: flex;
    align-items: center;
    gap: 8px;
}
.badge-strategy {
    background: linear-gradient(135deg, #f39c12, #e74c3c);
    color: white;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.7rem;
    font-weight: 600;
    margin-left: 6px;
}
.badge-clear {
    background: linear-gradient(135deg, #27ae60, #2ecc71);
    color: white;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.7rem;
    font-weight: 600;
    margin-left: 6px;
}
.bonus-hint {
    background: linear-gradient(135deg, #f1c40f, #f39c12);
    color: #333;
    padding: 3px 8px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 700;
    animation: pulse 1.5s infinite;
}
.current-mark {
    background: var(--primary);
    color: white;
    padding: 3px 8px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 600;
}
@keyframes pulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.8; transform: scale(1.05); }
}
.btn-success {
    background: linear-gradient(135deg, #27ae60, #2ecc71);
    color: white;
    border: none;
    font-weight: 700;
}
.btn-success:hover {
    background: linear-gradient(135deg, #219a52, #27ae60);
}
.learn-session-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 8px;
}

/* ====== Dialogue Bubbles (manga-style) ====== */
.dialogue-container {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 8px 0;
}
.dialogue-turn {
    display: flex;
    gap: 10px;
    align-items: flex-start;
    animation: bubbleIn 0.3s ease;
}
.dialogue-turn.student {
    flex-direction: row-reverse;
}
.dialogue-avatar {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: var(--bg);
    border: 2px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.3rem;
    flex-shrink: 0;
}
.dialogue-turn.student .dialogue-avatar {
    background: var(--primary-light);
    border-color: var(--primary);
}
.dialogue-bubble {
    max-width: 75%;
    padding: 10px 14px;
    border-radius: 16px;
    font-size: 0.95rem;
    line-height: 1.5;
    position: relative;
}
.dialogue-turn:not(.student) .dialogue-bubble {
    background: #f0e6ff;
    color: var(--text);
    border-bottom-left-radius: 4px;
}
.dialogue-turn.student .dialogue-bubble {
    background: var(--primary);
    color: white;
    border-bottom-right-radius: 4px;
}
.dialogue-speaker {
    font-size: 0.7rem;
    font-weight: 700;
    margin-bottom: 2px;
    opacity: 0.7;
}
/* Diagram block in dialogue */
.dialogue-diagram {
    background: var(--bg-card);
    border: 2px solid var(--border);
    border-radius: var(--radius);
    padding: 14px;
    margin: 4px 0;
    text-align: center;
    animation: bubbleIn 0.3s ease;
    overflow-x: auto;
}
.dialogue-diagram svg {
    max-width: 100%;
    height: auto;
}
.diagram-ascii {
    font-family: 'Courier New', monospace;
    font-size: 0.85rem;
    line-height: 1.4;
    white-space: pre;
    text-align: left;
    margin: 0;
    color: var(--text);
    overflow-x: auto;
}

/* ====== Exam Strategy Mode ====== */
.strategy-steps {
    background: linear-gradient(135deg, #fef3c7, #fde68a);
    border-radius: var(--radius);
    padding: 14px 18px;
    margin-bottom: 12px;
}
.strategy-steps h4 {
    color: #92400e;
    margin-bottom: 8px;
    font-size: 0.9rem;
}
.strategy-steps ol {
    margin: 0;
    padding-left: 20px;
    color: #78350f;
    font-size: 0.9rem;
    line-height: 1.7;
}
.strategy-steps .key-point {
    margin-top: 8px;
    padding: 8px 12px;
    background: rgba(255,255,255,0.6);
    border-radius: var(--radius-sm);
    font-weight: 700;
    color: #b45309;
    font-size: 0.85rem;
}
.technique-card {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 18px;
    cursor: pointer;
}
.technique-card .tech-difficulty {
    display: flex;
    gap: 2px;
}
.technique-card .tech-star {
    font-size: 0.8rem;
}
.technique-card .tech-info {
    flex: 1;
}
.technique-card .tech-name {
    font-weight: 700;
    font-size: 1rem;
}
.technique-card .tech-desc {
    font-size: 0.8rem;
    color: var(--text-light);
    margin-top: 2px;
}

/* Character PNG images */
.char-png, .dialogue-avatar img {
    object-fit: cover;
    image-rendering: auto;
}

/* ===== History detail: submitted answers ===== */
.user-answers-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 8px;
}
.user-answer-card {
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    padding: 10px 12px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
}
.user-answer-head {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 6px;
    font-size: 0.75rem;
    color: var(--text-light);
    flex-wrap: wrap;
}
.user-answer-label {
    background: linear-gradient(90deg, #e87fbf, #9b7fe8);
    color: #fff;
    padding: 2px 10px;
    border-radius: 10px;
    font-weight: 700;
    font-size: 0.72rem;
}
.user-answer-date {
    flex: 1;
}
.score-inline {
    font-weight: 800;
    font-size: 0.85rem;
    padding: 1px 8px;
    border-radius: 8px;
    background: #f9fafb;
}
.score-inline.score-high { color: #16a34a; background: #dcfce7; }
.score-inline.score-mid  { color: #d97706; background: #fef3c7; }
.score-inline.score-low  { color: #dc2626; background: #fee2e2; }
.user-answer-body {
    margin-top: 4px;
}
.user-answer-text {
    white-space: pre-wrap;
    font-size: 0.9rem;
    color: #374151;
    background: #f9fafb;
    border-left: 3px solid #9b7fe8;
    padding: 8px 10px;
    border-radius: 6px;
    margin-bottom: 6px;
    line-height: 1.6;
}
.user-answer-image-wrap {
    background: #f3f4f6;
    border-radius: 8px;
    padding: 4px;
    display: flex;
    justify-content: center;
}
.user-answer-image {
    max-width: 100%;
    max-height: 340px;
    border-radius: 6px;
    object-fit: contain;
    background: #fff;
    cursor: zoom-in;
}

/* ===== Feedback text (markdown rendered) ===== */
.feedback-text {
    line-height: 1.7;
    font-size: 0.95rem;
    color: #374151;
}
.feedback-text strong {
    color: #c9549a;
    font-weight: 800;
}
.feedback-text em {
    color: #6d28d9;
    font-style: normal;
    font-weight: 600;
}
.feedback-text code {
    background: #f3f4f6;
    border: 1px solid #e5e7eb;
    border-radius: 4px;
    padding: 1px 5px;
    font-family: 'SFMono-Regular', Consolas, monospace;
    font-size: 0.9em;
    color: #be185d;
}
.feedback-text h3 {
    font-size: 1.05rem;
    color: #c9549a;
    margin: 12px 0 6px;
    border-left: 4px solid #e87fbf;
    padding-left: 10px;
}
.feedback-text h4 {
    font-size: 0.95rem;
    color: #9b7fe8;
    margin: 10px 0 4px;
}
.feedback-text h5 {
    font-size: 0.9rem;
    color: #6b7280;
    margin: 8px 0 4px;
}
.feedback-text ul,
.feedback-text ol {
    margin: 6px 0 8px 0;
    padding-left: 22px;
}
.feedback-text li {
    margin: 3px 0;
}
.feedback-text li::marker {
    color: #e87fbf;
    font-weight: 700;
}

/* ===== Norma rule editor (parent dashboard) ===== */
.norma-rule-row {
    display: flex;
    gap: 6px;
    align-items: center;
    margin-bottom: 6px;
    padding: 6px;
    background: #fafafa;
    border-radius: 8px;
    border: 1px solid #e5e7eb;
}
.norma-rule-row select,
.norma-rule-row input[type="number"] {
    margin-top: 0;
    min-height: 36px;
    padding: 4px 6px;
    font-size: 0.85rem;
}
.norma-rule-row .norma-rule-subject,
.norma-rule-row .norma-rule-difficulty {
    flex: 1;
    min-width: 80px;
}
.norma-rule-row .norma-rule-count {
    width: 56px;
    text-align: center;
}

/* ===== Home: norma rules progress display ===== */
.home-rules-list {
    margin-top: 10px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.home-rule-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 10px;
    background: #fff;
    border-radius: 10px;
    border: 1px solid #e5e7eb;
    font-size: 0.85rem;
}
.home-rule-row.satisfied {
    background: #dcfce7;
    border-color: #86efac;
}
.home-rule-label {
    flex: 1;
    font-weight: 700;
}
.home-rule-progress {
    font-family: 'SFMono-Regular', Consolas, monospace;
    font-size: 0.9rem;
    color: #374151;
}
.home-rule-row.satisfied .home-rule-progress {
    color: #15803d;
}
.home-rule-icon {
    font-size: 1rem;
}

/* ===== Multiplier Banner ===== */
.multiplier-banner {
    margin-top: 12px;
    padding: 12px;
    background: linear-gradient(135deg, #fef3c7, #fde68a);
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}
.multiplier-current {
    display: flex;
    align-items: center;
    gap: 4px;
}
.multiplier-icon {
    font-size: 1.5rem;
}
.multiplier-value {
    font-size: 1.8rem;
    font-weight: 900;
    color: #d97706;
}
.multiplier-label {
    font-size: 1rem;
    font-weight: 600;
    color: #92400e;
}
.multiplier-next {
    font-size: 0.9rem;
    font-weight: 600;
    color: #92400e;
    text-align: right;
    animation: pulse 2s infinite;
}

/* ===== TTS button (speaking state) ===== */
.tts-btn {
    min-height: 32px;
    padding: 2px 10px;
    font-size: 0.85rem;
}
.tts-btn.tts-speaking {
    background: linear-gradient(135deg, #fef3c7, #fde68a);
    border-color: #f59e0b;
    animation: tts-pulse 1.2s ease-in-out infinite;
}
#problem-speak-btn.tts-speaking {
    background: linear-gradient(135deg, #fef3c7, #fde68a);
    animation: tts-pulse 1.2s ease-in-out infinite;
}
@keyframes tts-pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(245, 158, 11, 0.4); }
    50%      { box-shadow: 0 0 0 6px rgba(245, 158, 11, 0); }
}

/* ===== Dialogue image input (learn/strategy) ===== */
.dialogue-image-modal-content {
    max-width: 560px;
    width: 92vw;
}
.dialogue-image-mode-tabs {
    display: flex;
    gap: 6px;
    margin-bottom: 10px;
}
.dialogue-image-mode-tab {
    flex: 1;
    padding: 8px 12px;
    border-radius: 10px;
    border: 2px solid #e5e7eb;
    background: #fff;
    font-weight: 700;
    font-size: 0.9rem;
    cursor: pointer;
}
.dialogue-image-mode-tab.active {
    background: linear-gradient(135deg, #fef3c7, #fde68a);
    border-color: #f59e0b;
    color: #78350f;
}
.dialogue-image-pane.hidden {
    display: none;
}
.dialogue-canvas-container {
    width: 100%;
    height: 44vh;
    min-height: 240px;
    max-height: 420px;
    border: 2px dashed #a78bfa;
    border-radius: 10px;
    background: #fafafa;
    overflow: hidden;
    touch-action: none;
}
.dialogue-canvas-container canvas {
    display: block;
    width: 100%;
    height: 100%;
    cursor: crosshair;
}
.dialogue-canvas-tools {
    display: flex;
    gap: 8px;
    margin-top: 8px;
    flex-wrap: wrap;
    align-items: center;
}
.dialogue-color-btn {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    border: 3px solid #fff;
    box-shadow: 0 0 0 2px #d1d5db;
    cursor: pointer;
}
.dialogue-color-btn.active {
    box-shadow: 0 0 0 3px #e87fbf;
    transform: scale(1.1);
}
.dialogue-photo-picker {
    display: block;
    cursor: pointer;
}
.dialogue-photo-preview {
    border: 2px dashed #a78bfa;
    border-radius: 10px;
    min-height: 240px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #fafafa;
    color: var(--text-light);
    font-size: 1rem;
    overflow: hidden;
}
.dialogue-photo-preview img {
    max-width: 100%;
    max-height: 340px;
    object-fit: contain;
}

/* ===== History: pending (scoring in progress) item ===== */
.history-item-pending {
    position: relative;
    display: block !important;
    padding: 0 !important;
    background: linear-gradient(135deg, #f4f3ff 0%, #fff6fa 100%) !important;
    border: 2px solid #a78bfa !important;
    border-radius: 14px !important;
    overflow: hidden;
    margin-bottom: 10px;
    animation: pending-glow 2.4s ease-in-out infinite;
    cursor: default;
}
.history-item-pending:hover {
    transform: none !important;
}
.pending-ribbon {
    background: linear-gradient(90deg, #8b5cf6, #ec4899);
    color: #fff;
    font-weight: 800;
    font-size: 0.85rem;
    padding: 6px 14px;
    letter-spacing: 0.04em;
    display: flex;
    align-items: center;
    gap: 6px;
}
.pending-body {
    padding: 10px 14px 12px;
}
.pending-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 6px;
    font-size: 0.75rem;
    color: var(--text-light);
}
.pending-subject-badge {
    background: #fff;
    padding: 2px 8px;
    border-radius: 10px;
    font-weight: 700;
    border: 1px solid #e5e7eb;
}
.pending-date {
    font-size: 0.7rem;
}
.pending-title {
    font-size: 0.9rem;
    font-weight: 700;
    color: #374151;
    margin-bottom: 10px;
    line-height: 1.4;
}
.pending-queue {
    display: inline-flex;
    align-items: baseline;
    gap: 3px;
    background: #ede9fe;
    border: 1px solid #c4b5fd;
    border-radius: 999px;
    padding: 4px 12px;
    margin-bottom: 10px;
    font-family: 'SFMono-Regular', Consolas, monospace;
    color: #6d28d9;
}
.pending-queue-pos {
    font-size: 1.3rem;
    font-weight: 900;
}
.pending-queue-sep {
    font-size: 0.9rem;
    color: #a78bfa;
    margin: 0 1px;
}
.pending-queue-total {
    font-size: 0.9rem;
    color: #7c3aed;
    font-weight: 700;
}
.pending-queue-label {
    font-family: inherit;
    font-size: 0.72rem;
    font-weight: 700;
    color: #6d28d9;
    margin-left: 6px;
}
.pending-progress {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 8px;
}
.pending-spinner {
    display: inline-flex;
    gap: 4px;
    align-items: center;
}
.pending-spinner .dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #8b5cf6;
    animation: pending-dot 1.2s ease-in-out infinite;
}
.pending-spinner .dot:nth-child(2) { animation-delay: 0.2s; }
.pending-spinner .dot:nth-child(3) { animation-delay: 0.4s; }
.pending-eta {
    flex: 1;
    line-height: 1.3;
}
.pending-eta-main {
    font-size: 0.85rem;
    font-weight: 800;
    color: #6d28d9;
}
.pending-eta-sub {
    font-size: 0.7rem;
    color: #9ca3af;
    margin-top: 1px;
}
.pending-bar {
    height: 6px;
    background: rgba(139, 92, 246, 0.15);
    border-radius: 999px;
    overflow: hidden;
}
.pending-bar-fill {
    height: 100%;
    width: 40%;
    background: linear-gradient(90deg, #8b5cf6, #ec4899, #8b5cf6);
    background-size: 200% 100%;
    border-radius: 999px;
    animation: pending-bar-slide 1.8s linear infinite;
}
@keyframes pending-glow {
    0%, 100% { box-shadow: 0 0 0 0 rgba(139, 92, 246, 0.35); }
    50%      { box-shadow: 0 0 0 6px rgba(139, 92, 246, 0); }
}
@keyframes pending-dot {
    0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
    40%           { transform: scale(1);   opacity: 1; }
}
@keyframes pending-bar-slide {
    0%   { background-position: 200% 0; transform: translateX(-20%); }
    100% { background-position: -200% 0; transform: translateX(120%); }
}

/* ===== Score celebration popup ===== */
.celebration-overlay {
    backdrop-filter: blur(4px);
    z-index: 10000;
}
.celebration-card {
    background: linear-gradient(145deg, #fff, #fff4fa);
    border-radius: 28px;
    padding: 32px 40px;
    text-align: center;
    box-shadow: 0 20px 60px rgba(232, 127, 191, 0.4), 0 0 0 4px #fff, 0 0 0 6px #e87fbf;
    max-width: 88vw;
    animation: celeb-pop 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.celeb-emoji {
    font-size: 5rem;
    line-height: 1;
    margin-bottom: 8px;
    animation: celeb-bounce 0.6s ease-out;
}
.celeb-score {
    font-size: 4.5rem;
    font-weight: 900;
    line-height: 1;
    margin: 8px 0 16px;
    text-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}
.celeb-exp {
    background: linear-gradient(135deg, #fef3c7, #fde68a);
    border: 2px solid #f59e0b;
    border-radius: 16px;
    padding: 12px 18px;
    margin: 12px auto;
    max-width: 280px;
}
.celeb-exp-char {
    font-size: 0.95rem;
    font-weight: 700;
    color: #78350f;
    margin-bottom: 4px;
}
.celeb-exp-gain {
    font-size: 1.4rem;
    font-weight: 900;
    color: #b45309;
}
.celeb-levelup {
    font-size: 1.1rem;
    font-weight: 900;
    color: #c9549a;
    background: #fff;
    border-radius: 10px;
    padding: 6px 10px;
    margin: 6px 0;
    animation: celeb-levelup-pulse 1.2s ease-in-out infinite;
}
@keyframes celeb-fadein {
    from { opacity: 0; }
    to { opacity: 1; }
}
@keyframes celeb-fadeout {
    from { opacity: 1; }
    to { opacity: 0; }
}
@keyframes celeb-pop {
    0%   { transform: scale(0.4) rotate(-8deg); opacity: 0; }
    60%  { transform: scale(1.08) rotate(2deg); opacity: 1; }
    100% { transform: scale(1) rotate(0); }
}
@keyframes celeb-bounce {
    0%, 100% { transform: translateY(0); }
    30% { transform: translateY(-12px); }
    60% { transform: translateY(4px); }
}
@keyframes celeb-levelup-pulse {
    0%, 100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(201, 84, 154, 0.6); }
    50% { transform: scale(1.05); box-shadow: 0 0 0 8px rgba(201, 84, 154, 0); }
}

/* ===== Review Badge & Past Answers ===== */
.review-badge {
    display: inline-block;
    background: linear-gradient(135deg, #fbbf24, #f59e0b);
    color: #78350f;
    font-size: 0.9rem;
    font-weight: 700;
    padding: 6px 14px;
    border-radius: 20px;
    margin-bottom: 10px;
    animation: review-pulse 2s ease-in-out infinite;
    box-shadow: 0 2px 8px rgba(245, 158, 11, 0.4);
}
@keyframes review-pulse {
    0%, 100% { transform: scale(1); box-shadow: 0 2px 8px rgba(245, 158, 11, 0.4); }
    50% { transform: scale(1.03); box-shadow: 0 4px 16px rgba(245, 158, 11, 0.6); }
}
.past-answers-section {
    margin-top: 16px;
    padding-top: 12px;
    border-top: 2px dashed var(--border);
}
.past-answers-header {
    font-weight: 700;
    font-size: 0.95rem;
    color: var(--primary);
    margin-bottom: 10px;
}
.past-answer-card {
    background: #f9fafb;
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 10px 12px;
    margin-bottom: 10px;
}
.past-answer-attempt {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 6px;
}
.past-answer-score {
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 0.8rem;
    margin-left: 8px;
}
.past-answer-score.pass {
    background: #d1fae5;
    color: #065f46;
}
.past-answer-score.fail {
    background: #fee2e2;
    color: #991b1b;
}
.past-answer-img {
    max-width: 100%;
    max-height: 120px;
    border-radius: 8px;
    margin: 6px 0;
    cursor: pointer;
    border: 1px solid var(--border);
}
.past-answer-text {
    font-size: 0.8rem;
    color: var(--text-light);
    background: #fff;
    padding: 6px 8px;
    border-radius: 6px;
    margin-top: 4px;
}
.past-answer-feedback {
    font-size: 0.75rem;
    color: #6b7280;
    margin-top: 4px;
    padding: 4px 8px;
    background: #fffbeb;
    border-radius: 6px;
    border-left: 3px solid #f59e0b;
}

/* ===== Grade Warning Banner ===== */
.grade-warning-banner {
    margin: 12px 0;
    padding: 14px 16px;
    background: linear-gradient(135deg, #fef3c7, #fde68a);
    border: 2px solid #f59e0b;
    border-radius: 16px;
}

/* ===== Point Request Appeal Banner ===== */
.point-request-banner {
    margin: 12px 0;
    padding: 0;
    background: linear-gradient(135deg, #dbeafe, #bfdbfe);
    border: 3px solid #3b82f6;
    border-radius: 20px;
    overflow: hidden;
    animation: point-banner-glow 2s ease-in-out infinite;
}
@keyframes point-banner-glow {
    0%, 100% { box-shadow: 0 4px 20px rgba(59, 130, 246, 0.3); }
    50% { box-shadow: 0 6px 30px rgba(59, 130, 246, 0.6); }
}
.point-request-inner {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px;
}
.point-request-icon {
    font-size: 2.5rem;
    animation: point-bounce 1s ease-in-out infinite;
}
@keyframes point-bounce {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.15); }
}
.point-request-content {
    flex: 1;
}
.point-request-title {
    font-size: 0.9rem;
    font-weight: 600;
    color: #1e40af;
}
.point-request-amount {
    font-size: 1.4rem;
    font-weight: 900;
    color: #1d4ed8;
    margin: 4px 0;
}
.point-request-detail {
    font-size: 0.8rem;
    color: #3730a3;
}
.point-request-cta {
    padding: 12px 16px;
    font-size: 1rem;
    font-weight: 700;
    line-height: 1.3;
    background: linear-gradient(135deg, #22c55e, #16a34a);
    border: none;
    border-radius: 14px;
    color: white;
    animation: cta-pulse 1.5s ease-in-out infinite;
}
.point-request-cta:hover {
    background: linear-gradient(135deg, #16a34a, #15803d);
}
@keyframes cta-pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.05); }
}
.btn-success {
    background: linear-gradient(135deg, #22c55e, #16a34a);
    color: white;
}

/* ===== Learn Recommendation Banner ===== */
.learn-recommend-banner {
    margin: 12px 0;
    padding: 16px;
    background: linear-gradient(135deg, #ecfdf5, #d1fae5);
    border: 2px solid #10b981;
    border-radius: 16px;
}
.learn-recommend-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 12px;
}
.learn-recommend-icon {
    font-size: 1.5rem;
}
.learn-recommend-title {
    flex: 1;
    font-weight: 700;
    color: #065f46;
}
.learn-recommend-bonus {
    background: #fef3c7;
    color: #92400e;
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 0.85rem;
    font-weight: 700;
    animation: bonus-pulse 1.5s ease-in-out infinite;
}
@keyframes bonus-pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.08); }
}
.learn-recommend-topics {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 12px;
}
.learn-topic-chip {
    background: white;
    border: 1px solid #10b981;
    border-radius: 20px;
    padding: 6px 12px;
    font-size: 0.85rem;
    color: #065f46;
    cursor: pointer;
}
.learn-topic-chip:hover {
    background: #d1fae5;
}
.learn-topic-subject {
    font-size: 0.7rem;
    color: #6b7280;
}
.learn-recommend-cta {
    width: 100%;
    background: linear-gradient(135deg, #10b981, #059669);
}

/* ===== Learn View Topic Cards ===== */
.topic-card {
    padding: 12px;
    border-radius: 12px;
    margin-bottom: 8px;
    cursor: pointer;
    transition: all 0.2s;
}
.topic-card:hover {
    transform: translateX(4px);
}
.topic-card.completed {
    background: #ecfdf5;
    border: 2px solid #10b981;
}
.topic-card.current {
    background: #fef3c7;
    border: 2px solid #f59e0b;
}
.topic-card.future {
    background: #f3f4f6;
    border: 1px solid #e5e7eb;
    opacity: 0.7;
}
.topic-card.strategy {
    background: #ede9fe;
    border: 2px solid #8b5cf6;
}
.topic-period {
    font-size: 0.7rem;
    color: var(--text-light);
    margin-top: 4px;
}
.topic-status {
    font-size: 0.75rem;
    padding: 2px 8px;
    border-radius: 10px;
}
.topic-status.clear {
    background: #d1fae5;
    color: #065f46;
}
.topic-status.bonus {
    background: #fef3c7;
    color: #92400e;
}

/* ===== Retention Rate ===== */
.retention-card {
    text-align: center;
    padding: 20px;
}
.retention-value {
    font-size: 2.5rem;
    font-weight: 900;
}
.retention-value.excellent { color: #10b981; }
.retention-value.good { color: #3b82f6; }
.retention-value.stagnant { color: #f59e0b; }
.retention-value.needs_attention { color: #ef4444; }
.retention-label {
    font-size: 0.9rem;
    color: var(--text-light);
    margin-top: 4px;
}
.retention-message {
    margin-top: 12px;
    padding: 10px;
    border-radius: 10px;
    background: var(--bg);
}
.retention-section {
    margin-top: 24px;
}
.retention-display {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 16px;
    border-radius: 16px;
    margin: 12px 0;
}
.retention-display.retention-good {
    background: linear-gradient(135deg, #d1fae5, #a7f3d0);
}
.retention-display.retention-ok {
    background: linear-gradient(135deg, #dbeafe, #bfdbfe);
}
.retention-display.retention-neutral {
    background: linear-gradient(135deg, #f3f4f6, #e5e7eb);
}
.retention-display.retention-bad {
    background: linear-gradient(135deg, #fee2e2, #fecaca);
}
.retention-emoji {
    font-size: 2rem;
}
.retention-display .retention-value {
    font-size: 2rem;
    font-weight: 900;
}
.retention-desc {
    font-size: 0.9rem;
    color: var(--text-light);
}
.retention-detail {
    font-size: 0.85rem;
    color: var(--text-light);
    text-align: center;
}

/* Objection button */
.btn-objection {
    background: linear-gradient(135deg, #fef3c7, #fde68a);
    border: 2px solid #f59e0b;
    color: #92400e;
    font-weight: 600;
}
.btn-objection:hover {
    background: linear-gradient(135deg, #fde68a, #fbbf24);
}
.objection-section .hidden {
    display: none;
}
.objection-text {
    font-family: inherit;
}
.objection-result .card {
    padding: 12px;
}

/* ============================================
   きょうのノルマ カード (3.43〜)
   科目・難易度は子どもが選ばない。アプリが決めた
   ノルマの進捗と「次にやること」だけを見せる。
   ============================================ */
.norma-card {
    margin: 8px 0 4px;
    padding: 18px;
    background: linear-gradient(135deg, #eef2ff, #f5f3ff);
    border: 2px solid #c7d2fe;
}

.norma-headline {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    flex-wrap: wrap;
}

.norma-count {
    display: flex;
    align-items: baseline;
    gap: 2px;
    color: #3730a3;
}
.norma-count-done {
    font-size: 2.4rem;
    font-weight: 800;
    line-height: 1;
}
.norma-count-sep {
    font-size: 1.4rem;
    font-weight: 700;
    opacity: 0.5;
    margin: 0 2px;
}
.norma-count-total {
    font-size: 1.4rem;
    font-weight: 700;
    opacity: 0.75;
}
.norma-count-unit {
    font-size: 0.95rem;
    font-weight: 700;
    margin-left: 6px;
}

.norma-status-chip {
    font-size: 0.8rem;
    font-weight: 700;
    padding: 5px 12px;
    border-radius: 999px;
    background: #e0e7ff;
    color: #4338ca;
    white-space: nowrap;
}
.norma-status-chip.retry {
    background: #fef3c7;
    color: #b45309;
}
.norma-status-chip.done {
    background: #d1fae5;
    color: #047857;
}

.norma-progress {
    height: 12px;
    border-radius: 999px;
    background: #e0e7ff;
    overflow: hidden;
    margin: 12px 0 10px;
}
.norma-progress-fill {
    height: 100%;
    border-radius: 999px;
    background: linear-gradient(90deg, #6366f1, #a855f7);
    transition: width 0.4s ease-out;
}

.norma-lead {
    margin: 0 0 12px;
    font-size: 0.92rem;
    color: #4338ca;
    font-weight: 600;
    line-height: 1.5;
}

.norma-retry-notice {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    margin-bottom: 12px;
    background: #fffbeb;
    border: 2px solid #f59e0b;
    border-radius: 10px;
}
.norma-retry-title {
    font-weight: 800;
    color: #b45309;
    font-size: 0.92rem;
}
.norma-retry-sub {
    font-size: 0.78rem;
    color: #92400e;
}

.norma-rules {
    margin-bottom: 12px;
}
.norma-rule-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 10px;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.65);
    margin-bottom: 4px;
    font-size: 0.85rem;
}
.norma-rule-row.satisfied {
    background: #d1fae5;
}
.norma-rule-label {
    flex: 1;
    color: var(--text);
}
.norma-rule-progress {
    font-weight: 700;
    color: #4338ca;
}
.norma-rule-row.satisfied .norma-rule-progress {
    color: #047857;
}

.norma-start-btn {
    width: 100%;
}
.norma-start-btn:disabled {
    opacity: 0.6;
}

.norma-done-block {
    text-align: center;
    padding-top: 4px;
}
.norma-done-emoji {
    font-size: 2.6rem;
    line-height: 1;
}
.norma-done-title {
    font-weight: 800;
    font-size: 1.15rem;
    color: #047857;
    margin-top: 4px;
}
.norma-done-sub {
    font-size: 0.85rem;
    color: #065f46;
    margin-top: 2px;
}
.norma-extra-btn {
    width: 100%;
    margin-top: 8px;
}

/* --- 問題画面のノルマ表示 --- */
.problem-norma-strip {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 6px 12px;
    margin-bottom: 10px;
    background: #eef2ff;
    border-radius: 8px;
    font-size: 0.8rem;
}
.problem-norma-label {
    font-weight: 700;
    color: #4338ca;
}
.problem-norma-count {
    font-weight: 800;
    color: #6366f1;
}

/* --- やり直し(当日中の再出題) バナー --- */
.retry-banner {
    background: #fffbeb;
    border: 2px solid #f59e0b;
    border-radius: 10px;
    padding: 10px 12px;
    margin-bottom: 10px;
}
.retry-banner-head {
    display: flex;
    align-items: center;
    gap: 10px;
}
.retry-banner-title {
    font-weight: 800;
    color: #b45309;
    font-size: 0.95rem;
}
.retry-banner-sub {
    font-size: 0.8rem;
    color: #92400e;
}
.retry-banner-advice {
    margin-top: 8px;
    padding: 8px 10px;
    background: rgba(255, 255, 255, 0.7);
    border-radius: 8px;
    font-size: 0.82rem;
    color: #78350f;
    line-height: 1.5;
}
.retry-banner-hint {
    margin-top: 6px;
    font-size: 0.8rem;
    font-weight: 700;
    color: #b45309;
}

/* --- 採点モーダルの合否表示 --- */
.celeb-verdict {
    margin-top: 12px;
    padding: 10px 14px;
    border-radius: 10px;
}
.celeb-verdict.pass {
    background: #d1fae5;
    border: 2px solid #10b981;
    color: #065f46;
}
.celeb-verdict.fail {
    background: #ffe4e6;
    border: 2px solid #fb7185;
    color: #9f1239;
}
.celeb-verdict-title {
    font-weight: 800;
    font-size: 1rem;
}
.celeb-verdict-sub {
    font-size: 0.8rem;
    margin-top: 3px;
}

/* ============================================
   ごほうびショートストーリー
   「次の話が読みたい」を勉強の動機にするための表示。
   ノルマカード内のティーザーと、読むときのモーダル。
   ============================================ */
.story-teaser {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    margin-bottom: 12px;
    background: rgba(255, 255, 255, 0.75);
    border: 2px dashed #a5b4fc;
    border-radius: 10px;
}
.story-teaser.ready {
    background: linear-gradient(135deg, #fef3c7, #fde68a);
    border: 2px solid #f59e0b;
    border-style: solid;
    animation: story-pulse 1.6s ease-in-out infinite;
}
@keyframes story-pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(245, 158, 11, 0.45); }
    50%      { box-shadow: 0 0 0 8px rgba(245, 158, 11, 0); }
}
.story-teaser-icon {
    font-size: 1.5rem;
    line-height: 1;
}
.story-teaser-body {
    flex: 1;
    min-width: 0;
}
.story-teaser-title {
    font-weight: 800;
    font-size: 0.9rem;
    color: #4338ca;
}
.story-teaser.ready .story-teaser-title {
    color: #b45309;
}
.story-teaser-sub {
    font-size: 0.76rem;
    color: var(--text-light);
    margin-top: 2px;
}
.story-teaser.ready .story-teaser-sub {
    color: #92400e;
}
.story-teaser-btn {
    white-space: nowrap;
}

.story-library-btn {
    width: 100%;
    margin-top: 10px;
}

/* --- 読むモーダル --- */
.story-overlay {
    align-items: center;
}
.story-card {
    position: relative;
    width: min(680px, 94vw);
    max-height: 88vh;
    display: flex;
    flex-direction: column;
    background: #fffdf7;
    border-radius: var(--radius);
    padding: 22px 20px 16px;
    box-shadow: 0 18px 50px rgba(0, 0, 0, 0.25);
}
.story-close {
    position: absolute;
    top: 8px;
    right: 12px;
}
.story-head {
    display: flex;
    align-items: center;
    gap: 12px;
    padding-right: 28px;
    border-bottom: 2px solid #f1e7d0;
    padding-bottom: 12px;
    margin-bottom: 12px;
}
.story-char-img {
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
    background: #fff;
}
.story-episode {
    font-size: 0.76rem;
    font-weight: 700;
    color: #b45309;
    letter-spacing: 0.04em;
}
.story-title {
    margin: 2px 0 0;
    font-size: 1.2rem;
    line-height: 1.35;
    color: #422006;
}
.story-body {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    /* 読み物なので行間を広めに取る */
    font-size: 1.02rem;
    line-height: 1.95;
    color: #3f3a33;
    letter-spacing: 0.01em;
}
.story-body p {
    margin: 0 0 1em;
    text-indent: 1em;
}
/* 会話行(「で始まる)は日本語組版の慣習にあわせて字下げしない */
.story-body p.dialogue {
    text-indent: 0;
}
.story-body p:last-child {
    margin-bottom: 0;
}
.story-foot {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    border-top: 2px solid #f1e7d0;
    padding-top: 12px;
    margin-top: 12px;
}
.story-charcount {
    font-size: 0.75rem;
    color: var(--text-light);
}

/* --- あつめたおはなし一覧 --- */
.story-lib-modal {
    width: min(560px, 94vw);
    max-height: 86vh;
    overflow-y: auto;
}
.story-lib-list {
    margin-top: 14px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.story-lib-item {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 10px 12px;
    background: #fffdf7;
    border: 1px solid #f1e7d0;
    border-radius: 10px;
    font-family: inherit;
    font-size: 0.9rem;
    text-align: left;
    cursor: pointer;
}
.story-lib-item:active {
    transform: scale(0.99);
}
.story-lib-ep {
    font-size: 0.72rem;
    font-weight: 700;
    color: #b45309;
    background: #fef3c7;
    border-radius: 6px;
    padding: 2px 6px;
    white-space: nowrap;
}
.story-lib-title {
    flex: 1;
    font-weight: 700;
    color: var(--text);
}
.story-lib-char {
    font-size: 0.72rem;
    color: var(--text-light);
    white-space: nowrap;
}
