:root {
  --editor-bg: #1e1e1e;
  --header-bg: #252526;
  --border-color: #3c3c3c;
  --primary-color: #4cd97b;
  --cplusplus-color: #5b9bd5;
  --run-btn-color: #4CAF50;
  --error-color: #ff6b6b;
  --text-color: #d4d4d4;
  --output-bg: #1e1e1e;
  --turtle-bg: #ffffff;
  --backend-color: #9c27b0;
  --ai-color: #ff6b35;
}

html,
body {
  height: 100%;
  margin: 0;
  padding: 0;
  overflow: hidden;
}

body {
  background: linear-gradient(135deg, #1a2a3a, #0d1b26);
  color: #ecf0f1;
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.header {
  background: rgba(25, 25, 35, 0.9);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid rgba(60, 60, 60, 0.5);
  padding: 15px 0;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.header-container {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 15px;
}

.header-left {
  display: flex;
  align-items: center;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 15px;
  flex-wrap: wrap;
}

.editor-container,
.output-container {
  background-color: var(--editor-bg);
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  transition: all 0.3s ease;
  border: 1px solid var(--border-color);
  height: 100%;
  display: flex;
  flex-direction: column;
}

.editor-container:hover,
.output-container:hover {
  box-shadow: 0 15px 40px rgba(0, 0, 0, 0.7);
}

.editor-header,
.output-header,
.input-header {
  background-color: var(--header-bg);
  border-bottom: 1px solid var(--border-color);
  padding: 12px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.editor-title,
.output-title,
.input-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-color);
}

.run-btn {
  background: linear-gradient(135deg, var(--run-btn-color), #2E7D32);
  border: none;
  transition: all 0.3s ease;
  padding: 8px 20px;
  border-radius: 30px;
  font-weight: 600;
  min-width: 120px;
}

.backend-mode .run-btn {
  background: linear-gradient(135deg, var(--backend-color), #7b1fa2);
}

.cplusplus-mode .run-btn {
  background: linear-gradient(135deg, var(--cplusplus-color), #2e5c8a);
}

.run-btn:hover {
  transform: translateY(-3px);
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
}

.run-btn:active {
  transform: translateY(-1px);
}

.output-content,
.input-content {
  min-height: 200px;
  max-height: 300px;
  overflow-y: auto;
  padding: 20px;
  background-color: var(--output-bg);
  color: var(--text-color);
  font-family: 'Consolas', 'Courier New', monospace;
  font-size: 15px;
  line-height: 1.6;
  flex-grow: 1;
}

.input-content {
  min-height: 120px;
  max-height: 150px;
  resize: vertical;
}

.footer-text {
  color: #95a5a6;
  font-size: 14px;
  margin-top: 20px;
  text-align: center;
}

.CodeMirror {
  height: 100%;
  font-size: 16px;
  line-height: 1.6;
  padding: 10px 0;
  flex-grow: 1;
}

.code-line {
  padding: 3px 0;
  font-family: 'Consolas', 'Courier New', monospace;
  border-left: 3px solid transparent;
  padding-left: 10px;
}

.code-line.error {
  color: var(--error-color);
  border-left-color: var(--error-color);
}

.editor-footer {
  color: white;
  padding: 8px 20px;
  font-size: 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.python-footer {
  background: linear-gradient(90deg, #0078d7, #1e4c8a);
}

.cplusplus-footer {
  background: linear-gradient(90deg, #0046ad, #1e2c8a);
}

.backend-footer {
  background: linear-gradient(90deg, #7b1fa2, #4a148c);
}

.logo {
  font-weight: 700;
  color: var(--primary-color);
  font-size: 28px;
  text-shadow: 0 0 10px rgba(76, 217, 123, 0.5);
}

.cplusplus-mode .logo {
  color: var(--cplusplus-color);
  text-shadow: 0 0 10px rgba(91, 155, 213, 0.5);
}

.backend-mode .logo {
  color: var(--backend-color);
  text-shadow: 0 0 10px rgba(156, 39, 176, 0.5);
}

.status-badge {
  background: rgba(40, 40, 50, 0.7);
  border: 1px solid rgba(100, 100, 120, 0.5);
  border-radius: 20px;
  padding: 5px 15px;
  font-size: 14px;
  backdrop-filter: blur(5px);
  display: flex;
  align-items: center;
}

.cplusplus-badge {
  background: rgba(40, 40, 100, 0.7);
}

.backend-badge {
  background: rgba(80, 40, 90, 0.7);
}

.input-section {
  margin-bottom: 20px;
}

.input-area {
  background: rgba(30, 30, 40, 0.8);
  border: 1px solid var(--border-color);
  color: var(--text-color);
  width: 100%;
  min-height: 100px;
  padding: 15px;
  border-radius: 8px;
  font-family: 'Consolas', 'Courier New', monospace;
  resize: vertical;
}

.input-area:focus {
  outline: none;
  border-color: var(--primary-color);
  box-shadow: 0 0 0 3px rgba(76, 217, 123, 0.2);
}

.cplusplus-mode .input-area:focus {
  border-color: var(--cplusplus-color);
  box-shadow: 0 0 0 3px rgba(91, 155, 213, 0.2);
}

.backend-mode .input-area:focus {
  border-color: var(--backend-color);
  box-shadow: 0 0 0 3px rgba(156, 39, 176, 0.2);
}

.input-hint {
  font-size: 13px;
  color: #95a5a6;
  margin-top: 5px;
}

.output-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 200px;
  color: #7f8c8d;
  height: 100%;
}

.output-placeholder i {
  font-size: 48px;
  margin-bottom: 15px;
  opacity: 0.6;
}

.cursor-pointer {
  cursor: pointer;
}

.content-container {
  flex-grow: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: 0 15px;
}

.main-content {
  flex-grow: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.editor-wrapper {
  flex-grow: 1;
  display: flex;
  flex-direction: column;
}

.editor-body {
  flex-grow: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.turtle-canvas-container {
  flex-grow: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  height: 100%;
}

#te_canvas {
  flex-grow: 1;
  background: var(--turtle-bg);
  border-radius: 5px;
  min-height: 400px;
}

.mode-buttons {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.mode-buttons .btn {
  border-radius: 20px;
  padding: 6px 15px;
}

.output-section {
  flex-grow: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.row-container {
  flex-grow: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  height: 100%;
}

.row-grow {
  flex-grow: 1;
  min-height: 0;
  height: 100%;
}

.col-grow {
  display: flex;
  flex-direction: column;
  min-height: 0;
  height: 100%;
}

/* 右侧面板容器 */
#right-container {
  display: flex;
  flex-direction: column;
  height: 100%;
  gap: 20px;
  transition: gap 0.3s ease;
}

/* 海龟绘图模式下的布局调整 */
.turtle-mode #input-section,
.turtle-mode #output-section {
  display: none;
}

.turtle-mode #turtle-canvas-container {
  display: flex !important;
  flex-direction: column;
  flex-grow: 1;
  height: 100%;
}

.turtle-mode #right-container {
  gap: 0;
}

/* 绘图区域标题栏 */
.turtle-header {
  background-color: var(--header-bg);
  border-bottom: 1px solid var(--border-color);
  padding: 12px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

/* 海龟绘图容器 */
.turtle-canvas-wrapper {
  flex-grow: 1;
  display: flex;
  min-height: 0;
  padding: 15px;
}

/* 模式按钮激活状态 */
.mode-active {
  box-shadow: 0 0 0 3px rgba(76, 217, 123, 0.5);
  transform: scale(1.05);
}

.cplusplus-mode .mode-active {
  box-shadow: 0 0 0 3px rgba(91, 155, 213, 0.5);
}

.backend-mode .mode-active {
  box-shadow: 0 0 0 3px rgba(156, 39, 176, 0.5);
}

/* 绘图控制按钮 */
.turtle-controls {
  display: flex;
  gap: 10px;
  padding: 10px 20px;
  background: var(--header-bg);
  border-top: 1px solid var(--border-color);
}

/* 响应式调整 */
@media (max-width: 992px) {
  .header-container {
    flex-direction: column;
    align-items: flex-start;
  }

  .header-right {
    width: 100%;
    justify-content: space-between;
  }

  .logo {
    font-size: 24px;
  }

  .mode-buttons {
    width: 100%;
    justify-content: flex-end;
  }
}

@media (max-width: 768px) {
  .header-right {
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
  }

  .mode-buttons {
    justify-content: flex-start;
  }

  .row-grow {
    height: auto;
  }

  .col-grow {
    height: 50vh;
  }
}

/* 语言切换按钮 */
.language-switcher {
  display: flex;
  background: rgba(40, 40, 50, 0.7);
  border-radius: 30px;
  padding: 4px;
  border: 1px solid rgba(100, 100, 120, 0.5);
}

.language-btn {
  padding: 6px 20px;
  border-radius: 30px;
  border: none;
  background: transparent;
  color: var(--text-color);
  font-weight: 500;
  transition: all 0.3s ease;
  cursor: pointer;
}

.language-btn.active {
  background: var(--primary-color);
  color: #fff;
}

.cplusplus-mode .language-btn.active {
  background: var(--cplusplus-color);
}

.backend-mode .language-btn.active {
  background: var(--backend-color);
}

.language-btn:not(.active):hover {
  background: rgba(255, 255, 255, 0.1);
}

.cplusplus-mode .turtle-controls {
  display: none;
}

.backend-indicator {
  display: flex;
  align-items: center;
  background: rgba(80, 40, 90, 0.7);
  border-radius: 20px;
  padding: 5px 15px;
  border: 1px solid rgba(100, 100, 120, 0.5);
  font-size: 14px;
}

.backend-indicator i {
  margin-right: 8px;
  color: #d7a1f9;
}

.compile-options {
  display: flex;
  align-items: center;
  gap: 10px;
}

.backend-notice {
  background: rgba(156, 39, 176, 0.15);
  border-left: 4px solid var(--backend-color);
  padding: 12px;
  border-radius: 4px;
  margin-top: 10px;
  font-size: 14px;
}

.backend-notice i {
  margin-right: 8px;
  color: var(--backend-color);
}

.backend-loader {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.backend-loader .spinner {
  width: 50px;
  height: 50px;
  border: 5px solid rgba(156, 39, 176, 0.2);
  border-top: 5px solid var(--backend-color);
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin-bottom: 15px;
}

@keyframes spin {
  0% {
    transform: rotate(0deg);
  }

  100% {
    transform: rotate(360deg);
  }
}

.action-buttons {
  display: flex;
  gap: 10px;
  align-items: center;
}

.backend-stats {
  display: flex;
  gap: 15px;
  margin-top: 10px;
}

.stat-card {
  background: rgba(50, 50, 60, 0.5);
  border-radius: 8px;
  padding: 10px;
  flex: 1;
  text-align: center;
}

.stat-value {
  font-size: 18px;
  font-weight: bold;
  color: var(--primary-color);
}

.backend-mode .stat-value {
  color: var(--backend-color);
}

.stat-label {
  font-size: 12px;
  color: #95a5a6;
  margin-top: 5px;
}

/* 新增：隐藏C++模式下的普通模式和海龟模式按钮 */
.cplusplus-mode .mode-buttons #normal-mode-btn,
.cplusplus-mode .mode-buttons #turtle-mode-btn {
  display: none;
}

/* AI 智能补全开关 */
.ai-switch {
  position: relative;
  display: inline-block;
  width: 60px;
  height: 30px;
}

.ai-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.ai-slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: #ccc;
  transition: .4s;
  border-radius: 30px;
}

.ai-slider:before {
  position: absolute;
  content: "";
  height: 22px;
  width: 22px;
  left: 4px;
  bottom: 4px;
  background-color: white;
  transition: .4s;
  border-radius: 50%;
}

input:checked+.ai-slider {
  background: linear-gradient(135deg, var(--ai-color), #d14a00);
}

input:checked+.ai-slider:before {
  transform: translateX(30px);
}

.ai-toggle-container {
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(40, 40, 50, 0.7);
  border-radius: 30px;
  padding: 5px 15px;
  border: 1px solid rgba(100, 100, 120, 0.5);
}

.ai-toggle-container span {
  font-size: 14px;
  color: var(--text-color);
}

.ai-mode .logo {
  color: var(--ai-color);
  text-shadow: 0 0 10px rgba(255, 107, 53, 0.5);
}

.ai-mode .run-btn {
  background: linear-gradient(135deg, var(--ai-color), #d14a00);
}

/* AI 补全提示框 */
.CodeMirror-hints {
  z-index: 1000;
  background: #2d2d30;
  border: 1px solid #3c3c3c;
  border-radius: 6px;
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.5);
  font-family: 'Consolas', 'Courier New', monospace;
  max-height: 200px;
  overflow-y: auto;
}

.CodeMirror-hint {
  color: #d4d4d4;
  padding: 8px 12px;
  border-radius: 4px;
  transition: all 0.2s;
  display: flex;
  align-items: center;
}

.CodeMirror-hint:hover {
  background: rgba(76, 217, 123, 0.2);
  color: white;
}

.ai-mode .CodeMirror-hint:hover {
  background: rgba(255, 107, 53, 0.2);
}

.cplusplus-mode .CodeMirror-hint:hover {
  background: rgba(91, 155, 213, 0.2);
}

.backend-mode .CodeMirror-hint:hover {
  background: rgba(156, 39, 176, 0.2);
}

.CodeMirror-hint-active {
  background: rgba(76, 217, 123, 0.3) !important;
  color: white !important;
}

.ai-mode .CodeMirror-hint-active {
  background: rgba(255, 107, 53, 0.3) !important;
}

.cplusplus-mode .CodeMirror-hint-active {
  background: rgba(91, 155, 213, 0.3) !important;
}

.backend-mode .CodeMirror-hint-active {
  background: rgba(156, 39, 176, 0.3) !important;
}

.hint-icon {
  margin-right: 8px;
  color: #4cd97b;
}

.ai-mode .hint-icon {
  color: var(--ai-color);
}

.cplusplus-mode .hint-icon {
  color: var(--cplusplus-color);
}

.backend-mode .hint-icon {
  color: var(--backend-color);
}

.hint-type {
  font-size: 12px;
  color: #95a5a6;
  margin-left: 8px;
}