:root {
  --bg: #0d1117;
  --s1: #161c24;
  --s2: #1d2838;
  --ln: #1e2d3d;
  --ln2: #2c4056;
  --tx: #d8e8f5;
  --mt: #5a7a95;
  --ac: #c89a35;
  --ac2: #e8b84a;
  --ok: #3dbe8a;
  --er: #e05555;
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root {
    --bg: #f0f4f8;
    --s1: #ffffff;
    --s2: #e4ecf4;
    --ln: #c0d0e0;
    --ln2: #90aacc;
    --tx: #1a2636;
    --mt: #507090;
    color-scheme: light;
  }
}
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  background: var(--bg);
  color: var(--tx);
  font: 14px/1.55 system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--ac); outline-offset: 2px; }
button, input, textarea { font: inherit; color: inherit; }

/* ── Buttons ── */
.btn {
  display: inline-flex; align-items: center; gap: .35rem;
  padding: .38rem .75rem;
  background: var(--s1); border: 1px solid var(--ln2); border-radius: 5px;
  cursor: pointer; text-decoration: none; font-size: 13px; white-space: nowrap;
  transition: border-color .12s, background .12s;
}
.btn:hover { background: var(--s2); border-color: var(--ac); }
.btn.primary { background: var(--ac); color: #140f00; border-color: var(--ac); font-weight: 600; }
.btn.primary:hover { background: var(--ac2); }
.link { background: none; border: none; color: var(--mt); cursor: pointer; font-size: 13px; }
.link:hover { color: var(--tx); }
.fine { color: var(--mt); font-size: 12px; line-height: 1.6; }

/* ── Login ── */
#login {
  min-height: 100%;
  display: grid; place-items: center; padding: 2rem;
  background:
    radial-gradient(ellipse 70% 50% at 50% -5%, rgba(200,154,53,.13) 0%, transparent 65%),
    var(--bg);
}
.login-card { max-width: 440px; text-align: center; }
.login-logo {
  font-family: Georgia, "Iowan Old Style", serif;
  font-size: 2.8rem; letter-spacing: -.5px;
  color: var(--ac); line-height: 1.1; margin-bottom: .2rem;
}
.login-tagline {
  font-size: .78rem; color: var(--mt);
  text-transform: uppercase; letter-spacing: 3.5px;
  margin-bottom: 2rem;
}
.login-desc {
  color: var(--mt); font-size: .9rem; line-height: 1.75;
  margin-bottom: 2rem; max-width: 340px; margin-inline: auto;
}
.login-card .btn.primary { padding: .65rem 2.2rem; font-size: .95rem; border-radius: 7px; }

/* ── App Shell ── */
#app { height: 100%; display: flex; flex-direction: column; }
header {
  height: 48px; display: flex; align-items: center; gap: .8rem;
  padding: 0 1rem; border-bottom: 1px solid var(--ln);
  flex-shrink: 0; background: var(--s1);
}
.brand {
  font-family: Georgia, "Iowan Old Style", serif;
  font-size: 1.1rem; color: var(--ac); margin-right: auto;
}
.tabs { display: none; gap: .15rem; }
.tabs button {
  background: none; border: 1px solid transparent; border-radius: 5px;
  padding: .28rem .55rem; cursor: pointer; font-size: 13px; color: var(--mt);
}
.tabs button.on { border-color: var(--ac); color: var(--ac); }
#who { font-size: 13px; color: var(--mt); }

/* ── Main Layout ── */
main {
  flex: 1; min-height: 0;
  display: grid; grid-template-columns: 210px minmax(0,1fr) 370px;
}
.pane { overflow: auto; min-height: 0; }

/* ── Projects Sidebar ── */
#projects {
  border-right: 1px solid var(--ln); padding: .8rem;
  display: flex; flex-direction: column; gap: .7rem;
}
#newform { display: flex; gap: .4rem; }
#newname {
  flex: 1; min-width: 0;
  background: var(--bg); border: 1px solid var(--ln2); border-radius: 5px;
  padding: .38rem .6rem; font-size: 13px;
}
#newname:focus { border-color: var(--ac); outline: none; }
#plist { list-style: none; display: flex; flex-direction: column; gap: .2rem; }
#plist li {
  display: flex; align-items: center; gap: .45rem;
  padding: .48rem .6rem; border-radius: 5px; cursor: pointer;
  border: 1px solid transparent;
}
#plist li:hover { background: var(--s2); }
#plist li.on { background: var(--s1); border-color: var(--ln); box-shadow: inset 3px 0 0 var(--ac); }
.pdot {
  width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0;
  background: var(--ln2);
}
.pdot.building {
  background: var(--ac);
  box-shadow: 0 0 5px var(--ac);
  animation: pulse 1.3s ease-in-out infinite;
}
.pdot.done { background: var(--ok); }
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:.3} }
.pname { flex: 1; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#plist .del {
  background: none; border: none; color: var(--mt); cursor: pointer;
  opacity: 0; font-size: 15px; padding: 0 2px; line-height: 1;
}
#plist li:hover .del { opacity: 1; }

/* ── Chat ── */
#chat {
  display: flex; flex-direction: column; background: var(--bg);
}
#log {
  flex: 1; overflow-y: auto; padding: 1.2rem 1rem;
  display: flex; flex-direction: column; gap: .8rem;
}
.empty {
  color: var(--mt); text-align: center;
  padding: 3.5rem 1.5rem; font-size: .9rem; line-height: 1.9;
}
.msg {
  max-width: 70%; line-height: 1.6;
  padding: .55rem .85rem; border-radius: 8px;
  font-size: 14px; white-space: pre-wrap; overflow-wrap: anywhere;
}
.msg.user {
  align-self: flex-end;
  background: var(--s2); border: 1px solid var(--ln2);
  border-bottom-right-radius: 2px;
}
.msg.assistant {
  align-self: flex-start;
  border-left: 3px solid var(--ac);
  padding-left: .8rem;
  background: transparent;
}
.msg.assistant[data-loading]::after {
  content: "●  ●  ●";
  color: var(--mt); font-size: .82em; letter-spacing: 4px;
  animation: blink 1.3s steps(1) infinite;
}
@keyframes blink {
  0%,100% { color: var(--mt); }
  33%      { color: var(--ac); }
  66%      { color: var(--mt); }
}

#progress {
  margin: 0 1rem .6rem;
  background: #060b10; border: 1px solid var(--ln); border-radius: 6px;
  padding: .55rem .8rem;
  font-family: "Cascadia Code", "Fira Code", ui-monospace, "Courier New", monospace;
  font-size: 12px; line-height: 1.65;
  max-height: 9rem; overflow-y: auto; color: #7aaac8;
}
#progress .error { color: var(--er); }
#progress .done  { color: var(--ok); }
#progress .info  { color: var(--mt); }

#cform {
  padding: .7rem .9rem; border-top: 1px solid var(--ln);
  display: flex; gap: .55rem; align-items: flex-end;
  background: var(--s1); flex-shrink: 0;
}
#cinput {
  flex: 1; resize: none; min-height: 2.6rem; max-height: 10rem;
  background: var(--bg); border: 1px solid var(--ln2); border-radius: 7px;
  padding: .5rem .75rem; font-size: 14px; line-height: 1.5;
}
#cinput:focus { border-color: var(--ac); outline: none; }

/* ── Preview ── */
#preview {
  border-left: 1px solid var(--ln); background: var(--s1);
  padding: .9rem; display: flex; flex-direction: column; gap: .7rem;
  overflow-y: auto;
}
.pv-head { display: flex; justify-content: space-between; align-items: baseline; }
.pv-head h2 { font-family: Georgia, serif; font-size: 1rem; }
.score-big {
  font-family: Georgia, "Iowan Old Style", serif;
  font-size: 1.9rem; color: var(--ac); line-height: 1;
}
#map {
  width: 100%; height: auto; display: block;
  background: var(--bg); border: 1px solid var(--ln); border-radius: 6px;
}
.legend {
  display: flex; flex-wrap: wrap; gap: .4rem .8rem;
  font-size: 12px; color: var(--mt);
}
.legend i {
  display: inline-block; width: 8px; height: 8px;
  border-radius: 2px; margin-right: 3px; vertical-align: -1px;
}
.k-start   { background: #3dbe8a; }
.k-combat  { background: #5a7a95; }
.k-treasure{ background: #c89a35; }
.k-boss    { background: #e05555; }

h3 {
  font-size: .75rem; text-transform: uppercase;
  letter-spacing: 1.2px; color: var(--mt); margin: .2rem 0 .4rem;
}
.bar {
  display: grid; grid-template-columns: 6rem 1fr 2.5rem;
  gap: .4rem; align-items: center;
  font-size: 12px; color: var(--mt); margin-bottom: .28rem;
}
.track { height: 5px; background: var(--ln); border-radius: 3px; }
.fill  { height: 100%; background: var(--ac); border-radius: 3px; }

#checks { list-style: none; font-size: 12px; display: flex; flex-direction: column; gap: .18rem; }
#checks li.ok::before { content: "✓  "; color: var(--ok); }
#checks li.no::before { content: "✗  "; color: var(--er); }
#checks small { color: var(--mt); }
#note { font-size: 11px; color: var(--mt); line-height: 1.55; }

#builds { list-style: none; display: flex; flex-direction: column; gap: .45rem; }
#builds li {
  border: 1px solid var(--ln); border-radius: 6px;
  padding: .6rem .7rem; background: var(--bg);
}
#builds .bhead {
  display: flex; justify-content: space-between;
  align-items: center; margin-bottom: .2rem;
}
#builds .bhead strong { font-size: 13px; }
.bstatus { font-size: 11px; color: var(--mt); }
.bstatus.done { color: var(--ok); }
.bstatus.failed { color: var(--er); }
.bprompt {
  font-size: 12px; color: var(--mt); margin-bottom: .38rem;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.brow { display: flex; flex-wrap: wrap; gap: .28rem; }

/* ── Mobile ── */
@media (max-width: 960px) {
  main { display: block; }
  .tabs { display: flex; }
  .pane { display: none !important; height: calc(100dvh - 48px); }
  .pane.on { display: flex !important; flex-direction: column; }
  #chat.on { display: flex !important; }
  #projects.on, #preview.on { display: block !important; overflow: auto; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

.bar div.t{height:5px;background:var(--ln);border-radius:3px}
.bar div.t b{display:block;height:100%;background:var(--ac);border-radius:3px}
.score{font:1.8rem Georgia,serif;color:var(--ac)}
#builds .row{display:flex;gap:.35rem;flex-wrap:wrap;margin-top:.4rem}
#plist li>span:first-child{flex:1;min-width:0;overflow-wrap:anywhere}
#plist .st{font-size:12px;color:var(--ac)}
#plist .del:focus-visible{opacity:1}
@media(hover:none){#plist .del{opacity:1}}
:root{--mt:#93a8bc}
@media(prefers-color-scheme:light){:root{--mt:#4a627a}}
[hidden]{display:none!important}
