:root {
  --editor-font-size: 16px;
  --header-bg: linear-gradient(135deg, #7f52ff 0%, #c711e1 55%, #e44857 100%);
  --run-green: #21bf5b;
  --run-green-dark: #189c49;
  --console-bg: #1e1f29;
  --console-fg: #e6e6ef;
  --error-red: #d33c30;
  --warn-yellow: #b78103;
  --accent: #7f52ff;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: #f4f4f8;
}

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

/* ---------- login overlay ---------- */

.login-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--header-bg);
}

.login-card {
  background: white;
  border-radius: 18px;
  padding: 34px 38px;
  width: min(400px, 92vw);
  box-shadow: 0 12px 40px rgba(0,0,0,.35);
  display: flex;
  flex-direction: column;
  gap: 12px;
  text-align: center;
}

.login-logo { font-size: 30px; font-weight: 800; }
.login-tagline { margin: 0 0 6px; color: #666; }

.login-card input {
  font-size: 16px;
  padding: 11px 14px;
  border: 2px solid #ddd;
  border-radius: 10px;
}

.login-card input:focus { outline: none; border-color: var(--accent); }

.login-card button {
  font-size: 17px;
  font-weight: 700;
  padding: 12px;
  border: none;
  border-radius: 10px;
  background: var(--run-green);
  color: white;
  cursor: pointer;
}

.login-card button:hover { background: var(--run-green-dark); }

.login-hint { margin: 4px 0 0; font-size: 13px; color: #777; }
.login-msg { margin: 0; font-size: 14px; font-weight: 600; color: var(--error-red); min-height: 18px; }
.login-msg.ok { color: #1a8f47; }

/* ---------- header ---------- */

header {
  background: var(--header-bg);
  color: white;
  padding: 10px 16px 12px;
  box-shadow: 0 2px 8px rgba(0,0,0,.25);
  z-index: 10;
}

.brand {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 8px;
}

.logo { font-size: 22px; }
.title { font-size: 20px; font-weight: 800; letter-spacing: .5px; }
.subtitle { font-size: 13px; opacity: .85; font-weight: 500; }

.user-chip {
  font-size: 13px;
  font-weight: 600;
  background: rgba(255,255,255,.2);
  padding: 4px 12px;
  border-radius: 12px;
}

.logout-btn {
  font-size: 12px;
  font-weight: 600;
  border: 1px solid rgba(255,255,255,.5);
  background: transparent;
  color: white;
  padding: 4px 10px;
  border-radius: 10px;
  cursor: pointer;
}

.logout-btn:hover { background: rgba(255,255,255,.15); }

.toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.toolbar .spacer, .tab-bar .spacer, .brand .spacer { flex: 1; }

.toolbar button, .toolbar select {
  font-size: 14px;
  font-weight: 600;
  padding: 7px 12px;
  border: none;
  border-radius: 8px;
  background: rgba(255,255,255,.92);
  color: #333;
  cursor: pointer;
  transition: transform .06s, background .15s;
}

.toolbar button:hover, .toolbar select:hover { background: #fff; }
.toolbar button:active { transform: scale(.96); }

.run-btn {
  background: var(--run-green) !important;
  color: white !important;
  font-size: 15px !important;
  padding: 8px 22px !important;
  box-shadow: 0 2px 6px rgba(0,0,0,.25);
}

.run-btn:hover { background: var(--run-green-dark) !important; }
.run-btn:disabled {
  background: #8fd8ab !important;
  cursor: wait;
  transform: none !important;
}

.play-icon { font-size: 12px; margin-right: 2px; }

.small-btn { padding: 7px 10px !important; }

/* ---------- layout ---------- */

main {
  flex: 1;
  display: flex;
  min-height: 0;
}

/* ---------- sidebar ---------- */

.sidebar {
  width: 210px;
  flex: none;
  background: #edeaf6;
  border-right: 2px solid #ddd6f0;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  font-size: 14px;
  font-weight: 700;
  color: #4a3d75;
}

.sidebar-head button {
  border: none;
  background: var(--accent);
  color: white;
  width: 24px;
  height: 24px;
  border-radius: 7px;
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
}

.sidebar-head button:hover { background: #6a3fe0; }

.file-list { flex: 1; overflow-y: auto; padding: 0 8px 12px; }

.file-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 10px;
  border-radius: 8px;
  font-size: 14px;
  color: #333;
  cursor: pointer;
  margin-bottom: 2px;
}

.file-row:hover { background: #e0d9f3; }

.file-row.active {
  background: white;
  font-weight: 700;
  color: #4a3d75;
  box-shadow: 0 1px 3px rgba(0,0,0,.12);
}

.file-row .fname {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-row .file-btn {
  flex: none;
  border: none;
  background: transparent;
  font-size: 12px;
  cursor: pointer;
  opacity: 0;
  padding: 2px;
}

.file-row:hover .file-btn { opacity: .55; }
.file-row .file-btn:hover { opacity: 1; }

.file-empty { padding: 14px 10px; font-size: 13px; color: #777; }

/* ---------- work area ---------- */

.work-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}

.editor-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 14px;
  background: #fbfaff;
  border-bottom: 1px solid #e8e4f5;
  font-size: 13px;
}

.current-file { font-weight: 700; color: #4a3d75; }
.save-state { color: #999; font-weight: 500; }
.save-state.saved { color: #1a8f47; }

.editor-pane {
  flex: 1 1 58%;
  min-height: 120px;
  display: flex;
}

.editor-pane .CodeMirror {
  flex: 1;
  height: auto;
  font-family: "SF Mono", Menlo, Consolas, monospace;
  font-size: var(--editor-font-size);
  line-height: 1.5;
}

.cm-flash-line { background: #ffe9a8 !important; }
.cm-problem-line { background: #ffe2e0; }

/* ---------- bottom pane ---------- */

.bottom-pane {
  flex: 1 1 42%;
  min-height: 140px;
  display: flex;
  flex-direction: column;
  border-top: 2px solid #ddd;
  background: white;
}

.tab-bar {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 4px 8px 0;
  background: #ececf2;
}

.tab {
  border: none;
  background: transparent;
  font-size: 13px;
  font-weight: 600;
  color: #555;
  padding: 8px 14px;
  border-radius: 8px 8px 0 0;
  cursor: pointer;
}

.tab:hover { background: #e0e0ea; }
.tab.active { background: white; color: #222; }

.badge {
  display: inline-block;
  min-width: 18px;
  padding: 1px 5px;
  border-radius: 9px;
  background: var(--error-red);
  color: white;
  font-size: 11px;
  text-align: center;
}

.badge.warn { background: var(--warn-yellow); }

.status {
  font-size: 13px;
  font-weight: 600;
  color: #555;
  padding-right: 8px;
  white-space: nowrap;
}

.status.busy::before {
  content: "";
  display: inline-block;
  width: 11px;
  height: 11px;
  margin-right: 6px;
  border: 2px solid #999;
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin .7s linear infinite;
  vertical-align: -1px;
}

.status.ok { color: #1a8f47; }
.status.err { color: var(--error-red); }

@keyframes spin { to { transform: rotate(360deg); } }

.tab-body {
  flex: 1;
  min-height: 0;
  overflow: auto;
}

/* console */

.console {
  background: var(--console-bg);
  padding: 12px 14px;
}

.console pre {
  margin: 0;
  font-family: "SF Mono", Menlo, Consolas, monospace;
  font-size: calc(var(--editor-font-size) - 1px);
  line-height: 1.45;
  color: var(--console-fg);
  white-space: pre-wrap;
  word-break: break-word;
}

.console .meta { color: #8a8fa8; }
.console .err-text { color: #ff7b6e; }

/* problems */

.problem-list { padding: 6px; }

.problem-row {
  display: flex;
  gap: 10px;
  align-items: baseline;
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
}

.problem-row:hover { background: #f3f0ff; }

.problem-row .icon { flex: none; }

.problem-row .loc {
  flex: none;
  font-weight: 700;
  color: var(--accent);
  font-family: Menlo, monospace;
  font-size: 13px;
}

.problem-row .msg { color: #333; }
.problem-row.warning .loc { color: var(--warn-yellow); }

.empty-note {
  padding: 18px;
  color: #777;
  font-size: 14px;
}

/* input tab */

.input-pane {
  display: flex;
  flex-direction: column;
  padding: 10px 14px;
  gap: 8px;
}

.input-hint {
  margin: 0;
  font-size: 13px;
  color: #666;
}

.input-hint code {
  background: #eee;
  padding: 1px 5px;
  border-radius: 4px;
}

#stdin {
  flex: 1;
  min-height: 60px;
  resize: none;
  border: 1px solid #ccc;
  border-radius: 8px;
  padding: 8px 10px;
  font-family: Menlo, monospace;
  font-size: 14px;
}

#stdin:focus { outline: 2px solid var(--accent); border-color: transparent; }

.hidden { display: none !important; }

/* small screens (Chromebooks are ~1366x768; this is fine, but be graceful) */
@media (max-width: 760px) {
  .sidebar { width: 160px; }
}
