* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body {
  height: 100%;
  background: #ffffff;
  color: #1a1a2e;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  overflow: hidden;
}

/* Header */
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  height: 48px;
  background: #9E1B32;
  border-bottom: 1px solid #e2e8f0;
}

header h1 {
  font-size: 16px;
  font-weight: 600;
  color: #ffffff;
}

.header-controls {
  display: flex;
  align-items: center;
  gap: 10px;
}

.dashboard-link {
  color: #ffffff;
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  padding: 4px 12px;
  border: 1px solid rgba(255, 255, 255, 0.4);
  border-radius: 6px;
  transition: background 0.15s;
}
.dashboard-link:hover {
  background: rgba(255, 255, 255, 0.15);
  text-decoration: none;
}

.header-controls label {
  font-size: 13px;
  color: rgba(255, 255, 255, 0.8);
}

.header-controls select {
  background: rgba(255, 255, 255, 0.15);
  color: #ffffff;
  border: 1px solid rgba(255, 255, 255, 0.3);
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 13px;
  min-width: 180px;
}

.header-controls button {
  background: rgba(255, 255, 255, 0.15);
  color: #ffffff;
  border: 1px solid rgba(255, 255, 255, 0.3);
  padding: 4px 12px;
  border-radius: 4px;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s;
}

.header-controls button:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.25);
}

.header-controls button:disabled,
.header-controls select:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

#resetKnowledgeBtn {
  background: rgba(220, 38, 38, 0.2);
  color: #fef2f2;
  border: 1px solid rgba(220, 38, 38, 0.4);
}

#resetKnowledgeBtn:hover {
  background: rgba(220, 38, 38, 0.35);
}

/* Split container */
.split-container {
  display: flex;
  height: calc(100vh - 48px);
}

.panel {
  position: relative;
  overflow: hidden;
  min-width: 200px;
}

.left-panel {
  flex: 1 1 60%;
  display: flex;
  flex-direction: column;
}

.left-panel iframe {
  flex: 1;
  min-height: 0;
  width: 100%;
  border: none;
  background: white;
}

.right-panel {
  flex: 1 1 40%;
  background: #000;
}

#graphContainer {
  width: 100%;
  height: 100%;
}

/* Divider */
.divider {
  width: 6px;
  background: #e2e8f0;
  cursor: col-resize;
  flex-shrink: 0;
  transition: background 0.15s;
}

.divider:hover,
.divider.dragging {
  background: #9E1B32;
}

/* Overlays */
.overlay {
  position: absolute;
  z-index: 10;
  pointer-events: auto;
}

.status-message {
  bottom: 20px;
  left: 20px;
  right: 20px;
  background: rgba(0, 0, 0, 0.8);
  padding: 12px 16px;
  border-radius: 8px;
  font-size: 14px;
  line-height: 1.5;
  color: #f0f0f0;
  backdrop-filter: blur(8px);
  transition: opacity 0.3s;
}

.status-message:empty {
  display: none;
}

/* Info card */
.info-card {
  top: 16px;
  right: 16px;
  background: rgba(15, 17, 23, 0.9);
  border: 1px solid #334155;
  border-radius: 8px;
  padding: 12px 16px;
  min-width: 240px;
  max-width: 360px;
  backdrop-filter: blur(8px);
  color: #e0e0e0;
}

.info-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}

#infoCardName {
  font-size: 14px;
  font-weight: 600;
}

.status-badge {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  padding: 2px 8px;
  border-radius: 10px;
}

.status-badge.success { background: #dcfce7; color: #166534; }
.status-badge.warning { background: #fef9c3; color: #854d0e; }
.status-badge.error   { background: #fee2e2; color: #991b1b; }
.status-badge.unknown { background: #f3f4f6; color: #4b5563; }
.status-badge.inprogress { background: #dbeafe; color: #1e40af; }
.status-badge.hint    { background: #f3e8ff; color: #6b21a8; }
.status-badge.noproblem { background: #ccfbf1; color: #0f766e; }

.info-card-hints {
  font-size: 13px;
  color: #9ca3af;
}

.info-card-hints .hint-progress {
  display: flex;
  gap: 3px;
  margin-top: 6px;
}

.info-card-hints .hint-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #4b5563;
}

.info-card-hints .hint-dot.filled {
  background: #56EEF4;
}

/* LO list */
.lo-list {
  top: 16px;
  left: 16px;
  background: rgba(15, 17, 23, 0.9);
  border: 1px solid #2a2d3a;
  border-radius: 8px;
  padding: 8px 0;
  max-height: 300px;
  min-width: 220px;
  max-width: 320px;
  overflow-y: auto;
  backdrop-filter: blur(8px);
}

.lo-list-header {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  color: #9ca3af;
  padding: 4px 12px 8px;
  border-bottom: 1px solid #334155;
}

#loListItems {
  list-style: none;
}

#loListItems li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.1s;
}

#loListItems li:hover {
  background: rgba(86, 238, 244, 0.1);
}

#loListItems li .lo-status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.lo-status-dot.success { background: #4ade80; }
.lo-status-dot.warning { background: #fbbf24; }
.lo-status-dot.error   { background: #f87171; }
.lo-status-dot.unknown { background: #9ca3af; }
.lo-status-dot.inprogress { background: #60a5fa; }
.lo-status-dot.hint    { background: #c084fc; }
.lo-status-dot.noproblem { background: #56EEF4; }

/* Score overlay */
.score-overlay {
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(15, 17, 23, 0.95);
  border: 2px solid #9E1B32;
  border-radius: 16px;
  padding: 32px 48px;
  text-align: center;
  backdrop-filter: blur(12px);
  color: #e0e0e0;
}

#scoreContent {
  font-size: 18px;
}

#scoreContent .score-value {
  font-size: 48px;
  font-weight: 700;
  color: #9E1B32;
  margin: 12px 0;
}

#scoreContent .score-label {
  font-size: 14px;
  color: #9ca3af;
}

#scoreContent .score-error {
  color: #f87171;
  font-size: 16px;
}

/* Chat Panel */
.chat-panel {
  height: 180px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  background: #f1f5f9;
  border-top: 1px solid #e2e8f0;
}

.chat-header {
  display: flex;
  align-items: center;
  padding: 6px 12px;
  border-bottom: 1px solid #e2e8f0;
}

.chat-title {
  font-size: 14px;
  font-weight: 600;
  text-transform: uppercase;
  color: #9E1B32;
  letter-spacing: 0.05em;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 8px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.chat-bubble {
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 16px;
  line-height: 1.4;
  max-width: 85%;
  animation: chatFadeIn 0.3s ease-out;
}

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

.chat-bubble.tutor {
  background: #ffffff;
  border: 1px solid #e2e8f0;
  color: #1a1a2e;
  align-self: flex-start;
}

.chat-bubble.student {
  background: #e8eef4;
  border: 1px solid #cbd5e1;
  color: #1a1a2e;
  align-self: flex-end;
}

.chat-bubble .speaker {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  color: #9E1B32;
  margin-bottom: 2px;
}

.chat-bubble.student .speaker {
  color: #1e40af;
}

.chat-bubble.thinking .thinking-dots {
  animation: thinking-pulse 0.6s ease-in-out infinite alternate;
  color: #6b7280;
  font-style: italic;
}

@keyframes thinking-pulse {
  from { opacity: 0.3; }
  to   { opacity: 0.6; }
}

.chat-input {
  display: flex;
  gap: 6px;
  padding: 6px 12px;
  border-top: 1px solid #e2e8f0;
}

.chat-btn {
  padding: 8px 18px;
  border-radius: 6px;
  font-size: 18px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
  border: 1px solid;
}

.chat-btn.student {
  background: #e8eef4;
  color: #1e40af;
  border-color: #93c5fd;
}

.chat-btn.student:hover {
  background: #dbeafe;
  color: #1e3a8a;
}

.chat-btn.tutor {
  background: #f8f9fa;
  color: #9E1B32;
  border-color: #e2e8f0;
}

.chat-btn.tutor:hover {
  background: #e2e8f0;
}

/* Subproblem Modal */
.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  padding-left: 24px;
}

.modal[hidden] {
  display: none;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(4px);
}

/* --- Gradarius-style subproblem modal --- */

.grd-modal {
  position: relative;
  background: #ffffff;
  border-radius: 8px;
  width: 560px;
  max-width: 92vw;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.45);
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  color: #1a1a1a;
  padding: 0 0 24px;
}

.grd-modal.grd-modal-iframe {
  width: 1020px;
  height: 80vh;
  padding: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.grd-modal-iframe .grd-title {
  flex-shrink: 0;
}

.grd-iframe {
  flex: 1;
  width: 100%;
  border: none;
  border-radius: 0 0 8px 8px;
  background: #fff;
}

.grd-modal-close {
  position: absolute;
  top: 12px;
  right: 16px;
  background: none;
  border: none;
  color: #999;
  font-size: 22px;
  cursor: pointer;
  line-height: 1;
  z-index: 1;
}
.grd-modal-close:hover { color: #333; }

/* Subproblem success overlay */
.subproblem-success-overlay {
  position: absolute;
  inset: 0;
  background: rgba(34, 197, 94, 0);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 48px;
  font-weight: 700;
  color: rgba(255, 255, 255, 0);
  z-index: 10;
  transition: background 0.6s ease, color 0.6s ease;
  pointer-events: none;
}
.subproblem-success-overlay.visible {
  background: rgba(34, 197, 94, 0.85);
  color: #fff;
}

/* Shrink-away animation for modal */
.grd-modal.modal-shrink {
  transform: scale(0.05);
  opacity: 0;
  transition: transform 0.5s ease-in, opacity 0.5s ease-in;
}

.grd-title {
  font-size: 20px;
  font-weight: 700;
  color: #1a1a1a;
  padding: 24px 28px 16px;
  border-bottom: 1px solid #e5e7eb;
}

.grd-problem-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px 28px 12px;
}

.grd-icon {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
}

.grd-icon-bulb {
  background: #d1fae5;
}

.grd-icon-info {
  background: #d1fae5;
  font-size: 14px;
  font-weight: 700;
  color: #16a34a;
}

.grd-problem-text {
  font-size: 17px;
  color: #333;
  font-family: "Times New Roman", "STIX Two Math", serif;
}
.grd-problem-text i {
  font-style: italic;
}

.grd-workspace {
  padding: 8px 28px 0;
  min-height: 60px;
}

.grd-steps {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.grd-step {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 0;
  animation: grdStepIn 0.3s ease-out;
}

@keyframes grdStepIn {
  from { opacity: 0; transform: translateY(-6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.grd-step-expr {
  font-family: "Times New Roman", "STIX Two Math", serif;
  font-size: 18px;
  color: #1a1a1a;
  padding: 8px 14px;
  flex: 1;
  text-align: center;
}

.grd-step.active .grd-step-expr {
  border: 1.5px solid #93b4e8;
  border-radius: 4px;
  background: #fafbff;
}

.grd-step-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  color: #999;
  font-size: 14px;
  flex-shrink: 0;
}

.grd-step-actions .dots {
  font-size: 18px;
  letter-spacing: 1px;
}

.grd-step-actions .enter {
  font-size: 16px;
}

.grd-step-label {
  font-size: 11px;
  color: #999;
  margin-left: 4px;
  white-space: nowrap;
}

.grd-step.result .grd-step-expr {
  border-color: #4ade80;
  background: #f0fdf4;
}

.grd-new-row {
  padding: 12px 0;
  color: #9ca3af;
  font-size: 14px;
  cursor: default;
}
.grd-new-row .grd-plus {
  color: #9ca3af;
  margin-right: 4px;
}

.grd-bottom {
  display: flex;
  justify-content: flex-start;
  gap: 10px;
  padding: 20px 28px 0;
}

.grd-btn-next {
  background: #e8ecf1;
  color: #4a5568;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  padding: 8px 18px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s;
}
.grd-btn-next:hover { background: #d1d5db; }

.grd-btn-submit {
  background: #f5c6cb;
  color: #721c24;
  border: none;
  border-radius: 6px;
  padding: 10px 28px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}
.grd-btn-submit:hover { background: #f1aeb5; }
