:root {
  --bg: #d8bd8f;
  --bg-deep: #cda975;
  --ink: #191919;
  --muted: #5f5749;
  --panel: #f8f4ee;
  --line: #ccbda7;

  --felt: #171717;
  --groove: #2b2b2b;
  --groove-deep: #0f0f0f;
  --letter: #f8f8f8;
  --frame: linear-gradient(135deg, #b98a52, #8f6534 55%, #a87a45);

  --btn: #2f2f2f;
  --btn-ink: #f4f4f4;
  --btn-soft: #ddd4c7;
  --btn-soft-ink: #242424;

  --board-font: "Google Sans Flex", "Roboto Mono", Consolas, monospace;
  --ui-font: "Google Sans Flex", "Avenir Next", "Gill Sans", "Trebuchet MS", sans-serif;

  /* Where capitals sit in a line of text. Measured from the font by js/metrics.js. */
  --cap-shift: 0em;
  --arrow-shift: 0em;
}

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

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.11), rgba(255, 255, 255, 0) 25%),
    linear-gradient(120deg, var(--bg), var(--bg-deep));
  color: var(--ink);
  font-family: var(--ui-font);
}

.site-header,
main,
.site-footer {
  width: min(1180px, 100% - 1.5rem);
  margin-inline: auto;
}

h2 {
  margin: 0;
  font-size: 1rem;
}

:focus-visible {
  outline: 2px solid #1d4ed8;
  outline-offset: 2px;
}

/* --- Header ----------------------------------------------------------------- */

.site-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem 1rem;
  padding-block: 1rem 0.8rem;
}

/* The address on a strip of letter board. */
.brand {
  margin: 0;
  padding: 0.4rem 0.8rem 0.3rem;
  border: 4px solid #96693a;
  border-radius: 8px;
  background: repeating-linear-gradient(to bottom, var(--felt) 0 9px, var(--groove) 9px 10px, var(--groove-deep) 10px 12px);
  color: var(--letter);
  font: 640 clamp(1.15rem, 4.4vw, 1.9rem) / 1.15 var(--board-font);
  letter-spacing: 0.08em;
  white-space: nowrap;
  text-shadow: 0 0.04em 0.05em rgba(0, 0, 0, 0.9);
}

.brand i {
  display: inline-block;
  font-style: normal;
  line-height: 1;
  /* Turned around the middle of the capitals, so the letter stays on the line. */
  translate: 0 calc(-2 * var(--cap-shift));
  rotate: 180deg;
}

.tagline {
  margin: 0;
  color: var(--muted);
  font-size: 0.95rem;
}

/* --- Workspace -------------------------------------------------------------- */

.workspace {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.9rem;
  align-items: start;
}

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

.panel[inert] {
  opacity: 0.45;
}

.panel.is-rewriting {
  border-color: #9f8b6a;
  box-shadow: 0 0 0 2px rgba(123, 92, 39, 0.25);
}

.panel-head {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  min-height: 2.6rem;
  margin-bottom: 0.6rem;
}

.byline {
  margin: 0.1rem 0 0;
  min-height: 1.1em;
  color: var(--muted);
  font-size: 0.8rem;
}

.panel-actions {
  display: flex;
  gap: 0.4rem;
}

/* Keep board and tray on one screen where the window allows it. */
.panel .board {
  max-width: max(280px, (100dvh - 20rem) * 0.8125);
  margin-inline: auto;
}

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

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid transparent;
  border-radius: 9px;
  padding: 0.45rem 0.8rem;
  background: var(--btn-soft);
  color: var(--btn-soft-ink);
  font: 700 0.88rem / 1.2 var(--ui-font);
  text-decoration: none;
  cursor: pointer;
}

.btn:hover {
  filter: brightness(0.95);
}

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

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

.btn-small {
  padding: 0.3rem 0.55rem;
  border-radius: 7px;
  font-size: 0.76rem;
}

/* --- The board --------------------------------------------------------------
   Everything on a board is placed in board units: 1 unit is 1/520 of the board's
   width (--u), so a board looks the same at any size. See js/glyphs.js. */

.board {
  position: relative;
  padding: 7px;
  border-radius: 10px;
  background: var(--frame);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.3),
    0 5px 14px rgba(70, 45, 10, 0.28);
}

.board-face {
  container-type: inline-size;
  position: relative;
  aspect-ratio: 520 / 640;
}

.board-field {
  --u: calc(100cqw / 520);
  position: absolute;
  inset: 0;
  border-radius: 3px;
  background: repeating-linear-gradient(
    to bottom,
    var(--felt) 0 calc(15 * var(--u)),
    var(--groove) calc(15 * var(--u)) calc(17 * var(--u)),
    var(--groove-deep) calc(17 * var(--u)) calc(20 * var(--u))
  );
  box-shadow: inset 0 0 0 1px #000;
}

.tile {
  position: absolute;
  left: calc(var(--x) * var(--u));
  top: calc((var(--row) * 20 - 23.5) * var(--u));
  width: calc(var(--w) * var(--u));
  height: calc(47 * var(--u));
  display: grid;
  place-items: center;
  rotate: var(--turn, 0deg);
  transition: rotate 0.2s ease;
  user-select: none;
  -webkit-user-select: none;
}

/* A little more to get hold of than the letter itself. */
.tile::after {
  content: "";
  position: absolute;
  inset: 0 calc(-3 * var(--u));
}

.glyph {
  color: var(--letter);
  font: 640 calc(46.4 * var(--u)) / 1 var(--board-font);
  white-space: nowrap;
  translate: 0 var(--cap-shift);
  text-shadow:
    -0.01em -0.01em 0 rgba(255, 255, 255, 0.72),
    0.01em 0.01em 0 rgba(208, 208, 208, 0.34),
    0 0.04em 0.045em rgba(0, 0, 0, 0.9);
  pointer-events: none;
}

.tile[data-ch="<"] .glyph {
  font-size: calc(40 * var(--u));
  translate: 0 var(--arrow-shift);
}

.tile.is-used .glyph {
  color: rgba(255, 255, 255, 0.2);
  text-shadow: none;
}

.cursor {
  position: absolute;
  left: calc((var(--x) - 3) * var(--u));
  top: calc((var(--row) * 20 - 26) * var(--u));
  width: 2px;
  height: calc(52 * var(--u));
  border-radius: 1px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow:
    0 0 0 1px rgba(0, 0, 0, 0.55),
    0 0 10px rgba(255, 255, 255, 0.22);
  pointer-events: none;
  animation: blink 1.1s steps(2, jump-none) infinite;
}

@keyframes blink {
  to {
    opacity: 0.15;
  }
}

/* Letters on the two big boards can be picked up. */
.workspace .tile {
  cursor: grab;
  touch-action: none;
}

/* The previous message is tapped, not dragged, on a touch screen, so that the page can still be scrolled. */
.workspace #sourceBoard .tile {
  cursor: pointer;
  touch-action: manipulation;
}

.workspace .is-rewriting #sourceBoard .tile {
  cursor: grab;
  touch-action: none;
}

.workspace #sourceBoard .tile.is-used {
  cursor: alias;
}

/* A letter carried from one board to the other floats above both. */
.board.has-lifted {
  z-index: 5;
}

.tile.is-lifted {
  z-index: 5;
  cursor: grabbing;
}

.tile.is-leaving {
  opacity: 0.3;
}

.board.is-empty::after {
  content: attr(data-hint);
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 2rem;
  color: rgba(255, 255, 255, 0.38);
  font-size: 0.95rem;
  text-align: center;
  pointer-events: none;
}

/* --- Tray ------------------------------------------------------------------- */

.tray {
  display: grid;
  gap: 0.4rem;
  max-width: max(280px, (100dvh - 20rem) * 0.8125);
  margin: 0.65rem auto 0;
}

.tray-letters,
.tray-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
}

.key {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.25rem;
  min-width: 2.5rem;
  height: 2.5rem;
  border: 1px solid #000;
  border-radius: 7px;
  padding: 0 0.45rem;
  background: var(--felt);
  color: var(--letter);
  font: 640 1.15rem / 1 var(--board-font);
  cursor: pointer;
  touch-action: manipulation;
}

.key-count {
  align-self: flex-start;
  margin-top: 0.3rem;
  color: #b3ab9d;
  font: 600 0.66rem / 1 var(--ui-font);
}

.key.is-out {
  opacity: 0.32;
}

.key.is-shaking {
  animation: shake 0.3s;
}

@keyframes shake {
  25% {
    translate: -3px 0;
  }
  75% {
    translate: 3px 0;
  }
}

.tray-actions .key {
  flex: 1 1 auto;
  border-color: var(--line);
  background: var(--btn-soft);
  color: var(--btn-soft-ink);
  font: 700 0.82rem / 1 var(--ui-font);
}

.tray-actions .key[aria-pressed="true"] {
  border-color: var(--btn);
  background: var(--btn);
  color: var(--btn-ink);
}

/* --- Help and lists --------------------------------------------------------- */

.help {
  margin-top: 0.9rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
  padding: 0.6rem 0.8rem;
  font-size: 0.86rem;
}

.help summary {
  font-weight: 700;
  cursor: pointer;
}

.help ul {
  margin: 0.5rem 0 0.2rem;
  padding-left: 1.2rem;
  color: #4b4438;
}

.help li + li {
  margin-top: 0.3rem;
}

.list-section {
  margin-top: 1.6rem;
}

.list-section h2 {
  font-size: 1.15rem;
}

.list-note {
  margin: 0.2rem 0 0;
  color: var(--muted);
  font-size: 0.85rem;
}

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 0.8rem;
  margin-block: 0.7rem;
}

.card {
  display: grid;
  align-content: start;
  gap: 0.3rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
  padding: 0.55rem;
}

.card.is-active {
  border-color: var(--btn);
  box-shadow: 0 0 0 1px var(--btn);
}

.card .board {
  padding: 4px;
  border-radius: 6px;
  box-shadow: none;
}

.card-title {
  display: -webkit-box;
  margin: 0.2rem 0 0;
  overflow: hidden;
  font-size: 0.86rem;
  line-height: 1.25;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
}

.card-meta {
  margin: 0;
  overflow: hidden;
  color: var(--muted);
  font-size: 0.74rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.card-meta:empty {
  display: none;
}

.card-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  margin-top: 0.25rem;
}

.site-footer {
  padding-block: 1.4rem 1.6rem;
  color: #666;
  font-size: 0.86rem;
  text-align: right;
}

/* --- Dialogs and messages --------------------------------------------------- */

.dialog {
  width: min(92vw, 380px);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 0;
  background: var(--panel);
  color: var(--ink);
}

.dialog::backdrop {
  background: rgba(17, 17, 17, 0.55);
}

.dialog form {
  display: grid;
  gap: 0.6rem;
  padding: 1rem;
}

.dialog label {
  color: #4b4438;
  font-size: 0.8rem;
  font-weight: 700;
}

.dialog input {
  min-width: 0;
  border: 1px solid #b9ad9a;
  border-radius: 8px;
  padding: 0.5rem 0.6rem;
  background: #fffdf9;
  color: #242424;
  font: inherit;
  font-size: 0.92rem;
}

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

.dialog-note {
  margin: 0;
  color: var(--muted);
  font-size: 0.78rem;
}

.dialog-share {
  width: min(92vw, 440px);
}

.dialog-share .board {
  width: min(100%, 230px);
  margin-inline: auto;
  padding: 5px;
}

.share-title {
  margin: 0;
  font-weight: 700;
  text-align: center;
  overflow-wrap: anywhere;
}

.share-row {
  display: flex;
  gap: 0.4rem;
}

.share-row input {
  flex: 1;
}

.share-submit {
  display: grid;
  justify-items: start;
  gap: 0.35rem;
  border-top: 1px solid var(--line);
  padding-top: 0.7rem;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 1.2rem;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 0.8rem;
  width: max-content;
  max-width: calc(100vw - 1.5rem);
  border-radius: 10px;
  padding: 0.65rem 0.9rem;
  background: #222;
  color: #f6f1e8;
  font-size: 0.9rem;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
  translate: -50% 150%;
  opacity: 0;
  transition:
    translate 0.2s ease,
    opacity 0.2s ease;
}

.toast.is-visible {
  translate: -50% 0;
  opacity: 1;
}

.toast-action {
  border: 0;
  padding: 0;
  background: none;
  color: #f0c36b;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

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

@media (max-width: 860px) {
  .workspace {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 560px) {
  .panel {
    padding: 0.55rem;
  }

  .board {
    padding: 5px;
  }

  .key {
    min-width: 2.3rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
  }
}
