:root {
  --bg: #f5f5f5;
  --surface: #ffffff;
  --text: #333;
  --text-secondary: #555;
  --text-muted: #666;
  --text-hint: #999;
  --link: #4977a8;
  --border: #ddd;
  --border-focus: #4977a8;
  --shadow: rgba(0, 0, 0, 0.1);
  --btn-bg: #f8f9fa;
  --btn-bg-hover: #e9ecef;
  --btn-border-hover: #adb5bd;
  --btn-text: #555;
  --btn-text-hover: #333;
  --active-line: #f0f4ff;
  --output-bg: #f8f9fa;
  --output-text: #333;
  --output-border: #ddd;
  --run-bg: #28a745;
  --run-bg-hover: #1e7e34;
  --run-disabled: #6c757d;
  --clear-bg: #6c757d;
  --clear-bg-hover: #545b62;
  --hr: #ddd;
  --status-info-bg: #d1ecf1;
  --status-info-text: #0c5460;
  --status-info-border: #bee5eb;
  --status-error-bg: #f8d7da;
  --status-error-text: #721c24;
  --status-error-border: #f5c6cb;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1a1a1a;
    --surface: #242424;
    --text: #e0e0e0;
    --text-secondary: #b0b0b0;
    --text-muted: #909090;
    --text-hint: #707070;
    --link: #6fa8dc;
    --border: #3a3a3a;
    --border-focus: #6fa8dc;
    --shadow: rgba(0, 0, 0, 0.4);
    --btn-bg: #2e2e2e;
    --btn-bg-hover: #3a3a3a;
    --btn-border-hover: #555;
    --btn-text: #b0b0b0;
    --btn-text-hover: #e0e0e0;
    --active-line: #2a2a2a;
    --output-bg: #1a1a1a;
    --output-text: #c9c9c9;
    --output-border: #3a3a3a;
    --run-bg: #238636;
    --run-bg-hover: #2ea043;
    --run-disabled: #484848;
    --clear-bg: #484848;
    --clear-bg-hover: #606060;
    --hr: #3a3a3a;
    --status-info-bg: #1a3a3a;
    --status-info-text: #79c0c0;
    --status-info-border: #2a4a4a;
    --status-error-bg: #3a1a1a;
    --status-error-text: #f08080;
    --status-error-border: #5a2a2a;
  }
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial,
    sans-serif;
  max-width: 60rem;
  margin: 0 auto;
  background-color: var(--bg);
  color: var(--text);
}

#wrapper {
  background: var(--surface);
  border-bottom-left-radius: 0.5rem;
  border-bottom-right-radius: 0.5rem;
  padding: 2rem;
  margin-bottom: 2rem;
  box-shadow: 0 2px 1rem var(--shadow);
}

h1 {
  color: var(--text);
  text-align: center;
  margin-bottom: 0.25rem;
}

.subtitle {
  text-align: center;
  color: var(--text-muted);
  font-size: 14px;
  margin: 0 0 1rem;
}

h3 {
  color: var(--text-secondary);
  margin: 0 0 0.5rem 0;
}

hr {
  border-color: var(--hr);
}

a {
  color: var(--link);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

.examples {
  display: flex;
  gap: 0.5rem;
  margin: 1.5rem 0 1rem;
  flex-wrap: wrap;
  align-items: center;
}

.examples span {
  color: var(--text-muted);
  font-size: 14px;
  font-weight: bold;
}

.example-btn {
  padding: 0.25rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 1rem;
  cursor: pointer;
  font-size: 13px;
  background: var(--btn-bg);
  color: var(--btn-text);
  transition: all 0.2s;
}

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

/* CodeMirror editor */
.editor-container {
  margin: 1rem 0;
  border: 2px solid var(--border);
  border-radius: 4px;
  overflow: hidden;
}

.editor-container:focus-within {
  border-color: var(--border-focus);
}

.editor-container .cm-editor {
  font-size: 12px;
  min-height: 120px;
}

.editor-container .cm-editor.cm-focused {
  outline: none;
}

.editor-container .cm-scroller {
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  line-height: 1.5;
  padding: 0.5rem 0;
}

.editor-container .cm-content {
  padding: 0 0.75rem;
}

.editor-container .cm-activeLine {
  background-color: var(--active-line);
}

.controls {
  display: flex;
  gap: 0.5rem;
  margin: 0.5rem 0 1.5rem;
  align-items: center;
}

.controls-right {
  display: flex;
  gap: 0.5rem;
  margin-left: auto;
}

#runBtn {
  background-color: var(--run-bg);
  color: white;
}

#runBtn:hover:not(:disabled) {
  background-color: var(--run-bg-hover);
}

#runBtn:disabled {
  background-color: var(--run-disabled);
  cursor: not-allowed;
}

#clearBtn {
  background: none;
  color: var(--text-muted);
}

#clearBtn:hover {
  background-color: var(--clear-bg);
  color: white;
}

#shareBtn {
  background: none;
  color: var(--text-muted);
}

#shareBtn:hover {
  background-color: color-mix(in srgb, var(--border-focus) 15%, transparent);
}

button {
  padding: 0.5rem 1.5rem;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 14px;
  transition: background-color 0.2s;
  font-weight: bold;
  display: flex;
  align-items: center;
  justify-content: center;
}

[data-tooltip] {
  position: relative;
}

[data-tooltip]::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  padding: 0.3rem 0.6rem;
  border-radius: 4px;
  font-size: 12px;
  font-weight: normal;
  white-space: nowrap;
  background: var(--text);
  color: var(--bg);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s;
}

[data-tooltip]:hover::after {
  opacity: 1;
}

.output-container {
  margin: 1rem 0;
}

#outputs {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.output-box {
  padding: 0.4rem 0.6rem;
  border: 2px solid var(--output-border);
  border-radius: 4px;
}

pre.output-box {
  white-space: pre-wrap;
  word-wrap: break-word;
  margin: 0;
}

.output-box.text-box,
.output-box.print-box {
  background: var(--output-bg);
  color: var(--output-text);
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  font-size: 15px;
  line-height: 1.5;
}

.output-box.graphics-box {
  background: var(--surface);
  text-align: center;
}

.output-box.graphics-box svg {
  max-width: 100%;
  height: auto;
}

.output-box.warning-box {
  background: var(--status-info-bg);
  color: var(--status-info-text);
  border-color: var(--status-info-border);
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  font-size: 14px;
}

.output-box.error-box {
  background: var(--status-error-bg);
  color: var(--status-error-text);
  border-color: var(--status-error-border);
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  font-size: 14px;
}

.status {
  position: fixed;
  top: 1rem;
  right: 1rem;
  padding: 0.75rem 1rem;
  border-radius: 4px;
  display: none;
  z-index: 100;
  font-size: 14px;
}

.status.info {
  background-color: var(--status-info-bg);
  color: var(--status-info-text);
  border: 1px solid var(--status-info-border);
}

.status.error {
  background-color: var(--status-error-bg);
  color: var(--status-error-text);
  border: 1px solid var(--status-error-border);
}

.spinner {
  display: none;
  width: 14px;
  height: 14px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top: 2px solid #ffffff;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-left: 8px;
  flex-shrink: 0;
}

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

  100% {
    transform: rotate(360deg);
  }
}

@media (max-width: 640px) {
  #wrapper {
    padding: 1rem;
  }

  .controls {
    flex-wrap: wrap;
  }

  .controls-right {
    width: 100%;
  }

  .controls-right button {
    flex: 1;
  }
}
