/* The whiteboard (/whiteboard/app): a full-screen board, no page scroll.
 *
 * Uses the shared design tokens (tokens.css, base.css) with the dark chrome
 * of the public site. Layout: a top bar (brand link, undo/redo, save status,
 * menu); the canvas fills the rest; the toolbar floats on the left on wide
 * screens and along the bottom on phones (scrolling sideways when needed);
 * zoom controls float bottom-right. Only the canvas has touch-action: none.
 */

.wba-body {
  --wba-chrome: #15161c;
  --wba-chrome-raised: #1f2028;
  --wba-line: rgba(255, 255, 255, 0.12);
  --wba-text: #f4f5f8;
  --wba-muted: #a6a8b6;
  --wba-gold: var(--color-brand);
  --wba-control: 44px;
  --wba-radius: 14px;
  --wba-shadow: 0 18px 40px -18px rgba(0, 0, 0, 0.7), 0 0 0 1px rgba(0, 0, 0, 0.25);

  height: 100vh;
  height: 100dvh;
  margin: 0;
  overflow: hidden;
  background-color: #0b0b0e;
  color: var(--wba-text);
  font-family: var(--font-sans);
  overscroll-behavior: none;
}

.wba-body :focus-visible {
  outline: 2px solid var(--wba-gold);
  outline-offset: 2px;
}

.wba-nojs {
  display: grid;
  gap: 0.75rem;
  max-width: 34rem;
  margin: 15vh auto 0;
  padding: 2rem 1.25rem;
  color: var(--wba-muted);
  text-align: center;
}

.wba-nojs[hidden],
.wba[hidden] {
  display: none;
}

.wba-nojs__title {
  color: var(--wba-text);
  font-size: 1.4rem;
  font-weight: var(--font-weight-bold);
}

.wba-nojs a {
  color: var(--wba-gold);
}

.wba {
  position: relative;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  height: 100%;
}

/* Fixed rows, so the stage keeps the last row while the notice is hidden. */
.wba-top { grid-row: 1; }
.wba-notice { grid-row: 2; }
.wba-stage { grid-row: 3; }

/* -------------------------------------------------------------- Top bar */

.wba-top {
  z-index: 3;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  min-height: 56px;
  padding: 0.4rem max(0.75rem, env(safe-area-inset-right)) 0.4rem max(0.75rem, env(safe-area-inset-left));
  border-bottom: 1px solid var(--wba-line);
  background-color: var(--wba-chrome);
}

.wba-brand {
  min-width: 0;
  margin-right: auto;
  overflow: hidden;
  color: var(--wba-text);
  font-weight: var(--font-weight-semibold);
  text-decoration: none;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.wba-brand__company {
  color: var(--color-company);
  font-family: var(--font-company);
}

.wba-top__group {
  display: flex;
  gap: 0.25rem;
}

.wba-save {
  min-width: 4.5rem;
  color: var(--wba-muted);
  font-size: var(--font-size-xs);
  text-align: right;
}

@media (max-width: 479.98px) {
  .wba-save {
    display: none;
  }
}

.wba-icon,
.wba-tool,
.wba-menu__button,
.wba-zoom__value {
  display: inline-grid;
  place-items: center;
  min-width: var(--wba-control);
  height: var(--wba-control);
  padding: 0;
  border: 1px solid transparent;
  border-radius: 10px;
  background: transparent;
  color: var(--wba-text);
  font: inherit;
  cursor: pointer;
  transition: background-color var(--transition-fast), border-color var(--transition-fast), color var(--transition-fast);
}

.wba-icon svg,
.wba-tool svg {
  width: 1.3rem;
  height: 1.3rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.wba-icon:hover:not(:disabled),
.wba-tool:hover:not(:disabled),
.wba-menu__button:hover,
.wba-zoom__value:hover {
  background-color: rgba(255, 255, 255, 0.08);
}

.wba-icon:disabled,
.wba-tool:disabled {
  color: rgba(255, 255, 255, 0.3);
  cursor: not-allowed;
}

.wba-tool[aria-pressed="true"] {
  border-color: rgba(235, 196, 42, 0.6);
  background-color: rgba(235, 196, 42, 0.18);
  color: var(--wba-gold);
}

/* Menu. */
.wba-menu {
  position: relative;
}

.wba-menu__button {
  display: inline-flex;
  gap: 0.4rem;
  padding: 0 0.8rem;
  border-color: var(--wba-line);
}

.wba-menu__icon {
  width: 1.15rem;
  height: 1.15rem;
}

.wba-menu__panel {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  z-index: 10;
  display: grid;
  min-width: 14rem;
  padding: 0.35rem;
  border: 1px solid var(--wba-line);
  border-radius: var(--wba-radius);
  background-color: var(--wba-chrome-raised);
  box-shadow: var(--wba-shadow);
}

.wba-menu__panel[hidden] {
  display: none;
}

.wba-menu__panel [role="group"] {
  display: grid;
}

.wba-menu__item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-height: 40px;
  padding: 0 0.75rem;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--wba-text);
  font: inherit;
  font-size: var(--font-size-base);
  text-align: left;
  cursor: pointer;
}

.wba-menu__item:hover,
.wba-menu__item:focus-visible {
  background-color: rgba(255, 255, 255, 0.08);
  outline-offset: -2px;
}

.wba-menu__item[role="menuitemradio"]::before {
  content: "";
  width: 0.55rem;
  height: 0.55rem;
  border: 1.5px solid var(--wba-muted);
  border-radius: 50%;
}

.wba-menu__item[aria-checked="true"]::before {
  border-color: var(--wba-gold);
  background-color: var(--wba-gold);
}

.wba-menu__sep {
  height: 1px;
  margin: 0.3rem 0.4rem;
  background-color: var(--wba-line);
}

.wba-menu__label {
  padding: 0.35rem 0.75rem 0.15rem;
  color: var(--wba-muted);
  font-size: var(--font-size-xs);
  font-weight: var(--font-weight-semibold);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.wba-notice {
  z-index: 2;
  padding: 0.5rem 1rem;
  background-color: rgba(235, 196, 42, 0.16);
  color: var(--wba-text);
  font-size: var(--font-size-sm);
  text-align: center;
}

.wba-notice[hidden] {
  display: none;
}

/* ---------------------------------------------------------------- Stage */

.wba-stage {
  position: relative;
  min-height: 0;
  overflow: hidden;
  background-color: #ffffff;
}

.wba[data-background="dark"] .wba-stage {
  background-color: #17181d;
}

.wba-canvas {
  display: block;
  width: 100%;
  height: 100%;
  /* The board handles every touch gesture itself (draw, pinch, pan). */
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.wba-canvas:focus-visible {
  outline-offset: -3px;
}

/* The text editor sits exactly where the text will be drawn (positioned by tools.js). */
.wba-text {
  position: absolute;
  z-index: 2;
  min-width: 40px;
  margin: 0;
  padding: 0;
  overflow: hidden;
  border: 1px dashed #2563eb;
  border-radius: 2px;
  background: transparent;
  resize: none;
  white-space: pre;
  outline: none;
}

.wba-text[hidden] {
  display: none;
}

/* -------------------------------------------------------------- Toolbar */

.wba-toolbar {
  position: absolute;
  top: 72px;
  left: 12px;
  z-index: 3;
  display: grid;
  gap: 0.5rem;
  max-height: calc(100% - 96px);
  padding: 0.4rem;
  overflow-y: auto;
  border: 1px solid var(--wba-line);
  border-radius: var(--wba-radius);
  background-color: var(--wba-chrome);
  box-shadow: var(--wba-shadow);
  scrollbar-width: thin;
}

.wba-toolbar__group {
  display: grid;
  grid-template-columns: repeat(2, var(--wba-control));
  gap: 0.2rem;
}

.wba-toolbar__group--style {
  padding-top: 0.5rem;
  border-top: 1px solid var(--wba-line);
}

.wba-swatches,
.wba-widths {
  display: grid;
  grid-column: 1 / -1;
  grid-template-columns: repeat(2, var(--wba-control));
  gap: 0.2rem;
}

.wba-swatch {
  width: var(--wba-control);
  height: 34px;
  border: 2px solid rgba(255, 255, 255, 0.18);
  border-radius: 9px;
  cursor: pointer;
}

.wba-swatch[aria-pressed="true"] {
  border-color: var(--wba-gold);
  box-shadow: 0 0 0 2px var(--wba-chrome) inset;
}

.wba-custom {
  position: relative;
  display: grid;
  place-items: center;
  grid-column: 1 / -1;
  height: 34px;
  border: 2px dashed rgba(255, 255, 255, 0.25);
  border-radius: 9px;
  cursor: pointer;
}

.wba-custom:focus-within {
  outline: 2px solid var(--wba-gold);
  outline-offset: 2px;
}

.wba-custom__input {
  width: 100%;
  height: 100%;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
}

.wba-width {
  display: grid;
  place-items: center;
  width: var(--wba-control);
  height: 36px;
  border: 1px solid transparent;
  border-radius: 9px;
  background: transparent;
  cursor: pointer;
}

.wba-width:hover {
  background-color: rgba(255, 255, 255, 0.08);
}

.wba-width[aria-pressed="true"] {
  border-color: rgba(235, 196, 42, 0.6);
  background-color: rgba(235, 196, 42, 0.18);
}

.wba-width__dot {
  display: block;
  border-radius: 50%;
  background-color: var(--wba-text);
}

.wba-fill {
  grid-column: 1 / -1;
  width: 100%;
}

.wba-fill[aria-pressed="true"] svg {
  fill: currentColor;
  fill-opacity: 0.35;
}

/* Phones: the toolbar runs along the bottom and scrolls sideways. */
@media (max-width: 767.98px) {
  .wba-toolbar {
    top: auto;
    right: 8px;
    bottom: max(8px, env(safe-area-inset-bottom));
    left: 8px;
    display: flex;
    max-height: none;
    overflow-x: auto;
    overflow-y: hidden;
  }

  .wba-toolbar__group,
  .wba-swatches,
  .wba-widths {
    display: flex;
    flex: 0 0 auto;
  }

  .wba-toolbar__group--style {
    padding-top: 0;
    padding-left: 0.5rem;
    border-top: 0;
    border-left: 1px solid var(--wba-line);
  }

  .wba-swatch {
    width: 34px;
    height: var(--wba-control);
  }

  .wba-custom {
    width: 44px;
    height: var(--wba-control);
  }

  .wba-width {
    width: 40px;
    height: var(--wba-control);
  }

  .wba-fill {
    width: var(--wba-control);
  }
}

/* ----------------------------------------------------------------- Zoom */

.wba-zoom {
  position: absolute;
  right: 12px;
  bottom: 12px;
  z-index: 3;
  display: flex;
  align-items: center;
  gap: 0.15rem;
  padding: 0.25rem;
  border: 1px solid var(--wba-line);
  border-radius: var(--wba-radius);
  background-color: var(--wba-chrome);
  box-shadow: var(--wba-shadow);
}

.wba-zoom__value {
  min-width: 4rem;
  font-size: var(--font-size-sm);
  font-variant-numeric: tabular-nums;
}

@media (max-width: 767.98px) {
  .wba-zoom {
    top: 68px;
    right: 8px;
    bottom: auto;
  }
}

/* ------------------------------------------------------- Toast, dialogs */

.wba-toast {
  position: absolute;
  bottom: 84px;
  left: 50%;
  z-index: 5;
  max-width: min(90vw, 32rem);
  padding: 0.7rem 1.1rem;
  border-radius: 12px;
  background-color: #23252e;
  color: var(--wba-text);
  font-size: var(--font-size-sm);
  box-shadow: var(--wba-shadow);
  transform: translateX(-50%);
}

.wba-toast.is-error {
  background-color: #4a1f24;
}

.wba-toast[hidden] {
  display: none;
}

@media (prefers-reduced-motion: no-preference) {
  .wba-toast:not([hidden]) {
    animation: wba-toast 220ms ease-out;
  }
}

@keyframes wba-toast {
  from { opacity: 0; transform: translate(-50%, 8px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

.wba-dialog {
  width: min(92vw, 28rem);
  padding: 1.4rem;
  border: 1px solid var(--wba-line);
  border-radius: 16px;
  background-color: var(--wba-chrome-raised);
  color: var(--wba-text);
  box-shadow: var(--wba-shadow);
}

.wba-dialog--wide {
  width: min(94vw, 36rem);
  max-height: 86vh;
}

.wba-dialog::backdrop {
  background-color: rgba(0, 0, 0, 0.55);
}

.wba-dialog__title {
  margin-bottom: 0.6rem;
  font-size: 1.2rem;
  font-weight: var(--font-weight-bold);
}

.wba-dialog__text {
  color: var(--wba-muted);
  font-size: var(--font-size-md);
  line-height: 1.55;
}

.wba-dialog__actions {
  display: flex;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 1.25rem;
}

.wba-button {
  min-height: var(--wba-control);
  padding: 0 1.1rem;
  border: 1px solid var(--wba-gold);
  border-radius: 10px;
  background-color: var(--wba-gold);
  color: var(--color-brand-contrast);
  font: inherit;
  font-weight: var(--font-weight-semibold);
  cursor: pointer;
}

.wba-button--ghost {
  border-color: var(--wba-line);
  background-color: transparent;
  color: var(--wba-text);
}

.wba-keys {
  display: grid;
  gap: 0.35rem;
  margin: 0;
}

.wba-keys div {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.35rem 0;
  border-bottom: 1px solid var(--wba-line);
  font-size: var(--font-size-sm);
}

.wba-keys dt {
  color: var(--wba-muted);
}

.wba-keys dd {
  margin: 0;
  text-align: right;
}

kbd {
  display: inline-block;
  min-width: 1.6em;
  padding: 0.05rem 0.35rem;
  border: 1px solid var(--wba-line);
  border-bottom-width: 2px;
  border-radius: 5px;
  background-color: #2a2b34;
  color: var(--wba-text);
  font-family: var(--font-mono);
  font-size: 0.8em;
  text-align: center;
}

.wba-file {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
}
