* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: #1e1e1e;
  color: #d4d4d4;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

body {
  display: flex;
  flex-direction: column;
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  padding: 10px 16px;
  background: #252526;
  border-bottom: 1px solid #3c3c3c;
}

header h1 {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 600;
}

.controls {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

select, button {
  font: inherit;
  padding: 6px 12px;
  border-radius: 4px;
  border: 1px solid #3c3c3c;
  background: #2d2d2d;
  color: #d4d4d4;
  cursor: pointer;
}

button:hover:not(:disabled), select:hover { background: #383838; }
button:disabled { opacity: 0.45; cursor: default; }

#run { background: #0e639c; border-color: #0e639c; color: #fff; }
#run:hover:not(:disabled) { background: #1177bb; }

main {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1px;
  background: #3c3c3c;
  min-height: 0;
}

@media (max-width: 800px) {
  main { grid-template-columns: 1fr; grid-template-rows: 1fr 1fr; }
}

.pane {
  display: flex;
  flex-direction: column;
  background: #1e1e1e;
  min-height: 0;
  min-width: 0;
}

.pane-title {
  padding: 6px 12px;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #9da0a6;
  background: #252526;
  border-bottom: 1px solid #3c3c3c;
}

textarea {
  flex: 1;
  width: 100%;
  margin: 0;
  padding: 12px;
  border: none;
  outline: none;
  resize: none;
  background: #1e1e1e;
  color: #d4d4d4;
  font-family: "Fira Code", Consolas, "Courier New", monospace;
  font-size: 14px;
  line-height: 1.5;
  tab-size: 4;
}

#input {
  flex: 0 0 110px;
  border-bottom: 1px solid #3c3c3c;
}

#terminal {
  flex: 1;
  margin: 0;
  padding: 12px;
  overflow: auto;
  background: #0c0c0c;
  color: #cccccc;
  font-family: "Fira Code", Consolas, "Courier New", monospace;
  font-size: 14px;
  line-height: 1.4;
  white-space: pre-wrap;
  word-break: break-word;
}

#terminal .err { color: #f48771; }
#terminal .sys { color: #6a9955; font-style: italic; }

#status {
  padding: 4px 12px;
  font-size: 0.8rem;
  color: #9da0a6;
  min-height: 1.4em;
  border-top: 1px solid #3c3c3c;
}

/* Pagina di login */
body.login-page {
  align-items: center;
  justify-content: center;
}

.login-box {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: min(340px, 90vw);
  padding: 24px;
  background: #252526;
  border: 1px solid #3c3c3c;
  border-radius: 6px;
}

.login-box h1 { margin: 0 0 4px; font-size: 1.1rem; }

.login-box label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.85rem;
  color: #9da0a6;
}

.login-box input {
  font: inherit;
  padding: 8px;
  background: #1e1e1e;
  color: #d4d4d4;
  border: 1px solid #3c3c3c;
  border-radius: 4px;
}

.login-box button { margin-top: 4px; }

.login-error { margin: 0; color: #f48771; font-size: 0.9rem; }

.logout { color: #9da0a6; text-decoration: none; padding: 6px 12px; border: 1px solid #3c3c3c; border-radius: 4px; }
.logout:hover { background: #383838; }

/* Editor con evidenziazione sintassi: textarea trasparente sopra un livello colorato */
.code-wrap {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

#hl, #code {
  font-family: "Fira Code", Consolas, "Courier New", monospace;
  font-size: 14px;
  line-height: 1.5;
  tab-size: 4;
  padding: 12px;
  margin: 0;
  border: none;
  white-space: pre;
  word-wrap: normal;
}

#hl {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  background: #1e1e1e;
  color: #d4d4d4;
}

#code {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: auto;
  background: transparent;
  color: transparent;
  caret-color: #d4d4d4;
  z-index: 1;
}

.tk-com { color: #6a9955; font-style: italic; }
.tk-str { color: #ce9178; }
.tk-num { color: #b5cea8; }
.tk-kw  { color: #569cd6; }
.tk-ctl { color: #c586c0; }
.tk-fn  { color: #dcdcaa; }
.tk-pre { color: #c586c0; }
