@import url('https://fonts.googleapis.com/css2?family=Caveat:wght@500;600;700&family=Poppins:wght@400;500;600;700&display=swap');

:root {
  --ad-primary:     #057ab5;
  --ad-primary-h:   #046090;
  --ad-bg-card:     #ffffff;
  --ad-border:      #c8dcea;
  --ad-shadow:      0 8px 32px rgba(0,0,0,.10);
  --sol-blue:       #057ab5;
  --sol-blue-light: #e6f2fa;
  --sol-gold:       #fca5a5;
  --sol-gold-light: #e6f2fa;
  --sol-red-line:   #fca5a5;
  --sol-text:       #292524;
  --sol-text-mid:   #78716c;
  --sol-text-light: #9c8878;
}

/* ── Page ── */
.askD {
  min-height: 80vh; background: #eeeeeec9;
  display: flex; flex-direction: column;
  align-items: center; justify-content: flex-start;
  padding-top: 2rem !important;
}

/* ── Hero ── */
.ask-hero { text-align: center; margin-bottom: 2rem; }
.ask-hero .robot-wrap {
  width: 100px; height: 100px; margin: 0 auto 0.75rem;
  display: flex; align-items: center; justify-content: center;
}
.ask-hero .powered-tag {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: .78rem; font-weight: 600; letter-spacing: .08em;
  color: var(--sol-text-mid); text-transform: uppercase; margin-bottom: .9rem;
}
.ask-hero h1 {
  font-family: 'Poppins', Arial, sans-serif;
  font-size: clamp(1.7rem, 4vw, 2.6rem);
  font-weight: 700; color: var(--sol-text); margin: 0; line-height: 1.2;
}

/* ── Input Card ── */
.doubt-input-card {
  width: 100%; max-width: 960px;
  background: var(--ad-bg-card);
  border-radius: 20px; box-shadow: var(--ad-shadow);
  padding: 1.25rem 1.5rem 1rem; margin-bottom: 1.5rem;
}
@media(max-width:520px) {
  .doubt-input-card { padding: 1rem; border-radius: 14px; }
  .ask-hero h1 { font-size: 1.5rem; }
}

/* ── Editable input ── */
.doubt-editable {
  width: 100%; min-height: 66px; max-height: 200px; overflow-y: auto;
  font-family: 'Poppins', Arial, sans-serif;
  font-size: 1rem; color: var(--sol-text); line-height: 1.7;
  border: none; outline: none; background: transparent; word-break: break-word;
}
.doubt-editable:empty::before {
  content: attr(data-placeholder);
  color: var(--sol-text-light); pointer-events: none; display: block;
}
.doubt-textarea-wrap {
  width: 100%; min-height: 80px; margin-bottom: .75rem; padding-top: .75rem;
}

/* ── Toolbar ── */
.doubt-toolbar {
  display: flex; align-items: center; gap: .5rem;
  border-top: 1px solid #f0ebe3; padding-top: .75rem;
}
.doubt-tool-btn {
  background: none; border: none; cursor: pointer;
  padding: .4rem .5rem; border-radius: 8px;
  color: var(--sol-text-mid); font-size: 1.05rem;
  display: flex; align-items: center; justify-content: center;
  transition: background .15s, color .15s;
}
.doubt-tool-btn:hover { background: #e8f3fb; color: var(--ad-primary); }
.doubt-tool-btn svg { width: 20px; height: 20px; }
.doubt-tool-hint { font-size: .78rem; color: var(--sol-text-light); margin-left: .25rem; }
.doubt-submit-btn {
  margin-left: auto; background: var(--ad-primary);
  border: none; border-radius: 50%; width: 42px; height: 42px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; transition: background .18s, transform .12s; color: #fff;
}
.doubt-submit-btn:hover { background: var(--ad-primary-h); transform: scale(1.08); }
.doubt-submit-btn svg { width: 18px; height: 18px; }
#doubtImg { display: none; }

/* ── Math Keyboard ── */
#mathKeyboardCard {
  display: none; position: absolute;
  bottom: calc(100% + 8px); left: 0; right: 0; z-index: 500;
  background: #fff; border-radius: 16px;
  box-shadow: 0 -4px 24px rgba(0,0,0,.13);
  border: 1px solid #e0eaf3; overflow: hidden;
}
.math-keyboard-card-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: .75rem 1rem; border-bottom: 1px solid #e8f3fb;
  background: #f4f7fa; border-radius: 16px 16px 0 0;
}
.math-keyboard-card-title {
  font-size: .85rem; font-weight: 600; color: var(--ad-primary);
  display: flex; align-items: center; gap: 6px;
}
.math-keyboard-close {
  width: 26px; height: 26px; border-radius: 50%;
  background: #d0e6f3; border: none; cursor: pointer;
  font-size: .8rem; color: #046090;
  display: flex; align-items: center; justify-content: center;
  transition: background .15s;
}
.math-keyboard-close:hover { background: #b8d8ee; }
.math-key-grid { display: flex; flex-wrap: wrap; gap: .4rem; padding: .75rem 1rem 1rem; }
.math-key {
  background: #fff; border: 1.5px solid #cde0ed;
  border-radius: 8px; padding: .35rem .55rem;
  font-size: .92rem; color: var(--sol-text); cursor: pointer;
  min-width: 42px; text-align: center;
  font-family: 'Times New Roman', serif; line-height: 1.4;
  transition: background .13s, border-color .13s, transform .1s;
  user-select: none; white-space: nowrap;
}
.math-key:hover { background: #e8f3fb; border-color: var(--ad-primary); transform: translateY(-1px); }
.math-key:active { transform: scale(.95); }

/* ── Image Preview ── */
.inline-img-preview-wrap { margin-bottom: .85rem; }
.inline-img-preview { position: relative; display: inline-block; }
.inline-img-preview img {
  max-width: 220px; max-height: 180px;
  border-radius: 10px; border: 1.5px solid var(--ad-border);
  display: block; object-fit: cover;
}
.img-action-btn {
  position: absolute; width: 30px; height: 30px;
  border-radius: 50%; border: none; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  background: #292524; color: #fff; font-size: .8rem; font-weight: 600;
  box-shadow: 0 2px 6px rgba(0,0,0,.25);
  transition: background .15s, transform .12s; right: -10px;
}
.img-action-btn:hover { transform: scale(1.1); }
.img-remove-btn { top: -10px; }
.img-remove-btn:hover { background: #c62828; }
.img-crop-btn { top: 26px; }
.img-crop-btn:hover { background: var(--ad-primary); }

/* ── Result Card ── */
.result-card {
  width: 100%; max-width: 960px; background: #ffffff;
  border-radius: 20px; box-shadow: var(--ad-shadow);
  margin-bottom: 1rem; overflow: hidden;
}

/* ── Solution Paper ── */
.solution-paper {
  background: #ffffff; border-radius: .5rem;
  position: relative; overflow: hidden;
}
.solution-paper .red-line { display: none; }
@media(min-width:1024px) {
  .solution-paper .red-line {
    display: block; position: absolute; left: 70px; top: 0; bottom: 0;
    width: 1.5px; background: var(--sol-red-line); opacity: 0.6;
  }
}
.solution-inner { padding: 1.25rem; }
@media(min-width:1024px) { .solution-inner { padding: 2rem 3rem 2rem 6rem; } }

/* ── Question Block ── */
.question-display { margin-bottom: 2rem; }
.question-display .q-label {
  font-family: 'Caveat', cursive; font-size: 2.5rem;
  color: var(--sol-blue); font-style: italic; margin-bottom: .5rem;
}
.question-display .q-meta {
  font-family: 'Caveat', cursive; font-size: .95rem;
  color: var(--sol-blue); font-style: italic;
  display: flex; align-items: center; gap: 6px; margin-bottom: .65rem;
}
.question-display .q-text {
  padding: .5rem 1rem; background: #f0f5fc;
  border-left: 4px solid var(--sol-blue);
  border-radius: 0 .5rem .5rem 0;
  color: var(--sol-text); font-size: 1.05rem; line-height: 1.65;
}
.qa-divider { border: none; border-top: 1.5px dashed #e0d8cc; margin: 1.5rem 0; }

/* ── Solution Header ── */
.solution-header { margin-bottom: 1.25rem; }
.solution-title {
  font-family: 'Caveat', cursive; font-size: 2rem;
  color: var(--sol-text); font-weight: 700;
}
.solution-subtitle { font-size: .85rem; color: var(--sol-text-mid); margin-top: .15rem; }

/* ── AI Content ── */
#divAIContent { font-family: 'Poppins', Arial, sans-serif; max-height: none !important; }
#divAIContent mjx-container {
  overflow-x: auto;
  max-width: 100%;
  display: block;
}
#divAIContent .concept-intro {
  background: var(--sol-blue-light); border-left: 4px solid var(--sol-blue);
  padding: .85rem 1rem; border-radius: 0 .5rem .5rem 0;
  margin-bottom: 1.25rem; font-size: .95rem; line-height: 1.7; color: var(--sol-text);
}
#divAIContent .visual-container {
  background: #fffef9; border: 1px solid #e5e7eb;
  border-radius: .5rem; padding: .75rem;
  margin-bottom: 1.25rem; overflow-x: visible; text-align: center;
}
#divAIContent .visual-container svg {
  max-width: 50%; width: auto; height: auto; display: inline-block;
}
@media(max-width:640px) {
  #divAIContent .visual-container svg { max-width: 60%; width: 70%; }
}
#divAIContent .concept-section { margin-bottom: 1.25rem; }
#divAIContent .concept-section h3 {
  font-size: 1.05rem; font-weight: 700; color: var(--sol-blue);
  margin-bottom: .5rem; padding-bottom: .3rem;
  border-bottom: 2px solid var(--sol-gold); display: inline-block;
}
#divAIContent .concept-section p {
  font-size: .93rem; line-height: 1.75; color: var(--sol-text); margin-bottom: .5rem;
}
#divAIContent .concept-section ul,
#divAIContent .concept-section ol {
  padding-left: 0; font-size: .93rem; line-height: 1.8;
  color: var(--sol-text); list-style: none;
}
#divAIContent .concept-section ul li,
#divAIContent .concept-section ol li {
  display: flex; align-items: flex-start; gap: .6rem; margin-bottom: .5rem;
  background: var(--sol-blue-light); border-left: 3px solid var(--sol-blue);
  border-radius: 0 6px 6px 0; padding: .5rem .75rem;
}
#divAIContent .concept-section ul li::before {
  content: '▶'; color: var(--sol-blue); font-size: .7rem;
  margin-top: .25rem; flex-shrink: 0;
}
#divAIContent .concept-section ol { counter-reset: ol-counter; }
#divAIContent .concept-section ol li { counter-increment: ol-counter; }
#divAIContent .concept-section ol li::before {
  content: counter(ol-counter) '.'; color: var(--sol-blue);
  font-weight: 700; font-size: .85rem; flex-shrink: 0; margin-top: .05rem;
}
#divAIContent .insight-box {
  background: linear-gradient(135deg, var(--sol-gold-light), #fef6e4);
  border: 1px solid var(--sol-gold); border-radius: .5rem;
  padding: .85rem 1rem; font-size: .93rem; line-height: 1.7; color: var(--sol-text);
  margin-bottom: 1rem; display: flex; align-items: flex-start; gap: .6rem;
}
#divAIContent .insight-box::before { content: '💡'; font-size: 1.1rem; flex-shrink: 0; }
#divAIContent .step-section {
  background: var(--ad-bg-card); border: 1px solid #e5e7eb;
  border-radius: 10px; margin-bottom: .75rem; overflow: visible;
}
#divAIContent .step-section summary {
  display: flex; align-items: center; gap: .75rem; padding: .75rem 1rem;
  cursor: pointer; font-weight: 600; font-size: .95rem; color: var(--sol-text);
  list-style: none; background: #f8fafc; border-bottom: 1px solid #e5e7eb;
  white-space: normal; word-break: break-word; overflow-wrap: anywhere;
}
#divAIContent .step-section summary span:last-child {
  flex: 1; min-width: 0;
}
#divAIContent .step-section summary::-webkit-details-marker { display: none; }
#divAIContent .step-number {
  width: 28px; height: 28px; background: var(--sol-blue); color: #fff;
  border-radius: 50%; display: flex; align-items: center; justify-content: center;
  font-size: .8rem; font-weight: 700; flex-shrink: 0;
}
#divAIContent .step-section.final-answer .step-number { background: #16a34a; }
#divAIContent .step-content {
  padding: .85rem 1rem;
  font-size: .93rem; line-height: 1.75; color: var(--sol-text);
  overflow-x: auto;
}
#divAIContent .intro-text {
  font-size: .95rem; line-height: 1.7; color: var(--sol-text); margin-bottom: 1rem;
}
#divAIContent .final-code-heading h3 {
  font-size: 1rem; font-weight: 700; color: var(--sol-blue); margin: 1rem 0 .5rem;
}
#divAIContent pre { overflow: visible; white-space: pre-wrap; word-break: break-word; }
#divAIContent code { font-family: 'Fira Mono', 'Courier New', monospace; }
#divAIContent .algorithm-list { padding-left: 0; list-style: none; }
#divAIContent .algorithm-list li {
  padding: .4rem 0; border-bottom: 1px dashed #e5e7eb;
  font-size: .93rem; line-height: 1.6; color: var(--sol-text);
}
#divAIContent .chat-response { font-size: .95rem; line-height: 1.75; color: var(--sol-text); }
#divAIContent .quick-practice,
#divAIContent [class*="practice"],
#divAIContent [class*="quiz"] { display: none !important; }

/* ── Keywords ── */
#divAIContent .keywords-section {
  margin-top: 1.5rem; padding: 1rem; border-radius: 10px;
  background: #f8fafc; border: 1px solid #e5e7eb;
}
#divAIContent .keywords-title {
  font-size: 1rem; font-weight: 700; color: var(--sol-blue); margin-bottom: 0.5rem;
}
#divAIContent .keywords-list { list-style: none; padding: 0; }
#divAIContent .keywords-list li {
  background: #e6f2fa; border-left: 3px solid var(--sol-blue);
  border-radius: 0 6px 6px 0; padding: 0.5rem 0.75rem;
  margin-bottom: 0.4rem; font-size: 0.9rem; line-height: 1.6;
}

/* ── Loading ── */
#aiLoadingSteps { padding: .5rem 0 1rem; }

/* ── Streaming cursor ── */
#divAIContent.streaming::after {
  content: '▋'; display: inline-block;
  animation: blink .7s steps(1) infinite;
  color: var(--ad-primary); margin-left: 2px;
}
@keyframes blink { 0%,100%{opacity:1} 50%{opacity:0} }

/* ── Solution Footer ── */
.solution-footer {
  display: flex; justify-content: space-between; align-items: center;
  padding: 1rem 1.5rem; border-top: 1.5px dashed #d6d3d1;
  flex-wrap: wrap; gap: .75rem; background: #ffffff;
}
@media(min-width:1024px) { .solution-footer { padding: 1rem 3rem 1rem 6rem; } }
.sol-action-btn {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: .82rem; color: var(--sol-text-mid);
  background: none; border: none; cursor: pointer;
  padding: .3rem .5rem; border-radius: 6px;
  font-family: 'Poppins', Arial, sans-serif;
  transition: color .15s, background .15s;
}
.sol-action-btn:hover { color: var(--sol-text); background: #e8f3fb; }
.sol-action-btn.helpful:hover { color: #16a34a; }
.sol-action-btn.nothelpful:hover { color: #dc2626; }
.sol-action-btn.helpful.active { color: #16a34a; background: #dcfce7; font-weight: 600; }
.sol-action-btn.nothelpful.active { color: #dc2626; background: #fee2e2; font-weight: 600; }
.sol-action-btn.helpful.active svg,
.sol-action-btn.nothelpful.active svg { stroke-width: 2.5; }
.sol-feedback-count {
  font-size: .78rem; font-weight: 700; background: #e8f3fb; color: var(--sol-text-mid);
  border-radius: 20px; padding: .1rem .45rem; margin-left: 2px;
  min-width: 18px; text-align: center; display: inline-block;
  transition: background .2s, color .2s;
}
.sol-action-btn.helpful.active  .sol-feedback-count { background: #bbf7d0; color: #15803d; }
.sol-action-btn.nothelpful.active .sol-feedback-count { background: #fecaca; color: #b91c1c; }
.sol-signed {
  font-family: 'Caveat', cursive; font-size: 1.1rem; color: #d6d3d1;
  text-align: right; padding: .25rem 1.5rem .75rem; background: #ffffff;
}
@media(min-width:1024px) { .sol-signed { padding-right: 3rem; } }

/* ── Crop Modal ── */
#cropDiv {
  display: none !important; position: fixed; inset: 0; z-index: 9999;
  background: rgba(0,0,0,.6); align-items: center; justify-content: center;
}
#cropDiv.open { display: flex !important; }
.crop-modal {
  background: #fff; border-radius: 16px; width: 90%; max-width: 700px;
  box-shadow: 0 24px 80px rgba(0,0,0,.3); display: flex; flex-direction: column;
  overflow: hidden; max-height: 92vh;
}
.crop-modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: .9rem 1.25rem; border-bottom: 1px solid #eee; flex-shrink: 0;
}
.crop-modal-title { font-size: 1rem; font-weight: 600; color: var(--sol-text); }
.crop-modal-close {
  background: none; border: none; cursor: pointer; color: var(--sol-text-mid);
  padding: .3rem; border-radius: 6px; display: flex; align-items: center;
  transition: background .15s;
}
.crop-modal-close:hover { background: #f5f5f5; }
.crop-modal-body {
  flex: 1; overflow: auto; background: #1a1a2e;
  display: flex; align-items: center; justify-content: center; min-height: 280px;
}
.crop-modal-body img { max-height: 56vh; object-fit: contain; display: block; }
.crop-modal-footer {
  display: flex; align-items: center; justify-content: space-between;
  padding: .8rem 1.25rem; border-top: 1px solid #eee;
  background: #fff; flex-shrink: 0; gap: .75rem;
}
.crop-footer-left { display: flex; align-items: center; gap: .45rem; }
.crop-footer-right { display: flex; align-items: center; gap: .6rem; }
.crop-ctrl-btn {
  display: inline-flex; align-items: center; gap: 5px; background: #fff;
  border: 1.5px solid #d5d5d5; border-radius: 8px; padding: .38rem .7rem;
  font-size: .84rem; color: var(--sol-text); cursor: pointer;
  transition: background .15s, border-color .15s;
}
.crop-ctrl-btn:hover { background: #e8f3fb; border-color: var(--ad-primary); color: var(--ad-primary); }
.crop-degree-display {
  font-size: .84rem; font-weight: 600; color: var(--sol-text); background: #fff;
  border: 1.5px solid #d5d5d5; border-radius: 8px; padding: .38rem .65rem;
  min-width: 42px; text-align: center;
}
.crop-divider { width: 1px; height: 22px; background: #ddd; margin: 0 .2rem; }
.crop-cancel-btn {
  background: #fff; border: 1.5px solid #d5d5d5; border-radius: 10px;
  padding: .48rem 1.1rem; font-size: .9rem; font-weight: 500;
  color: var(--sol-text); cursor: pointer; transition: background .15s;
}
.crop-cancel-btn:hover { background: #f5f5f5; }
.crop-apply-btn {
  background: var(--ad-primary); border: none; border-radius: 10px;
  padding: .48rem 1.4rem; font-size: .9rem; font-weight: 600;
  color: #fff; cursor: pointer; transition: background .15s;
}
.crop-apply-btn:hover { background: var(--ad-primary-h); }

/* ── Responsive ── */
@media(max-width:640px) {
  .solution-footer { padding: 1rem; }
  .sol-signed { padding: .25rem 1rem .5rem; }
  #divAIContent .step-content { padding-left: 1rem; }
  #divAIContent .concept-section ul li,
  #divAIContent .concept-section ol li { padding: .4rem .6rem; }
}

/* ── Mic ── */
#micTrigger.mic-listening {
  background: #fee2e2; color: #dc2626;
  animation: micPulse 1.2s ease-in-out infinite;
}
#micTrigger.mic-listening svg { stroke: #dc2626; }
@keyframes micPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(220,38,38,0.4); }
  50%       { box-shadow: 0 0 0 6px rgba(220,38,38,0); }
}
#micStatusBar {
  display: none; align-items: center; gap: 8px;
  padding: 6px 10px; margin-bottom: 6px;
  background: #fef2f2; border: 1px solid #fecaca;
  border-radius: 8px; font-size: 0.8rem; color: #b91c1c;
  font-family: 'Poppins', Arial, sans-serif;
}
#micStatusBar.active { display: flex; }
.mic-wave { display: flex; align-items: center; gap: 3px; }
.mic-wave span {
  display: inline-block; width: 4px; height: 4px; border-radius: 50%;
  background: #dc2626; animation: micWave 1s ease-in-out infinite;
}
.mic-wave span:nth-child(2) { animation-delay: 0.15s; }
.mic-wave span:nth-child(3) { animation-delay: 0.30s; }
@keyframes micWave {
  0%, 100% { transform: scaleY(1); opacity: 0.5; }
  50%       { transform: scaleY(2.2); opacity: 1; }
}
