/* Dashboard styling. Dark-only by design: this panel sits next to Discord all
   day and a light variant would fight the card previews it renders. */

:root {
  --bg: #0d1017;
  --surface: #151a22;
  --surface-2: #1b212b;
  --surface-3: #222a36;
  --border: #2a3341;
  --border-soft: #202834;
  --text: #e6edf3;
  --muted: #8b98a8;
  --faint: #5c6878;
  --accent: #5865f2;
  --accent-soft: #5865f233;
  --success: #3ba55d;
  --danger: #ed4245;
  --warn: #faa81a;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 12px 32px rgba(0, 0, 0, 0.45);
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  color-scheme: dark;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -0.01em; }
h1 { font-size: 22px; }
h2 { font-size: 17px; }
h3 { font-size: 14px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }
p { margin: 0 0 12px; }

/* ---------- standalone pages ---------- */

.page-message, .page-login {
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: 24px;
}

.notice, .login-card {
  max-width: 460px;
  width: 100%;
  padding: 32px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  text-align: center;
}

.login-card .logo {
  width: 56px; height: 56px;
  margin: 0 auto 18px;
  display: grid; place-items: center;
  border-radius: 16px;
  background: linear-gradient(140deg, var(--accent), #8f45f0);
  font-size: 26px;
}

.login-card p { color: var(--muted); }
.login-card .scopes { margin-top: 20px; font-size: 13px; color: var(--faint); }

/* ---------- layout ---------- */

.shell {
  display: grid;
  grid-template-columns: 232px 1fr;
  min-height: 100vh;
}

.sidebar {
  border-right: 1px solid var(--border);
  background: var(--surface);
  padding: 18px 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.brand {
  display: flex; align-items: center; gap: 10px;
  padding: 6px 8px 18px;
}
.brand .mark {
  width: 34px; height: 34px; flex: none;
  border-radius: 10px;
  background: linear-gradient(140deg, var(--accent), #8f45f0);
  display: grid; place-items: center; font-size: 17px;
}
.brand strong { display: block; font-size: 15px; }
.brand span { display: block; font-size: 12px; color: var(--faint); }

.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 10px;
  border-radius: var(--radius-sm);
  color: var(--muted);
  font-size: 14px;
  cursor: pointer;
  border: 1px solid transparent;
  background: none;
  width: 100%;
  text-align: left;
  font-family: inherit;
}
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active { background: var(--accent-soft); color: var(--text); border-color: #5865f255; }
.nav-item[disabled] { opacity: 0.35; cursor: not-allowed; }
.nav-item .icon { font-size: 15px; width: 18px; text-align: center; }

.sidebar-foot { margin-top: auto; padding-top: 14px; border-top: 1px solid var(--border-soft); }
.who { display: flex; align-items: center; gap: 10px; padding: 8px; font-size: 13px; }
.who img { width: 30px; height: 30px; border-radius: 50%; }
.who div { min-width: 0; }
.who strong { display: block; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.who span { color: var(--faint); font-size: 11px; }

.main { padding: 26px 30px 60px; max-width: 1180px; }
.view-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 22px; }
.view-head p { color: var(--muted); font-size: 14px; margin: 6px 0 0; max-width: 62ch; }

/* ---------- primitives ---------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}
.card + .card { margin-top: 16px; }
.card > h2 { margin-bottom: 4px; }
.card > .hint { color: var(--muted); font-size: 13px; margin-bottom: 16px; }

.art-word-preview { margin: 8px 0 12px; }
.art-word-preview summary { cursor: pointer; color: var(--muted); font-size: 13px; }
.art-word-preview > div { margin-top: 6px; line-height: 1.6; }

.art-packs { display: grid; gap: 10px; }
.art-pack {
  display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap;
  background: var(--surface-2); border: 1px solid var(--border-soft); border-radius: var(--radius-sm);
  padding: 12px 14px; transition: border-color 0.12s, opacity 0.12s;
  opacity: 0.62;
}
.art-pack.on { border-color: var(--accent); opacity: 1; }

/* The on/off switch: the whole point of a pack is that it can be turned off. */
.switch { position: relative; display: inline-flex; width: 38px; height: 22px; flex: none; }
.switch input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; }
.switch span {
  position: absolute; inset: 0; border-radius: 99px; pointer-events: none;
  background: var(--surface-3); border: 1px solid var(--border); transition: background 0.15s, border-color 0.15s;
}
.switch span::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%;
  background: var(--faint); transition: transform 0.15s, background 0.15s;
}
.switch input:checked + span { background: var(--accent-soft); border-color: var(--accent); }
.switch input:checked + span::after { transform: translateX(16px); background: var(--accent); }
.switch input:disabled + span { opacity: 0.5; }
.switch input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.art-pack .hint { margin: 4px 0 2px; font-size: 13px; }
.art-pack .fit-hint { font-size: 12px; }
.art-pack > div:first-child { min-width: 0; flex: 1; }
/* The sample line is a taste of the pack, not its contents: two lines is plenty. */
.art-pack-sample { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

.grid { display: grid; gap: 16px; }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.grid.stats { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }

.stat {
  background: var(--surface-2);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
}
.stat .value { font-size: 24px; font-weight: 650; letter-spacing: -0.02em; }
.stat .label { font-size: 12px; color: var(--muted); margin-top: 2px; }

.button, button.button {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 9px 15px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font: inherit; font-size: 14px;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s;
}
.button:hover { background: var(--surface-3); text-decoration: none; }
.button:disabled { opacity: 0.45; cursor: not-allowed; }
.button.primary { background: var(--accent); border-color: var(--accent); }
.button.primary:hover { background: #4752d4; }
.button.danger { color: var(--danger); border-color: #ed424555; }
.button.danger:hover { background: #ed424518; }
.button.small { padding: 6px 11px; font-size: 13px; }
.button.ghost { background: none; }

label.field { display: block; margin-bottom: 14px; }
label.field > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }

input[type="text"], input[type="number"], input[type="url"], select, textarea {
  width: 100%;
  padding: 9px 11px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font: inherit; font-size: 14px;
}
textarea { min-height: 76px; resize: vertical; font-size: 13px; }
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft);
}
input[type="range"] { width: 100%; accent-color: var(--accent); }
input[type="checkbox"] { accent-color: var(--accent); width: 15px; height: 15px; }

.inline { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.inline.tight { gap: 6px; }
.row-actions { display: flex; gap: 6px; flex-wrap: wrap; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  padding: 5px 10px;
  border-radius: 99px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--muted);
  font-size: 12.5px;
  cursor: pointer;
  user-select: none;
  font-family: inherit;
}
.chip:hover { color: var(--text); }
.chip.on { color: #fff; border-color: transparent; }
.chip .dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; margin-right: 6px; vertical-align: 1px; }

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 99px;
  font-size: 11.5px;
  background: var(--surface-3);
  color: var(--muted);
}
.badge.ok { background: #3ba55d22; color: #6ee19a; }
.badge.bad { background: #ed424522; color: #ff8b8d; }
.badge.warn { background: #faa81a22; color: #ffcc70; }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th {
  text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--faint); font-weight: 600; padding: 0 10px 8px;
}
td { padding: 11px 10px; border-top: 1px solid var(--border-soft); vertical-align: middle; }
tr:hover td { background: #ffffff05; }
code, .mono { font-family: var(--mono); font-size: 12.5px; }
td code { background: var(--surface-2); padding: 2px 6px; border-radius: 5px; }

.empty { padding: 34px; text-align: center; color: var(--faint); font-size: 14px; }

/* ---------- fit editor ---------- */

.fit-layout { display: grid; grid-template-columns: minmax(260px, 340px) 1fr; gap: 22px; }
.fit-stage {
  position: relative;
  border-radius: var(--radius);
  overflow: hidden;
  background:
    repeating-conic-gradient(#1a212b 0% 25%, #141a22 0% 50%) 50% / 20px 20px;
  border: 1px solid var(--border);
  cursor: grab;
  touch-action: none;
  aspect-ratio: 618 / 854;
}
.fit-stage.dragging { cursor: grabbing; }
.fit-stage canvas { display: block; width: 100%; height: 100%; }
.fit-stage .placeholder {
  position: absolute; inset: 0;
  display: grid; place-items: center;
  color: var(--faint); font-size: 13px; text-align: center; padding: 24px;
}
.fit-hint { font-size: 12px; color: var(--faint); margin-top: 8px; }

.preview-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 14px;
  margin-top: 16px;
}
.preview-item {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--surface-2);
}
.preview-item img { display: block; width: 100%; background: #0a0d12; }
.preview-item .meta { padding: 9px 11px; font-size: 12px; }
.preview-item .meta strong { display: block; font-size: 12.5px; }
.preview-item .meta span { color: var(--muted); }
.preview-item .bar { height: 3px; }

/* ---------- locations ---------- */

.location-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}
.location-tile {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--surface-2);
}
.location-tile > img {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  background: #0a0d12;
}
.location-body { padding: 12px 14px 14px; }

.location-preview { margin-top: 14px; }
.location-preview img {
  display: block;
  width: 100%;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  margin-top: 8px;
}

/* ---------- greetings ---------- */

.greeting-layout {
  display: grid;
  grid-template-columns: minmax(300px, 1fr) minmax(300px, 1fr);
  gap: 24px;
  align-items: start;
}
.greeting-preview {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background:
    repeating-conic-gradient(#1a212b 0% 25%, #141a22 0% 50%) 50% / 20px 20px;
  padding: 10px;
  position: sticky;
  top: 20px;
}
.greeting-preview img { display: block; width: 100%; border-radius: 6px; }
.greeting-preview .fit-hint { margin-top: 8px; }

.color-input {
  width: 100%;
  height: 36px;
  padding: 3px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg);
  cursor: pointer;
}
.range-row { display: flex; align-items: center; gap: 10px; }
.range-value {
  min-width: 44px;
  text-align: right;
  font-family: var(--mono);
  font-size: 12.5px;
  color: var(--muted);
}

/* ---------- member rows ---------- */

.member { display: flex; align-items: center; gap: 9px; min-width: 0; }
.member img { width: 26px; height: 26px; border-radius: 50%; flex: none; }
.rank {
  display: inline-grid; place-items: center;
  width: 22px; height: 22px; flex: none;
  border-radius: 6px;
  background: var(--surface-3);
  color: var(--muted);
  font-size: 11.5px;
  font-variant-numeric: tabular-nums;
}
.link-button {
  background: none; border: none; padding: 0;
  color: var(--text); font: inherit; font-size: 14px;
  cursor: pointer; text-align: left;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.link-button:hover { color: var(--accent); }
.chip.static { cursor: default; }

/* ---------- distribution meter ---------- */

.meter {
  position: relative;
  height: 9px;
  border-radius: 99px;
  background: var(--surface-3);
  overflow: hidden;
}
.meter-fill {
  height: 100%;
  border-radius: 99px;
  min-width: 2px;
  transition: width 0.25s ease-out;
}
/* Where the configured drop chance would put the bar. */
.meter-mark {
  position: absolute;
  top: -2px;
  width: 2px;
  height: 13px;
  background: var(--text);
  opacity: 0.55;
  border-radius: 1px;
}

/* ---------- toast ---------- */

.toasts { position: fixed; right: 20px; bottom: 20px; display: grid; gap: 10px; z-index: 50; max-width: 380px; }
.toast {
  padding: 12px 15px;
  border-radius: var(--radius-sm);
  background: var(--surface-3);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  font-size: 13.5px;
  animation: rise 0.18s ease-out;
}
.toast.ok { border-left: 3px solid var(--success); }
.toast.err { border-left: 3px solid var(--danger); }
.toast.warn { border-left: 3px solid var(--warn); }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } }

.spinner {
  width: 15px; height: 15px;
  border: 2px solid #ffffff35;
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- modal ---------- */

.modal-back {
  position: fixed; inset: 0;
  background: #05070ac9;
  display: grid; place-items: center;
  padding: 24px;
  z-index: 40;
}
.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
  width: min(560px, 100%);
  max-height: 86vh;
  overflow-y: auto;
}
.modal h2 { margin-bottom: 14px; }

@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar {
    position: static; height: auto;
    flex-direction: row; flex-wrap: wrap; align-items: center;
    border-right: none; border-bottom: 1px solid var(--border);
  }
  .brand { padding: 0 10px 0 0; }
  .nav-item { width: auto; }
  .sidebar-foot { margin-top: 0; padding-top: 0; border: none; margin-left: auto; }
  .fit-layout { grid-template-columns: 1fr; }
  .greeting-layout { grid-template-columns: 1fr; }
  .greeting-preview { position: static; }
  .main { padding: 20px 16px 50px; }
}

/* ---------- private AI chat ---------- */

.chat-tokens { flex: none; }

.chat-layout {
  display: grid;
  grid-template-columns: 250px 1fr;
  gap: 16px;
  /* The log scrolls inside itself, so the page itself never grows a scrollbar
     while an answer streams in. */
  height: calc(100vh - 220px);
  min-height: 460px;
}

.chat-threads {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 0;
}
.chat-threads .chat-new { justify-content: center; }
.chat-threads-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  overflow-y: auto;
  min-height: 0;
  padding-right: 2px;
}

.chat-thread {
  display: block;
  width: 100%;
  text-align: left;
  padding: 9px 11px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  cursor: pointer;
}
.chat-thread:hover { background: var(--surface-2); }
.chat-thread.active { background: var(--accent-soft); border-color: #5865f255; }
.chat-thread strong {
  display: block;
  font-size: 13.5px;
  font-weight: 600;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.chat-thread span {
  display: block;
  font-size: 12px;
  color: var(--muted);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.chat-thread .chat-thread-meta { color: var(--faint); font-size: 11px; margin-top: 2px; }

.chat-main {
  display: grid;
  grid-template-rows: auto 1fr auto;
  min-height: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.chat-header { padding: 16px 18px; border-bottom: 1px solid var(--border-soft); }
.chat-title-row {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; margin-bottom: 12px;
}
.chat-title {
  background: none; border: none; padding: 0;
  color: var(--text); font: inherit; font-size: 17px; font-weight: 650;
  cursor: pointer; text-align: left;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.chat-title:hover { color: var(--accent); }

.chat-settings {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr auto;
  gap: 10px;
  align-items: end;
}
.chat-settings label { display: block; min-width: 0; }
.chat-settings label > span {
  display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px;
}
.chat-settings select { font-size: 13px; padding: 7px 9px; }

.chat-log {
  overflow-y: auto;
  min-height: 0;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  background: var(--bg);
}

.chat-msg { display: flex; flex-direction: column; gap: 4px; max-width: 78%; }
.chat-msg.user { align-self: flex-end; align-items: flex-end; }
.chat-msg.assistant { align-self: flex-start; }

.chat-bubble {
  padding: 11px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--border-soft);
  background: var(--surface-2);
  font-size: 14.5px;
  line-height: 1.55;
  /* Model output arrives as plain text; newlines have to survive it. */
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.chat-msg.user .chat-bubble {
  background: var(--accent-soft);
  border-color: #5865f255;
}
.chat-bubble pre {
  margin: 10px 0 4px;
  padding: 11px 12px;
  border-radius: var(--radius-sm);
  background: #0a0d12;
  border: 1px solid var(--border);
  overflow-x: auto;
  white-space: pre;
}
.chat-bubble pre code { font-size: 12.5px; line-height: 1.5; }
.chat-bubble code {
  font-family: var(--mono);
  font-size: 12.5px;
  background: #ffffff10;
  padding: 1px 5px;
  border-radius: 4px;
}
.chat-bubble pre code { background: none; padding: 0; }

.chat-meta {
  display: flex; align-items: center; gap: 7px; flex-wrap: wrap;
  font-size: 11.5px; color: var(--faint);
  padding: 0 4px;
}
.chat-meta .spinner { width: 11px; height: 11px; border-width: 2px; }

.chat-composer {
  padding: 14px 18px 16px;
  border-top: 1px solid var(--border-soft);
  display: flex; flex-direction: column; gap: 10px;
}
.chat-input {
  min-height: 54px;
  max-height: 220px;
  font-size: 14.5px;
  resize: none;
}
.chat-composer-actions { display: flex; align-items: center; gap: 12px; }

@media (max-width: 900px) {
  .chat-layout {
    grid-template-columns: 1fr;
    height: auto;
    min-height: 0;
  }
  .chat-threads-list { max-height: 190px; }
  .chat-log { height: 55vh; }
  .chat-settings { grid-template-columns: 1fr 1fr; }
  .chat-msg { max-width: 92%; }
}

/* ---------- drawing game: Activity setup checklist ---------- */

.art-setup-steps { margin: 6px 0 0; padding-left: 20px; display: grid; gap: 8px; font-size: 14px; }
.art-setup-steps code { background: var(--surface-2); padding: 1px 6px; border-radius: 5px; }
