:root {
  --ink: #17202a;
  --muted: #667085;
  --line: #d6dbe3;
  --paper: #f7f7f2;
  --panel: #ffffff;
  --accent: #0077ed;
  --accent-dark: #005db9;
  --green: #17a56b;
  --shadow: 0 18px 45px rgba(26, 37, 54, 0.14);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #edf0f3;
}

button,
input,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  display: grid;
  grid-template-columns: 292px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 22px;
  background: rgba(255, 255, 255, 0.82);
  border-right: 1px solid var(--line);
  backdrop-filter: blur(18px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding-bottom: 8px;
}

.brand-mark {
  overflow: hidden;
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  color: #fff;
  font-weight: 800;
  border-radius: 8px;
  background: linear-gradient(135deg, #0077ed, #17a56b);
}

.brand-mark img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.brand h1,
.topbar h2,
.panel h2,
.dialog-card h2 {
  margin: 0;
  letter-spacing: 0;
}

.brand h1 {
  font-size: 17px;
}

.brand p,
.topbar p,
.status {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.panel {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.panel h2 {
  margin-bottom: 12px;
  font-size: 13px;
  color: #3b4654;
}

.tool-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
}

.zoom-controls {
  display: grid;
  grid-template-columns: 42px 1fr 42px;
  gap: 8px;
  margin-bottom: 10px;
}

.tool-button {
  display: grid;
  place-items: center;
  min-width: 0;
  aspect-ratio: 1;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: #253044;
  background: #f8fafc;
  font-size: 20px;
}

.tool-button svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.tool-button[data-tool="select"] svg path {
  fill: currentColor;
  stroke-width: 0;
}

.tool-button.active {
  color: #fff;
  border-color: var(--accent);
  background: var(--accent);
}

.field {
  display: grid;
  gap: 8px;
  margin-top: 12px;
  color: #475467;
  font-size: 13px;
}

.field input {
  width: 100%;
}

.field input[type="url"] {
  min-height: 42px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.primary-button,
.quiet-button {
  width: 100%;
  min-height: 42px;
  border-radius: 8px;
  border: 1px solid transparent;
  font-weight: 700;
}

.primary-button {
  color: #fff;
  background: var(--accent);
}

.primary-button:hover {
  background: var(--accent-dark);
}

.quiet-button {
  color: #344054;
  background: #f8fafc;
  border-color: var(--line);
}

.danger-button {
  color: #b42318;
}

.owner-controls {
  display: grid;
  gap: 8px;
  margin-top: 10px;
}

.zoom-value {
  min-width: 0;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: #344054;
  background: #fff;
  font-size: 13px;
  font-weight: 800;
}

.workspace {
  display: grid;
  grid-template-rows: auto 1fr;
  min-width: 0;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 16px;
  padding: 18px 24px;
  border-bottom: 1px solid var(--line);
  background: rgba(247, 248, 250, 0.86);
}

.topbar > div:first-child {
  min-width: 0;
  flex: 1 1 auto;
}

.topbar h2 {
  font-size: 20px;
}

.presence {
  order: 3;
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 38px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: #475467;
  font-size: 13px;
  white-space: nowrap;
}

.live-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #98a2b3;
}

.presence.is-online .live-dot {
  background: var(--green);
  box-shadow: 0 0 0 4px rgba(23, 165, 107, 0.12);
}

.participant-list {
  order: 2;
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
  min-width: 0;
}

.participant-chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  max-width: 150px;
  height: 34px;
  padding: 0 10px 0 6px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.92);
  color: #344054;
  font-size: 12px;
  font-weight: 700;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.08);
}

button.participant-chip {
  cursor: pointer;
  font: inherit;
}

button.participant-chip:hover {
  border-color: rgba(0, 119, 237, 0.36);
  box-shadow: 0 10px 28px rgba(0, 119, 237, 0.14);
}

.participant-avatar {
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  flex: 0 0 auto;
  border-radius: 999px;
  color: #fff;
  font-size: 11px;
  font-weight: 900;
}

.participant-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.participant-chip.is-active {
  border-color: rgba(0, 119, 237, 0.32);
  background: #fff;
}

.participant-chip.is-active::after {
  content: "操作中";
  color: var(--accent);
  font-size: 11px;
  font-weight: 800;
}

.board {
  position: relative;
  min-height: 0;
  overflow: hidden;
  background-color: var(--paper);
  background-image:
    linear-gradient(rgba(23, 32, 42, 0.06) 1px, transparent 1px),
    linear-gradient(90deg, rgba(23, 32, 42, 0.06) 1px, transparent 1px);
  background-size: 28px 28px;
  background-position: var(--board-x, 0px) var(--board-y, 0px);
  background-size: var(--grid-size, 28px) var(--grid-size, 28px);
  touch-action: none;
}

.history-controls {
  position: absolute;
  top: 12px;
  left: 12px;
  z-index: 35;
  display: flex;
  gap: 6px;
  padding: 6px;
  border: 1px solid rgba(15, 23, 42, 0.12);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.68);
  box-shadow: 0 12px 28px rgba(15, 23, 42, 0.14);
  backdrop-filter: blur(12px);
}

.history-controls button {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border: 1px solid rgba(15, 23, 42, 0.12);
  border-radius: 8px;
  color: #17202a;
  background: rgba(255, 255, 255, 0.78);
  font-size: 20px;
  font-weight: 800;
}

.history-controls button:disabled {
  cursor: default;
  opacity: 0.36;
}

#inkCanvas,
.item-layer {
  position: absolute;
  inset: 0;
}

#inkCanvas {
  z-index: 1;
}

.item-layer {
  z-index: 2;
  pointer-events: none;
  transform: translate(var(--board-x, 0px), var(--board-y, 0px)) scale(var(--board-scale, 1));
  transform-origin: 0 0;
}

.empty-hint {
  position: absolute;
  left: 50%;
  top: 48%;
  z-index: 0;
  display: grid;
  gap: 6px;
  width: min(360px, calc(100% - 48px));
  transform: translate(-50%, -50%);
  color: rgba(23, 32, 42, 0.42);
  text-align: center;
}

.empty-hint strong {
  font-size: 20px;
}

.board.has-items .empty-hint {
  display: none;
}

.board.select-mode #inkCanvas {
  pointer-events: none;
}

.board.select-mode {
  cursor: grab;
}

.board.select-mode.is-panning {
  cursor: grabbing;
}

.board.pen-mode #inkCanvas {
  cursor: none;
}

.board.eraser-mode #inkCanvas {
  cursor: none;
}

.snap-guide {
  position: absolute;
  z-index: 4;
  pointer-events: none;
  background: rgba(0, 119, 237, 0.62);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.7);
}

.snap-guide-x {
  top: 0;
  bottom: 0;
  width: 1px;
}

.snap-guide-y {
  right: 0;
  left: 0;
  height: 1px;
}

.brush-preview {
  position: absolute;
  z-index: 5;
  border: 1.5px solid #1f2937;
  border-radius: 50%;
  pointer-events: none;
  background: rgba(255, 255, 255, 0.22);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.72);
}

.brush-preview.eraser-preview {
  border-color: rgba(15, 23, 42, 0.72);
  background: rgba(255, 255, 255, 0.5);
}

.board-item {
  position: absolute;
  pointer-events: auto;
  user-select: none;
  border-radius: 8px;
  box-shadow: var(--shadow);
  transform-origin: center center;
}

.board-item:hover,
.board-item.is-transforming,
.board-item.is-selected {
  outline: 1px solid rgba(0, 119, 237, 0.56);
  outline-offset: 4px;
}

.transform-handle {
  position: absolute;
  z-index: 8;
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border: 1px solid rgba(15, 23, 42, 0.14);
  border-radius: 999px;
  color: #17202a;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: 0 8px 20px rgba(15, 23, 42, 0.18);
  font-size: 14px;
  font-weight: 900;
  opacity: 0;
  transform: scale(0.92);
  transition: opacity 120ms ease, transform 120ms ease, background 120ms ease;
}

.board-item:hover .transform-handle,
.board-item.is-transforming .transform-handle {
  opacity: 1;
  transform: scale(1);
}

.transform-handle:hover {
  color: #fff;
  background: var(--accent);
}

.rotate-handle {
  top: -42px;
  left: 50%;
  transform: translateX(-50%) scale(0.92);
  cursor: grab;
}

.board-item:hover .rotate-handle,
.board-item.is-transforming .rotate-handle {
  transform: translateX(-50%) scale(1);
}

.scale-handle {
  right: -14px;
  bottom: -14px;
  cursor: nwse-resize;
}

.note {
  width: 218px;
  min-height: 160px;
  padding: 14px;
  background: #fff178;
  border: 1px solid rgba(128, 110, 0, 0.2);
}

.note textarea {
  width: 100%;
  min-height: 126px;
  height: 100%;
  resize: none;
  border: 0;
  outline: 0;
  color: #3f3512;
  background: transparent;
  line-height: 1.45;
}

.link-card,
.tweet-card,
.image-card,
.pdf-card,
.file-card {
  display: grid;
  overflow: hidden;
  border: 1px solid rgba(23, 32, 42, 0.12);
  background: #fff;
}

.link-card {
  grid-template-rows: 96px auto;
  width: 280px;
}

.tweet-card {
  width: 520px;
  padding: 0;
  border-color: rgba(15, 23, 42, 0.16);
  background:
    linear-gradient(#ffffff, #ffffff) padding-box,
    linear-gradient(135deg, rgba(15, 23, 42, 0.24), rgba(0, 119, 237, 0.28), rgba(23, 165, 107, 0.18)) border-box;
  box-shadow: 0 22px 60px rgba(15, 23, 42, 0.18);
}

.image-card {
  width: 360px;
  line-height: 0;
}

.file-card {
  grid-template-columns: 86px minmax(0, 1fr);
  width: 320px;
}

.pdf-card {
  width: 640px;
  aspect-ratio: 0.707 / 1;
  line-height: 0;
  overflow: hidden;
  border: 0;
  background: #fff;
  box-shadow:
    0 1px 2px rgba(15, 23, 42, 0.12),
    0 24px 58px rgba(15, 23, 42, 0.22);
}

.pdf-preview {
  width: 220%;
  height: 220%;
  border: 0;
  border-radius: 2px;
  background: #fff;
  pointer-events: none;
  transform: scale(0.454545);
  transform-origin: top left;
}

.file-preview {
  display: grid;
  min-height: 96px;
  place-items: center;
  color: #12324a;
  background: linear-gradient(135deg, #d9f99d, #bae6fd);
  font-size: 16px;
  font-weight: 900;
}

.link-preview {
  display: grid;
  place-items: center;
  color: #fff;
  background:
    linear-gradient(135deg, rgba(0, 119, 237, 0.96), rgba(23, 165, 107, 0.92)),
    radial-gradient(circle at 20% 20%, rgba(255, 255, 255, 0.32), transparent 32%);
  font-size: 28px;
  font-weight: 900;
}

.tweet-card .open-button {
  top: 12px;
  right: 12px;
  min-width: 62px;
  height: 32px;
  border: 1px solid rgba(255, 255, 255, 0.38);
  color: #fff;
  background: rgba(15, 23, 42, 0.82);
  box-shadow: 0 8px 22px rgba(15, 23, 42, 0.22);
  backdrop-filter: blur(10px);
}

.tweet-card .open-button:hover {
  background: rgba(0, 119, 237, 0.92);
}

.tweet-custom {
  display: grid;
  background: #fff;
}

.tweet-media {
  display: grid;
  place-items: center;
  width: 100%;
  min-height: 260px;
  max-height: 680px;
  overflow: hidden;
  background: #eef2f6;
}

.tweet-media img {
  display: block;
  width: 100%;
  height: auto;
  max-height: 680px;
  object-fit: contain;
  pointer-events: none;
}

.tweet-media-empty {
  min-height: 280px;
  padding: 24px;
  color: #667085;
  font-size: 14px;
  font-weight: 800;
}

.tweet-body {
  display: grid;
  gap: 14px;
  padding: 18px;
  border-top: 1px solid rgba(15, 23, 42, 0.08);
}

.tweet-body p {
  margin: 0;
  color: #17202a;
  font-size: 15px;
  line-height: 1.55;
  white-space: pre-wrap;
}

.tweet-meta {
  display: flex;
  align-items: baseline;
  gap: 8px;
  min-width: 0;
}

.tweet-meta strong {
  color: #111827;
  font-size: 14px;
  overflow-wrap: anywhere;
}

.tweet-meta span {
  color: var(--muted);
  font-size: 13px;
  overflow-wrap: anywhere;
}

.image-preview {
  display: block;
  width: 100%;
  height: auto;
  max-height: 640px;
  border-radius: 8px;
  object-fit: contain;
  background: #f8fafc;
  pointer-events: none;
}

.link-body {
  display: grid;
  gap: 6px;
  padding: 12px;
}

.link-body strong {
  color: #111827;
  font-weight: 800;
  overflow-wrap: anywhere;
}

.link-body span {
  color: var(--muted);
  font-size: 12px;
  overflow-wrap: anywhere;
}

.delete-button {
  position: absolute;
  top: 6px;
  right: 6px;
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border: 0;
  border-radius: 50%;
  color: #fff;
  background: rgba(17, 24, 39, 0.58);
}

.open-button {
  position: absolute;
  top: 6px;
  right: 38px;
  min-width: 52px;
  height: 28px;
  border: 0;
  border-radius: 999px;
  color: #fff;
  background: rgba(0, 119, 237, 0.92);
  font-size: 12px;
  font-weight: 800;
}

.retry-button {
  position: absolute;
  top: 12px;
  left: 12px;
  min-width: 64px;
  height: 32px;
  border: 1px solid rgba(15, 23, 42, 0.12);
  border-radius: 999px;
  color: #17202a;
  background: rgba(255, 255, 255, 0.9);
  font-size: 12px;
  font-weight: 800;
  box-shadow: 0 8px 22px rgba(15, 23, 42, 0.16);
  backdrop-filter: blur(10px);
}

.context-menu {
  position: fixed;
  z-index: 50;
  display: grid;
  min-width: 154px;
  padding: 6px;
  border: 1px solid rgba(15, 23, 42, 0.14);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 18px 45px rgba(15, 23, 42, 0.18);
  backdrop-filter: blur(14px);
}

.context-menu button {
  min-height: 34px;
  padding: 0 10px;
  border: 0;
  border-radius: 6px;
  color: #17202a;
  background: transparent;
  text-align: left;
  font-size: 13px;
  font-weight: 700;
}

.context-menu button:hover {
  background: #eef4ff;
}

.context-menu button.danger {
  color: #b42318;
}

.context-menu button.danger:hover {
  background: #fff1f0;
}

.item-inspector {
  position: absolute;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 6px;
  max-width: min(520px, calc(100% - 24px));
  min-height: 40px;
  padding: 6px;
  border: 1px solid rgba(15, 23, 42, 0.14);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 14px 36px rgba(15, 23, 42, 0.18);
  backdrop-filter: blur(14px);
  pointer-events: auto;
}

.item-inspector button,
.item-inspector select {
  min-width: 34px;
  height: 30px;
  border: 1px solid rgba(15, 23, 42, 0.12);
  border-radius: 6px;
  color: #17202a;
  background: #fff;
  font-size: 12px;
  font-weight: 800;
}

.item-inspector select {
  min-width: 68px;
}

.item-inspector button:hover,
.item-inspector select:hover {
  background: #eef4ff;
}

.item-inspector .swatch-button {
  width: 24px;
  min-width: 24px;
  border-color: rgba(15, 23, 42, 0.2);
}

.item-inspector .transparent-swatch {
  background:
    linear-gradient(45deg, rgba(15, 23, 42, 0.16) 25%, transparent 25% 75%, rgba(15, 23, 42, 0.16) 75%),
    linear-gradient(45deg, rgba(15, 23, 42, 0.16) 25%, transparent 25% 75%, rgba(15, 23, 42, 0.16) 75%) 6px 6px,
    #fff !important;
  background-size: 12px 12px;
}

.item-inspector .danger {
  min-width: 46px;
  color: #b42318;
}

dialog {
  border: 0;
  padding: 0;
  border-radius: 8px;
  box-shadow: var(--shadow);
  z-index: 20;
}

dialog::backdrop {
  background: rgba(15, 23, 42, 0.36);
}

.dialog-card {
  width: min(420px, calc(100vw - 32px));
  padding: 18px;
  background: #fff;
}

.user-name-card {
  display: grid;
  gap: 12px;
  width: min(380px, calc(100vw - 32px));
  padding: 24px;
  text-align: center;
}

.user-name-card p {
  margin: 0;
  color: #667085;
  font-size: 13px;
  line-height: 1.5;
}

.user-name-avatar {
  display: grid;
  place-items: center;
  width: 52px;
  height: 52px;
  margin: 0 auto 2px;
  border-radius: 16px;
  color: #fff;
  background: linear-gradient(135deg, #0077ed, #17a56b);
  font-size: 22px;
  font-weight: 900;
  box-shadow: 0 16px 32px rgba(0, 119, 237, 0.2);
}

.user-name-field {
  grid-template-columns: 58px minmax(0, 1fr);
  margin-top: 4px;
  text-align: left;
}

.user-name-field input {
  min-height: 44px;
  border: 1px solid rgba(15, 23, 42, 0.16);
  border-radius: 8px;
  padding: 0 12px;
  font: inherit;
  font-weight: 700;
}

.user-name-field input:focus {
  outline: 2px solid rgba(0, 119, 237, 0.18);
  border-color: rgba(0, 119, 237, 0.55);
}

.dialog-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 16px;
}

.user-name-card .dialog-actions {
  grid-template-columns: 1fr;
}

@media (max-width: 780px) {
  .topbar {
    justify-content: flex-start;
  }

  .topbar > div:first-child {
    flex: 1 1 auto;
    min-width: 0;
  }

  .participant-list {
    order: 2;
    margin-left: auto;
  }

  .presence {
    order: 3;
    flex: 0 0 auto;
  }
}

@media (max-width: 780px) {
  body {
    min-height: 100dvh;
    overflow: hidden;
  }

  .app-shell {
    display: block;
    height: 100dvh;
    min-height: 0;
  }

  .sidebar {
    position: fixed;
    left: max(10px, env(safe-area-inset-left));
    right: max(10px, env(safe-area-inset-right));
    bottom: max(10px, env(safe-area-inset-bottom));
    z-index: 50;
    display: flex;
    align-items: center;
    gap: 8px;
    width: auto;
    padding: 8px;
    border: 1px solid rgba(15, 23, 42, 0.12);
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.94);
    box-shadow: 0 18px 48px rgba(15, 23, 42, 0.2);
    backdrop-filter: blur(18px);
  }

  .brand {
    flex: 0 0 auto;
    gap: 8px;
    padding: 0;
  }

  .brand-mark {
    width: 34px;
    height: 34px;
  }

  .brand h1 {
    font-size: 14px;
  }

  .brand p {
    display: none;
  }

  .panel {
    padding: 10px;
  }

  .panel h2 {
    margin-bottom: 8px;
    font-size: 12px;
  }

  .tools-panel {
    flex: 1 1 auto;
    min-width: 0;
    padding: 0;
    border: 0;
    background: transparent;
  }

  .tools-panel h2,
  .share-panel,
  .board-panel {
    display: none;
  }

  .pen-panel {
    flex: 0 0 148px;
    display: grid;
    grid-template-columns: 26px minmax(0, 1fr);
    align-items: center;
    gap: 4px 8px;
    padding: 0;
    border: 0;
    background: transparent;
  }

  .pen-panel h2 {
    grid-row: 1 / span 2;
    margin: 0;
    writing-mode: vertical-rl;
    color: #667085;
    font-size: 11px;
  }

  .pen-panel .field {
    display: grid;
    grid-template-columns: 30px minmax(0, 1fr);
    align-items: center;
    gap: 6px;
    margin: 0;
    font-size: 11px;
  }

  .pen-panel input[type="color"] {
    width: 34px;
    height: 28px;
    padding: 0;
  }

  .pen-panel input[type="range"] {
    min-width: 0;
  }

  .tool-grid {
    grid-template-columns: repeat(6, minmax(40px, 1fr));
    gap: 6px;
  }

  .tool-button {
    min-height: 42px;
    aspect-ratio: auto;
    font-size: 14px;
  }

  .field {
    grid-template-columns: 42px minmax(0, 1fr);
    align-items: center;
    gap: 8px;
    margin-top: 8px;
  }

  .zoom-controls {
    grid-template-columns: 46px 1fr 46px;
    margin-bottom: 8px;
  }

  .topbar {
    position: fixed;
    top: max(8px, env(safe-area-inset-top));
    left: max(10px, env(safe-area-inset-left));
    right: max(10px, env(safe-area-inset-right));
    z-index: 40;
    align-items: center;
    flex-direction: row;
    gap: 10px;
    padding: 8px 10px;
    border: 1px solid rgba(15, 23, 42, 0.1);
    border-radius: 10px;
    background: rgba(247, 248, 250, 0.86);
    backdrop-filter: blur(14px);
  }

  .topbar h2 {
    font-size: 16px;
  }

  .topbar p {
    display: none;
  }

  .presence {
    width: auto;
    min-height: 32px;
    justify-content: flex-start;
    padding: 0 10px;
    font-size: 12px;
  }

  .participant-list {
    margin-left: auto;
    gap: 4px;
  }

  .participant-chip {
    max-width: 36px;
    width: 32px;
    height: 32px;
    padding: 0;
    justify-content: center;
  }

  .participant-name,
  .participant-chip.is-active::after {
    display: none;
  }

  .board {
    min-height: 0;
    height: 100dvh;
  }

  .workspace {
    display: block;
    height: 100dvh;
    min-height: 0;
  }

  .dialog-card {
    width: min(360px, calc(100vw - 24px));
  }

  .history-controls {
    top: 58px;
    left: max(10px, env(safe-area-inset-left));
    gap: 4px;
    padding: 4px;
    border-radius: 9px;
  }

  .history-controls button {
    width: 30px;
    height: 30px;
    border-radius: 7px;
    font-size: 17px;
  }
}

@media (max-width: 520px) {
  .sidebar {
    left: max(8px, env(safe-area-inset-left));
    right: max(8px, env(safe-area-inset-right));
    bottom: max(8px, env(safe-area-inset-bottom));
    flex-wrap: nowrap;
    gap: 5px;
    padding: 6px;
  }

  .brand {
    flex: 0 0 28px;
  }

  .brand-mark {
    width: 28px;
    height: 28px;
    border-radius: 7px;
    font-size: 13px;
  }

  .brand h1 {
    display: none;
  }

  .tool-grid {
    grid-template-columns: repeat(6, minmax(0, 1fr));
    gap: 4px;
  }

  .tools-panel {
    flex: 1 1 auto;
    min-width: 0;
  }

  .pen-panel {
    flex: 0 0 96px;
    grid-template-columns: 22px 1fr;
    gap: 3px 5px;
    padding-top: 0;
    border-top: 0;
  }

  .pen-panel h2 {
    grid-row: 1 / span 2;
    writing-mode: vertical-rl;
    font-size: 10px;
  }

  .pen-panel .field {
    grid-template-columns: 18px minmax(0, 1fr);
    gap: 4px;
    font-size: 10px;
  }

  .pen-panel input[type="color"] {
    width: 24px;
    height: 22px;
  }

  .tool-button {
    min-height: 32px;
    padding: 0 4px;
    font-size: 12px;
  }

  .tool-button svg {
    width: 18px;
    height: 18px;
  }

  .primary-button,
  .quiet-button,
  .zoom-value {
    min-height: 38px;
    font-size: 12px;
  }

  .topbar {
    padding: 7px 9px;
  }

  .history-controls {
    top: 50px;
    left: max(8px, env(safe-area-inset-left));
  }

  .presence {
    min-height: 30px;
  }

}

@media (max-width: 390px) {
  .sidebar {
    gap: 4px;
    padding: 5px;
  }

  .brand {
    flex-basis: 24px;
  }

  .brand-mark {
    width: 24px;
    height: 24px;
    font-size: 12px;
  }

  .pen-panel {
    flex-basis: 78px;
    grid-template-columns: 18px 1fr;
  }

  .pen-panel h2,
  .pen-panel .field span {
    display: none;
  }

  .pen-panel .field {
    grid-template-columns: 1fr;
  }

  .tool-button {
    min-height: 30px;
    padding: 0 2px;
  }
}

@media (max-width: 520px) {
  .topbar {
    justify-content: flex-start;
    gap: 6px;
  }

  .topbar > div:first-child {
    flex: 1 1 auto;
    min-width: 0;
  }

  .participant-list {
    order: 2;
    margin-left: auto;
  }

  .presence {
    order: 3;
    display: flex;
    min-height: 30px;
    padding: 0 8px;
    font-size: 11px;
  }

  .participant-chip {
    width: 30px;
    height: 30px;
  }

  .participant-avatar {
    width: 22px;
    height: 22px;
  }
}

.participant-chip.is-active {
  border-color: rgba(0, 119, 237, 0.72);
  background: #fff;
  box-shadow:
    0 0 0 3px rgba(0, 119, 237, 0.12),
    0 10px 28px rgba(0, 119, 237, 0.16);
}

.participant-chip.is-active::after {
  content: none !important;
  display: none !important;
}

@media (max-width: 390px) {
  .pen-panel {
    grid-template-columns: 34px minmax(0, 0.8fr) minmax(0, 1.4fr);
    bottom: calc(max(8px, env(safe-area-inset-bottom)) + 50px);
    gap: 6px;
    padding: 7px 8px;
  }

  .pen-panel h2,
  .pen-panel .field span {
    display: block;
    font-size: 10px;
  }

  .pen-panel .field {
    grid-template-columns: auto minmax(0, 1fr);
  }

  .pen-panel input[type="color"] {
    width: 30px;
    height: 24px;
  }
}

@media (max-width: 520px) {
  .sidebar {
    left: max(8px, env(safe-area-inset-left));
    right: max(8px, env(safe-area-inset-right));
    bottom: max(8px, env(safe-area-inset-bottom));
    display: block;
    padding: 6px;
    overflow: visible;
  }

  .brand {
    display: none;
  }

  .brand h1,
  .brand p,
  .share-panel,
  .board-panel {
    display: none;
  }

  .pen-panel {
    position: fixed;
    left: max(8px, env(safe-area-inset-left));
    right: max(8px, env(safe-area-inset-right));
    bottom: calc(max(8px, env(safe-area-inset-bottom)) + 54px);
    z-index: 49;
    display: none;
    grid-template-columns: 42px minmax(0, 1fr) minmax(0, 1.6fr);
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    border: 1px solid rgba(15, 23, 42, 0.12);
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.94);
    box-shadow: 0 14px 36px rgba(15, 23, 42, 0.18);
    backdrop-filter: blur(16px);
  }

  body.show-mobile-pen-menu .pen-panel {
    display: grid !important;
  }

  .pen-panel h2 {
    margin: 0;
    color: #667085;
    font-size: 12px;
    writing-mode: horizontal-tb;
  }

  .pen-panel .field {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    align-items: center;
    gap: 6px;
    margin: 0;
    font-size: 12px;
  }

  .pen-panel input[type="color"] {
    width: 36px;
    height: 28px;
    padding: 0;
  }

  .tools-panel {
    width: 100%;
    min-width: 0;
  }

  .tool-grid {
    display: grid;
    grid-template-columns: repeat(6, minmax(0, 1fr));
    gap: 5px;
  }

  .tool-button {
    min-height: 36px;
    padding: 0;
  }

  .tool-button svg {
    width: 19px;
    height: 19px;
  }

  .topbar {
    top: max(8px, env(safe-area-inset-top));
    left: max(8px, env(safe-area-inset-left));
    right: max(8px, env(safe-area-inset-right));
    min-height: 36px;
    padding: 6px 8px;
  }

  .topbar h2 {
    font-size: 14px;
  }

  .presence {
    display: none;
  }

  .history-controls {
    top: calc(max(8px, env(safe-area-inset-top)) + 44px);
    left: max(8px, env(safe-area-inset-left));
    right: auto;
    gap: 4px;
    padding: 3px;
    border-radius: 9px;
  }

  .history-controls button {
    width: 34px;
    height: 30px;
    font-size: 16px;
  }
}
