/* dou.sinluke.com — editorial craft style (see design1.png / design2.png):
   cream paper + faint grid, ink borders, bold condensed uppercase type,
   coral red + teal accents, dark header bar. */

:root {
  --paper: #faf7f2;
  --paper-2: #f3efe7;
  --ink: #141414;
  --ink-soft: #55524c;
  --line: #e4ded2;
  --red: #e14b4b;
  --teal: #1f7a72;
  --teal-bright: #3fd0c4;
  --border: 2px solid var(--ink);
  --mono: ui-monospace, "SF Mono", Menlo, monospace;
  --sans: -apple-system, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  font-family: var(--sans);
  background: var(--paper);
  background-image:
    linear-gradient(var(--line) 1px, transparent 1px),
    linear-gradient(90deg, var(--line) 1px, transparent 1px);
  background-size: 56px 56px;
  color: var(--ink);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  height: 100dvh;
}

.panel-title {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ink);
}

/* ---------- header ---------- */
#topbar {
  height: 52px;
  flex: none;
  background: #101010;
  color: #f5f2ec;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 14px;
  border-bottom: 3px solid #000;
}
.brand {
  font-weight: 900;
  letter-spacing: 0.14em;
  font-size: 15px;
  color: var(--teal-bright);
  display: flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
  overflow: hidden;
}
.brand .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--teal-bright); flex: none; }
.brand-dim { color: #8b877f; font-weight: 700; }
.brand-sub {
  font-size: 10px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: #6f6b64;
  font-weight: 700;
  margin-left: 6px;
}
.actions { margin-left: auto; display: flex; gap: 8px; }
.hbtn {
  font: 700 11px/1 var(--sans);
  letter-spacing: 0.16em;
  text-transform: uppercase;
  background: transparent;
  color: #f5f2ec;
  border: 1px solid #4a4740;
  padding: 8px 12px;
  cursor: pointer;
}
.hbtn:hover { border-color: #f5f2ec; }
.hbtn.balance { font-family: var(--mono); font-weight: 700; letter-spacing: 0.04em; }
.hbtn.balance.low { border-color: #d99a2b; color: #f0c674; }
.hbtn.balance.empty { background: var(--red); border-color: var(--red); color: #fff; }
#creditBody { padding: 16px; font-size: 13.5px; line-height: 1.55; }
#creditBody .credit-bar { height: 10px; border: 1px solid var(--ink); background: #fff; margin: 12px 0 6px; }
#creditBody .credit-fill { height: 100%; background: var(--red); }
#creditBody .credit-nums { display: flex; justify-content: space-between; font: 11px var(--mono); color: var(--ink-soft); }
#creditBody .credit-note {
  margin-top: 14px; padding: 10px 12px; border-left: 4px solid var(--teal); background: var(--paper-2); font-size: 12.5px;
}
.hbtn-accent { background: var(--red); border-color: var(--red); }
.hbtn-accent:hover { background: #c93d3d; }
.iconbtn {
  background: transparent;
  border: none;
  color: inherit;
  font-size: 18px;
  cursor: pointer;
  padding: 6px 8px;
}
#trayBtn { display: none; }

/* ---------- layout ---------- */
#layout {
  flex: 1;
  display: grid;
  grid-template-columns: 250px 1fr 380px;
  min-height: 0;
}

/* ---------- sidebar ---------- */
#sidebar {
  border-right: var(--border);
  background: var(--paper);
  padding: 16px 14px;
  overflow-y: auto;
}
/* ---------- sidebar identity ---------- */
/* the wordmark lives in the header on desktop, at the top of the tray on mobile */
.sidebar-brand {
  display: none;
  align-items: center;
  gap: 8px;
  font-weight: 900;
  letter-spacing: 0.14em;
  font-size: 13px;
  color: var(--teal);
  margin-bottom: 14px;
}
.sidebar-brand .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--teal); flex: none; }
.sidebar-brand .brand-dim { color: var(--ink-soft); font-weight: 700; }

.profile-card {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  text-align: left;
  border: 1px solid var(--ink);
  background: #fff;
  padding: 8px 10px;
  margin-bottom: 18px;
  cursor: pointer;
  font: inherit;
}
.profile-card:hover { background: var(--paper-2); }
.profile-card img, .profile-card .pc-avatar {
  width: 32px; height: 32px; flex: none;
  border: 1px solid var(--ink); object-fit: cover; background: var(--paper-2);
  display: flex; align-items: center; justify-content: center; font-size: 16px;
}
.pc-text { min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.pc-name {
  font-size: 12px; font-weight: 700;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.pc-balance { font: 700 11px var(--mono); color: var(--teal); }
.pc-balance.low { color: #b07d16; }
.pc-balance.empty { color: var(--red); }

/* ---------- board switcher ---------- */
.panel-head { display: flex; align-items: center; justify-content: space-between; }
.mini-btn {
  border: 1px solid var(--ink);
  background: #fff;
  width: 22px; height: 22px;
  font: 700 14px/1 var(--sans);
  cursor: pointer;
}
.mini-btn:hover { background: var(--ink); color: #fff; }
#boardList { margin-top: 8px; display: flex; flex-direction: column; gap: 4px; max-height: 32vh; overflow-y: auto; }
.board-item {
  display: flex; align-items: center; gap: 8px;
  border: 1px solid var(--line);
  background: #fff;
  padding: 6px 8px;
  cursor: pointer;
}
.board-item:hover { border-color: var(--ink); }
.board-item.active { border-color: var(--ink); border-left: 4px solid var(--red); background: var(--paper-2); }
.board-item .b-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--line); flex: none; }
.board-item.active .b-dot { background: var(--red); }
.board-item .b-main { min-width: 0; flex: 1; }
.board-item .b-name { font-size: 12px; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.board-item .b-meta { font: 10px var(--mono); color: var(--ink-soft); }
.board-item .b-del { border: none; background: none; cursor: pointer; color: var(--ink-soft); font-size: 12px; padding: 2px 4px; }
.board-item .b-del:hover { color: var(--red); }

/* ---------- profile ---------- */
#profileBody { overflow-y: auto; padding: 14px; }
.prof-id { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; }
.prof-id img, .prof-avatar {
  width: 46px; height: 46px; border: 2px solid var(--ink); object-fit: cover;
  display: flex; align-items: center; justify-content: center; font-size: 22px; background: #fff;
}
.prof-name { font-weight: 800; font-size: 15px; }
.prof-email { font: 11px var(--mono); color: var(--ink-soft); }
.prof-spend { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 16px; }
.prof-spend > div { border: 1px solid var(--ink); background: #fff; padding: 8px 10px; }
.prof-spend strong { display: block; font-size: 20px; font-weight: 900; }
.prof-label { font: 700 9px var(--sans); letter-spacing: 0.16em; text-transform: uppercase; color: var(--ink-soft); }
.prof-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.prof-table th {
  text-align: left; font: 700 9px var(--sans); letter-spacing: 0.14em; text-transform: uppercase;
  color: var(--ink-soft); border-bottom: 1px solid var(--ink); padding: 4px 6px;
}
.prof-table td { padding: 5px 6px; border-bottom: 1px dashed var(--line); }
.prof-table .num, .prof-table th.num { text-align: right; }
.prof-table .mono { font: 11px var(--mono); }
.prof-empty { font-size: 12px; color: var(--ink-soft); padding: 10px 0; }
.prof-signout {
  margin-top: 16px; width: 100%;
  border: var(--border); background: #fff; cursor: pointer;
  font: 800 11px var(--sans); letter-spacing: 0.14em; text-transform: uppercase; padding: 10px;
}
.prof-signout:hover { background: var(--red); color: #fff; border-color: var(--red); }

/* ---------- login gate ---------- */
#loginGate {
  position: fixed; inset: 0; z-index: 60;
  background: var(--paper);
  background-image: linear-gradient(var(--line) 1px, transparent 1px), linear-gradient(90deg, var(--line) 1px, transparent 1px);
  background-size: 56px 56px;
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.login-card {
  border: var(--border); background: #fff; padding: 32px 28px;
  max-width: 420px; width: 100%;
  box-shadow: 8px 8px 0 rgba(20, 20, 20, 0.15);
}
.login-brand { font-weight: 900; letter-spacing: 0.14em; font-size: 14px; color: var(--teal); display: flex; align-items: center; gap: 8px; }
.login-brand .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--teal); }
.login-card h1 { font-size: 30px; font-weight: 900; line-height: 1.05; margin: 14px 0 10px; text-transform: uppercase; }
.login-card p { font-size: 13.5px; line-height: 1.5; color: var(--ink-soft); margin-bottom: 22px; }
.google-btn {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  width: 100%; padding: 12px; cursor: pointer;
  border: var(--border); background: #fff;
  font: 800 12px var(--sans); letter-spacing: 0.1em; text-transform: uppercase;
}
.google-btn:hover { background: var(--ink); color: #fff; }

#dropzone {
  margin-top: 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 20px 10px;
  border: 2px dashed var(--ink);
  cursor: pointer;
  text-align: center;
  background: var(--paper);
}
#dropzone.dragover { background: #eef7f5; border-color: var(--teal); }
#dropzone strong { font-size: 12px; text-transform: uppercase; letter-spacing: 0.1em; }
.dz-icon { font-size: 18px; }
.dz-hint { font-size: 10px; color: var(--ink-soft); letter-spacing: 0.08em; }
#assetList { margin-top: 10px; display: flex; flex-direction: column; gap: 8px; }
.asset {
  display: flex;
  gap: 10px;
  align-items: center;
  border: 1px solid var(--ink);
  background: #fff;
  padding: 6px;
  cursor: pointer;
}
.asset:hover { outline: 2px solid var(--teal); }
.asset img { width: 44px; height: 44px; object-fit: cover; border: 1px solid var(--line); background: var(--paper-2); }
.asset .a-name { font-size: 12px; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.asset .a-meta { font: 10px var(--mono); color: var(--ink-soft); }
.asset .a-id { color: var(--teal); font-weight: 700; }
.asset .a-del { margin-left: auto; border: none; background: none; cursor: pointer; color: var(--ink-soft); font-size: 13px; padding: 4px; }
.asset .a-del:hover { color: var(--red); }

/* ---------- board ---------- */
#boardArea { position: relative; min-width: 0; min-height: 0; overflow: hidden; }
#board { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; display: block; }
#boardToolbar {
  position: absolute;
  /* clear of the sticky top ruler (18px) */
  top: 26px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 2px;
  background: #fff;
  border: var(--border);
  padding: 4px;
  box-shadow: 4px 4px 0 rgba(20, 20, 20, 0.15);
}
.tbtn {
  width: 38px;
  height: 38px;
  border: 1px solid transparent;
  background: transparent;
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.tbtn:hover { border-color: var(--ink); }
.tbtn.active { background: var(--ink); color: #fff; }
.tsep { width: 1px; background: var(--line); margin: 4px 2px; }
#colorSwatch { width: 18px; height: 18px; border: 1px solid var(--ink); background: #e14b4b; display: block; }
#hoverInfo {
  position: absolute;
  pointer-events: none;
  background: var(--ink);
  color: #fff;
  font: 10px var(--mono);
  padding: 4px 7px;
  transform: translate(12px, -28px);
  white-space: nowrap;
  z-index: 5;
}
#boardMeta {
  position: absolute;
  /* clear of the sticky left ruler (28px) */
  left: 36px;
  bottom: 10px;
  font: 11px var(--mono);
  color: var(--ink-soft);
  background: rgba(250, 247, 242, 0.85);
  padding: 3px 8px;
  border: 1px solid var(--line);
}

/* ---------- chat ---------- */
#chatPane {
  border-left: var(--border);
  background: var(--paper);
  display: flex;
  flex-direction: column;
  min-height: 0;
  position: relative;
}
#chatLog { flex: 1; overflow-y: auto; padding: 46px 16px 12px; display: flex; flex-direction: column; gap: 12px; }
#chatFade {
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 46px;
  background: linear-gradient(var(--paper), rgba(250, 247, 242, 0));
  pointer-events: none;
  z-index: 2;
}
.msg { max-width: 94%; }
.msg-user { align-self: flex-end; }
.msg-user .bubble {
  background: var(--ink);
  color: #f5f2ec;
  padding: 9px 12px;
  font-size: 13.5px;
  line-height: 1.45;
}
.msg-role {
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--ink-soft);
  margin-bottom: 4px;
}
.msg-assistant .msg-role { color: var(--red); }
.msg-assistant .bubble { font-size: 13.5px; line-height: 1.5; white-space: pre-wrap; }
.msg-assistant .bubble code { font-family: var(--mono); font-size: 12px; background: var(--paper-2); padding: 1px 4px; }
.chip {
  display: block;
  width: fit-content;
  max-width: 100%;
  border: 1px solid var(--ink);
  background: #fff;
  font: 700 10.5px var(--mono);
  letter-spacing: 0.04em;
  padding: 5px 9px;
  margin: 3px 0;
  cursor: pointer;
}
.chip .chip-status { color: var(--teal); }
.chip.err .chip-status { color: var(--red); }
.chip.running .chip-status { color: var(--ink-soft); }
.chip-detail {
  display: none;
  font: 10px var(--mono);
  white-space: pre-wrap;
  word-break: break-all;
  max-height: 180px;
  overflow-y: auto;
  margin-top: 6px;
  color: var(--ink-soft);
  border-top: 1px dashed var(--line);
  padding-top: 5px;
}
.chip.open .chip-detail { display: block; }
#agentStatus {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 14px 8px;
  font: 700 10.5px var(--mono);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-soft);
}
.dots { display: inline-flex; gap: 3px; }
.dots i {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--teal);
  animation: dotpulse 1s infinite ease-in-out;
}
.dots i:nth-child(2) { animation-delay: 0.15s; }
.dots i:nth-child(3) { animation-delay: 0.3s; }
@keyframes dotpulse {
  0%, 100% { opacity: 0.25; transform: translateY(0); }
  50% { opacity: 1; transform: translateY(-3px); }
}

#suggestions { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 12px 8px; }
.sugg {
  border: 1px solid var(--ink);
  border-radius: 999px;
  background: #fff;
  font: 600 12px/1.3 var(--sans);
  padding: 7px 12px;
  cursor: pointer;
  text-align: left;
  max-width: 100%;
}
.sugg:hover { background: var(--ink); color: #fff; }
.sugg-hint { font: italic 11px var(--sans); color: var(--ink-soft); padding: 7px 2px; }
#chatForm {
  flex: none;
  display: flex;
  gap: 8px;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  border-top: var(--border);
  background: var(--paper);
}
#chatInput {
  flex: 1;
  resize: none;
  border: 1px solid var(--ink);
  background: #fff;
  font: 14px/1.4 var(--sans);
  padding: 10px;
  max-height: 110px;
  outline: none;
}
#chatInput:focus { outline: 2px solid var(--teal); }
#sendBtn, #stopBtn {
  font: 800 11px var(--sans);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  border: var(--border);
  background: var(--red);
  color: #fff;
  padding: 0 16px;
  cursor: pointer;
}
#stopBtn { background: #fff; color: var(--ink); }
.thinking { font: italic 12px var(--sans); color: var(--ink-soft); }

/* ---------- sheets / popovers ---------- */
#scrim { position: fixed; inset: 0; background: rgba(16, 16, 16, 0.45); z-index: 20; }
.sheet {
  position: fixed;
  z-index: 30;
  background: var(--paper);
  border: var(--border);
  box-shadow: 6px 6px 0 rgba(20, 20, 20, 0.2);
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: min(480px, calc(100vw - 24px));
  max-height: min(70vh, 560px);
  display: flex;
  flex-direction: column;
}
.sheet-head { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-bottom: 1px solid var(--ink); }
.sheet-head .sheet-close { margin-left: auto; color: var(--ink); }
#brandSelect { font: 700 11px var(--sans); border: 1px solid var(--ink); background: #fff; padding: 4px 6px; }
#paletteGrid { overflow-y: auto; padding: 12px; display: grid; grid-template-columns: repeat(auto-fill, minmax(34px, 1fr)); gap: 4px; }
.pcell { aspect-ratio: 1; border: 1px solid rgba(0, 0, 0, 0.25); cursor: pointer; position: relative; }
.pcell:hover { outline: 2px solid var(--ink); z-index: 1; }
.pcell.sel { outline: 3px solid var(--red); z-index: 1; }
#beadsList { overflow-y: auto; padding: 8px 14px 14px; }
.beadrow { display: flex; align-items: center; gap: 10px; padding: 6px 0; border-bottom: 1px dashed var(--line); font: 12px var(--mono); }
.beadrow .b-swatch { width: 18px; height: 18px; border: 1px solid var(--ink); flex: none; }
.beadrow .b-count { margin-left: auto; font-weight: 700; }

#toast {
  position: fixed;
  bottom: calc(24px + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  background: var(--ink);
  color: #fff;
  font: 700 12px var(--sans);
  letter-spacing: 0.06em;
  padding: 10px 16px;
  z-index: 50;
}

/* ---------- mobile: board on top, chat at bottom, sidebar becomes a tray ---------- */
@media (max-width: 900px) {
  #layout { display: flex; flex-direction: column; }
  #trayBtn { display: block; }
  /* the wordmark moves into the tray; the header keeps only board actions */
  .brand { display: none; }
  .sidebar-brand { display: flex; }
  #beadsBtn { display: none; }

  #sidebar {
    position: fixed;
    z-index: 25;
    top: 52px;
    bottom: 0;
    left: 0;
    width: min(78vw, 300px);
    transform: translateX(-102%);
    transition: transform 0.22s ease;
    box-shadow: 6px 0 0 rgba(20, 20, 20, 0.12);
  }
  #sidebar.open { transform: translateX(0); }

  #boardArea { flex: 1 1 52%; min-height: 40dvh; border-bottom: var(--border); }
  #boardToolbar { top: auto; bottom: 10px; }
  #boardMeta { bottom: auto; top: 24px; }

  #chatPane { flex: 1 1 48%; border-left: none; min-height: 0; }
  #chatLog { padding-top: 34px; }
  #chatFade { height: 34px; }
}
