/* ---------- The app: layout, top bar, buttons, library, Write, Mark toolbar, dialogs ---------- */

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--paper);
  color: var(--ink);
  font: 16px/1.5 var(--sans);
  -webkit-font-smoothing: antialiased;
}

[hidden] {
  display: none !important;
}

/* The app appears once it has drawn itself, not in two goes. (If its script
   ever failed, the page still appears after a moment.) */
#main {
  transition: opacity 0.15s;
}

.booting #main {
  opacity: 0;
  animation: appear 0s 1.5s forwards;
}

@keyframes appear {
  to {
    opacity: 1;
  }
}

button,
input,
textarea {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.fine {
  color: var(--ink-faint);
  font-size: 0.875rem;
}

/* ---------- Top bar ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 1rem;
  min-height: var(--head-height);
  padding: 0.6rem 1.25rem;
  padding-top: max(0.6rem, env(safe-area-inset-top));
  background: color-mix(in srgb, var(--paper) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--rule);
}

.brand {
  view-transition-name: logo;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.25rem 0.4rem;
  border: 0;
  border-radius: var(--radius-sm);
  background: none;
  font-family: var(--serif);
  font-size: 1.15rem;
  letter-spacing: 0.01em;
}

.brand-mark {
  display: none; /* the mark alone, for small screens */
  width: 1.5rem;
  height: 1.5rem;
  fill: var(--accent);
}

.brand-name {
  display: block;
  height: 1.55rem;
  width: auto;
}

@media (prefers-color-scheme: dark) {
  .brand-name {
    filter: invert(1) hue-rotate(180deg) brightness(1.1);
  }
}

.doc-head {
  min-width: 0;
}

.title-input {
  width: 100%;
  padding: 0.35rem 0.6rem;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  font-family: var(--serif);
  font-size: 1.1rem;
  text-overflow: ellipsis;
}

.title-input:hover {
  border-color: var(--rule);
}

.title-input:focus {
  border-color: var(--accent);
  background: var(--sheet);
  outline: none;
}

.modes {
  display: flex;
  padding: 3px;
  border-radius: 999px;
  background: var(--rule);
}

.modes button {
  min-width: 5.5rem;
  padding: 0.4rem 1rem;
  border: 0;
  border-radius: 999px;
  background: none;
  color: var(--ink-soft);
  font-weight: 500;
}

.modes button[aria-selected="true"] {
  background: var(--sheet);
  color: var(--ink);
  box-shadow: 0 1px 3px rgb(0 0 0 / 10%);
}

.topbar-end {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  justify-self: end;
}

.chip {
  padding: 0.35rem 0.8rem;
  border: 1px solid var(--rule);
  border-radius: 999px;
  background: var(--sheet);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.chip-label {
  color: var(--ink-faint);
}

.chip.over {
  border-color: var(--danger);
  color: var(--danger);
}

.icon-btn {
  display: inline-grid;
  place-items: center;
  min-width: 2.25rem;
  height: 2.25rem;
  padding: 0 0.4rem;
  border: 0;
  border-radius: var(--radius-sm);
  background: none;
  color: var(--ink-soft);
}

.icon-btn:hover:not(:disabled) {
  background: var(--rule);
  color: var(--ink);
}

.icon-btn:disabled {
  opacity: 0.35;
  cursor: default;
}

.icon-btn svg {
  width: 1.25rem;
  height: 1.25rem;
  fill: currentColor;
}

#undo svg,
#redo svg,
svg.stroke {
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ---------- Menu ---------- */

.menu-wrap {
  position: relative;
}

.menu {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  min-width: 14rem;
  padding: 0.35rem;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  background: var(--sheet);
  box-shadow: var(--shadow);
}

.menu button,
.menu-link {
  display: block;
  width: 100%;
  padding: 0.55rem 0.75rem;
  border: 0;
  border-radius: var(--radius-sm);
  background: none;
  text-align: left;
}

.menu-link {
  color: var(--accent);
  font-weight: 500;
  text-decoration: none;
}

.menu button:hover,
.menu button:focus-visible,
.menu-link:hover,
.menu-link:focus-visible {
  background: var(--paper);
}

.menu hr {
  margin: 0.3rem 0.5rem;
  border: 0;
  border-top: 1px solid var(--rule);
}

.danger {
  color: var(--danger);
}

/* ---------- Buttons ---------- */

.btn {
  padding: 0.6rem 1.15rem;
  border: 1px solid var(--rule);
  border-radius: 999px;
  background: var(--sheet);
  font-weight: 500;
}

.btn:hover {
  border-color: var(--ink-faint);
}

.btn.primary {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--accent-ink);
}

.btn.primary:hover {
  filter: brightness(1.08);
}

.btn.danger {
  border-color: var(--danger);
  background: var(--danger);
  color: #fff;
}

/* ---------- Views and the page of script ---------- */

.view {
  padding: 2rem 1.25rem 6rem;
}

.page {
  max-width: calc(var(--measure) + 5rem);
  margin: 0 auto;
  padding: 2.5rem;
  border-radius: var(--radius);
  background: var(--sheet);
  box-shadow: var(--shadow);
}

/* ---------- Library ---------- */

.library {
  max-width: 52rem;
  margin: 0 auto;
}

.library-head {
  padding: 2rem 0 1.5rem;
}

.library h1 {
  margin: 0 0 0.4rem;
  font: 400 2.4rem/1.15 var(--serif);
  letter-spacing: -0.01em;
}

.lede {
  margin: 0 0 1.5rem;
  max-width: 34rem;
  color: var(--ink-soft);
  font-size: 1.1rem;
}

.library-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  margin-bottom: 0.6rem;
}

.speech-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(15rem, 1fr));
  gap: 1rem;
  margin: 1rem 0 0;
  padding: 0;
  list-style: none;
}

.card {
  position: relative;
  display: flex;
  flex-direction: column;
  height: 100%;
  padding: 1.1rem 1.2rem 1rem;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  background: var(--sheet);
  transition:
    box-shadow 0.15s,
    border-color 0.15s;
}

.card:hover {
  border-color: var(--ink-faint);
  box-shadow: var(--shadow);
}

.card-delete {
  position: absolute;
  top: 0.6rem;
  right: 0.6rem;
  z-index: 1;
  opacity: 0;
  transition: opacity 0.15s;
}

.card:hover .card-delete,
.card:focus-within .card-delete {
  opacity: 1;
}

@media (hover: none) {
  .card-delete {
    opacity: 1;
  }
}

.card h2 {
  padding-right: 2rem;
}

.card-open {
  all: unset;
  position: absolute;
  inset: 0;
  border-radius: var(--radius);
  cursor: pointer;
}

.card-open:focus-visible {
  outline: 2px solid var(--accent);
}

.card h2 {
  margin: 0 0 0.35rem;
  font: 400 1.2rem/1.3 var(--serif);
}

.card p {
  flex: 1;
  margin: 0 0 0.9rem;
  color: var(--ink-soft);
  font-family: var(--serif);
  font-size: 0.95rem;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card-meta {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  color: var(--ink-faint);
  font-size: 0.8rem;
}

.empty {
  grid-column: 1 / -1;
  padding: 3rem 1rem;
  border: 1px dashed var(--rule);
  border-radius: var(--radius);
  color: var(--ink-faint);
  text-align: center;
}

.app-foot {
  margin-top: 4rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--rule);
  color: var(--ink-faint);
  font-size: 0.85rem;
}

.app-foot p {
  margin: 0.3rem 0;
}

.app-foot a {
  color: var(--ink-soft);
  text-underline-offset: 3px;
}

/* ---------- Write ---------- */

.script {
  display: block;
  width: 100%;
  min-height: 60vh;
  padding: 0;
  border: 0;
  background: transparent;
  font: var(--script-size) / 1.75 var(--serif);
  resize: none;
  field-sizing: content;
}

.script:focus {
  outline: none;
}

.script::placeholder {
  color: var(--ink-faint);
}

.write-foot {
  max-width: calc(var(--measure) + 5rem);
  margin: 0.75rem auto 0;
  text-align: center;
}

/* ---------- Mark: the toolbar ---------- */

.toolbar {
  position: sticky;
  top: 3.7rem;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  width: fit-content;
  max-width: 100%;
  margin: 0 auto 0.5rem;
  padding: 0.45rem;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  background: var(--sheet);
  box-shadow: var(--shadow);
}

.tools {
  display: flex;
  align-items: center;
  gap: 0.15rem;
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: none;
}

.tool-sep {
  width: 1px;
  height: 1.6rem;
  margin: 0 0.25rem;
  background: var(--rule);
}

.tool {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.4rem 0.7rem;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: none;
  font-size: 0.92rem;
}

.tool:hover {
  background: var(--paper);
}

.tool[aria-pressed="true"] {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.tool.subtle {
  color: var(--ink-soft);
}

.tool:disabled {
  opacity: 0.4;
  cursor: default;
}

.tool-glyph {
  display: inline-grid;
  place-items: center;
  min-width: 1.1rem;
  color: var(--accent);
  font: 600 1.05rem/1 var(--serif);
}

.tool-glyph.em {
  text-decoration: underline 2px;
  text-underline-offset: 3px;
}

.tool-glyph.pace {
  padding: 0.1rem 0.3rem;
  border-radius: 4px;
  font: 600 0.62rem/1.2 var(--sans);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.tool-glyph.slower {
  background: var(--slower);
  color: var(--slower-ink);
}

.tool-glyph.faster {
  background: var(--faster);
  color: var(--faster-ink);
}

.tool kbd {
  color: var(--ink-faint);
  font: 0.72rem var(--sans);
  text-transform: uppercase;
}

.toolbar-end {
  flex: none;
  display: flex;
  padding-left: 0.4rem;
  border-left: 1px solid var(--rule);
  align-items: center;
  gap: 0.15rem;
}

.hint {
  max-width: calc(var(--measure) + 5rem);
  min-height: 1.5rem;
  margin: 0 auto 0.75rem;
  color: var(--ink-faint);
  font-size: 0.875rem;
  text-align: center;
}

/* ---------- Dialogs ---------- */

.dialog {
  width: min(28rem, calc(100vw - 2rem));
  padding: 1.6rem 1.6rem 1.2rem;
  border: 0;
  border-radius: 16px;
  background: var(--sheet);
  color: var(--ink);
  box-shadow: var(--shadow);
}

.dialog.wide {
  width: min(36rem, calc(100vw - 2rem));
}

.dialog::backdrop {
  background: rgb(20 18 14 / 35%);
  backdrop-filter: blur(2px);
}

.dialog h2 {
  margin: 0 0 1rem;
  font: 400 1.5rem/1.2 var(--serif);
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 1.25rem;
}

.field {
  display: block;
  margin-bottom: 1.1rem;
}

.field-label {
  display: flex;
  justify-content: space-between;
  margin-bottom: 0.4rem;
  font-weight: 500;
}

.field-label output {
  color: var(--accent);
  font-weight: 500;
}

.field input[type="text"] {
  width: 100%;
  padding: 0.6rem 0.8rem;
  border: 1px solid var(--rule);
  border-radius: var(--radius-sm);
  background: var(--paper);
}

.field input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}

.field-scale {
  display: flex;
  justify-content: space-between;
  color: var(--ink-faint);
  font-size: 0.78rem;
}

.steps {
  margin: 0 0 1rem;
  padding-left: 1.2rem;
}

.steps li {
  margin-bottom: 0.6rem;
}

/* ---------- Toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: max(1.5rem, env(safe-area-inset-bottom));
  z-index: 50;
  max-width: calc(100vw - 2rem);
  padding: 0.7rem 1.1rem;
  border-radius: 999px;
  background: var(--ink);
  color: var(--paper);
  font-size: 0.92rem;
  box-shadow: var(--shadow);
  transform: translateX(-50%);
}

.print-sheet {
  display: none;
}

/* ---------- Small screens ---------- */

@media (max-width: 1100px) {
  .tool kbd {
    display: none;
  }
}

@media (max-width: 760px) {
  .topbar {
    grid-template-columns: auto minmax(0, 1fr) auto;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem;
  }

  .brand-name {
    display: none;
  }

  .brand-mark {
    display: block;
  }

  /* On your speeches page there's room for the whole logo, as on the home page */
  .topbar:has(.doc-head[hidden]) .brand-name {
    display: block;
  }

  .topbar:has(.doc-head[hidden]) .brand-mark {
    display: none;
  }

  .modes {
    grid-column: 1 / -1;
    grid-row: 2;
    justify-self: center;
  }

  .chip-label {
    display: none;
  }

  .toolbar {
    top: 6.4rem;
  }

  .tool kbd,
  .tool-label {
    display: none;
  }

  .tool {
    padding: 0.45rem 0.55rem;
  }

  .toolbar {
    flex-wrap: wrap;
    justify-content: center;
    width: auto;
  }

  .tools {
    flex-wrap: wrap;
    justify-content: center;
    overflow: visible;
  }

  .tool-sep,
  .toolbar #clear-marks {
    display: none;
  }

  .toolbar-end {
    padding-left: 0;
    border-left: 0;
  }

  .view {
    padding: 1rem 0.6rem 5rem;
  }

  .page {
    padding: 1.4rem 1.2rem;
  }

  .library h1 {
    font-size: 2rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
    scroll-behavior: auto !important;
  }
}
