:root {
  --ink:      #1a1a2e;
  --ink-mid:  #2d2d4e;
  --paper:    #f5f0e8;
  --paper-2:  #ede7d9;
  --red:      #c0392b;
  --gold:     #b8860b;
  --teal:     #0d7377;
  --teal-lt:  #14a085;
  --correct:  #1a7a4a;
  --wrong:    #c0392b;
  --muted:    #8a8070;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Noto Sans JP', sans-serif;
  background: var(--paper);
  color: var(--ink);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 32px 16px 64px;
  background-image:
    repeating-linear-gradient(0deg, transparent, transparent 39px, rgba(0,0,0,0.04) 40px),
    repeating-linear-gradient(90deg, transparent, transparent 39px, rgba(0,0,0,0.02) 40px);
}

/* ── Global Ruby/Furigana Styles ── */
rt {
  font-size: 0.6rem;
  color: var(--teal);
  font-weight: 500;
  letter-spacing: 0.01em;
}


/* ── Header ── */
header {
  text-align: center;
  margin-bottom: 40px;
}
.title-jp {
  font-family: 'Noto Serif JP', serif;
  font-size: clamp(2rem, 5vw, 3.2rem);
  font-weight: 700;
  letter-spacing: 0.12em;
  color: var(--ink);
  position: relative;
  display: inline-block;
}
.title-jp::after {
  content: '';
  display: block;
  height: 3px;
  background: linear-gradient(90deg, var(--teal), var(--gold));
  border-radius: 2px;
  margin-top: 8px;
}
.title-en {
  font-size: 0.78rem;
  letter-spacing: 0.3em;
  text-transform: uppercase;
  color: var(--muted);
  margin-top: 10px;
  font-family: 'DM Mono', monospace;
}

/* ── Card ── */
.card {
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 4px 30px rgba(26,26,46,0.10), 0 1px 4px rgba(26,26,46,0.06);
  padding: 40px 36px;
  width: 100%;
  max-width: 660px;
  position: relative;
  overflow: hidden;
}
.card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 4px;
  background: linear-gradient(90deg, var(--teal), var(--gold));
}

/* ── Progress ── */
.progress-bar-wrap {
  background: var(--paper-2);
  border-radius: 99px;
  height: 6px;
  margin-bottom: 28px;
  overflow: hidden;
}
.progress-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--teal), var(--gold));
  border-radius: 99px;
  transition: width 0.5s ease;
  width: 0%;
}
.progress-label {
  font-family: 'DM Mono', monospace;
  font-size: 0.72rem;
  color: var(--muted);
  text-align: right;
  margin-bottom: 6px;
}

/* ── Question section ── */
.question-label {
  font-family: 'DM Mono', monospace;
  font-size: 0.68rem;
  letter-spacing: 0.25em;
  text-transform: uppercase;
  color: var(--teal);
  margin-bottom: 12px;
}
.question-text {
  font-family: 'Noto Serif JP', serif;
  font-size: clamp(1.1rem, 3vw, 1.5rem);
  font-weight: 400;
  line-height: 1.7;
  color: var(--ink);
  min-height: 56px;
  margin-bottom: 8px;
}

/* â”€â”€ Translate feature â”€â”€ */
.translate-row {
  margin-bottom: 28px;
}
.translate-link {
  display: inline-block;
  font-family: 'DM Mono', monospace;
  font-size: 0.75rem;
  color: var(--teal);
  cursor: pointer;
  letter-spacing: 0.03em;
  transition: color 0.2s, opacity 0.2s;
  user-select: none;
  opacity: 0.85;
  text-decoration: none;
}
.translate-link:hover {
  color: var(--teal-lt);
  opacity: 1;
  text-decoration: underline;
}
.translate-link.loading {
  pointer-events: none;
  opacity: 0.5;
}
.translate-result {
  font-family: 'Noto Sans JP', sans-serif;
  font-size: 0.82rem;
  color: var(--muted);
  font-style: italic;
  line-height: 1.6;
  margin-top: 6px;
  padding-left: 2px;
  max-height: 0;
  overflow: hidden;
  opacity: 0;
  transition: max-height 0.4s ease, opacity 0.4s ease, margin-top 0.3s ease;
}
.translate-result.visible {
  max-height: 200px;
  opacity: 1;
  margin-top: 6px;
}


/* ── Status pulse ── */
.status-area {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 48px;
  margin-bottom: 20px;
}
.pulse-dot {
  width: 12px; height: 12px;
  border-radius: 50%;
  background: var(--muted);
  flex-shrink: 0;
  transition: background 0.3s;
}
.pulse-dot.speaking {
  background: var(--gold);
  animation: blink 0.8s infinite;
}
.pulse-dot.listening {
  background: var(--red);
  animation: blink 0.5s infinite;
}
.pulse-dot.checking { background: var(--teal); animation: blink 1s infinite; }
@keyframes blink {
  0%,100% { opacity: 1; transform: scale(1); }
  50%      { opacity: 0.4; transform: scale(0.7); }
}
.status-text {
  font-family: 'DM Mono', monospace;
  font-size: 0.8rem;
  color: var(--muted);
}

/* ── Transcript box ── */
.transcript-box {
  background: var(--paper);
  border: 1.5px solid var(--paper-2);
  border-radius: 10px;
  padding: 14px 18px;
  min-height: 52px;
  font-family: 'Noto Serif JP', serif;
  font-size: 1rem;
  color: var(--ink-mid);
  margin-bottom: 20px;
  transition: border-color 0.3s;
  word-break: break-all;
}
.transcript-box.active { border-color: var(--teal); }
.transcript-placeholder { color: var(--muted); font-style: italic; font-size: 0.85rem; font-family: 'Noto Sans JP', sans-serif; }
.transcript-furigana {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--paper-2);
  font-size: 0.88rem;
  color: var(--teal);
  font-family: 'Noto Sans JP', sans-serif;
}
.trans-small {
  font-size: 0.75rem;
  color: var(--muted);
  font-style: italic;
  margin-top: 2px;
}

/* ── AI Recording indicator ── */
.ai-recording-indicator {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: 'Noto Sans JP', sans-serif;
  font-size: 0.9rem;
  color: var(--teal);
  animation: ai-rec-fade 1.8s ease-in-out infinite;
}
.ai-recording-indicator .rec-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--red);
  animation: ai-rec-pulse 1s ease-in-out infinite;
  flex-shrink: 0;
}
@keyframes ai-rec-pulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.4); opacity: 0.5; }
}
@keyframes ai-rec-fade {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}
.ai-transcribing-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: 'Noto Sans JP', sans-serif;
  font-size: 0.9rem;
  color: var(--gold);
}
.ai-transcribing-indicator .dots::after {
  content: '';
  animation: ai-dots 1.5s steps(4, end) infinite;
}
@keyframes ai-dots {
  0%  { content: ''; }
  25% { content: '.'; }
  50% { content: '..'; }
  75% { content: '...'; }
}

/* ── Result badge ── */
.result-badge {
  display: none;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 18px;
  border-radius: 10px;
  margin-bottom: 20px;
  font-size: 0.9rem;
}
.result-badge.correct  { display:flex; background: #e6f4ee; border: 1.5px solid #1a7a4a; color: var(--correct); }
.result-badge.wrong    { display:flex; background: #fdf0ef; border: 1.5px solid #c0392b; color: var(--wrong); }
.result-badge .icon    {
  flex: 0 0 28px;
  width: 28px;
  line-height: 1.2;
  margin-top: 1px;
  font-size: 1.2rem;
  text-align: center;
}
.result-badge .answer-reveal { margin-top: 6px; font-size: 0.83rem; color: var(--ink-mid); }

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 13px 28px;
  border-radius: 10px;
  border: none;
  font-family: 'Noto Sans JP', sans-serif;
  font-size: 0.95rem;
  font-weight: 500;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s, background 0.2s;
  letter-spacing: 0.03em;
}
.btn:active { transform: scale(0.97); }
.btn-primary {
  background: var(--teal);
  color: #fff;
  box-shadow: 0 4px 14px rgba(13,115,119,0.30);
}
.btn-primary:hover { background: var(--teal-lt); box-shadow: 0 6px 20px rgba(13,115,119,0.35); }
.btn-secondary {
  background: var(--paper-2);
  color: var(--ink);
  border: 1.5px solid #d0c8b8;
}
.btn-secondary:hover { background: #e0d8ca; }
.btn-danger {
  background: var(--wrong);
  color: #fff;
  box-shadow: 0 4px 14px rgba(192,57,43,0.25);
}
.btn-danger:hover { background: #a93226; }
.btn-disabled {
  opacity: 0.45;
  cursor: not-allowed;
  pointer-events: none;
  box-shadow: none !important;
}
.btn-submit {
  background: linear-gradient(135deg, var(--teal), var(--teal-lt));
  color: #fff;
  font-size: 1rem;
  padding: 14px 32px;
  box-shadow: 0 4px 18px rgba(13,115,119,0.35);
  animation: submitPulse 1.8s ease-in-out infinite;
}
.btn-submit:hover { filter: brightness(1.1); }
@keyframes submitPulse {
  0%,100% { box-shadow: 0 4px 18px rgba(13,115,119,0.30); }
  50%      { box-shadow: 0 4px 28px rgba(13,115,119,0.65); }
}
.btn-row {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 8px;
  align-items: center;
}
.btn-group-record {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
}

/* ── Start screen ── */
#screen-start { text-align: center; }
#screen-start .big-icon { font-size: 4rem; margin-bottom: 16px; }
#screen-start h2 { font-family:'Noto Serif JP',serif; font-size:1.5rem; margin-bottom:10px; }
#screen-start p { color: var(--muted); font-size:0.9rem; line-height:1.7; margin-bottom:28px; }
.info-chips { display:flex; justify-content:center; gap:10px; flex-wrap:wrap; margin-bottom:28px; }
.chip {
  background: var(--paper-2);
  border-radius: 99px;
  padding: 4px 14px;
  font-size: 0.75rem;
  font-family: 'DM Mono', monospace;
  color: var(--ink-mid);
  border: 1px solid #d0c8b8;
}

/* ── Import section ── */
.import-section {
  border: 1.5px dashed var(--paper-2);
  border-radius: 10px;
  padding: 20px;
  margin: 28px 0;
  background: #fafaf7;
}
.import-section h3 {
  font-size: 0.9rem;
  color: var(--ink);
  margin-bottom: 12px;
  font-weight: 500;
}
.import-section p {
  font-size: 0.8rem;
  color: var(--muted);
  margin-bottom: 12px;
  line-height: 1.5;
}
#file-input { display: none; }
.import-buttons {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
}
.btn-import {
  background: var(--paper-2);
  color: var(--ink);
  border: 1.5px solid #d0c8b8;
  padding: 10px 18px;
  font-size: 0.85rem;
}
.btn-import:hover { background: #e0d8ca; }
.import-status {
  font-size: 0.8rem;
  margin-top: 8px;
  padding: 8px 12px;
  border-radius: 6px;
  display: none;
}
.import-status.success {
  display: block;
  background: #e6f4ee;
  color: var(--correct);
  border: 1px solid #b2dfc5;
}
.import-status.error {
  display: block;
  background: #fdf0ef;
  color: var(--wrong);
  border: 1px solid #f0b8b2;
}
.import-status.info {
  display: block;
  background: #f0f4f8;
  color: var(--teal);
  border: 1px solid #d0e4f0;
}

/* ── Results screen ── */
.score-hero {
  text-align: center;
  padding: 20px 0 28px;
}
.score-big {
  font-family: 'Noto Serif JP', serif;
  font-size: clamp(3.5rem, 10vw, 5rem);
  font-weight: 700;
  color: var(--teal);
  line-height: 1;
}
.score-label { color: var(--muted); font-size: 0.85rem; margin-top: 8px; }
.score-bar-wrap { background: var(--paper-2); height: 10px; border-radius:99px; overflow:hidden; margin: 16px 0 24px; }
.score-bar { height:100%; border-radius:99px; background: linear-gradient(90deg, var(--teal), var(--gold)); transition: width 1s ease; }
.results-list { margin-top: 8px; display: flex; flex-direction: column; gap: 12px; }
.result-row {
  border-radius: 10px;
  padding: 14px 16px;
  border: 1.5px solid transparent;
  font-size: 0.88rem;
}
.result-row.c { background: #e6f4ee; border-color: #b2dfc5; }
.result-row.w { background: #fdf0ef; border-color: #f0b8b2; }
.result-row .rq { font-family:'Noto Serif JP',serif; font-weight:500; color:var(--ink); margin-bottom:5px; font-size:0.95rem; }
.result-row .rc { color: var(--correct); font-size:0.82rem; }
.result-row .rw { color: var(--wrong); font-size:0.82rem; }
.result-row .ra { color: var(--ink-mid); font-size:0.82rem; margin-top:3px; }
.result-row .tag { font-family:'DM Mono',monospace; font-size:0.7rem; padding:2px 8px; border-radius:99px; margin-bottom:6px; display:inline-block; }
.tag-ok  { background:#1a7a4a22; color:var(--correct); }
.tag-ng  { background:#c0392b22; color:var(--wrong); }

.target-answer-box {
  display: none;
  background: #f0fdf4;
  border: 1.5px solid #bbf7d0;
  border-radius: 10px;
  padding: 14px 18px;
  margin-bottom: 16px;
  text-align: center;
  transition: all 0.3s ease;
}
.target-label {
  font-family: 'DM Mono', monospace;
  font-size: 0.7rem;
  text-transform: uppercase;
  color: #16a34a;
  letter-spacing: 0.1em;
  margin-bottom: 8px;
  font-weight: bold;
}
#target-answer-text {
  font-family: 'Noto Serif JP', serif;
  font-size: 1.1rem;
  color: var(--ink);
  margin-bottom: 4px;
}
.target-romaji {
  font-family: 'DM Mono', monospace;
  font-size: 0.85rem;
  color: var(--muted);
  font-style: italic;
}
.warning-box {
  display: none;
  background: #fff8e1;
  border: 1.5px solid #f0c040;
  border-radius: 10px;
  padding: 12px 16px;
  font-size: 0.82rem;
  color: #7a5c00;
  margin-bottom: 16px;
  line-height: 1.6;
}

/* ── AI Settings section ── */
.settings-section {
  border: 1.5px dashed var(--teal);
  border-radius: 10px;
  padding: 20px;
  margin: 0 0 28px;
  background: linear-gradient(135deg, #f0faf9 0%, #fafaf7 100%);
}
.settings-section h3 {
  font-size: 0.9rem;
  color: var(--ink);
  margin-bottom: 12px;
  font-weight: 500;
}
.settings-section p {
  font-size: 0.8rem;
  color: var(--muted);
  margin-bottom: 12px;
  line-height: 1.5;
}
.api-key-row {
  display: flex;
  gap: 8px;
  align-items: center;
}
.api-key-input {
  flex: 1;
  padding: 10px 14px;
  border: 1.5px solid #d0c8b8;
  border-radius: 8px;
  font-family: 'DM Mono', monospace;
  font-size: 0.82rem;
  background: #fff;
  color: var(--ink);
  outline: none;
  transition: border-color 0.2s;
}
.api-key-input:focus {
  border-color: var(--teal);
}
.api-key-input::placeholder {
  color: var(--muted);
  font-family: 'Noto Sans JP', sans-serif;
}
.btn-sm {
  padding: 8px 12px;
  font-size: 0.82rem;
  min-width: 40px;
}
.chip-ai {
  border-color: var(--teal);
  color: var(--teal);
  background: #e6f7f7;
}
.chip-ai.active {
  background: linear-gradient(135deg, #0d737722, #14a08522);
  border-color: var(--teal-lt);
}

#ai-settings-section[data-mode="wizard"] .edit-only { display: none !important; }
#ai-settings-section[data-mode="edit"] .wizard-only { display: none !important; }

/* ── AI Feedback in result badge ── */
.result-badge-content {
  flex: 1;
  min-width: 0;
}
.ai-feedback {
  margin-top: 10px;
  font-size: 0.82rem;
  line-height: 1.6;
}
.ai-feedback:empty {
  display: none;
}
.ai-feedback-text {
  color: var(--ink-mid);
  margin-bottom: 8px;
  font-style: italic;
  overflow-wrap: anywhere;
}
.ai-feedback-notes {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 6px;
}
.ai-note {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  padding: 6px 10px;
  border-radius: 6px;
  background: rgba(255,255,255,0.6);
  font-size: 0.78rem;
}
.ai-note-label {
  font-family: 'DM Mono', monospace;
  font-weight: 500;
  white-space: nowrap;
  color: var(--teal);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  min-width: 70px;
}
.ai-note-text {
  color: var(--ink-mid);
  min-width: 0;
  overflow-wrap: anywhere;
}
.result-badge.correct .ai-note {
  background: rgba(26, 122, 74, 0.06);
}
.result-badge.wrong .ai-note {
  background: rgba(192, 57, 43, 0.06);
}

/* ── AI feedback in results list ── */
.result-row .ai-result-feedback {
  margin-top: 6px;
  padding: 8px 10px;
  border-radius: 6px;
  background: rgba(255,255,255,0.5);
  font-size: 0.78rem;
  color: var(--ink-mid);
  line-height: 1.5;
}
.result-row .ai-result-feedback .ai-note {
  margin-top: 4px;
}

/* ── VOICEVOX Setup Guide ── */
.vv-connection-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border-radius: 99px;
  font-size: 0.8rem;
  font-weight: 500;
  margin-bottom: 16px;
  border: 1px solid transparent;
}
.vv-connection-badge.disconnected {
  background: #fdf0ef;
  color: var(--wrong);
  border-color: #f0b8b2;
}
.vv-connection-badge.connected {
  background: #e6f4ee;
  color: var(--correct);
  border-color: #b2dfc5;
}
.vv-status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}
.vv-connection-badge.disconnected .vv-status-dot { background: var(--wrong); }
.vv-connection-badge.connected .vv-status-dot { background: var(--correct); }

.vv-setup-steps {
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin-bottom: 20px;
}
.vv-step {
  display: flex;
  gap: 12px;
  align-items: flex-start;
}
.vv-step-num {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  background: var(--teal);
  color: #fff;
  border-radius: 50%;
  font-size: 0.8rem;
  font-weight: bold;
  flex-shrink: 0;
  margin-top: 2px;
}
.vv-step-content {
  flex: 1;
}
.vv-step-content strong {
  display: block;
  font-size: 0.85rem;
  color: var(--ink);
  margin-bottom: 4px;
}
.vv-step-content p {
  font-size: 0.75rem;
  color: var(--muted);
  margin: 0;
  line-height: 1.4;
}

.vv-advanced-details {
  background: var(--paper-2);
  border-radius: 8px;
  overflow: hidden;
}
.vv-advanced-summary {
  padding: 10px 14px;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--ink);
  cursor: pointer;
  user-select: none;
}
.vv-advanced-summary:hover {
  background: rgba(0,0,0,0.03);
}
.vv-advanced-content {
  padding: 14px;
  border-top: 1px solid rgba(0,0,0,0.05);
}
.vv-cors-note {
  background: #fff8e1;
  border: 1px solid #f0c040;
  border-radius: 6px;
  padding: 10px;
  font-size: 0.75rem;
  color: #7a5c00;
  margin-top: 12px;
}

/* ── Final Score Overlay ── */
#final-score-overlay {
  position: fixed;
  inset: 0;
  background: rgba(26, 26, 46, 0.85);
  backdrop-filter: blur(8px);
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 1s ease;
  opacity: 0;
}

.final-score-card {
  background: white;
  padding: 40px;
  border-radius: 24px;
  text-align: center;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.3);
  max-width: 320px;
  width: 90%;
}

/* ── Rich AI Feedback Styling (Unique Custom Aesthetic) ── */
.rich-feedback-section {
  margin-top: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.rich-feedback-header {
  font-family: 'DM Mono', monospace;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.15em;
  color: var(--teal);
  display: flex;
  align-items: center;
  gap: 12px;
}
.rich-feedback-header::before,
.rich-feedback-header::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--teal);
  opacity: 0.2;
}

.rich-breakdown-card {
  background: linear-gradient(145deg, #ffffff, #fdfbf7);
  border: 1px solid rgba(0,0,0,0.05);
  border-radius: 12px;
  padding: 16px;
  box-shadow: 
    0 4px 12px rgba(0, 0, 0, 0.03),
    inset 0 2px 0 rgba(255, 255, 255, 1);
  position: relative;
  transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
}

.rich-breakdown-card:hover {
  transform: translateY(-3px) scale(1.01);
  box-shadow: 
    0 12px 24px rgba(13, 115, 119, 0.08),
    inset 0 2px 0 rgba(255, 255, 255, 1);
  border-color: rgba(13, 115, 119, 0.15);
}

.rich-breakdown-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  gap: 12px;
  flex-wrap: wrap;
}

.rich-breakdown-changes {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  background: #f4f6f8;
  padding: 6px 14px;
  border-radius: 8px;
  font-family: 'Noto Serif JP', serif;
  font-size: 1.1rem;
  box-shadow: inset 0 1px 3px rgba(0,0,0,0.04);
}

.rich-breakdown-old {
  color: var(--wrong);
  text-decoration: line-through;
  text-decoration-color: rgba(192, 57, 43, 0.5);
  text-decoration-thickness: 2px;
  opacity: 0.7;
}

.rich-breakdown-arrow {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  background: #fff;
  border-radius: 50%;
  box-shadow: 0 2px 6px rgba(0,0,0,0.06);
  color: var(--teal);
  font-size: 0.8rem;
  font-weight: bold;
}

.rich-breakdown-new {
  color: var(--correct);
  font-weight: 700;
  position: relative;
}
.rich-breakdown-new::after {
  content: '';
  position: absolute;
  bottom: -2px;
  left: 0;
  width: 100%;
  height: 2px;
  background: var(--correct);
  border-radius: 2px;
  opacity: 0.3;
}

.rich-breakdown-tag {
  font-family: 'DM Mono', monospace;
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 5px 12px;
  border-radius: 99px;
  font-weight: 600;
  display: inline-block;
  border: 1px solid transparent;
}

/* Unique Tag Aesthetics */
.rich-tag-default { background: #f1f3f5; color: #495057; border-color: #dee2e6; }
.rich-tag-sentence-structure { background: #e7f5ff; color: #1971c2; border-color: #d0ebff; }
.rich-tag-word-choice { background: #f3f0ff; color: #6741d9; border-color: #e5dbff; }
.rich-tag-particle { background: #fff0f6; color: #c2255c; border-color: #ffdeeb; }
.rich-tag-conjugation { background: #fff4e6; color: #e8590c; border-color: #ffe8cc; }

.rich-breakdown-desc {
  font-size: 0.88rem;
  line-height: 1.6;
  color: var(--ink-mid);
  padding: 10px 14px;
  background: rgba(13, 115, 119, 0.03);
  border-left: 3px solid var(--teal-lt);
  border-radius: 0 8px 8px 0;
  margin-top: 10px;
}

/* ── Utility ── */
.hidden { display: none !important; }
.divider { border: none; border-top: 1.5px solid var(--paper-2); margin: 24px 0; }

/* ── AI Study Assistant ── */
.btn-ai-float {
  position: fixed;
  bottom: 32px;
  right: 32px;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: var(--teal);
  color: #fff;
  font-size: 1.8rem;
  border: none;
  cursor: pointer;
  box-shadow: 0 8px 24px rgba(13, 115, 119, 0.4);
  z-index: 9000;
  transition: transform 0.2s, background 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
}
.btn-ai-float:hover {
  transform: scale(1.1);
  background: var(--teal-lt);
}

.btn-translate-float {
  position: fixed;
  bottom: 100px;
  right: 32px;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: var(--ink);
  color: #fff;
  font-size: 1.8rem;
  border: none;
  cursor: pointer;
  box-shadow: 0 8px 24px rgba(26, 26, 46, 0.35);
  z-index: 9000;
  transition: transform 0.2s, background 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
}
.btn-translate-float:hover {
  transform: scale(1.1);
  background: #2d2d4a;
}

.translate-panel {
  height: 420px;
}

.translate-tool-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: #fafafa;
}

.translate-tool-hint {
  margin: 0;
  font-size: 0.82rem;
  color: var(--muted);
  line-height: 1.5;
}

.translate-input {
  width: 100%;
  padding: 10px 12px;
  border: 1.5px solid var(--paper-2);
  border-radius: 8px;
  outline: none;
  font-family: 'Noto Sans JP', sans-serif;
  font-size: 0.95rem;
  resize: vertical;
  min-height: 72px;
  background: #fff;
  box-sizing: border-box;
}
.translate-input:focus {
  border-color: var(--teal);
}

.translate-status {
  min-height: 1.2em;
  font-size: 0.8rem;
  color: var(--muted);
}
.translate-status.info { color: var(--teal); }
.translate-status.success { color: #2e7d32; }
.translate-status.error { color: var(--red, #c0392b); }

.translate-tool-actions {
  margin-top: 4px;
}

.translate-result-area {
  margin-top: 4px;
  padding: 12px;
  background: #fff;
  border: 1.5px solid var(--paper-2);
  border-radius: 10px;
}

.translate-result-label {
  font-size: 0.75rem;
  font-weight: bold;
  color: var(--muted);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.translate-result-text {
  font-size: 1.2rem;
  line-height: 1.7;
  font-family: 'Noto Sans JP', sans-serif;
  margin-bottom: 10px;
  word-break: break-word;
}

.btn-ai-mic.recording {
  background: #ffe0e0;
  border-color: #e57373;
  animation: pulse-mic 1.2s ease-in-out infinite;
}

@keyframes pulse-mic {
  0%, 100% { box-shadow: 0 0 0 0 rgba(229, 115, 115, 0.4); }
  50% { box-shadow: 0 0 0 6px rgba(229, 115, 115, 0); }
}

.ai-panel {
  position: fixed;
  bottom: 100px;
  right: 32px;
  width: 360px;
  max-width: calc(100vw - 64px);
  height: 500px;
  background: #fff;
  border-radius: 20px;
  box-shadow: 0 12px 40px rgba(26, 26, 46, 0.2);
  display: flex;
  flex-direction: column;
  z-index: 9001;
  border: 1px solid var(--paper-2);
  transition: opacity 0.3s, transform 0.3s ease;
}

.ai-panel-resizer {
  position: absolute;
  right: 0;
  bottom: 0;
  width: 16px;
  height: 16px;
  cursor: nwse-resize;
  background: linear-gradient(135deg, transparent 50%, var(--paper-2) 50%);
  border-bottom-right-radius: 20px;
  z-index: 10;
}
.ai-panel.hidden {
  display: none;
}

.ai-panel-header {
  padding: 16px 20px;
  background: linear-gradient(135deg, var(--teal), var(--teal-lt));
  color: #fff;
  border-radius: 20px 20px 0 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: bold;
  font-family: 'Noto Sans JP', sans-serif;
  cursor: move;
  user-select: none;
}
.btn-close-ai {
  background: none;
  border: none;
  color: #fff;
  font-size: 1.2rem;
  cursor: pointer;
  opacity: 0.8;
  transition: opacity 0.2s;
}
.btn-close-ai:hover { opacity: 1; }

.ai-chat-history {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: #fafafa;
}

.ai-msg {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 1rem;
  line-height: 1.6;
  word-wrap: break-word;
}

.ai-msg p {
  margin-bottom: 12px;
}

.ai-msg p:last-child {
  margin-bottom: 0;
}

.ai-msg ul {
  margin: 8px 0 12px 20px;
  padding: 0;
  list-style: none;
}

.ai-msg li {
  margin-bottom: 6px;
  position: relative;
}

.ai-msg li::before {
  content: '•';
  color: var(--teal);
  font-weight: bold;
  display: inline-block;
  width: 1em;
  margin-left: -1em;
}

.ai-msg strong, .ai-msg b {
  color: var(--ink);
  font-weight: 700;
}
.ai-msg.user {
  align-self: flex-end;
  background: var(--teal);
  color: #fff;
  border-bottom-right-radius: 2px;
}
.ai-msg.assistant {
  align-self: flex-start;
  background: var(--paper-2);
  color: var(--ink);
  border-bottom-left-radius: 2px;
  border: 1px solid #d0c8b8;
}

.ai-reading-highlight {
  color: var(--teal);
  font-weight: 500;
}


.ai-panel-input {
  padding: 12px 16px;
  border-top: 1px solid var(--paper-2);
  display: flex;
  gap: 8px;
  background: #fff;
  border-radius: 0 0 20px 20px;
  align-items: center;
  justify-content: space-between;
}
#ai-chat-input {
  flex: 1;
  padding: 10px 14px;
  border: 1.5px solid var(--paper-2);
  border-radius: 8px;
  outline: none;
  font-family: 'Noto Sans JP', sans-serif;
  font-size: 0.9rem;
  min-width: 0;
}
#ai-chat-input:focus {
  border-color: var(--teal);
}
.btn-ai-mic, .btn-ai-send {
  padding: 8px 14px;
  border-radius: 8px;
  border: none;
  cursor: pointer;
  transition: background 0.2s;
  font-size: 0.9rem;
  flex-shrink: 0;
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.btn-ai-mic {
  background: var(--paper-2);
  color: var(--ink);
  border: 1.5px solid #d0c8b8;
}
.btn-ai-mic:hover { background: #e0d8ca; }
.btn-ai-send {
  background: var(--teal);
  color: #fff;
}
.btn-ai-send:hover { background: var(--teal-lt); }

/* ── Live2D Avatar ── */
#avatar-container {
  width: 100%;
  max-width: 400px;
  height: 400px;
  margin: 0 auto 20px;
  display: flex;
  justify-content: center;
  align-items: flex-end;
  overflow: hidden;
  position: relative;
  pointer-events: none; /* Prevent avatar from blocking clicks on buttons */
}

/* Voicevox static image: bust-crop wrapper */
#avatar-container.voicevox-mode {
  align-items: flex-start;
  justify-content: center;
  padding: 20px 0 0; /* top padding = bounce headroom */
  height: 400px;
}

.voicevox-avatar {
  width: auto;
  height: 220%; /* Large enough so waist-up fills the container */
  max-width: none;
  object-fit: contain;
  filter: drop-shadow(0 6px 16px rgba(0,0,0,0.12));
  transition: transform 0.2s ease;
  /* Crop at waist level — head to waist visible */
  clip-path: inset(0 0 55% 0);
}

.voicevox-avatar.avatar-square {
  height: 100%;
  clip-path: none;
  object-fit: contain;
}

.voicevox-avatar.bouncing {
  animation: vv-bounce 0.5s infinite alternate cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes vv-bounce {
  0% { transform: translateY(0); }
  100% { transform: translateY(-12px); }
}

/* ── Tutorial Target Answer Box (pulsing) ── */
.target-answer-box {
  background: linear-gradient(135deg, #e8f6ef, #d0ece1);
  border: 2px solid var(--teal);
  border-radius: 12px;
  padding: 16px 20px;
  margin: 14px 0;
  text-align: center;
  position: relative;
  animation: tutorial-pulse 2s ease-in-out infinite;
  box-shadow: 0 0 0 0 rgba(13, 115, 119, 0.3);
}

@keyframes tutorial-pulse {
  0%   { box-shadow: 0 0 0 0 rgba(13, 115, 119, 0.35); border-color: var(--teal); }
  50%  { box-shadow: 0 0 16px 6px rgba(13, 115, 119, 0.12); border-color: var(--teal-lt); }
  100% { box-shadow: 0 0 0 0 rgba(13, 115, 119, 0.35); border-color: var(--teal); }
}

.target-answer-box .target-label {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--teal);
  margin-bottom: 8px;
  letter-spacing: 0.03em;
}

.target-answer-box #target-answer-text {
  font-family: 'Noto Serif JP', serif;
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--ink);
  margin-bottom: 4px;
}

.target-answer-box .target-romaji {
  font-family: 'DM Mono', monospace;
  font-size: 0.82rem;
  color: var(--muted);
}

/* ── Bug Report Modal ── */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(26, 26, 46, 0.6);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 20000;
  padding: 20px;
}
.modal-card {
  background: white;
  width: 100%;
  max-width: 480px;
  border-radius: 16px;
  padding: 32px;
  box-shadow: 0 20px 40px rgba(0,0,0,0.2);
  animation: modal-slide-up 0.3s ease-out;
}
@keyframes modal-slide-up {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}
#bug-message {
  width: 100%;
  height: 120px;
  padding: 12px;
  border: 1.5px solid var(--paper-2);
  border-radius: 8px;
  font-family: 'Noto Sans JP', sans-serif;
  font-size: 0.9rem;
  margin-bottom: 20px;
  resize: none;
  outline: none;
}
#bug-message:focus { border-color: var(--teal); }
.file-input-row { margin-bottom: 24px; display: flex; flex-direction: column; gap: 8px; }
.file-input-row label { font-size: 0.8rem; font-weight: 500; color: var(--ink-mid); }
.modal-btn-row { display: flex; justify-content: flex-end; gap: 12px; }

.btn-submit {
  background: linear-gradient(135deg, var(--teal), var(--teal-lt));
  color: #fff;
  font-size: 1rem;
  padding: 14px 32px;
  box-shadow: 0 4px 18px rgba(13,115,119,0.35);
  animation: submitPulse 1.8s ease-in-out infinite;
}
@keyframes submitPulse {
  0%,100% { box-shadow: 0 4px 18px rgba(13,115,119,0.30); }
  50%      { box-shadow: 0 4px 28px rgba(13,115,119,0.65); }
}
.vv-loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(26, 26, 46, 0.65);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  opacity: 0;
  animation: overlay-fade-in 0.3s ease forwards;
}

@keyframes overlay-fade-in {
  to { opacity: 1; }
}

.vv-loading-card {
  background: var(--paper);
  border-radius: 16px;
  padding: 32px 48px;
  text-align: center;
  box-shadow: 0 12px 40px rgba(0,0,0,0.25);
  max-width: 360px;
}

.vv-loading-card .vv-spinner {
  width: 48px;
  height: 48px;
  border: 4px solid var(--paper-2);
  border-top-color: var(--teal);
  border-radius: 50%;
  animation: vv-spin 0.8s linear infinite;
  margin: 0 auto 16px;
}

@keyframes vv-spin {
  to { transform: rotate(360deg); }
}

.vv-loading-card h3 {
  font-family: 'Noto Sans JP', sans-serif;
  font-size: 1rem;
  color: var(--ink);
  margin-bottom: 6px;
}

.vv-loading-card p {
  font-size: 0.82rem;
  color: var(--muted);
}


/* ── Show Text Highlight Pulse ── */
.highlight-pulse {
  animation: btn-highlight-pulse 1.5s ease-in-out infinite;
  box-shadow: 0 0 0 0 rgba(20, 160, 133, 0.4);
  border-color: var(--teal-lt) !important;
  color: var(--teal) !important;
  font-weight: bold;
}

@keyframes btn-highlight-pulse {
  0%   { box-shadow: 0 0 0 0 rgba(20, 160, 133, 0.4); }
  50%  { box-shadow: 0 0 12px 4px rgba(20, 160, 133, 0.2); }
  100% { box-shadow: 0 0 0 0 rgba(20, 160, 133, 0.4); }
}

/* ── AI Grading Breakdown ── */
.ai-feedback-main {
  font-weight: 600;
  margin-bottom: 12px;
  font-size: 0.95rem;
}

.ai-breakdown-container {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 8px;
}

.breakdown-row {
  background: var(--paper-2);
  border-radius: 6px;
  padding: 8px 12px;
  border-left: 3px solid var(--teal);
}

.breakdown-main {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.9rem;
  margin-bottom: 4px;
  line-height: 1.4;
}

.breakdown-original {
  color: var(--red);
  text-decoration: line-through;
  opacity: 0.8;
}

.breakdown-arrow {
  color: var(--muted);
  font-weight: bold;
}

.breakdown-corrected {
  color: var(--correct);
  font-weight: 600;
}

.breakdown-details {
  display: flex;
  align-items: baseline;
  gap: 6px;
  font-size: 0.8rem;
}

.breakdown-category {
  font-weight: bold;
  color: var(--ink-mid);
  text-transform: uppercase;
  font-size: 0.7rem;
  background: #ddd;
  padding: 2px 4px;
  border-radius: 3px;
}

.breakdown-explanation {
  color: var(--muted);
  font-style: italic;
}

/* ── Voicevox Batch Preload Modal ── */
.vv-preload-progress-track {
  width: 100%;
  height: 10px;
  background: var(--paper-2);
  border-radius: 99px;
  overflow: hidden;
  margin: 16px 0 8px;
}

.vv-preload-progress-fill {
  height: 100%;
  width: 0%;
  border-radius: 99px;
  background: linear-gradient(90deg, var(--teal), var(--gold));
  transition: width 0.3s ease;
}

.vv-preload-count {
  font-family: 'DM Mono', monospace;
  font-size: 0.82rem;
  color: var(--muted);
  margin-bottom: 16px;
}

.vv-preload-skip {
  background: none;
  border: 1.5px solid var(--paper-2);
  border-radius: 8px;
  padding: 8px 20px;
  font-size: 0.82rem;
  color: var(--muted);
  cursor: pointer;
  transition: background 0.2s, color 0.2s, border-color 0.2s;
}

.vv-preload-skip:hover {
  background: var(--paper-2);
  color: var(--ink);
  border-color: var(--border);
}

/* ── Rich Feedback Format ── */
.rich-feedback-section {
  margin-top: 16px;
  background: white;
  border-radius: 8px;
  padding: 16px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.05);
}
.rich-feedback-header {
  font-family: 'Noto Sans JP', sans-serif;
  font-size: 1.1rem;
  font-weight: bold;
  color: var(--ink);
  margin-bottom: 12px;
}
.rich-feedback-subheader {
  font-family: 'Noto Sans JP', sans-serif;
  font-size: 0.95rem;
  font-weight: bold;
  color: var(--ink);
  margin-bottom: 8px;
  margin-top: 16px;
}
.rich-corrected-box {
  background: #fcfcfc;
  border: 1px solid #eee;
  border-radius: 8px;
  padding: 12px 16px;
  font-family: 'Noto Serif JP', serif;
  font-size: 1.05rem;
  color: var(--ink);
  line-height: 1.6;
}
.rich-breakdown-card {
  background: white;
  border: 1px solid #f0f0f0;
  border-radius: 8px;
  padding: 12px 16px;
  margin-bottom: 10px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.02);
}
.rich-breakdown-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 8px;
  gap: 12px;
}
.rich-breakdown-changes {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  font-size: 0.95rem;
  font-family: 'Noto Sans JP', sans-serif;
}
.rich-breakdown-old {
  color: var(--red);
  text-decoration: line-through;
  opacity: 0.9;
}
.rich-breakdown-arrow {
  color: var(--muted);
  font-size: 0.8rem;
}
.rich-breakdown-new {
  color: var(--correct);
  font-weight: 500;
}
.rich-breakdown-tag {
  font-size: 0.65rem;
  font-weight: 600;
  padding: 4px 8px;
  border-radius: 4px;
  text-transform: capitalize;
  white-space: nowrap;
}
.rich-tag-sentence-structure { background: #fdf5d3; color: #8a6a00; }
.rich-tag-word-choice { background: #e2f7e8; color: #1a7a4a; }
.rich-tag-particle { background: #e0ecff; color: #1a4a99; }
.rich-tag-conjugation { background: #fbe6e6; color: #c0392b; }
.rich-tag-default { background: #f0f0f0; color: #555; }

.rich-breakdown-desc {
  font-size: 0.85rem;
  color: var(--ink-mid);
  line-height: 1.5;
}
