/* World — product chrome.
   One dark "night ink" system shared by the canvas notch, the editor
   window and the field guide. The authored page is never styled here. */

@font-face {
  font-family: Bricolage;
  src: url("/bricolage.woff2") format("woff2");
  font-weight: 400 800;
  font-display: swap;
}

* {
  box-sizing: border-box;
}

:root {
  /* Surfaces, darkest to lightest */
  --ink-0: #131218;
  --ink-1: #18171e;
  --ink-2: #201f28;
  --ink-3: #2a2833;
  --ink-4: #35333f;
  --hair: #2f2d38;
  --hair-strong: #403d4b;
  /* Text */
  --text: #eeebf5;
  --text-2: #aaa6b6;
  --text-3: #75717f;
  /* Signals */
  --accent: #c4b5ff;
  --accent-soft: #c4b5ff1f;
  --accent-ink: #1d1830;
  --live: #7ddca6;
  --warn: #f3c776;
  --warn-soft: #f3c7761a;
  --error: #ff958c;
  --error-soft: #ff958c1c;
  /* Shape */
  --radius-s: 6px;
  --radius-m: 10px;
  --radius-l: 16px;
  --shadow: 0 10px 30px #0000005c, 0 2px 6px #00000040;
  --ui: Bricolage, Inter, -apple-system, BlinkMacSystemFont, "Segoe UI",
    system-ui, sans-serif;
  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas,
    "Liberation Mono", monospace;

  font-family: var(--ui);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

body {
  margin: 0;
  background: white;
  overflow: hidden;
}

button,
input,
textarea {
  font: inherit;
}
button {
  cursor: pointer;
  color: inherit;
  background: transparent;
  border: 0;
  padding: 0;
}
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
[hidden] {
  display: none !important;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
  }
}

/* ───────────────────────── Canvas page ───────────────────────── */

main,
#canvas {
  position: fixed;
  inset: 0;
}
#canvas {
  overflow: hidden;
}
iframe {
  display: block;
  width: 100%;
  height: 100%;
  border: 0;
  background: white;
}

#dock {
  position: fixed;
  top: 0;
  right: max(14px, env(safe-area-inset-right));
  z-index: 3;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
  pointer-events: none;
}

/* The notch hangs from the top edge like a small tab of ink. */
.notch {
  display: flex;
  align-items: stretch;
  height: 34px;
  background: var(--ink-1);
  border: 1px solid #ffffff14;
  border-top: 0;
  border-radius: 0 0 14px 14px;
  box-shadow:
    0 6px 18px #0c0b1033,
    0 1px 2px #0c0b1040;
  overflow: hidden;
  pointer-events: auto;
}
#toggle,
#info-link {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text);
  transition:
    background 0.15s,
    color 0.15s;
}
#toggle {
  gap: 7px;
  padding: 0 11px 0 10px;
  min-width: 58px;
  height: 100%;
}
#toggle svg {
  width: 17px;
  height: 17px;
  fill: none;
  stroke: var(--accent);
  stroke-width: 1.6;
  transition: transform 0.4s cubic-bezier(0.3, 0.7, 0.2, 1);
}
#toggle:hover svg {
  transform: rotate(-18deg);
}
#toggle .live {
  width: 6px;
  height: 6px;
  margin-right: -2px;
  border-radius: 50%;
  background: var(--text-3);
}
#toggle[data-state="live"] .live {
  background: var(--live);
}
#online-count {
  min-width: 1ch;
  font:
    650 13px/1 var(--ui),
    sans-serif;
  font-variant-numeric: tabular-nums;
}
#info-link {
  position: relative;
  width: 34px;
  color: var(--text-2);
  text-decoration: none;
}
#info-link::before {
  content: "";
  position: absolute;
  left: 0;
  height: 14px;
  border-left: 1px solid var(--hair-strong);
}
#info-link svg {
  width: 17px;
  height: 17px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.5;
  stroke-linecap: round;
}
#info-link svg .fill {
  fill: currentColor;
  stroke: none;
}
#toggle:hover,
#info-link:hover {
  background: var(--ink-3);
}
#info-link:hover {
  color: var(--text);
}
#toggle:focus-visible,
#info-link:focus-visible {
  outline-offset: -3px;
}

#popup-fallback {
  pointer-events: auto;
  padding: 9px 13px;
  border-radius: var(--radius-m);
  background: var(--ink-1);
  border: 1px solid var(--hair-strong);
  box-shadow: var(--shadow);
  color: var(--text-2);
  font-size: 13px;
  text-decoration: none;
}
#popup-fallback strong {
  color: var(--accent);
  font-weight: 650;
}

/* ───────────────────────── Presence markers ───────────────────────── */

#pointers,
#carets {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 2;
}
#carets {
  position: fixed;
  z-index: 4;
}
.pointer,
.caret {
  position: absolute;
  top: 0;
  left: 0;
  pointer-events: none;
  user-select: none;
}
/* Keep the hotspot fixed while letting its label fit inside the viewport. */
.pointer b,
.caret b {
  position: absolute;
  left: 0;
  max-width: calc(100vw - 8px);
  overflow: hidden;
  text-overflow: ellipsis;
  unicode-bidi: isolate;
  white-space: pre;
  background: var(--color);
  color: white;
  box-shadow:
    0 0 0 1px #ffffff40 inset,
    0 2px 8px #0c0b1033;
  font:
    600 11px/1.1 var(--ui),
    system-ui;
  letter-spacing: 0.01em;
}
.pointer svg {
  position: absolute;
  left: -1px;
  top: -1px;
  width: 17px;
  height: 20px;
  fill: var(--color);
  stroke: white;
  stroke-width: 1.4;
  stroke-linejoin: round;
  filter: drop-shadow(0 1px 2px #0c0b1059);
}
.pointer b {
  bottom: 3px;
  padding: 4px 7px;
  border-radius: 9px 9px 2px 9px;
  transform: translateX(
    clamp(
      calc(4px - var(--x)),
      calc(-100% - 3px),
      calc(100vw - var(--x) - 100% - 4px)
    )
  );
}
.pointer.near-top b {
  bottom: auto;
  top: 18px;
}
.caret {
  width: 2px;
  border-radius: 1px;
  background: var(--color);
  box-shadow: 0 0 0 0.5px #ffffff80;
}
.caret b {
  bottom: 100%;
  padding: 3px 6px;
  border-radius: 6px 6px 6px 1px;
  transform: translateX(
    clamp(calc(4px - var(--x)), 0px, calc(100vw - var(--x) - 100% - 4px))
  );
}
.caret b i {
  font-style: normal;
  font-weight: 500;
  opacity: 0.72;
  font-variant-numeric: tabular-nums;
}
.caret.near-top b,
.caret.local b {
  bottom: auto;
  top: 100%;
  border-radius: 1px 6px 6px 6px;
}

/* ───────────────────────── Editor window ───────────────────────── */

.editor-window {
  background: var(--ink-0);
}
#drawer {
  display: flex;
  flex-direction: column;
  position: fixed;
  inset: 0;
  overflow: hidden;
  color-scheme: dark;
  background: var(--ink-0);
}

.icon-button {
  display: grid;
  place-items: center;
  flex: none;
  width: 32px;
  height: 32px;
  border-radius: var(--radius-s);
  color: var(--text-2);
}
.icon-button svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.icon-button:hover {
  color: var(--text);
  background: var(--ink-3);
}
#remove:hover {
  color: var(--error);
}

/* Header: brand · file tabs · presence */
.panel-head {
  display: flex;
  align-items: center;
  gap: 10px;
  height: 48px;
  padding: 0 8px 0 14px;
  padding-top: env(safe-area-inset-top);
  background: var(--ink-1);
  border-bottom: 1px solid var(--hair);
  flex: none;
}
#drawer-title {
  display: flex;
  align-items: center;
  gap: 7px;
  margin: 0;
  flex: none;
  font:
    700 18px/1 var(--ui),
    system-ui;
  letter-spacing: -0.04em;
  white-space: nowrap;
}
#drawer-title .mark {
  width: 19px;
  height: 19px;
  fill: none;
  stroke: var(--accent);
  stroke-width: 1.7;
}
.files {
  display: flex;
  align-items: center;
  align-self: stretch;
  flex: 1;
  min-width: 0;
  gap: 2px;
  padding-left: 10px;
  border-left: 1px solid var(--hair);
  margin-left: 4px;
}
#tabs {
  display: flex;
  align-items: stretch;
  align-self: stretch;
  gap: 2px;
  min-width: 0;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  scrollbar-width: none;
}
#tabs::-webkit-scrollbar {
  display: none;
}
#tabs button {
  position: relative;
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 0 11px;
  color: var(--text-2);
  white-space: nowrap;
  font:
    500 12.5px/1 var(--mono);
  letter-spacing: -0.01em;
}
#tabs button::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 2px;
  background: var(--kind, var(--text-3));
  opacity: 0.85;
}
#tabs button[data-kind="html"] {
  --kind: #f0a37a;
}
#tabs button[data-kind="css"] {
  --kind: #7fb7ff;
}
#tabs button[data-kind="js"] {
  --kind: #f2d36b;
}
#tabs button::after {
  content: "";
  position: absolute;
  inset: auto 8px -1px;
  height: 2px;
  border-radius: 2px 2px 0 0;
  background: transparent;
}
#tabs button:hover {
  color: var(--text);
}
#tabs button.active {
  color: var(--text);
}
#tabs button.active::after {
  background: var(--accent);
}
#tabs button:focus-visible {
  outline-offset: -4px;
}

.session {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: none;
  margin-left: auto;
}
#people {
  display: flex;
  padding-left: 4px;
}
#people span {
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  margin-left: -4px;
  border-radius: 50%;
  background: var(--color, var(--ink-4));
  box-shadow: 0 0 0 2px var(--ink-1);
  color: white;
  font:
    650 10px/1 var(--ui),
    system-ui;
  text-transform: uppercase;
}
#people span.more {
  background: var(--ink-4);
  color: var(--text-2);
  text-transform: none;
}
#online {
  font-size: 12.5px;
  color: var(--text-2);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

/* Source editor */
#editors {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  background: var(--ink-0);
}
#editors .cm-editor {
  height: 100%;
  font-size: 13.5px;
}
#editors .cm-editor.cm-focused {
  outline: 0;
}
#editors .cm-scroller {
  overflow: auto;
  font-family: var(--mono);
  line-height: 1.7;
  scrollbar-width: thin;
  scrollbar-color: var(--ink-4) transparent;
}

/* Status bar */
.editor-status {
  position: relative;
  display: flex;
  align-items: center;
  gap: 4px;
  min-height: 40px;
  padding: 4px 8px;
  padding-bottom: max(4px, env(safe-area-inset-bottom));
  background: var(--ink-1);
  border-top: 1px solid var(--hair);
  font-size: 12.5px;
  color: var(--text-2);
  flex: none;
}
.chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
  height: 30px;
  padding: 0 9px;
  border-radius: var(--radius-s);
  color: var(--text-2);
  white-space: nowrap;
}
.chip:hover {
  background: var(--ink-3);
  color: var(--text);
}
#profile {
  color: var(--text);
  font-weight: 550;
}
#nickname {
  overflow: hidden;
  text-overflow: ellipsis;
}
#dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--text-3);
  box-shadow: 0 0 0 2px #ffffff26;
  flex: none;
}
#profile .pen {
  width: 13px;
  height: 13px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linejoin: round;
  opacity: 0;
  margin-left: -2px;
  transition: opacity 0.15s;
}
#profile:hover .pen,
#profile:focus-visible .pen {
  opacity: 0.7;
}
#problems {
  color: var(--error);
  background: var(--error-soft);
  font-weight: 600;
}
#problems::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
}
#problems:hover {
  background: #ff958c30;
  color: #ffb6b0;
}

/* Line timer: a status chip that discloses its history card on demand. */
#line-history {
  min-width: 0;
}
#line-history summary {
  list-style: none;
  cursor: pointer;
  font-variant-numeric: tabular-nums;
}
#line-history summary::-webkit-details-marker {
  display: none;
}
#line-history[open] summary {
  background: var(--ink-3);
  color: var(--text);
}
#line-number {
  color: var(--text);
  font-weight: 600;
}
#line-remaining {
  color: var(--accent);
  overflow: hidden;
  text-overflow: ellipsis;
}
.orbit {
  flex: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: conic-gradient(var(--accent) var(--life, 0%), var(--ink-4) 0);
  mask: radial-gradient(circle, transparent 46%, black 52%);
}
.disclosure {
  flex: none;
  width: 14px;
  height: 14px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
  opacity: 0.6;
  transition: transform 0.18s;
}
#line-history[open] .disclosure {
  transform: rotate(180deg);
}
.history-card {
  position: absolute;
  z-index: 5;
  left: 8px;
  bottom: calc(100% + 8px);
  width: min(400px, calc(100vw - 16px));
  padding: 14px 16px 16px;
  background: var(--ink-2);
  border: 1px solid var(--hair-strong);
  border-radius: var(--radius-l);
  box-shadow: var(--shadow);
  color: var(--text);
  animation: rise 0.16s ease-out;
}
.history-lede {
  margin: 0 0 12px;
  color: var(--text-2);
  font-size: 13px;
  line-height: 1.45;
}
#line-history dl {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px 18px;
  margin: 0;
  max-height: 40dvh;
  overflow: auto;
}
#line-history dl > div:first-child {
  grid-column: 1 / -1;
}
#line-history dt {
  color: var(--text-3);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
#line-history dd {
  margin: 3px 0 0;
  font-size: 14px;
  line-height: 1.35;
  overflow-wrap: anywhere;
}
@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
}

#saved {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
  padding: 0 6px;
  white-space: nowrap;
}
#saved::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--live);
}
#saved[data-state="saving"]::before {
  background: var(--accent);
  animation: pulse 1s ease-in-out infinite;
}
#saved[data-state="offline"] {
  color: var(--warn);
}
#saved[data-state="offline"]::before {
  background: var(--warn);
}
@keyframes pulse {
  50% {
    opacity: 0.3;
  }
}
#size {
  position: relative;
  padding: 0 6px 0 10px;
  font:
    500 11px/1 var(--mono);
  color: var(--text-3);
  white-space: nowrap;
}
#size::before {
  content: "";
  position: absolute;
  left: 0;
  top: 50%;
  height: 12px;
  margin-top: -6px;
  border-left: 1px solid var(--hair-strong);
}
#size[data-level="high"] {
  color: var(--warn);
}

/* Notices float just above the status bar without shifting the editor. */
#notice {
  position: relative;
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 0;
  padding: 9px 10px 9px 14px;
  background: #2a251c;
  border-top: 1px solid #f3c7762e;
  color: var(--warn);
  font-size: 13px;
  line-height: 1.4;
  flex: none;
}
#notice > span {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 10px;
}
#notice button {
  flex: none;
  padding: 6px 11px;
  border-radius: var(--radius-s);
  background: var(--warn-soft);
  border: 1px solid #f3c77640;
  color: var(--warn);
  font-weight: 600;
  font-size: 12.5px;
}
#notice button:hover {
  background: #f3c77630;
}

/* Dialog: nickname, new file, local recovery */
dialog {
  color-scheme: dark;
  width: min(420px, calc(100vw - 32px));
  max-width: none;
  padding: 20px;
  background: var(--ink-2);
  color: var(--text);
  border: 1px solid var(--hair-strong);
  border-radius: var(--radius-l);
  box-shadow: var(--shadow);
}
dialog:has(#recovery:not([hidden])) {
  width: min(720px, calc(100vw - 32px));
}
dialog[open] {
  animation: rise 0.18s ease-out;
}
dialog::backdrop {
  background: #0b0a0fa6;
  backdrop-filter: blur(2px);
}
dialog label {
  display: block;
  margin-bottom: 4px;
  font-size: 18px;
  font-weight: 650;
  letter-spacing: -0.02em;
}
#promptHint {
  margin: 0 0 14px;
  color: var(--text-2);
  font-size: 13.5px;
  line-height: 1.45;
}
dialog label + input,
dialog label + textarea {
  margin-top: 10px;
}
dialog input,
dialog textarea {
  display: block;
  width: 100%;
  padding: 10px 12px;
  background: var(--ink-0);
  color: var(--text);
  border: 1px solid var(--hair-strong);
  border-radius: var(--radius-m);
  font-size: 15px;
  transition: border-color 0.15s;
}
dialog input:focus,
dialog textarea:focus {
  border-color: var(--accent);
  outline: 0;
  box-shadow: 0 0 0 3px var(--accent-soft);
}
dialog textarea {
  resize: vertical;
  min-height: 40dvh;
  font:
    13px/1.6 var(--mono);
}
.dialog-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 18px;
}
.dialog-actions button {
  height: 36px;
  padding: 0 16px;
  border-radius: var(--radius-m);
  font-weight: 600;
  font-size: 14px;
}
#cancel {
  color: var(--text-2);
}
#cancel:hover {
  background: var(--ink-3);
  color: var(--text);
}
#confirm {
  background: var(--accent);
  color: var(--accent-ink);
}
#confirm:hover {
  background: #d4c9ff;
}

/* Mobile and touch: keep typing at 16px so iOS never zooms. */
@media (any-pointer: coarse), (max-width: 600px) {
  #editors .cm-editor,
  #editors .cm-textfield,
  dialog input,
  dialog textarea {
    font-size: max(16px, 1rem);
  }
}
@media (max-width: 600px) {
  #dock {
    right: max(8px, env(safe-area-inset-right));
  }
  .notch {
    height: 40px;
    border-radius: 0 0 16px 16px;
  }
  #toggle {
    min-width: 64px;
    padding: 0 13px 0 12px;
  }
  #info-link {
    width: 40px;
  }
  .panel-head {
    gap: 4px;
    padding: 0 4px 0 12px;
    padding-top: env(safe-area-inset-top);
  }
  #drawer-title .wordmark,
  #online {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
  }
  .files {
    padding-left: 6px;
    margin-left: 6px;
  }
  #tabs button {
    padding: 0 9px;
    font-size: 13px;
  }
  .icon-button {
    width: 36px;
    height: 36px;
  }
  .session {
    gap: 2px;
  }
  #people span {
    width: 20px;
    height: 20px;
  }
  .editor-status {
    gap: 2px;
    padding-inline: 4px;
  }
  .chip {
    height: 34px;
    padding: 0 8px;
  }
  #nickname {
    max-width: 9ch;
  }
  #line-remaining {
    display: none;
  }
  #size:not([data-level="high"]) {
    display: none;
  }
  #saved {
    font-size: 12px;
  }
  .history-card {
    left: 6px;
    right: 6px;
    width: auto;
  }
  #line-history dd {
    font-size: 15px;
  }
  dialog {
    margin: auto auto max(12px, env(safe-area-inset-bottom));
    width: calc(100vw - 16px);
  }
  dialog:has(#recovery:not([hidden])) {
    width: calc(100vw - 16px);
  }
  .dialog-actions button {
    flex: 1;
    height: 44px;
  }
  #cancel {
    background: var(--ink-3);
  }
}

/* ───────────────────────── Field guide (/info) ───────────────────────── */

.info-window {
  overflow: auto;
  background:
    radial-gradient(120% 60% at 100% 0%, #c4b5ff14, transparent 60%),
    var(--ink-0);
  color: var(--text);
  font:
    16px/1.55 var(--ui),
    system-ui,
    sans-serif;
}
.field-guide {
  position: static;
  max-width: 38rem;
  margin: auto;
  padding: clamp(22px, 6vw, 48px);
}
.field-guide header {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.02em;
}
.field-guide header span:last-child {
  margin-left: auto;
  padding: 4px 9px;
  border: 1px solid var(--hair-strong);
  border-radius: 99px;
  color: var(--text-2);
  font-size: 12px;
  font-weight: 550;
  letter-spacing: 0;
}
.field-guide h1 {
  margin: 40px 0 18px;
  font:
    650 clamp(40px, 9vw, 64px) / 0.98 var(--ui),
    system-ui;
  letter-spacing: -0.055em;
}
.field-guide .intro {
  max-width: 36ch;
  margin: 0 0 28px;
  color: #dcd6e6;
  font-size: 19px;
  line-height: 1.45;
}
.guide-steps {
  margin: 0 0 28px;
  padding: 0;
  list-style: none;
  counter-reset: step;
}
.guide-steps li {
  display: grid;
  grid-template-columns: 34px 1fr;
  column-gap: 12px;
  padding: 18px 0;
  border-top: 1px solid var(--hair);
  counter-increment: step;
}
.guide-steps li::before {
  content: counter(step, decimal-leading-zero);
  grid-row: span 2;
  padding-top: 3px;
  color: var(--accent);
  font:
    600 13px/1.4 var(--mono);
}
.field-guide h2 {
  margin: 0 0 4px;
  font-size: 19px;
  letter-spacing: -0.025em;
}
.guide-steps p {
  max-width: 55ch;
  margin: 0;
  color: var(--text-2);
}
.guide-edit {
  display: inline-flex;
  align-items: center;
  gap: 18px;
  padding: 12px 18px;
  background: var(--accent);
  color: var(--accent-ink);
  border-radius: var(--radius-m);
  font-weight: 650;
  text-decoration: none;
  transition: background 0.15s;
}
.guide-edit:hover {
  background: #d4c9ff;
}
.guide-edit:focus-visible {
  outline: 2px solid white;
  outline-offset: 4px;
}
