*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  touch-action: manipulation;
}

html, body {
  width: 100%;
  height: 100%;
  background: #000;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

#title-bar {
  width: 100%;
  padding: 4px 12px;
  font-size: 13px;
  font-family: sans-serif;
  font-style: italic;
  color: #ffd88a;
  text-align: center;
  flex-shrink: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#bc-spacer {
  height: 50px;
  flex-shrink: 0;
}

@keyframes help-pulse {
  0%, 100% { color: #cccccc; }
  50%       { color: #FFD700; }
}

#help-bar {
  position: fixed;
  bottom: 8px;
  left: 0;
  right: 0;
  padding: 4px 12px;
  font-size: 13px;
  font-family: sans-serif;
  color: #cccccc;
  background: transparent;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-align: center;
  pointer-events: none;
  z-index: 5;
  animation: help-pulse 0.5s ease-in-out 30;
}

#cy-buddy {
  width: 100%;
  height: 36px;
  flex-shrink: 0;
  background: #001f4d;
  margin-bottom: 10px;
  cursor: url('cursor-wings.svg') 16 16, auto;
}

#pair-control {
  position: fixed;
  top: 34px;
  right: 8px;
  display: flex;
  align-items: center;
  gap: 8px;
  z-index: 10;
  font-size: 11px;
  font-family: sans-serif;
}

#chat-btn, #pair-btn {
  background: #3d2e00;
  border: 1px solid #a07820;
  border-radius: 4px;
  color: #ffd88a;
  font-size: 14px;
  cursor: pointer;
  padding: 3px 11px;
  line-height: 1.4;
}

#chat-btn:hover:not(:disabled), #pair-btn:hover:not(:disabled) {
  border-color: #ffd88a;
  color: #fff;
}

#chat-btn.active {
  border-color: #ffd88a;
  background: #5a4400;
  color: #fff;
}

#back-btn {
  display: none;
  position: fixed;
  top: 34px;
  left: 8px;
  z-index: 10;
  background: #3d2e00;
  border: 1px solid #a07820;
  border-radius: 4px;
  color: #ffd88a;
  font-size: 18px;
  cursor: pointer;
  padding: 4px 12px;
  line-height: 1;
  font-family: sans-serif;
}

#back-btn.visible {
  display: block;
}

#back-btn:hover {
  border-color: #ffd88a;
  color: #fff;
}

#chat-btn:disabled,
#pair-btn:disabled {
  opacity: 0.45;
  cursor: default;
}

#pair-status {
  color: #aaa;
  white-space: nowrap;
}


#cy-you {
  width: 100%;
  height: 36px;
  flex-shrink: 0;
  background: #5a5000;                  /* brighter yellow — matches local card head */
  cursor: url('cursor-wings.svg') 16 16, auto;
}

#cy {
  position: fixed;
  left: 0;
  right: 0;
  top: 158px;   /* set precisely by JS; fallback matches BARS_BOTTOM */
  bottom: 34px; /* above help bar */
  z-index: 1;
  cursor: url('cursor-wings.svg') 16 16, auto;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
}

#cy canvas {
  cursor: url('cursor-wings.svg') 16 16, auto !important;
}

#chat-panel {
  display: none;
  width: 40%;
  height: 33dvh;
  flex-shrink: 0;
  align-self: center;
  background: #0a0a1a;
  align-items: flex-start;
  gap: 8px;
  padding: 8px;
}

@media (max-width: 767px) {
  #chat-panel {
    width: 100%;
    height: 33dvh;
  }
}

#chat-panel.active {
  display: flex;
}

/* Default (system-message) panel — visible whenever the chat panel is not active */
#default-panel {
  display: flex;
  width: 40%;
  height: 34dvh;                       /* doubled from 17dvh on 2026-06-23 to give system messages more room */
  flex-shrink: 0;
  align-self: center;
  background: #0a0a1a;
  align-items: flex-start;
  gap: 8px;
  padding: 8px;
}

@media (max-width: 767px) {
  #default-panel { width: 100%; }
}

#chat-panel.active ~ #default-panel { display: none; }

#default-stack {
  flex: 1;
  min-width: 0;
  width: 100%;
  height: 100%;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  align-content: flex-start;
  gap: 6px;
  padding: 4px;
  overflow-y: auto;
  background: #0a0a1a;
  border: 1px solid #444;
  border-radius: 6px;
}

.card.system {
  background: #1c1a30;
}

/* default-panel system card is the panel's only scroller — it must stretch */
#default-stack .card.system {
  flex: 1;                             /* fill the default-stack vertically */
}

#default-stack .card.system .card-body {
  position: relative;                  /* offsetParent for inserted spans */
  flex: 1;                             /* fill the card minus the head */
  min-height: 0;                       /* allow shrink-to-overflow inside flex parent */
  white-space: pre-wrap;
  word-wrap: break-word;
  overflow-y: auto;
}

/* chat-panel system card — pure black body; head stripe carries the kind signal */
#chat-stack .card.system {
  background: #000;
}

#chat-stack {
  flex: 1;
  min-width: 0;
  width: 100%;
  height: 100%;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;             /* top-down; newest card prepended so it sits at top */
  align-content: flex-start;
  gap: 6px;
  padding: 4px;
  overflow-y: auto;
  background: #0a0a1a;
  border: 1px solid #444;
  border-radius: 6px;
}

.card { flex: 0 0 auto; }              /* don't stretch to fill the panel */

.card {
  display: flex;
  flex-direction: column;
  border: 1px solid #333;
  border-radius: 4px;
  overflow: hidden;
}

.card-head {
  padding: 3px 8px;
  background: rgba(255,255,255,0.04);
  color: #ffffff;
  font-family: sans-serif;
  font-size: 12px;
  border-bottom: 1px solid #2a2a3a;
  user-select: none;
}

/* Card heads colour-coded to mirror the bar / title palette. White text
   throughout — body backgrounds are very dark so the head reads as a
   distinct stripe. Local takes the brighter yellow (user's compose
   area should stand out); system fades back to the dimmer green. */
.card.local    .card-head { background: #5a5000; }   /* brighter yellow, matches #cy-you breadcrumb */
.card.received .card-head { background: #001f4d; }   /* dark navy, matches #cy-buddy breadcrumb */
#chat-stack .card.system .card-head { background: #2a2a00; }   /* pure yellow R=G, modestly brighter than before but still much dimmer than local */

.card-body {
  width: 100%;
  box-sizing: border-box;
  background: transparent;
  color: #ffffff;
  border: 0;
  padding: 8px 10px;
  font-family: sans-serif;
  font-size: 16px;
  line-height: 1.6;
  resize: none;
  outline: none;
  min-height: 8.5em;                  /* ~5 lines visible; with ~1.5em head ≈ 10em per card → 3 cards fill the 33dvh panel */
}

/* Non-editable cards size to content — no writing room needed. The 8.5em
   floor is for the local textarea. System / received bodies are divs that
   shrink-wrap their text, freeing vertical space in the chat-stack. */
#chat-stack .card.system .card-body,
.card.received .card-body {
  min-height: 0;
}

/* Body backgrounds — pure black for all kinds. The coloured head stripe
   already signals kind, and dim hue tints in the body were proving more
   confusing than helpful. N=k labels distinguish adjacent local cards. */
.card.local    { background: #000; }
.card.received { background: #000; }

/* Hidden ghost N=0 — conceptual anchor only, never shown */
.card.card-hidden {
  display: none;
}
.card-delivered {
  margin-left: 0.6em;
  font-size: 0.85em;
  opacity: 0.8;
  font-style: italic;
}

#chat-right-col,
#default-right-col {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding-top: 6px;
  padding-bottom: 6px;
}

#default-save-btn {
  margin-top: auto;
  background: #1a1a2e;
  border: 1px solid #555;
  border-radius: 3px;
  color: #cccccc;
  font-family: sans-serif;
  font-size: 11px;
  line-height: 1.1;
  padding: 4px 10px;
  cursor: pointer;
  text-align: center;
}

#default-save-btn:hover:not(:disabled) {
  border-color: #aaa;
  color: #fff;
}

#default-save-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

#default-save-status {
  color: #cccccc;
  font-family: sans-serif;
  font-size: 10px;
  line-height: 1.1;
  text-align: center;
  min-height: 1em;
}

#chat-send-btn,
#chat-new-card-btn {
  background: #1a1a2e;
  border: 1px solid #555;
  border-radius: 3px;
  color: #cccccc;
  font-family: sans-serif;
  font-size: 10px;
  line-height: 1.1;
  padding: 3px 6px;
  cursor: pointer;
  text-align: center;
}

#chat-send-btn {
  margin-top: auto;
  font-size: 11px;
  padding: 4px 10px;
}

#chat-send-btn:hover:not(:disabled),
#chat-new-card-btn:hover {
  border-color: #aaa;
  color: #fff;
}

#chat-send-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

#media-bar {
  display: none;
  position: fixed;
  top: 34px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.75);
  border: 1px solid #444;
  padding: 3px 8px;
  color: #fff;
  font-size: 11px;
  font-family: sans-serif;
  white-space: nowrap;
  z-index: 10;
}

#media-bar.active {
  display: flex;
  align-items: center;
  gap: 6px;
}

#cluster-editor-bar {
  position: fixed;
  align-items: center;
  gap: 10px;
  padding: 8px 13px;
  background: rgba(0,0,0,0.75);
  border: 1px solid #444;
  font-size: 13px;
  font-family: sans-serif;
  color: #cccccc;
  white-space: nowrap;
  z-index: 10;
}

.spinner-group {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
}

.spinner-group input {
  width: 62px;
  font-size: 14px;
  text-align: center;
  background: #1a1a2e;
  color: #ffffff;
  border: 1px solid #444;
  border-radius: 3px;
  padding: 3px;
}

#editor-save-btn, #editor-delete-btn, #editor-clone-btn {
  font-size: 14px;
  padding: 5px 13px;
  border-radius: 3px;
  cursor: pointer;
  align-self: flex-end;
}

#editor-save-btn {
  background: #4A8C4F;
  color: #ffffff;
  border: none;
}

#editor-delete-btn {
  background: #C0504D;
  color: #ffffff;
  border: none;
}

#editor-clone-btn {
  background: #4A7BC0;
  color: #ffffff;
  border: none;
}

#clone-panel {
  position: fixed;
  align-items: center;
  gap: 10px;
  padding: 5px 13px;
  background: rgba(0, 0, 0, 0.75);
  border: 1px solid #444;
  font-size: 14px;
  font-family: sans-serif;
  z-index: 10;
  white-space: nowrap;
}

#clone-name-input {
  width: 260px;
  font-size: 14px;
  background: #1a1a2e;
  color: #ffffff;
  border: 1px solid #444;
  border-radius: 3px;
  padding: 4px 8px;
}

#clone-confirm-btn {
  background: #4A8C4F;
  color: #ffffff;
  border: none;
  border-radius: 3px;
  padding: 4px 10px;
  font-size: 14px;
  cursor: pointer;
}

#clone-cancel-btn {
  background: #444;
  color: #cccccc;
  border: none;
  border-radius: 3px;
  padding: 4px 10px;
  font-size: 14px;
  cursor: pointer;
}

.mp-select {
  background: #1a1a1a;
  border: 1px solid #555;
  color: #ccc;
  font-size: 11px;
  font-family: sans-serif;
  padding: 1px 3px;
  min-width: 130px;
  cursor: pointer;
}

.media-close {
  background: none;
  border: none;
  color: #888;
  font-size: 14px;
  cursor: pointer;
  padding: 0 0 0 6px;
  line-height: 1;
}

.media-close:hover {
  color: #fff;
}


.mp-btn {
  background: none;
  border: 1px solid #888;
  border-radius: 4px;
  color: #fff;
  font-size: 13px;
  cursor: pointer;
  padding: 2px 8px;
  line-height: 1.4;
  flex-shrink: 0;
}

.mp-btn:hover {
  border-color: #fff;
}


#loading-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.88);
  z-index: 500;
  align-items: center;
  justify-content: center;
}

#loading-overlay.active {
  display: flex;
}

#loading-box {
  background: #111;
  border: 1px solid #444;
  padding: 28px 32px;
  text-align: center;
  font-family: sans-serif;
  max-width: 300px;
}

#loading-box p {
  color: #ccc;
  font-size: 14px;
  line-height: 1.7;
  margin: 0;
}


#session-expired {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.88);
  z-index: 500;
  align-items: center;
  justify-content: center;
}

#session-expired.active {
  display: flex;
}

#session-expired-box {
  background: #111;
  border: 1px solid #444;
  padding: 28px 32px;
  text-align: center;
  font-family: sans-serif;
  max-width: 300px;
}

#session-expired-box p {
  color: #ccc;
  font-size: 14px;
  line-height: 1.7;
  margin-bottom: 20px;
}

#session-expired-box button {
  background: #1a3a6b;
  border: 1px solid #3a6abf;
  color: #aac4ff;
  padding: 6px 18px;
  font-size: 12px;
  font-family: sans-serif;
  letter-spacing: 0.06em;
  cursor: pointer;
}

#session-expired-box button:hover {
  color: #fff;
  border-color: #6a9adf;
}

#dev-panel {
  position: fixed;
  bottom: 34px;
  left: 16px;
  display: flex;
  align-items: center;
  gap: 6px;
  z-index: 10;
  font-family: sans-serif;
}

#dev-code {
  background: #111;
  border: 1px solid #444;
  color: #ccc;
  /* iOS Safari auto-zooms any input under 16px on focus. Keeping >= 16px
     prevents the zoom-in / can't-zoom-back problem on iPhone. */
  font-size: 16px;
  padding: 2px 6px;
  width: 96px;
  border-radius: 3px;
}

#dev-code::placeholder { color: #555; }

.dev-btn {
  background: none;
  border: 1px solid #555;
  border-radius: 4px;
  color: #aaa;
  font-size: 11px;
  cursor: pointer;
  padding: 2px 8px;
  line-height: 1.4;
}

.dev-btn:hover { border-color: #aaa; color: #fff; }

#dev-status {
  color: #888;
  font-size: 11px;
  white-space: nowrap;
}

#edit-mode-label {
  color: #888;
  font-size: 11px;
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}

#user-count-panel {
  position: fixed;
  bottom: 8px;
  right: 16px;
  background: rgba(0, 0, 0, 0.6);
  border: 1px solid #444;
  color: #888;
  font-size: 11px;
  font-family: sans-serif;
  padding: 3px 8px;
  z-index: 10;
  display: none;
}

#user-count-panel.active {
  display: block;
}

#label-tooltip {
  position: fixed;
  background: rgba(0, 0, 0, 0.7);
  color: #fff;
  border: 1px solid #444;
  padding: 8px 12px;
  font-size: 13px;
  font-family: sans-serif;
  line-height: 1.6;
  white-space: pre-wrap;
  width: min(500px, calc(100vw - 28px));
  pointer-events: none;
  display: none;
  z-index: 100;
}
