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

body {
  background: #1a1a2e;
  color: #e0e0f0;
  font-family: 'Courier New', monospace;
  height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

#header {
  padding: 0.5rem 1rem;
  background: #12122a;
  border-bottom: 1px solid #2a2a4a;
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-shrink: 0;
}

#header h1 {
  font-size: 1.1rem;
  color: #a0c0ff;
  letter-spacing: 0.1em;
}

.header-btns {
  display: flex;
  gap: 0.4rem;
  margin-left: auto;
}

.btn {
  padding: 0.3rem 0.8rem;
  border: 1px solid #3a3a6a;
  background: #1e1e40;
  color: #c0d0ff;
  border-radius: 4px;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.8rem;
  transition: background 0.15s, border-color 0.15s;
}

.btn:hover { background: #2a2a5a; border-color: #6070c0; }

.btn-run {
  background: #1a4a2a;
  border-color: #2a7a4a;
  color: #80ffa0;
}
.btn-run:hover { background: #205a34; border-color: #40a060; }

.btn-stop {
  background: #4a1a1a;
  border-color: #7a2a2a;
  color: #ffa080;
}
.btn-stop:hover { background: #5a2020; }

#main {
  display: flex;
  flex: 1;
  overflow: hidden;
  gap: 0;
}

#canvas-panel {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #111122;
  position: relative;
}

#turtle-canvas {
  border: 1px solid #2a2a4a;
  background: #0a0a1a;
  display: block;
}

#right-panel {
  width: 30%;
  min-width: 220px;
  max-width: 380px;
  display: flex;
  flex-direction: column;
  border-left: 1px solid #2a2a4a;
}

#editor-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#editor-label {
  padding: 0.3rem 0.6rem;
  background: #12122a;
  border-bottom: 1px solid #2a2a4a;
  font-size: 0.7rem;
  color: #6070a0;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

#code-editor {
  flex: 1;
  background: #0e0e22;
  color: #d0e0ff;
  border: none;
  outline: none;
  padding: 0.6rem;
  font-family: 'Courier New', monospace;
  font-size: 0.85rem;
  resize: none;
  line-height: 1.5;
  overflow-y: auto;
}

#code-editor::placeholder { color: #3a3a6a; }

#console-area {
  height: 30%;
  min-height: 100px;
  display: flex;
  flex-direction: column;
  border-top: 1px solid #2a2a4a;
}

#console-label {
  padding: 0.3rem 0.6rem;
  background: #12122a;
  border-bottom: 1px solid #2a2a4a;
  font-size: 0.7rem;
  color: #6070a0;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

#clear-console {
  background: none;
  border: none;
  color: #4a5a8a;
  cursor: pointer;
  font-size: 0.7rem;
  font-family: inherit;
  padding: 0;
}
#clear-console:hover { color: #8090c0; }

#console-output {
  flex: 1;
  overflow-y: auto;
  padding: 0.5rem;
  font-size: 0.78rem;
  line-height: 1.5;
}

.console-line { margin-bottom: 0.1rem; }
.console-error { color: #ff8080; }
.console-info { color: #80c0ff; }
.console-print { color: #c0ffc0; }

#examples-bar {
  padding: 0.3rem 0.5rem;
  background: #12122a;
  border-top: 1px solid #2a2a4a;
  display: flex;
  gap: 0.3rem;
  flex-wrap: wrap;
  flex-shrink: 0;
}

.example-btn {
  padding: 0.2rem 0.5rem;
  background: #1a1a3a;
  border: 1px solid #2a2a5a;
  color: #8090c0;
  border-radius: 3px;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.72rem;
  transition: background 0.1s;
}
.example-btn:hover { background: #252548; color: #a0b0d0; }

#cmdline-area {
  display: flex;
  border-top: 1px solid #2a2a4a;
  background: #0e0e22;
  flex-shrink: 0;
}

#cmdline {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: #c0e0ff;
  padding: 0.4rem 0.6rem;
  font-family: 'Courier New', monospace;
  font-size: 0.82rem;
}

#cmdline::placeholder { color: #3a3a5a; }

#cmd-run-btn {
  padding: 0.4rem 0.7rem;
  background: #1a3a2a;
  border: none;
  border-left: 1px solid #2a2a4a;
  color: #60d080;
  cursor: pointer;
  font-size: 0.82rem;
  font-family: inherit;
}
#cmd-run-btn:hover { background: #204a34; }

.btn-save {
  background: #1a2a4a;
  border-color: #2a4a8a;
  color: #80b0ff;
}
.btn-save:hover { background: #223360; border-color: #4060a0; }

.btn-gallery {
  background: #2a1a40;
  border-color: #5a2a8a;
  color: #c080ff;
}
.btn-gallery:hover { background: #361f50; border-color: #7040a0; }

.btn-download {
  background: #1a3a3a;
  border-color: #2a6a6a;
  color: #80e0e0;
}
.btn-download:hover { background: #224848; border-color: #40a0a0; }

/* ── Modals ─────────────────────────────────────────────────────────────────── */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.72);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
}

.modal-overlay.hidden { display: none; }

.modal-box {
  background: #12122a;
  border: 1px solid #3a3a6a;
  border-radius: 8px;
  padding: 1.4rem;
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
  width: min(340px, 90vw);
}

.modal-title {
  font-size: 0.95rem;
  color: #a0b0e0;
  letter-spacing: 0.06em;
}

#save-preview-img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  border: 1px solid #2a2a5a;
  border-radius: 4px;
  background: #0a0a1a;
  display: block;
}

#save-name {
  background: #0e0e22;
  border: 1px solid #3a3a6a;
  border-radius: 4px;
  color: #d0e0ff;
  padding: 0.5rem 0.6rem;
  font-family: 'Courier New', monospace;
  font-size: 0.85rem;
  outline: none;
  width: 100%;
}

#save-name:focus { border-color: #6080c0; }

.modal-btns {
  display: flex;
  gap: 0.5rem;
  justify-content: flex-end;
}

/* ── Gallery panel ──────────────────────────────────────────────────────────── */

#gallery-panel {
  background: #12122a;
  border: 1px solid #3a3a6a;
  border-radius: 8px;
  width: min(860px, 88vw);
  height: 78vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#gallery-header {
  padding: 0.65rem 1rem;
  border-bottom: 1px solid #2a2a4a;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-shrink: 0;
}

#gallery-title {
  color: #a0b0e0;
  font-size: 0.9rem;
  letter-spacing: 0.06em;
}

#gallery-close {
  background: none;
  border: none;
  color: #6070a0;
  cursor: pointer;
  font-size: 1rem;
  padding: 0;
  line-height: 1;
}

#gallery-close:hover { color: #c0d0ff; }

#gallery-grid {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 0.8rem;
  align-content: start;
}

#gallery-empty {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #4a5a8a;
  font-size: 0.82rem;
  text-align: center;
  padding: 2rem;
  line-height: 1.8;
}

#gallery-empty.hidden { display: none; }
#gallery-grid.hidden { display: none; }

.gallery-card {
  background: #1a1a36;
  border: 1px solid #2a2a5a;
  border-radius: 6px;
  overflow: hidden;
  transition: border-color 0.15s, transform 0.12s;
  display: flex;
  flex-direction: column;
}

.gallery-card:hover { border-color: #5060a0; transform: translateY(-2px); }

.gallery-card-thumb {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  display: block;
  background: #0a0a1a;
  cursor: pointer;
}

.gallery-card-info {
  padding: 0.35rem 0.5rem 0.2rem;
}

.gallery-card-name {
  font-size: 0.76rem;
  color: #c0d0ff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.gallery-card-date {
  font-size: 0.63rem;
  color: #4a5a8a;
  margin-top: 0.1rem;
}

.gallery-card-actions {
  display: flex;
  gap: 0.3rem;
  padding: 0.3rem 0.4rem 0.4rem;
  margin-top: auto;
}

.gallery-card-btn {
  flex: 1;
  padding: 0.2rem 0.3rem;
  font-size: 0.66rem;
  background: #1e1e40;
  border: 1px solid #3a3a6a;
  color: #a0b0d0;
  border-radius: 3px;
  cursor: pointer;
  font-family: 'Courier New', monospace;
  transition: background 0.1s;
}

.gallery-card-btn:hover { background: #2a2a58; }

.gallery-card-btn.delete {
  background: #3a1a1a;
  border-color: #6a2a2a;
  color: #e08080;
}

.gallery-card-btn.delete:hover { background: #4a2424; }
