.editor-toolbar {
  padding: 6px 14px;
  touch-action: manipulation;
}

.editor-tools {
  display: flex;
  width: 100%;
  min-width: 0;
  align-items: center;
  flex-wrap: wrap;
  gap: 7px;
}

.editor-tools button,
.tool-select {
  min-height: var(--target);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface-glass);
}

.editor-tools button {
  display: inline-grid;
  padding: 8px 11px;
  place-items: center;
  cursor: pointer;
  touch-action: manipulation;
}

.editor-tools .tool-icon-button {
  width: 46px;
  min-width: 46px;
  height: 46px;
  padding: 0;
}

.editor-tools button:hover {
  border-color: var(--line-strong);
  background: var(--surface-raised);
}

.editor-tools button[aria-pressed="true"] {
  border-color: #bfd0f2;
  background: var(--accent-soft);
  color: var(--accent);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--accent) 12%, transparent);
}

.tool-select {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding-left: 11px;
  color: var(--muted);
  font-size: 0.82rem;
}

.tool-select select {
  min-height: 40px;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--ink);
}

.ink-tools {
  display: none;
  align-items: center;
  flex-wrap: wrap;
  gap: 7px;
}

.editor-root[data-editor-mode="highlight"] .ink-tools,
.editor-pane[data-editor-mode="highlight"] .ink-tools,
.editor-root[data-editor-mode="canvas"] .ink-tools,
.editor-pane[data-editor-mode="canvas"] .ink-tools {
  display: inline-flex;
}

.editor-root[data-editor-mode="highlight"] .canvas-setting,
.editor-pane[data-editor-mode="highlight"] .canvas-setting,
.eraser-size {
  display: none;
}

.editor-root[data-ink-tool="eraser"] .pen-setting,
.editor-pane[data-ink-tool="eraser"] .pen-setting,
.editor-root[data-ink-tool="eraser"] .color-setting,
.editor-pane[data-ink-tool="eraser"] .color-setting {
  display: none;
}

.editor-root[data-ink-tool="eraser"] .eraser-size,
.editor-pane[data-ink-tool="eraser"] .eraser-size {
  display: inline-flex;
}

.client-version {
  align-self: center;
  margin-left: auto;
  color: var(--muted);
  font-size: 0.72rem;
  font-variant-numeric: tabular-nums;
}

.color-picker-wrap {
  position: relative;
  display: inline-flex;
}

.editor-tools .color-picker {
  display: grid;
  width: 46px;
  min-width: 46px;
  height: 46px;
  padding: 0;
  place-items: center;
}

.current-color {
  width: 26px;
  height: 26px;
  border: 3px solid var(--surface);
  border-radius: 50%;
  background: var(--selected-color);
  box-shadow: 0 0 0 1px var(--line-strong);
}

.color-palette {
  position: fixed;
  z-index: 80;
  top: calc(env(safe-area-inset-top) + 146px);
  left: 50%;
  display: grid;
  width: min(620px, calc(100vw - 28px));
  max-height: min(70dvh, 470px);
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  background: var(--surface-glass);
  box-shadow: var(--shadow);
  opacity: 1;
  transform: translate3d(-50%, 0, 0);
  backdrop-filter: blur(22px) saturate(120%);
  animation: palette-in 150ms var(--ease-out) both;
}

@keyframes palette-in {
  from {
    opacity: 0;
    transform: translate3d(-50%, -8px, 0) scale(0.985);
  }

  to {
    opacity: 1;
    transform: translate3d(-50%, 0, 0) scale(1);
  }
}

.color-palette-row {
  display: grid;
  min-width: 528px;
  grid-template-columns: repeat(12, 44px);
}

.editor-tools .color-cell {
  width: 44px;
  min-width: 44px;
  height: 40px;
  min-height: 40px;
  border: 0;
  border-radius: 0;
  padding: 0;
  background: var(--swatch-color);
}

.color-palette-row:first-child .color-cell:first-child {
  border-radius: 11px 0 0;
}

.color-palette-row:first-child .color-cell:last-child {
  border-radius: 0 11px 0 0;
}

.color-palette-row:last-child .color-cell:first-child {
  border-radius: 0 0 0 11px;
}

.color-palette-row:last-child .color-cell:last-child {
  border-radius: 0 0 11px;
}

.editor-tools .color-cell[aria-pressed="true"] {
  position: relative;
  z-index: 1;
  outline: 3px solid var(--focus);
  outline-offset: -4px;
}

.eraser-size input {
  width: 96px;
}

.eraser-size output {
  min-width: 2ch;
  padding-right: 8px;
  color: var(--ink);
  text-align: right;
}

.editor-stage {
  position: relative;
  min-height: 70vh;
  background: var(--paper);
}

.editor-pane[data-page-motion="forward"] .editor-stage {
  animation: page-in-forward var(--motion-page) var(--ease-out) both;
}

.editor-pane[data-page-motion="backward"] .editor-stage {
  animation: page-in-backward var(--motion-page) var(--ease-out) both;
}

@keyframes page-in-forward {
  from {
    opacity: 0;
    transform: translate3d(14px, 0, 0);
  }

  to {
    opacity: 1;
    transform: translate3d(0, 0, 0);
  }
}

@keyframes page-in-backward {
  from {
    opacity: 0;
    transform: translate3d(-14px, 0, 0);
  }

  to {
    opacity: 1;
    transform: translate3d(0, 0, 0);
  }
}

.text-editor {
  position: relative;
  z-index: 1;
  min-height: 70vh;
  outline: none;
  font-size: 28px;
  line-height: 1.2857142857;
  overflow-wrap: anywhere;
  overflow-x: auto;
  white-space: pre-wrap;
}

.text-editor > :first-child {
  margin-top: 0;
}

.text-editor p,
.text-editor h1,
.text-editor h2,
.text-editor li {
  position: relative;
  min-height: 1.2857142857em;
  margin: 0;
  padding: 0;
  background: transparent;
}

.text-editor h2 {
  font-weight: bold;
}

.text-editor h1 {
  min-height: 2.4em;
  font-size: 40px;
  font-weight: bold;
  line-height: 1.2;
}

.text-editor table {
  width: max-content;
  min-width: 100%;
  max-width: none;
  border-collapse: collapse;
  background: color-mix(in srgb, var(--accent) 4%, var(--paper));
}

.text-editor th,
.text-editor td {
  min-width: 4em;
  border: 1px solid var(--line-strong);
  padding: 0.35em 0.55em;
  vertical-align: top;
  background: transparent;
}

.text-editor th {
  background: color-mix(in srgb, var(--accent) 9%, var(--paper));
}

.editor-root[data-editor-mode="highlight"] .text-editor,
.editor-root[data-editor-mode="canvas"] .text-editor,
.editor-root[data-editor-mode="highlight"] .text-editor *,
.editor-root[data-editor-mode="canvas"] .text-editor * {
  caret-color: transparent;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
}

.editor-root[data-editor-mode="highlight"] .editor-stage,
.editor-root[data-editor-mode="canvas"] .editor-stage {
  overscroll-behavior: contain;
  touch-action: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
}

.editor-pane[data-editor-mode="highlight"],
.editor-pane[data-editor-mode="canvas"] {
  overscroll-behavior: contain;
  touch-action: none;
}

.ink-canvas {
  position: absolute;
  z-index: 2;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  touch-action: none;
}

.eraser-preview {
  position: absolute;
  z-index: 3;
  left: var(--eraser-x, 0);
  top: var(--eraser-y, 0);
  width: var(--eraser-size, 20px);
  height: var(--eraser-size, 20px);
  border: 1px solid #111111;
  border-radius: 50%;
  background: transparent;
  box-shadow:
    0 0 0 1px rgb(255 255 255 / 58%),
    0 2px 6px rgb(33 43 63 / 16%);
  pointer-events: none;
  transform: translate3d(-50%, -50%, 0);
  will-change: left, top, width, height;
}

.editor-root[data-editor-mode="highlight"] .ink-canvas,
.editor-root[data-editor-mode="canvas"] .ink-canvas {
  pointer-events: auto;
  cursor: crosshair;
}

mark.jp-highlight {
  border-radius: 0.16em;
  padding: 0 0.05em;
  background: var(--highlight);
  color: inherit;
}

mark.jp-source-red {
  border-radius: 0.16em;
  padding: 0 0.05em;
  background: rgb(250 204 21 / 38%);
  color: #9f0000;
}

:root[data-theme="dark"] mark.jp-source-red {
  background: rgb(250 204 21 / 75%);
  color: #740000;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) mark.jp-source-red {
    background: rgb(250 204 21 / 75%);
    color: #740000;
  }
}

.jn-font-12 { font-size: 12px; }
.jn-font-14 { font-size: 14px; }
.jn-font-16 { font-size: 16px; }
.jn-font-18 { font-size: 18px; }
.jn-font-20 { font-size: 20px; }
.jn-font-24 { font-size: 24px; }
.jn-font-28 { font-size: 28px; }
.jn-font-32 { font-size: 32px; }
.jn-font-40 { font-size: 40px; }

ruby rt {
  color: var(--muted);
  font-size: 0.55em;
}

@media (max-width: 820px) {
  .editor-toolbar {
    padding: 6px 8px;
  }

  .editor-tools {
    gap: 5px;
  }

  .editor-tools .tool-icon-button,
  .editor-tools .color-picker {
    width: 44px;
    min-width: 44px;
    height: 44px;
  }

  .client-version {
    margin-left: 2px;
  }

  .color-palette {
    top: calc(env(safe-area-inset-top) + 136px);
  }
}
