/* ==========================================================================
   FarmScript — feuille de style unique.
   Aucune police distante, aucune image : tout est local.
   ========================================================================== */

:root {
  --bg: #10151c;
  --bg-panel: #18202a;
  --bg-sunken: #121922;
  --border: #26313f;
  --border-strong: #33415280;
  --text: #dde5ee;
  --text-dim: #8896a8;
  --accent: #6fd08c;
  --accent-dim: #2f6b45;
  --amber: #e8b04b;
  --blue: #6ba7e8;
  --red: #e8756b;
  --radius: 10px;
  --code-line-height: 22px;
  --font-ui: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-code: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

.app {
  height: 100%;
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 12px;
  padding: 12px;
  max-width: 1500px;
  margin: 0 auto;
}

/* ------------------------------------------------------------- barre haute */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 14px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.brand { display: flex; align-items: center; gap: 12px; }

.brand-mark {
  width: 26px;
  height: 20px;
  border-radius: 5px;
  background: var(--accent);
  position: relative;
  flex: none;
}
.brand-mark::before,
.brand-mark::after {
  content: "";
  position: absolute;
  top: 6px;
  width: 4px;
  height: 4px;
  background: var(--bg-panel);
}
.brand-mark::before { left: 6px; }
.brand-mark::after { right: 6px; }

.brand-text { display: flex; flex-direction: column; line-height: 1.25; }
.brand-text strong { font-size: 16px; letter-spacing: 0.3px; }
.brand-text span { color: var(--text-dim); font-size: 12px; }

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

/* --------------------------------------------------------------- panneaux */

.layout {
  display: grid;
  grid-template-columns: minmax(320px, 1fr) minmax(380px, 520px);
  gap: 12px;
  min-height: 0;
}

.panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  gap: 10px;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.panel-head h2 {
  margin: 0;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 1.4px;
  text-transform: uppercase;
  color: var(--text-dim);
}

.badge {
  font-family: var(--font-code);
  font-size: 11px;
  color: var(--text-dim);
  background: var(--bg-sunken);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 2px 10px;
}
.badge.is-running { color: var(--accent); border-color: var(--accent-dim); }
.badge.is-error { color: var(--red); border-color: #6b3a35; }

.canvas-wrap {
  flex: 1;
  min-height: 240px;
  display: grid;
  place-items: center;
  background: var(--bg-sunken);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}

#farm-canvas { display: block; }

.hint { margin: 0; color: var(--text-dim); font-size: 12px; }

/* --------------------------------------------------------------- éditeur */

.editor-shell {
  flex: 1;
  min-height: 200px;
  display: flex;
  background: var(--bg-sunken);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}

.gutter {
  flex: none;
  width: 44px;
  padding: 10px 8px 10px 0;
  overflow: hidden;
  text-align: right;
  font-family: var(--font-code);
  font-size: 13px;
  line-height: var(--code-line-height);
  color: #56637380;
  background: #0e141b;
  border-right: 1px solid var(--border);
  user-select: none;
}
.gutter div { height: var(--code-line-height); }
.gutter div.is-error { color: var(--red); font-weight: 700; }

.editor-area {
  position: relative;
  flex: 1;
  min-width: 0;
}

.highlight,
.editor-area textarea {
  margin: 0;
  padding: 10px 12px;
  font-family: var(--font-code);
  font-size: 13px;
  line-height: var(--code-line-height);
  tab-size: 4;
  white-space: pre;
  overflow: auto;
  border: 0;
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.highlight {
  pointer-events: none;
  color: var(--text);
  overflow: hidden;
}

.editor-area textarea {
  background: transparent;
  color: transparent;
  caret-color: var(--accent);
  resize: none;
  outline: none;
}
.editor-area textarea::selection { background: #35507080; }

.error-band {
  position: absolute;
  left: 0;
  right: 0;
  height: var(--code-line-height);
  background: #e8756b1f;
  border-left: 2px solid var(--red);
  pointer-events: none;
}

/* Coloration syntaxique — produite par notre propre analyseur. */
.tok-keyword { color: #d089e0; }
.tok-builtin { color: var(--blue); }
.tok-number  { color: var(--amber); }
.tok-string  { color: #8fd6a8; }
.tok-comment { color: #5b6b7d; font-style: italic; }
.tok-op      { color: #9aa8b8; }

/* ---------------------------------------------------------------- outils */

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

.btn {
  font: inherit;
  color: var(--text);
  background: #212c38;
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 7px 14px;
  cursor: pointer;
  transition: background 120ms ease, border-color 120ms ease;
}
.btn:hover:not(:disabled) { background: #2a3745; border-color: #3d4c5e; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-primary { background: var(--accent-dim); border-color: #3d8a5b; color: #eafff1; font-weight: 600; }
.btn-primary:hover:not(:disabled) { background: #377d51; }
.btn-ghost { background: transparent; }
.btn-danger { color: #ffdedb; background: #5c322e; border-color: #7a4540; }
.btn-small { padding: 3px 9px; font-size: 12px; }

.field {
  display: flex;
  align-items: center;
  gap: 7px;
  color: var(--text-dim);
  font-size: 12px;
}
.field-block { flex-direction: column; align-items: flex-start; width: 100%; }

select, input[type="number"] {
  font: inherit;
  color: var(--text);
  background: var(--bg-sunken);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 5px 8px;
}

/* -------------------------------------------------------- erreur, console */

.error-panel {
  display: flex;
  align-items: baseline;
  gap: 8px;
  flex-wrap: wrap;
  padding: 9px 12px;
  background: #3a201d;
  border: 1px solid #6b3a35;
  border-radius: 8px;
  font-size: 13px;
}
.error-panel strong { color: var(--red); }
.error-panel.is-info { background: #1b2a38; border-color: #2f4c66; }
.error-panel.is-info strong { color: var(--blue); }

.console {
  flex: none;
  height: 108px;
  overflow-y: auto;
  padding: 8px 10px;
  background: var(--bg-sunken);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-family: var(--font-code);
  font-size: 12px;
  color: var(--text-dim);
}
.console p { margin: 0 0 2px; white-space: pre-wrap; word-break: break-word; }
.console .log-print { color: var(--text); }
.console .log-good { color: var(--accent); }
.console .log-bad { color: var(--red); }

/* --------------------------------------------------------- autocomplétion */

.autocomplete {
  position: fixed;
  z-index: 60;
  min-width: 240px;
  max-width: 380px;
  max-height: 208px;
  overflow-y: auto;
  padding: 4px;
  background: #1b2530;
  border: 1px solid #3a4757;
  border-radius: 8px;
  box-shadow: 0 12px 32px #05080cbb;
  font-family: var(--font-code);
  font-size: 12px;
}
.autocomplete[hidden] { display: none; }

.ac-item {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 5px 8px;
  border-radius: 5px;
  cursor: pointer;
  white-space: nowrap;
}
.ac-item.is-active { background: #2f3f50; }
.ac-item:hover { background: #27343f; }

.ac-name { color: var(--blue); flex: none; }
.ac-item.is-keyword .ac-name { color: #d089e0; }
.ac-item.is-user .ac-name { color: var(--accent); }

.ac-detail {
  color: var(--text-dim);
  font-size: 11px;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ------------------------------------------------------------ ressources */

.resources {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  padding: 10px 14px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.resource {
  display: flex;
  align-items: baseline;
  gap: 7px;
  padding: 3px 12px 3px 0;
  border-right: 1px solid var(--border);
}
.resource:last-child { border-right: 0; }
.resource em {
  font-style: normal;
  font-size: 11px;
  letter-spacing: 0.8px;
  text-transform: uppercase;
  color: var(--text-dim);
}
.resource b { font-family: var(--font-code); font-size: 15px; }
.resource-wide b { font-size: 12px; color: var(--text-dim); font-weight: 500; }

/* -------------------------------------------------------------- dialogues */

.dialog {
  width: min(560px, 92vw);
  color: var(--text);
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}
.dialog::backdrop { background: #05080cc4; }
.dialog h3 { margin: 0 0 4px; font-size: 16px; }
.dialog-lead { margin: 0 0 14px; color: var(--text-dim); font-size: 12px; }
.dialog-actions { margin: 14px 0; }
.dialog form { margin-top: 16px; text-align: right; }

.entry {
  padding: 9px 0;
  border-top: 1px solid var(--border);
}
.entry:first-child { border-top: 0; }
.entry code {
  font-family: var(--font-code);
  color: var(--blue);
  font-size: 13px;
}
.entry p { margin: 2px 0 0; color: var(--text-dim); font-size: 12px; }
.entry.is-locked code { color: var(--text-dim); text-decoration: line-through; }

.shop-item {
  display: flex;
  align-items: center;
  gap: 12px;
  justify-content: space-between;
}
.shop-item .price { font-family: var(--font-code); color: var(--amber); }
.shop-item.is-owned .price { color: var(--accent); }

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .app { height: auto; }
  .panel-farm .canvas-wrap { min-height: 320px; }
}
