/* The workspace guide (track 58): Niijii in the Sky (star or sun), Cod in
   the Sea (fish). cod-body.js draws it on .cod-stage; .cod is the invisible,
   focusable button riding on top. The bubble is a chat thread with the
   input always at the bottom. Replaces the "i" sidecar (<html class="cod-on">). */

:root.cod-on #sidecar {
  display: none !important;
}

.cod-stage {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  z-index: 879;
  pointer-events: none;
}

.cod {
  position: fixed;
  left: 0;
  top: 0;
  z-index: 880;
  width: 84px;
  height: 84px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.cod:focus-visible {
  outline: 2px solid var(--accent-2);
  outline-offset: 2px;
}

/* The element the guide is talking about. */
.cod-spot {
  outline: 2px solid var(--accent-2) !important;
  outline-offset: 6px;
  border-radius: 14px;
  transition: outline-color 200ms ease;
}

/* ---- bubble ---------------------------------------------------------- */
.cod-bubble {
  position: fixed;
  left: 0;
  top: 0;
  z-index: 881;
  width: min(370px, calc(100vw - 32px));
  max-height: min(72vh, 580px);
  display: flex;
  flex-direction: column;
  color: var(--text-primary);
  background: var(--glass-fill-2);
  -webkit-backdrop-filter: blur(22px) saturate(140%);
  backdrop-filter: blur(22px) saturate(140%);
  border: 1px solid var(--glass-border-strong);
  border-radius: 16px;
  box-shadow: var(--shadow-glass, 0 14px 40px rgba(0, 0, 0, 0.35));
  font-size: 0.95rem;
  line-height: 1.5;
  opacity: 0;
  transition: opacity 180ms ease;
}
:root[data-theme="dark"] .cod-bubble {
  background: rgba(14, 30, 34, 0.88);
}
:root[data-world="sea"][data-theme="dark"] .cod-bubble {
  background: rgba(6, 34, 43, 0.9);
}
.cod-bubble.open {
  opacity: 1;
}
/* A phone coaching bubble has no controls: taps go to the page beneath it
   (cod.js coach(); it closes itself after a read). */
.cod-bubble.cod-passthrough {
  pointer-events: none;
}
/* The unprompted first-visit offer: a small card, so it can find clear space
   even on a dense page (track 59 QA). Opening the guide gives the full chat. */
.cod-bubble.cod-compact {
  width: min(270px, calc(100vw - 32px));
}
.cod-bubble.cod-compact .cod-head,
.cod-bubble.cod-compact .cod-form,
.cod-bubble.cod-compact .cod-fine {
  display: none;
}
.cod-bubble.cod-compact .cod-thread {
  min-height: 0;
  padding-top: 0.7rem;
}
.cod-bubble.cod-compact .cod-msg {
  max-width: 100%;
}
/* A modal dialog is open (cod.js placeBubble): stand aside until it closes. */
.cod-bubble.cod-under-modal {
  visibility: hidden;
  pointer-events: none;
}
.cod-bubble[hidden] {
  display: none;
}

.cod-head {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.7rem 0.9rem 0.35rem;
  font-size: 0.74rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  font-weight: 700;
  color: var(--accent-2);
}
:root[data-theme="light"] .cod-head {
  color: var(--accent);
}
.cod-head .ctx {
  font-weight: 500;
  letter-spacing: 0.06em;
  color: var(--text-tertiary);
  text-transform: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cod-head .x {
  margin-left: auto;
  flex: none;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 1px solid var(--glass-border);
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
}

.cod-thread {
  flex: 1 1 auto;
  min-height: 60px;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 0.2rem 0.9rem 0.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}
.cod-msg {
  max-width: 94%;
  padding: 0.55rem 0.75rem;
  border-radius: 12px;
  white-space: pre-wrap;
}
.cod-msg.me {
  align-self: flex-end;
  background: var(--accent);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.cod-msg.cod-says {
  align-self: flex-start;
  background: var(--glass-fill);
  border: 1px solid var(--glass-border);
  border-bottom-left-radius: 4px;
}
.cod-msg h4 {
  margin: 0 0 0.3rem;
  font-size: 1.02rem;
  line-height: 1.3;
}
.cod-msg p {
  margin: 0 0 0.45rem;
  color: var(--text-secondary);
}
.cod-msg p:last-child {
  margin-bottom: 0;
}
.cod-msg ul {
  margin: 0.2rem 0 0.2rem;
  padding-left: 1.1rem;
  color: var(--text-secondary);
}
.cod-msg li {
  margin-bottom: 0.3rem;
}
.cod-step {
  font-size: 0.78rem;
  color: var(--text-tertiary);
}
.cod-tag {
  display: block;
  margin-bottom: 0.3rem;
  font-size: 0.68rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--warn, #c89b3c);
}
:root[data-theme="light"] .cod-tag {
  color: #8a5a12;
}
.cod-msg p.cod-src {
  margin-top: 0.4rem;
  font-size: 0.78rem;
  color: var(--text-tertiary);
}
.cod-caret {
  display: inline-block;
  width: 0.5em;
  height: 1em;
  margin-left: 1px;
  vertical-align: -0.12em;
  border-radius: 2px;
  background: var(--accent-2);
  opacity: 0.75;
  animation: codCaret 0.9s steps(2) infinite;
}
@keyframes codCaret {
  50% { opacity: 0; }
}
.cod-typing {
  display: inline-flex;
  gap: 4px;
}
.cod-typing i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-tertiary);
  animation: codDots 1s infinite;
}
.cod-typing i:nth-child(2) { animation-delay: 0.15s; }
.cod-typing i:nth-child(3) { animation-delay: 0.3s; }
@keyframes codDots {
  0%, 100% { opacity: 0.3; transform: translateY(0); }
  50% { opacity: 1; transform: translateY(-3px); }
}

.cod-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  padding: 0 0.9rem;
  opacity: 0;
  transform: translateY(4px);
  transition: opacity 220ms ease, transform 220ms ease;
}
.cod-chips:empty {
  display: none;
}
.cod-chips.in {
  opacity: 1;
  transform: none;
  padding-bottom: 0.55rem;
}
.cod-btn {
  border: 1px solid var(--glass-border-strong);
  background: var(--glass-fill);
  color: var(--text-primary);
  border-radius: 999px;
  padding: 0.38rem 0.8rem;
  font: inherit;
  font-size: 0.84rem;
  font-weight: 600;
  cursor: pointer;
  min-height: 34px;
  text-align: left;
}
.cod-btn:hover {
  border-color: var(--accent-2);
}
.cod-btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.cod-btn.ghost {
  background: transparent;
  font-weight: 500;
}

/* The input, always at the bottom. */
.cod-form {
  display: flex;
  gap: 0.4rem;
  padding: 0.6rem 0.9rem 0.2rem;
  border-top: 1px solid var(--glass-border);
}
.cod-form input {
  flex: 1;
  min-width: 0;
  min-height: 40px;
  border-radius: 999px;
  border: 1px solid var(--glass-border-strong);
  background: var(--field-bg, rgba(255, 255, 255, 0.06));
  color: var(--text-primary);
  padding: 0 0.9rem;
  font: inherit;
}
.cod-form input:focus {
  outline: none;
  border-color: var(--accent-2);
}
.cod-fine {
  margin: 0.25rem 0.9rem 0.7rem;
  font-size: 0.72rem;
  color: var(--text-tertiary);
}

@media (max-width: 640px) {
  .cod {
    width: 64px;
    height: 64px;
  }
  .cod-bubble {
    max-height: 60vh;
  }
  /* A speech bubble, not a card of boxes: the guide's words sit straight in
     it, and the tail (cod.js sets --tail-x and the side) points at the guide. */
  .cod-msg.cod-says {
    max-width: 100%;
    padding: 0.15rem 0;
    background: none;
    border: 0;
    border-radius: 0;
  }
  .cod-bubble.cod-tail-up::before,
  .cod-bubble.cod-tail-down::before {
    content: "";
    position: absolute;
    left: calc(var(--tail-x, 50%) - 9px);
    width: 18px;
    height: 18px;
    background: inherit;
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
    transform: rotate(45deg);
    pointer-events: none;
  }
  .cod-bubble.cod-tail-up::before {
    top: -9px;
    border-top: 1px solid var(--glass-border-strong);
    border-left: 1px solid var(--glass-border-strong);
    clip-path: polygon(0 0, 100% 0, 0 100%);
  }
  .cod-bubble.cod-tail-down::before {
    bottom: -9px;
    border-right: 1px solid var(--glass-border-strong);
    border-bottom: 1px solid var(--glass-border-strong);
    clip-path: polygon(100% 0, 100% 100%, 0 100%);
  }
}
@media (prefers-reduced-motion: reduce) {
  .cod-caret {
    animation: none;
  }
  .cod-bubble,
  .cod-chips {
    transition: none;
  }
}

/* ---- Customize window (cod-customize.js) ------------------------------- */
.cod-custom {
  position: fixed;
  inset: 0;
  z-index: 950;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(6, 12, 12, 0.55);
  opacity: 0;
  transition: opacity 180ms ease;
}
.cod-custom[hidden] {
  display: none;
}
.cod-custom.open {
  opacity: 1;
}
.cod-custom-card {
  width: min(780px, 100%);
  max-height: 88vh;
  overflow-y: auto;
  overscroll-behavior: contain;
  color: var(--text-primary);
  background: var(--glass-fill-2);
  -webkit-backdrop-filter: blur(22px) saturate(140%);
  backdrop-filter: blur(22px) saturate(140%);
  border: 1px solid var(--glass-border-strong);
  border-radius: 18px;
  box-shadow: var(--shadow-glass, 0 14px 40px rgba(0, 0, 0, 0.35));
  padding: 1.1rem 1.2rem 1rem;
}
:root[data-theme="dark"] .cod-custom-card {
  background: rgba(14, 24, 26, 0.92);
}
.cod-custom-head {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}
.cod-custom-head h2 {
  margin: 0;
  font-size: 1.35rem !important;
  line-height: 1.2 !important;
}
.cod-custom-head .x {
  margin-left: auto;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 1px solid var(--glass-border);
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 1.1rem;
}
.cod-custom-sub {
  margin: 0.35rem 0 0.8rem;
  color: var(--text-secondary);
  font-size: 0.92rem;
}
.cod-custom-group h3 {
  margin: 0.9rem 0 0.5rem;
  font-size: 1rem;
}
.cod-custom-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(165px, 1fr));
  gap: 0.6rem;
}
.cod-opt {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  padding: 0.5rem;
  text-align: left;
  border-radius: 12px;
  border: 1px solid var(--glass-border);
  background: var(--glass-fill);
  color: var(--text-primary);
  font: inherit;
  cursor: pointer;
}
.cod-opt:hover {
  border-color: var(--glass-border-strong);
}
.cod-opt.on {
  border-color: var(--accent-2);
  box-shadow: 0 0 0 2px var(--accent-2) inset;
}
.cod-opt:focus-visible {
  outline: 2px solid var(--accent-2);
  outline-offset: 2px;
}
.cod-opt-fig {
  display: block;
  aspect-ratio: 16 / 10;
  border-radius: 8px;
  overflow: hidden;
  background: rgba(0, 0, 0, 0.18);
}
.cod-opt-fig img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.cod-opt-fig.shuffle {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
  font-weight: 700;
  color: var(--accent-2);
}
.cod-opt-name {
  font-weight: 700;
  font-size: 0.92rem;
}
.cod-opt-desc {
  font-size: 0.8rem;
  line-height: 1.35;
  color: var(--text-secondary);
}
.cod-custom-foot {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 1rem;
}
@media (max-width: 520px) {
  .cod-custom-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
