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

/* A Google Docs page: Letter-sized, one-inch margins, on Docs' cool grey. */
html {
  /* One soft shadow for everything that sits above the background: the page, the toolbar pill, 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);
  --glass: rgba(255, 255, 255, 0.72);
  --blur: blur(20px) saturate(180%);
  background: #f9fbfd;
  color: #1f1f1f;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

/* 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: rgba(249, 251, 253, 0.7);
  -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: #80868b;
  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: rgba(60, 64, 67, 0.08);
  color: #1f1f1f;
}

@media (hover: hover) {
  .tools button:hover,
  .row button:hover,
  #link-bubble button:hover {
    background: rgba(60, 64, 67, 0.08);
    color: #1f1f1f;
  }
}

.tools button.on,
.row button.on {
  background: rgba(60, 64, 67, 0.12);
  color: #1f1f1f;
}

.divider {
  flex: none;
  width: 1px;
  height: 18px;
  margin: 0 6px;
  background: #e3e3e3;
}

#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 #dadce0;
  border-radius: 4px;
  color: #444746;
  font-variant-numeric: tabular-nums;
}

.swatch {
  fill: #1f1f1f;
}

/* 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: #3c4043;
  color: #fff;
  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: #fff;
  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;
}

#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: #1155cc;
}

/* 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: #fff;
  }

  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: rgba(255, 255, 255, 0.72);
  }

  #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;
  }

  #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 {
    height: 40px;
    font-size: 16px;
  }

  #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: #1f1f1f;
  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: #f1f3f4;
  }
}

.item:disabled {
  color: #9aa0a6;
  cursor: default;
}

.mark {
  display: inline-flex;
  width: 18px;
  color: #444746;
}

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

.label {
  flex: 1;
}

.keys {
  margin-left: 24px;
  color: #80868b;
  font-size: 13px;
}

.separator {
  height: 1px;
  margin: 6px 0;
  background: #e3e3e3;
}

.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 rgba(0, 0, 0, 0.1);
  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 #dadce0;
  border-radius: 6px;
  color: inherit;
  font: inherit;
  outline: none;
}

#link-input:focus {
  border-color: #1a73e8;
  box-shadow: 0 0 0 1px #1a73e8;
}

#link-input.invalid {
  border-color: #d93025;
  box-shadow: 0 0 0 1px #d93025;
}

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

@media (hover: hover) {
  #link-editor button:hover {
    background: rgba(26, 115, 232, 0.06);
  }
}

#link-remove {
  color: #5f6368 !important;
}

@media (hover: hover) {
  #link-remove:hover {
    background: rgba(60, 64, 67, 0.08) !important;
  }
}

#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: #1155cc;
  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: rgba(249, 251, 253, 0.7);
  -webkit-backdrop-filter: var(--blur);
  backdrop-filter: var(--blur);
  color: #5f6368;
  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: #bdc1c6;
  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: #3c4043;
  color: #fff;
  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 {
  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;
  }
}
