/* Terrain share viewer. Mirrors the app: near-white canvas, green accent,
   quiet chrome. */

:root {
  --green: #50A264;
  --ink: #1a1a1a;
  --muted: #71717a;
  --canvas-bg: #f7f7f7;
  --card-bg: #fcfcfc;
  --line: #e4e4e7;
}

* { box-sizing: border-box; }

/* display:flex on modal/panel would otherwise beat the hidden attribute. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: #fff;
}

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

.muted { color: var(--muted); }

/* --- Top bar --- */

.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--line);
}

.brand { display: flex; align-items: center; gap: 8px; font-weight: 650; }
.brand-dot {
  width: 12px; height: 12px; border-radius: 4px;
  background: var(--green);
}

.share-meta {
  flex: 1;
  display: flex;
  align-items: baseline;
  gap: 10px;
  min-width: 0;
}
#share-title { font-weight: 550; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#share-date { font-size: 13px; white-space: nowrap; }

.auth-area { display: flex; align-items: center; gap: 10px; font-size: 14px; }

/* --- Buttons --- */

.btn {
  font: inherit;
  font-size: 14px;
  padding: 6px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
  color: var(--ink);
}
.btn:hover { background: #fafafa; }
.btn-primary {
  background: var(--green);
  border-color: var(--green);
  color: #fff;
}
.btn-primary:hover { background: #47935a; }
.btn[disabled] { opacity: 0.5; cursor: default; }

.icon-btn {
  font: inherit;
  font-size: 18px;
  line-height: 1;
  border: none;
  background: none;
  color: var(--muted);
  cursor: pointer;
  padding: 4px;
}

/* --- Main --- */

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

.status {
  margin: auto;
  color: var(--muted);
  font-size: 15px;
  padding: 40px;
  text-align: center;
}

/* --- Chat transcript --- */

.chat-view {
  flex: 1;
  overflow-y: auto;
  padding: 28px 20px 60px;
  max-width: 760px;
  width: 100%;
  margin: 0 auto;
}

.msg { margin-bottom: 18px; }

.msg-user .msg-bubble {
  background: #f1f1f0;
  border-radius: 14px;
  padding: 10px 14px;
  margin-left: 15%;
}

.msg-assistant .msg-bubble { padding: 0 2px; }

.msg-bubble { font-size: 15px; line-height: 1.55; overflow-wrap: break-word; }
.msg-bubble p { margin: 0 0 10px; }
.msg-bubble p:last-child { margin-bottom: 0; }
.msg-bubble h1, .msg-bubble h2, .msg-bubble h3 { margin: 14px 0 8px; line-height: 1.3; }
.msg-bubble h1 { font-size: 20px; }
.msg-bubble h2 { font-size: 18px; }
.msg-bubble h3 { font-size: 16px; }
.msg-bubble pre {
  background: #f4f4f5;
  border-radius: 8px;
  padding: 10px 12px;
  overflow-x: auto;
  font-size: 13px;
}
.msg-bubble code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.9em;
  background: #f4f4f5;
  border-radius: 4px;
  padding: 1px 4px;
}
.msg-bubble pre code { background: none; padding: 0; }
.msg-bubble ul, .msg-bubble ol { margin: 0 0 10px; padding-left: 22px; }

.msg-attachments {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 6px 15% 6px 0;
  justify-content: flex-end;
}
.msg-assistant .msg-attachments { justify-content: flex-start; margin-right: 0; }
.msg-attachments img {
  max-width: 220px;
  max-height: 220px;
  border-radius: 10px;
  border: 1px solid var(--line);
}
.attachment-pdf {
  font-size: 13px;
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 12px;
  text-decoration: none;
  background: var(--card-bg);
}

/* --- Canvas --- */

.canvas-view {
  flex: 1;
  min-height: 0;
  position: relative;
  background: var(--canvas-bg);
  overflow: hidden;
}

#canvas-svg { display: block; cursor: grab; touch-action: none; }
#canvas-svg.panning { cursor: grabbing; }

.node-card { cursor: pointer; }
.node-card.static { cursor: default; }

.branch-panel {
  position: absolute;
  top: 0; right: 0; bottom: 0;
  width: min(420px, 90%);
  background: #fff;
  border-left: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  box-shadow: -8px 0 24px rgba(0, 0, 0, 0.06);
}
.branch-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  font-weight: 550;
}
.branch-panel .chat-view { padding: 20px 16px 40px; }

/* --- Auth modal --- */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.25);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
}
.modal {
  position: relative;
  background: #fff;
  border-radius: 14px;
  padding: 26px;
  width: 360px;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.18);
}
.modal h2 { margin: 0 0 6px; font-size: 18px; }
.modal .muted { font-size: 14px; margin: 0 0 14px; }
.modal input {
  font: inherit;
  width: 100%;
  padding: 8px 10px;
  margin-bottom: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
}
.modal .btn { width: 100%; }
.modal-close { position: absolute; top: 12px; right: 12px; }
.auth-error { color: #dc2626; font-size: 13px; margin: 10px 0 0; }

.footer {
  padding: 10px 20px;
  font-size: 12px;
  border-top: 1px solid var(--line);
}
.footer a { color: var(--green); }
