/* Paste, by Daniel Styrlund · danielstyrlund.com */

/* A Google Docs page: Letter-sized, one-inch margins, on Docs' cool grey. Every colour is a token
   here, so dark mode can swap them all at once. */
html {
  color-scheme: light;
  --canvas: #f9fbfd;
  --page: #fff;
  --ink: #1f1f1f;
  --black: #000;
  --icon: #80868b;
  --mark: #444746;
  --muted: #5f6368;
  --muted-2: #80868b;
  --disabled: #9aa0a6;
  --line: #e3e3e3;
  --field: #dadce0;
  --hover: rgba(60, 64, 67, 0.08);
  --on: rgba(60, 64, 67, 0.12);
  --item-hover: #f1f3f4;
  --info: #bdc1c6;
  --link: #1155cc;
  --accent: #1a73e8;
  --accent-hover: rgba(26, 115, 232, 0.06);
  --danger: #d93025;
  --tip: #3c4043;
  --tip-ink: #fff;
  --swatch-ring: rgba(0, 0, 0, 0.1);
  /* The toolbar pill and the note: the background at 70%, frosted. Menus: the page at 72%. */
  --pill: rgba(249, 251, 253, 0.7);
  --glass: rgba(255, 255, 255, 0.72);
  /* One soft shadow for everything that sits above the background: the page and the menus. */
  --shadow: 0 0 0 1px rgba(60, 64, 67, 0.08), 0 1px 2px rgba(60, 64, 67, 0.06), 0 8px 24px rgba(60, 64, 67, 0.07);
  --blur: blur(20px) saturate(180%);
  background: var(--canvas);
  color: var(--ink);
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  transition: background-color 0.2s, color 0.2s;
}

/* Dark mode, following the system unless the toolbar's button says otherwise: a neutral, cool
   take on Claude's grey, with the page a step lighter than the background, as the white page is. */
html[data-theme="dark"] {
  color-scheme: dark;
  --canvas: #1e1f22;
  --page: #26272a;
  --ink: #e3e3e3;
  --black: var(--ink);
  --icon: #9aa0a6;
  --mark: #c4c7c5;
  --muted: #9aa0a6;
  --muted-2: #80868b;
  --disabled: #5f6368;
  --line: #3a3b3e;
  --field: #4a4b4f;
  --hover: rgba(255, 255, 255, 0.08);
  --on: rgba(255, 255, 255, 0.12);
  --item-hover: rgba(255, 255, 255, 0.06);
  --info: #5f6368;
  --link: #8ab4f8;
  --accent: #8ab4f8;
  --accent-hover: rgba(138, 180, 248, 0.1);
  --danger: #f28b82;
  --tip: #e3e3e3;
  --tip-ink: #1f1f1f;
  --swatch-ring: rgba(255, 255, 255, 0.15);
  --pill: rgba(30, 31, 34, 0.7);
  --glass: rgba(38, 39, 42, 0.72);
  /* Shadows don't show on dark, so a faint light edge does the lifting. */
  --shadow: 0 0 0 1px rgba(255, 255, 255, 0.06), 0 1px 2px rgba(0, 0, 0, 0.24), 0 8px 24px rgba(0, 0, 0, 0.24);
}

@media (prefers-color-scheme: dark) {
  html:not([data-theme="light"]) {
    color-scheme: dark;
    --canvas: #1e1f22;
    --page: #26272a;
    --ink: #e3e3e3;
    --black: var(--ink);
    --icon: #9aa0a6;
    --mark: #c4c7c5;
    --muted: #9aa0a6;
    --muted-2: #80868b;
    --disabled: #5f6368;
    --line: #3a3b3e;
    --field: #4a4b4f;
    --hover: rgba(255, 255, 255, 0.08);
    --on: rgba(255, 255, 255, 0.12);
    --item-hover: rgba(255, 255, 255, 0.06);
    --info: #5f6368;
    --link: #8ab4f8;
    --accent: #8ab4f8;
    --accent-hover: rgba(138, 180, 248, 0.1);
    --danger: #f28b82;
    --tip: #e3e3e3;
    --tip-ink: #1f1f1f;
    --swatch-ring: rgba(255, 255, 255, 0.15);
    --pill: rgba(30, 31, 34, 0.7);
    --glass: rgba(38, 39, 42, 0.72);
    /* Shadows don't show on dark, so a faint light edge does the lifting. */
    --shadow: 0 0 0 1px rgba(255, 255, 255, 0.06), 0 1px 2px rgba(0, 0, 0, 0.24), 0 8px 24px rgba(0, 0, 0, 0.24);
  }
}

/* All the interface text is 13px, the same as the toolbar's; only the page's own text differs. */
body {
  margin: 0;
  padding: 0 24px 96px;
  font: 13px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.sprite {
  display: none;
}

/* No grey flash or double-tap zoom when buttons are tapped. */
button {
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

svg {
  flex: none;
  width: 18px;
  height: 18px;
  fill: currentColor;
}

/* Toolbar: a pill of the background colour, frosted like glass, the same as on copy.nyc and
   designschool.nyc. It can't be seen until the page scrolls under it. */
#toolbar {
  position: sticky;
  top: 0;
  z-index: 10;
  margin: 0 -24px;
  padding: 6px 24px 4px;
  pointer-events: none;
}

.tools {
  display: flex;
  align-items: center;
  gap: 1px;
  width: max-content;
  max-width: 100%;
  box-sizing: border-box;
  margin: 0 auto;
  padding: 4px 8px;
  border-radius: 9999px;
  background: var(--pill);
  -webkit-backdrop-filter: var(--blur);
  backdrop-filter: var(--blur);
  pointer-events: auto;
}

.tools button,
.row button,
#link-bubble button {
  position: relative;
  display: inline-flex;
  flex: none;
  align-items: center;
  justify-content: center;
  height: 28px;
  min-width: 28px;
  padding: 0 5px;
  border: 0;
  border-radius: 6px;
  background: none;
  color: var(--icon);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  transition: background-color 0.12s, color 0.12s;
}

/* Hover styles only where there's a mouse, so a tapped button doesn't stay lit on a phone. */
.tools button.open {
  background: var(--hover);
  color: var(--ink);
}

@media (hover: hover) {
  .tools button:hover,
  .row button:hover,
  #link-bubble button:hover {
    background: var(--hover);
    color: var(--ink);
  }
}

.tools button.on,
.row button.on {
  background: var(--on);
  color: var(--ink);
}

.divider {
  flex: none;
  width: 1px;
  height: 18px;
  margin: 0 6px;
  background: var(--line);
}

#font-button {
  justify-content: space-between;
  width: 118px;
  padding: 0 2px 0 8px;
}

#font-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.caret {
  width: 16px;
  height: 16px;
}

#size-button {
  min-width: 30px;
  height: 24px;
  margin: 0 2px;
  padding: 0 4px;
  box-shadow: inset 0 0 0 1px var(--field);
  border-radius: 4px;
  color: var(--mark);
  font-variant-numeric: tabular-nums;
}

.swatch {
  fill: var(--ink);
}

/* The dark-mode button shows the mode it switches to: a moon in light mode, a sun in dark. */
#theme-button {
  width: 28px;
}

#theme-button svg {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  transition: opacity 0.2s ease-out, transform 0.2s ease-out;
}

#theme-button .sun,
#theme-button.dark .moon {
  opacity: 0;
  transform: translate(-50%, -50%) rotate(-45deg) scale(0.8);
}

#theme-button.dark .sun {
  opacity: 1;
  transform: translate(-50%, -50%);
}

/* Docs-style tooltips, after a short pause. */
.tools [data-tip]::after {
  content: attr(data-tip);
  position: absolute;
  top: calc(100% + 6px);
  left: 50%;
  z-index: 1;
  padding: 4px 8px;
  border-radius: 4px;
  background: var(--tip);
  color: var(--tip-ink);
  font-size: 13px;
  line-height: 16px;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transform: translateX(-50%);
  transition: opacity 0.1s;
}

@media (hover: hover) {
  .tools [data-tip]:hover::after {
    opacity: 1;
    transition-delay: 0.6s;
  }
}

@media (hover: none) {
  .tools [data-tip]::after {
    display: none;
  }
}

.tools [data-tip]:active::after,
.tools button.open::after {
  opacity: 0;
  transition-delay: 0s;
}

@media (max-width: 860px) {
  .tools {
    overflow-x: auto;
    scrollbar-width: none;
  }

  .tools::-webkit-scrollbar {
    display: none;
  }

  .tools [data-tip]::after {
    display: none;
  }

  .tools.more-right {
    -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 32px), transparent);
    mask-image: linear-gradient(to right, #000 calc(100% - 32px), transparent);
  }

  .tools.more-left {
    -webkit-mask-image: linear-gradient(to left, #000 calc(100% - 32px), transparent);
    mask-image: linear-gradient(to left, #000 calc(100% - 32px), transparent);
  }

  .tools.more-left.more-right {
    -webkit-mask-image: linear-gradient(to right, transparent, #000 32px, #000 calc(100% - 32px), transparent);
    mask-image: linear-gradient(to right, transparent, #000 32px, #000 calc(100% - 32px), transparent);
  }
}

/* The page starts Letter-shaped (8.5 × 11 in) and grows with the text. */
#editor {
  box-sizing: border-box;
  width: 100%;
  max-width: 816px;
  aspect-ratio: 8.5 / 11;
  margin: 4px auto 0;
  padding: 96px;
  border-radius: 16px;
  background: var(--page);
  box-shadow: var(--shadow);
  outline: none;
  --base: 11pt;
  font-size: var(--base);
  line-height: 1.5;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  tab-size: 4;
  transition: background-color 0.2s, box-shadow 0.2s;
}

#editor ul,
#editor ol {
  margin: 0;
  padding-left: 28px;
}

#editor ol ol {
  list-style-type: lower-alpha;
}

#editor ol ol ol {
  list-style-type: lower-roman;
}

#editor ul ul {
  list-style-type: circle;
}

#editor ul ul ul {
  list-style-type: square;
}

#editor a {
  color: var(--link);
}

/* Text in the default colour, in either theme, follows the theme. Black turns light in dark mode,
   and highlighted text stays dark there so it reads on its highlight. Copying still sends the
   real colours. */
#editor :is(font[color="#1f1f1f" i], font[color="#e3e3e3" i],
  [style^="color: rgb(31, 31, 31)"], [style*="; color: rgb(31, 31, 31)"],
  [style^="color: rgb(227, 227, 227)"], [style*="; color: rgb(227, 227, 227)"]) {
  color: var(--ink);
}

#editor :is(font[color="#000000" i], font[color="#000" i],
  [style^="color: rgb(0, 0, 0)"], [style*="; color: rgb(0, 0, 0)"]) {
  color: var(--black);
}

html[data-theme="dark"] #editor [style*="background-color"]:not([style*="transparent"]) {
  color: #1f1f1f;
}

@media (prefers-color-scheme: dark) {
  html:not([data-theme="light"]) #editor [style*="background-color"]:not([style*="transparent"]) {
    color: #1f1f1f;
  }
}

/* Font sizes 1–7 from the toolbar, in points like Docs (8, 10, 11, 14, 18, 24 and 36pt on a
   computer), scaled from the page's own size so they grow with it on a phone. */
#editor font[size="1"] { font-size: calc(var(--base) * 8 / 11); }
#editor font[size="2"] { font-size: calc(var(--base) * 10 / 11); }
#editor font[size="3"] { font-size: var(--base); }
#editor font[size="4"] { font-size: calc(var(--base) * 14 / 11); }
#editor font[size="5"] { font-size: calc(var(--base) * 18 / 11); }
#editor font[size="6"] { font-size: calc(var(--base) * 24 / 11); }
#editor font[size="7"] { font-size: calc(var(--base) * 36 / 11); }

/* On a phone, like Docs on a phone: the page fills the screen edge to edge, with bigger text,
   and the toolbar spans the top, frosted white once the text scrolls under it. */
@media (max-width: 600px) {
  html {
    background: var(--page);
  }

  body {
    padding: 0;
  }

  #toolbar {
    margin: 0;
    padding: env(safe-area-inset-top) 0 0;
  }

  .tools {
    width: 100%;
    margin: 0;
    padding: 4px max(8px, env(safe-area-inset-right)) 4px max(8px, env(safe-area-inset-left));
    border-radius: 0;
    background: var(--glass);
  }

  #font-button {
    width: 100px;
  }

  #editor {
    --base: 16px;
    max-width: none;
    /* svh stays put while Safari's bars shrink and grow during a scroll; dvh would shift the page. */
    min-height: calc(100svh - 48px);
    aspect-ratio: auto;
    margin: 0;
    padding: 12px max(20px, env(safe-area-inset-right)) 96px max(20px, env(safe-area-inset-left));
    border-radius: 0;
    box-shadow: none;
  }

  #about {
    right: calc(8px + env(safe-area-inset-right));
    bottom: calc(8px + env(safe-area-inset-bottom));
  }

  #toast {
    bottom: calc(24px + env(safe-area-inset-bottom));
  }
}

/* Fingers need bigger targets, and inputs under 16px make iPhones zoom in. */
@media (pointer: coarse) {
  .tools button,
  .row button,
  #link-bubble button {
    height: 40px;
    min-width: 40px;
  }

  .tools svg,
  .row svg,
  #link-bubble svg {
    width: 20px;
    height: 20px;
  }

  .tools .caret {
    width: 16px;
    height: 16px;
  }

  #size-button {
    height: 30px;
  }

  #theme-button {
    width: 40px;
  }

  #toolbar,
  #popover,
  #about {
    -webkit-user-select: none;
    user-select: none;
  }

  .item {
    min-height: 44px;
  }

  .palette {
    grid-template-columns: repeat(10, 26px);
    gap: 6px;
  }

  .palette button {
    width: 26px;
    height: 26px;
  }

  #link-input,
  #find-input,
  #replace-input {
    height: 40px;
    font-size: 16px;
  }

  #finder button {
    height: 40px;
  }

  #link-editor button {
    height: 40px;
  }

  #about-button {
    width: 40px;
    height: 40px;
  }

  #about-button svg {
    top: 10px;
    left: 10px;
  }

  /* Nothing sits above the keyboard while typing. */
  #about {
    transition: opacity 0.15s;
  }

  body:has(#editor:focus) #about {
    opacity: 0;
    pointer-events: none;
  }
}

/* Menus, the link editor, the link bubble and the info note. */
.card {
  position: fixed;
  z-index: 20;
  box-sizing: border-box;
  border-radius: 12px;
  background: var(--glass);
  box-shadow: var(--shadow);
  -webkit-backdrop-filter: var(--blur);
  backdrop-filter: var(--blur);
  color: var(--ink);
  font-size: 13px;
}

[hidden] {
  display: none !important;
}

.card:not([hidden]) {
  animation: appear 0.12s ease-out;
}

@keyframes appear {
  from {
    opacity: 0;
    transform: translateY(-4px);
  }
}

#popover {
  min-width: 160px;
  padding: 6px 0;
}

.item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 6px 16px 6px 12px;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  text-align: left;
  white-space: nowrap;
  cursor: pointer;
}

@media (hover: hover) {
  .item:hover:not(:disabled) {
    background: var(--item-hover);
  }
}

.item:disabled {
  color: var(--disabled);
  cursor: default;
}

.mark {
  display: inline-flex;
  width: 18px;
  color: var(--mark);
}

.item:disabled .mark {
  color: inherit;
}

.label {
  flex: 1;
}

.keys {
  margin-left: 24px;
  color: var(--muted-2);
  font-size: 13px;
}

.separator {
  height: 1px;
  margin: 6px 0;
  background: var(--line);
}

.palette {
  display: grid;
  grid-template-columns: repeat(10, 18px);
  gap: 5px;
  padding: 6px 14px 10px;
}

.palette button {
  width: 18px;
  height: 18px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  box-shadow: inset 0 0 0 1px var(--swatch-ring);
  cursor: pointer;
  transition: transform 0.1s;
}

@media (hover: hover) {
  .palette button:hover {
    transform: scale(1.18);
  }
}

.row {
  display: flex;
  gap: 2px;
  padding: 0 6px;
}

#link-editor {
  display: flex;
  align-items: center;
  gap: 4px;
  width: min(400px, calc(100vw - 16px));
  padding: 10px;
}

#link-input {
  flex: 1;
  min-width: 0;
  height: 32px;
  margin-right: 4px;
  padding: 0 10px;
  border: 1px solid var(--field);
  border-radius: 6px;
  background: transparent;
  color: inherit;
  font: inherit;
  outline: none;
}

#link-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}

#link-input.invalid {
  border-color: var(--danger);
  box-shadow: 0 0 0 1px var(--danger);
}

#link-editor button {
  height: 32px;
  padding: 0 12px;
  border: 0;
  border-radius: 6px;
  background: none;
  color: var(--accent);
  font: inherit;
  font-weight: 500;
  cursor: pointer;
}

@media (hover: hover) {
  #link-editor button:hover {
    background: var(--accent-hover);
  }
}

#link-remove {
  color: var(--muted) !important;
}

@media (hover: hover) {
  #link-remove:hover {
    background: var(--hover) !important;
  }
}

/* Find and replace, centred under the toolbar, like Docs' dialog but lighter. */
#finder {
  top: 56px;
  right: 0;
  left: 0;
  width: min(380px, calc(100vw - 16px));
  margin: 0 auto;
  padding: 10px;
}

.finder-row {
  display: flex;
  align-items: center;
  gap: 4px;
}

.finder-row + .finder-row {
  margin-top: 8px;
}

#find-input,
#replace-input {
  flex: 1;
  min-width: 0;
  height: 32px;
  margin-right: 4px;
  padding: 0 10px;
  border: 1px solid var(--field);
  border-radius: 6px;
  background: transparent;
  color: inherit;
  font: inherit;
  outline: none;
}

#find-input:focus,
#replace-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}

#find-count {
  min-width: 64px;
  color: var(--muted-2);
  text-align: right;
  white-space: nowrap;
}

#finder button {
  height: 32px;
  padding: 0 10px;
  border: 0;
  border-radius: 6px;
  background: none;
  color: var(--accent);
  font: inherit;
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
}

@media (hover: hover) {
  #finder button:hover {
    background: var(--accent-hover);
  }
}

/* Matches, marked without touching the text: all of them softly, the current one strongly. */
::highlight(find) {
  background-color: rgba(251, 188, 4, 0.3);
}

::highlight(find-current) {
  background-color: rgba(251, 188, 4, 0.75);
  color: #1f1f1f;
}

#link-bubble {
  display: flex;
  align-items: center;
  gap: 2px;
  max-width: min(400px, calc(100vw - 16px));
  padding: 4px 4px 4px 14px;
}

#link-open {
  flex: 1;
  min-width: 0;
  margin-right: 6px;
  overflow: hidden;
  color: var(--link);
  font-size: 13px;
  text-decoration: none;
  text-overflow: ellipsis;
  white-space: nowrap;
}

@media (hover: hover) {
  #link-open:hover {
    text-decoration: underline;
  }
}

/* The P in the corner. Hovering it turns it G-train green and brings up the note as plain
   text, frosted like the toolbar pill only where it overlaps the page. */
#about {
  position: fixed;
  right: 14px;
  bottom: 14px;
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
  pointer-events: none;
}

#note {
  position: relative;
  padding: 6px 10px;
  border-radius: 12px;
  background: var(--pill);
  -webkit-backdrop-filter: var(--blur);
  backdrop-filter: var(--blur);
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
  text-align: right;
  white-space: nowrap;
  opacity: 0;
  transform: translateY(4px);
  transition: opacity 0.15s ease-out 0.1s, transform 0.15s ease-out 0.1s;
}

/* Bridges the gap to the P, so moving between them keeps the note up. */
#note::after {
  content: "";
  position: absolute;
  top: 100%;
  right: 0;
  left: 0;
  height: 6px;
}

#note p {
  margin: 0;
}

/* At rest, a thin grey circle with an "i". On hover it turns into the green P, the same size. */
#about-button {
  position: relative;
  width: 28px;
  height: 28px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: none;
  color: var(--info);
  cursor: default;
  pointer-events: auto;
}

#about-button svg {
  position: absolute;
  top: 4px;
  left: 4px;
  width: 20px;
  height: 20px;
  transition: opacity 0.2s ease-out, transform 0.2s ease-out;
}

#about-button .p {
  color: #6cbe45;
  opacity: 0;
  transform: scale(0.85);
}

/* Shown on hover with a mouse, on keyboard focus, or by a tap on a touch screen. */
#about:is(.open, :has(:focus-visible)) #note {
  opacity: 1;
  transform: none;
  pointer-events: auto;
  transition-delay: 0s;
}

#about:is(.open, :has(:focus-visible)) #about-button .info {
  opacity: 0;
  transform: scale(0.85);
}

#about:is(.open, :has(:focus-visible)) #about-button .p {
  opacity: 1;
  transform: none;
}

@media (hover: hover) {
  #about:hover #note {
    opacity: 1;
    transform: none;
    pointer-events: auto;
    transition-delay: 0s;
  }

  #about:hover #about-button .info {
    opacity: 0;
    transform: scale(0.85);
  }

  #about:hover #about-button .p {
    opacity: 1;
    transform: none;
  }
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

#toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  z-index: 30;
  padding: 10px 16px;
  border-radius: 8px;
  background: var(--tip);
  color: var(--tip-ink);
  font-size: 13px;
  pointer-events: none;
  opacity: 0;
  transform: translate(-50%, 8px);
  transition: opacity 0.2s, transform 0.2s;
}

#toast.shown {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* Printing gives just the text on white paper with Docs' one-inch margins: no toolbar, background,
   shadow or corner note. Emptying every page-margin box stops the browser adding its own date,
   title, address and page numbers, which Docs doesn't print either. */
@page {
  margin: 1in;

  @top-left-corner { content: ""; }
  @top-left { content: ""; }
  @top-center { content: ""; }
  @top-right { content: ""; }
  @top-right-corner { content: ""; }
  @right-top { content: ""; }
  @right-middle { content: ""; }
  @right-bottom { content: ""; }
  @bottom-right-corner { content: ""; }
  @bottom-right { content: ""; }
  @bottom-center { content: ""; }
  @bottom-left { content: ""; }
  @bottom-left-corner { content: ""; }
  @left-bottom { content: ""; }
  @left-middle { content: ""; }
  @left-top { content: ""; }
}

@media print {
  /* Paper is always white, whichever theme is showing. */
  html {
    color-scheme: light !important;
    --ink: #1f1f1f !important;
    --black: #000 !important;
    --page: #fff !important;
    --link: #1155cc !important;
  }

  html,
  body {
    background: #fff;
  }

  body {
    padding: 0;
  }

  #toolbar,
  #about,
  .card,
  #toast {
    display: none !important;
  }

  #editor {
    --base: 11pt;
    width: auto;
    max-width: none;
    min-height: 0;
    aspect-ratio: auto;
    margin: 0;
    padding: 0;
    border-radius: 0;
    box-shadow: none;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
}
