:root {
  --gold: #d4af37;
  --gold-deep: #a57917;
  --ink: #0a0a0c;
  --panel: #141416;
  --panel-2: #1c1c20;
  --line: #2a2a30;
  --body: #e5e7eb;
  --muted: #9ca3af;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: 'Nunito', system-ui, sans-serif;
  background: var(--ink);
  color: var(--body);
  overflow: hidden;
}

/* ---------------- Gate ---------------- */
.gate {
  position: fixed; inset: 0;
  display: grid; place-items: center;
  background:
    radial-gradient(900px 500px at 15% 0%, rgba(212, 175, 55, 0.12), transparent 60%),
    radial-gradient(700px 500px at 90% 100%, rgba(165, 121, 23, 0.1), transparent 60%),
    var(--ink);
  padding: 20px;
  z-index: 30;
}
.gate-card {
  width: min(430px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 36px 34px 26px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.55);
}
.gate-brand { text-align: center; margin-bottom: 26px; }
.gate-logo { color: var(--gold); font-size: 26px; }
.gate-brand h1 {
  font-family: 'Fraunces', serif;
  font-size: 34px; margin: 8px 0 6px; letter-spacing: 0.5px; color: #fff;
}
.gate-brand h1 span { color: var(--gold); }
.gate-tag { color: var(--muted); font-size: 13.5px; margin: 0; }
.gate-card label {
  display: block; font-size: 12.5px; font-weight: 800; letter-spacing: 0.06em;
  text-transform: uppercase; color: var(--muted); margin: 16px 0 6px;
}
.gate-card label em { color: var(--gold); font-style: normal; text-transform: none; letter-spacing: 0; }
.gate-card input {
  width: 100%; padding: 12px 14px; font-size: 15px;
  background: var(--panel-2); color: #fff;
  border: 1px solid var(--line); border-radius: 10px; outline: none;
}
.gate-card input:focus { border-color: var(--gold); }
.gate-card button {
  width: 100%; margin-top: 22px; padding: 13px;
  font-size: 15.5px; font-weight: 800;
  color: #141200; background: linear-gradient(135deg, var(--gold), var(--gold-deep));
  border: 0; border-radius: 10px; cursor: pointer;
}
.gate-card button:disabled { opacity: 0.55; cursor: wait; }
.gate-error { color: #f87171; font-size: 13.5px; margin: 12px 0 0; text-align: center; }
.gate-hint { color: var(--muted); font-size: 12.5px; text-align: center; margin: 18px 0 0; }

/* ---------------- App shell ---------------- */
.app { display: grid; grid-template-rows: 52px 1fr; height: 100vh; }
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 14px; background: var(--panel); border-bottom: 1px solid var(--line); z-index: 10;
}
.topbar-left { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand { font-family: 'Fraunces', serif; color: #fff; font-size: 17px; white-space: nowrap; }
.brand b { color: var(--gold); }
.board-title {
  color: var(--muted); font-size: 14px; font-weight: 700;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 40vw;
}
.topbar-right { display: flex; align-items: center; gap: 10px; }
.online-users { display: flex; align-items: center; }
.online-users .pill {
  width: 30px; height: 30px; border-radius: 50%;
  display: grid; place-items: center;
  font-size: 12px; font-weight: 800; color: #141200;
  border: 2px solid var(--panel); margin-left: -8px;
}
.icon-btn, .ghost-btn {
  background: transparent; color: var(--body);
  border: 1px solid var(--line); border-radius: 8px;
  padding: 6px 10px; font-size: 14px; cursor: pointer;
}
.ghost-btn:hover, .icon-btn:hover { border-color: var(--gold); color: #fff; }

.sidebar {
  position: absolute; top: 52px; left: 0; bottom: 0; width: 264px;
  background: var(--panel); border-right: 1px solid var(--line);
  padding: 16px 14px; z-index: 8; overflow-y: auto;
  transition: transform 0.2s ease;
}
.sidebar.closed { transform: translateX(-100%); }
.sidebar-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.sidebar-head h2 { font-size: 14px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); margin: 0; }
.gold-btn {
  background: linear-gradient(135deg, var(--gold), var(--gold-deep));
  color: #141200; border: 0; border-radius: 8px;
  font-weight: 800; font-size: 13px; padding: 7px 12px; cursor: pointer;
}
.board-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.board-list li {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 12px; cursor: pointer; display: flex; justify-content: space-between; align-items: center; gap: 8px;
}
.board-list li:hover { border-color: var(--gold); }
.board-list li.active { border-color: var(--gold); background: rgba(212, 175, 55, 0.08); }
.board-list .bname { font-size: 14px; font-weight: 700; color: #fff; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.board-list .bmeta { font-size: 11.5px; color: var(--muted); }
.board-list .bdel { background: none; border: 0; color: var(--muted); cursor: pointer; font-size: 14px; padding: 2px 4px; }
.board-list .bdel:hover { color: #f87171; }

.stage { position: relative; overflow: hidden; }
#canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; cursor: crosshair; }
#canvas.panning { cursor: grabbing; }
#canvas.select { cursor: default; }

.cursors { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.cursor-tag {
  position: absolute; transform: translate(-2px, -2px);
  transition: left 0.05s linear, top 0.05s linear;
}
.cursor-tag .arrow { width: 0; height: 0; border-left: 7px solid transparent; border-right: 7px solid transparent; border-bottom: 12px solid; transform: rotate(-45deg); transform-origin: 3px 9px; }
.cursor-tag .label {
  color: #141200; font-size: 11px; font-weight: 800;
  padding: 2px 8px; border-radius: 10px; margin-top: 2px; white-space: nowrap;
}

.toolbar {
  position: absolute; left: 50%; bottom: 18px; transform: translateX(-50%);
  display: flex; align-items: center; gap: 4px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
  padding: 6px 8px; box-shadow: 0 14px 40px rgba(0, 0, 0, 0.5); z-index: 9;
}
.tool {
  width: 38px; height: 38px; border-radius: 9px; border: 0;
  background: transparent; color: var(--body); font-size: 17px; cursor: pointer;
  display: grid; place-items: center;
}
.tool:hover { background: var(--panel-2); }
.tool.active { background: rgba(212, 175, 55, 0.16); outline: 1px solid var(--gold); }
.tool.danger:hover { background: rgba(248, 113, 113, 0.14); }
.tool-sep { width: 1px; height: 24px; background: var(--line); margin: 0 4px; }
#colorPicker {
  width: 34px; height: 34px; border: 0; background: none; padding: 0; cursor: pointer;
}
#colorPicker::-webkit-color-swatch-wrapper { padding: 2px; }
#colorPicker::-webkit-color-swatch { border: 1px solid var(--line); border-radius: 8px; }

.empty-state {
  position: absolute; inset: 0; display: grid; place-content: center; text-align: center;
  color: var(--muted); pointer-events: none;
}
.empty-state h2 { font-family: 'Fraunces', serif; color: #fff; margin: 0 0 6px; }

.text-editor {
  position: absolute; z-index: 12;
  background: transparent; border: 1px dashed var(--gold);
  color: #fff; font-family: 'Nunito', sans-serif; font-size: 16px;
  padding: 6px 8px; border-radius: 6px; resize: none; outline: none; min-width: 140px;
}

@media (max-width: 720px) {
  .sidebar { width: 220px; }
  .toolbar { bottom: 10px; max-width: 96vw; overflow-x: auto; }
}
