/* ============================
   Python 小乐园 — 左右分栏布局
   UI/UX Pro Max 设计系统
   ============================ */

/* --- Fonts --- */
@import url('https://fonts.googleapis.com/css2?family=Baloo+2:wght@400;500;600;700;800&family=Comic+Neue:wght@300;400;700&family=Fira+Code:wght@400;500&display=swap');

/* --- CSS Custom Properties --- */
:root {
  --bg-primary: #0F172A;
  --bg-secondary: #1E293B;
  --bg-tertiary: #334155;
  --bg-card: #1E293B;
  --bg-hover: #334155;

  --accent-green: #22C55E;
  --accent-green-hover: #16A34A;
  --accent-green-glow: rgba(34, 197, 94, 0.15);
  --accent-red: #EF4444;
  --accent-yellow: #FACC15;
  --accent-blue: #3B82F6;
  --accent-purple: #A78BFA;

  --text-primary: #F8FAFC;
  --text-secondary: #94A3B8;
  --text-muted: #64748B;
  --text-inverse: #0F172A;

  --border-color: #334155;
  --border-focus: #22C55E;

  --font-display: 'Baloo 2', 'Comic Neue', 'PingFang SC', cursive;
  --font-body: 'Comic Neue', 'Baloo 2', 'PingFang SC', sans-serif;
  --font-code: 'Fira Code', 'Source Code Pro', 'Menlo', monospace;

  --font-size-xs: 12px;
  --font-size-sm: 14px;
  --font-size-base: 16px;
  --font-size-lg: 18px;
  --font-size-xl: 22px;
  --font-size-2xl: 28px;

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-full: 9999px;

  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.5);
  --shadow-glow: 0 0 20px var(--accent-green-glow);

  --transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-base: 250ms cubic-bezier(0.4, 0, 0.2, 1);

  --header-height: 60px;
  --footer-height: 36px;
  --z-dropdown: 50;
  --z-overlay: 100;
}

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

html {
  font-size: var(--font-size-base);
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-body);
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

/* --- App Container --- */
.app-container {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

/* --- Header (Floating Navbar) --- */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--header-height);
  padding: 0 20px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
  flex-shrink: 0;
  z-index: 10;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 16px;
}

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

.app-title {
  font-family: var(--font-display);
  font-size: var(--font-size-xl);
  font-weight: 800;
  color: var(--text-primary);
  letter-spacing: 0.5px;
}

.app-subtitle {
  font-size: var(--font-size-sm);
  color: var(--text-muted);
  font-weight: 400;
  display: none;
}

@media (min-width: 1024px) {
  .app-subtitle {
    display: block;
  }
}

.header-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* --- Buttons --- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border: none;
  border-radius: var(--radius-md);
  font-family: var(--font-display);
  font-size: var(--font-size-sm);
  font-weight: 700;
  cursor: pointer;
  transition: all var(--transition-fast);
  white-space: nowrap;
  line-height: 1;
}

.btn:focus-visible {
  outline: 2px solid var(--border-focus);
  outline-offset: 2px;
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid transparent;
}

.btn-ghost:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
  border-color: var(--border-color);
}

.btn-primary {
  background: var(--accent-green);
  color: var(--text-inverse);
  box-shadow: var(--shadow-glow);
  padding: 8px 24px;
}

.btn-primary:hover {
  background: var(--accent-green-hover);
  box-shadow: 0 0 30px var(--accent-green-glow);
  transform: translateY(-1px);
}

.btn-primary:active {
  transform: translateY(0);
}

.btn-primary.running {
  background: var(--accent-yellow);
  color: var(--text-inverse);
  cursor: wait;
}

.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.btn-icon:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

/* --- Icons --- */
.icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

.icon-sm {
  width: 14px;
  height: 14px;
}

/* --- Example Dropdown --- */
.example-dropdown {
  position: relative;
}

.example-menu {
  display: none;
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  min-width: 280px;
  z-index: var(--z-dropdown);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  animation: dropdown-in 200ms ease-out;
}

.example-menu.show {
  display: block;
}

@keyframes dropdown-in {
  from {
    opacity: 0;
    transform: translateY(-8px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.example-item {
  padding: 12px 16px;
  cursor: pointer;
  transition: background var(--transition-fast);
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.example-item:last-child {
  border-bottom: none;
}

.example-item:hover {
  background: var(--bg-hover);
}

.example-item .example-name {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: var(--font-size-sm);
  color: var(--text-primary);
  margin-bottom: 2px;
}

.example-item .example-desc {
  font-size: var(--font-size-xs);
  color: var(--text-muted);
}

/* --- Split Panel Layout --- */
.split-panel {
  display: flex;
  flex: 1;
  overflow: hidden;
  gap: 0;
}

.panel {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
  overflow: hidden;
}

.panel-editor {
  border-right: 1px solid var(--border-color);
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
  flex-shrink: 0;
}

.panel-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-display);
  font-size: var(--font-size-sm);
  font-weight: 700;
  color: var(--text-secondary);
}

.panel-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border-radius: var(--radius-full);
  font-size: var(--font-size-xs);
  font-weight: 600;
  color: var(--accent-green);
  background: var(--accent-green-glow);
}

.panel-badge.error {
  color: var(--accent-red);
  background: rgba(239, 68, 68, 0.15);
}

.panel-badge.checking {
  color: var(--accent-blue);
  background: rgba(59, 130, 246, 0.15);
}

.panel-body {
  flex: 1;
  overflow: auto;
}

/* --- Editor Styles --- */
.editor-body {
  overflow: hidden;
}

.CodeMirror {
  height: 100% !important;
  font-family: var(--font-code);
  font-size: var(--font-size-base);
  line-height: 1.65;
  background: var(--bg-primary) !important;
}

.CodeMirror-scroll {
  padding: 8px 0;
}

.cm-s-dracula .CodeMirror-gutters {
  background: var(--bg-primary) !important;
  border-right: 1px solid var(--border-color) !important;
}

.cm-s-dracula .CodeMirror-linenumber {
  color: var(--text-muted) !important;
  font-size: var(--font-size-sm);
}

.cm-s-dracula .CodeMirror-cursor {
  border-left: 2px solid var(--accent-green) !important;
}

.cm-s-dracula .CodeMirror-activeline-background {
  background: rgba(34, 197, 94, 0.05) !important;
}

.cm-s-dracula .CodeMirror-selected {
  background: rgba(167, 139, 250, 0.2) !important;
}

/* --- Turtle Canvas --- */
.turtle-wrapper {
  position: relative;
  margin: 16px auto;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  background: var(--bg-secondary);
  box-shadow: var(--shadow-md);
  overflow: hidden;
}

.turtle-canvas {
  display: block;
}

.turtle-overlay {
  position: absolute;
  top: 0;
  left: 0;
  pointer-events: none;
}

/* --- Output Styles --- */
.output-body {
  background: var(--bg-primary);
}

.output-content {
  font-family: var(--font-code);
  font-size: var(--font-size-sm);
  line-height: 1.7;
  white-space: pre-wrap;
  word-break: break-word;
  padding: 16px;
  min-height: 100%;
  color: var(--text-primary);
}

.output-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  min-height: 300px;
  text-align: center;
  color: var(--text-muted);
  gap: 12px;
}

.output-placeholder .placeholder-icon {
  opacity: 0.3;
}

.output-placeholder p {
  font-family: var(--font-display);
  font-size: var(--font-size-base);
  font-weight: 600;
}

.output-placeholder .hint {
  font-size: var(--font-size-xs);
  opacity: 0.6;
}

.output-error {
  color: var(--accent-red);
  background: rgba(239, 68, 68, 0.08);
  border-left: 3px solid var(--accent-red);
  padding: 10px 14px;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  margin: 4px 0;
  display: block;
}

.output-success {
  color: var(--accent-green);
}

/* --- Status Bar --- */
.status-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--footer-height);
  padding: 0 16px;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border-color);
  font-size: var(--font-size-xs);
  color: var(--text-muted);
  flex-shrink: 0;
}

.status-left {
  display: flex;
  align-items: center;
  gap: 8px;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent-yellow);
  transition: background var(--transition-base);
}

.status-dot.ready {
  background: var(--accent-green);
  box-shadow: 0 0 6px var(--accent-green-glow);
}

.status-dot.error {
  background: var(--accent-red);
}

.status-text {
  font-weight: 600;
}

/* --- Loading Overlay --- */
.loading-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg-primary);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: var(--z-overlay);
  gap: 16px;
  transition: opacity 400ms ease;
}

.loading-overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

.loading-icon {
  color: var(--accent-green);
  animation: spin 1s linear infinite;
}

@keyframes spin {
  from {
    transform: rotate(0deg);
  }

  to {
    transform: rotate(360deg);
  }
}

.loading-text {
  font-family: var(--font-display);
  font-size: var(--font-size-xl);
  font-weight: 700;
  color: var(--text-primary);
}

.loading-sub {
  font-size: var(--font-size-sm);
  color: var(--text-muted);
}

/* --- Responsive: Stack on small screens --- */
@media (max-width: 768px) {
  .split-panel {
    flex-direction: column;
  }

  .panel-editor {
    border-right: none;
    border-bottom: 1px solid var(--border-color);
    flex: 1;
  }

  .panel-output {
    flex: 1;
  }

  .app-header {
    padding: 0 12px;
    flex-wrap: wrap;
    height: auto;
    padding: 10px 12px;
    gap: 8px;
  }

  .header-right {
    width: 100%;
    justify-content: flex-end;
  }

  .btn span {
    display: none;
  }

  .btn-primary span {
    display: inline;
  }

  body {
    overflow: auto;
  }

  .app-container {
    height: auto;
    min-height: 100vh;
  }

  .CodeMirror {
    height: 300px !important;
  }
}

/* --- Reduced Motion --- */
@media (prefers-reduced-motion: reduce) {

  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}