:root {
  --paper: #eef0f8;
  --paper-2: #e2e5f3;
  --ink: #1b1f3b;
  --ink-2: #565c80;
  --ink-3: #8b90ae;
  --wire: #a9afce;
  --pill: #ffffff;
  --blue: #3451f5;
  --green: #0e9f62;
  --green-bg: #d8f6e6;
  --green-ink: #075a37;
  --gold: #e39a00;
  --gold-bg: #fff0c7;
  --gold-ink: #5c3d00;
  --red: #d6453d;
  --font: "Schibsted Grotesk", "Avenir Next", "Segoe UI", system-ui, sans-serif;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #13152a;
    --paper-2: #1c1f3a;
    --ink: #eceefb;
    --ink-2: #a9afd4;
    --ink-3: #7077a0;
    --wire: #454b78;
    --pill: #22264a;
    --blue: #8fa2ff;
    --green: #3ddc97;
    --green-bg: #103a2b;
    --green-ink: #b9f5d9;
    --gold: #ffc53d;
    --gold-bg: #3b2e08;
    --gold-ink: #ffe7a6;
    --red: #ff7a70;
  }
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
}

body {
  display: grid;
  grid-template-rows: auto 1fr auto;
  height: 100dvh;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.45;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

button {
  font: inherit;
  color: inherit;
}

/* ---- top bar ---- */

.bar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 20px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: inherit;
  text-decoration: none;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 38px;
  height: 26px;
  border-radius: 999px;
  background: var(--ink);
  color: var(--paper);
  font-family: Georgia, "Times New Roman", serif;
  font-weight: 700;
  font-size: 17px;
  line-height: 1;
}

.brand-name {
  font-weight: 800;
  font-size: 21px;
  letter-spacing: -0.02em;
}

.puzzle-no {
  margin: 0;
  color: var(--ink-2);
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}

.bar-actions {
  display: flex;
  gap: 4px;
  margin-left: auto;
}

.text-button {
  padding: 8px 12px;
  border: 0;
  border-radius: 999px;
  background: none;
  font-weight: 600;
  cursor: pointer;
}

.text-button:hover {
  background: var(--paper-2);
}

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

/* ---- board ---- */

.board {
  position: relative;
  overflow: hidden;
  touch-action: none;
  cursor: grab;
  user-select: none;
  -webkit-user-select: none;
}

.board.panning {
  cursor: grabbing;
}

.world {
  position: absolute;
  left: 0;
  top: 0;
  width: 0;
  height: 0;
  transform-origin: 0 0;
  will-change: transform;
}

.wires {
  position: absolute;
  left: 0;
  top: 0;
  width: 1px;
  height: 1px;
  overflow: visible;
  pointer-events: none;
}

.wire {
  fill: none;
  stroke: var(--wire);
  stroke-width: 2.5;
  stroke-linecap: round;
}

.arrow {
  fill: var(--wire);
}

.edge.on-path .wire {
  stroke: var(--gold);
  stroke-width: 4;
}

.edge.on-path .arrow {
  fill: var(--gold);
}

.goal {
  fill: none;
  stroke: var(--ink-3);
  stroke-width: 3;
  stroke-linecap: round;
  stroke-dasharray: 0.1 11;
}

.goal-badge circle {
  fill: var(--paper);
  stroke: var(--ink-3);
  stroke-width: 2;
  stroke-dasharray: 3 4;
}

.goal-badge text {
  fill: var(--ink-2);
  font-weight: 700;
  font-size: 19px;
  font-variant-numeric: tabular-nums;
}

.solved .goal {
  stroke: var(--gold);
  stroke-dasharray: none;
  stroke-width: 2.5;
  opacity: 0.55;
}

.solved .goal-badge circle {
  fill: var(--gold);
  stroke: var(--gold);
  stroke-dasharray: none;
}

.solved .goal-badge text {
  fill: #2a1c00;
}

.stub {
  fill: none;
  stroke: var(--ink-3);
  stroke-width: 2;
  stroke-dasharray: 5 6;
  stroke-linecap: round;
}

.stub.valid {
  stroke: var(--green);
  stroke-dasharray: none;
  stroke-width: 2.5;
}

/* ---- pills ---- */

.pill {
  display: inline-flex;
  align-items: center;
  height: 44px;
  padding: 0 20px;
  border: 2px solid var(--ink);
  border-radius: 999px;
  background: var(--pill);
  box-shadow: 0 3px 0 var(--ink);
  color: var(--ink);
  font-family: var(--font);
  font-weight: 600;
  font-size: 18px;
  letter-spacing: -0.005em;
  line-height: 1;
  white-space: nowrap;
}

.pills {
  position: absolute;
  left: 0;
  top: 0;
}

.pills .pill {
  position: absolute;
  left: 0;
  top: 0;
  transform: translate(-50%, -50%);
  transform-origin: 0 0;
  cursor: pointer;
  touch-action: none;
}

.pills .pill.fresh {
  animation: pop 0.22s cubic-bezier(0.2, 1.4, 0.4, 1);
}

@keyframes pop {
  from {
    scale: 0.7;
    opacity: 0;
  }
}

.pill.start {
  background: var(--ink);
  color: var(--paper);
}

.pill.end {
  border-style: dashed;
  background: var(--paper);
  box-shadow: none;
}

.pill.on-path {
  border-color: var(--gold);
  background: var(--gold-bg);
  box-shadow: 0 3px 0 var(--gold);
  color: var(--gold-ink);
}

.pill.start.on-path {
  border-color: var(--ink);
  background: var(--ink);
  box-shadow: 0 3px 0 var(--gold);
  color: var(--paper);
}

.pill.end.on-path,
.pill.end.solved {
  border-style: solid;
  border-color: var(--gold);
  background: var(--gold);
  box-shadow: 0 3px 0 var(--gold-ink);
  color: #2a1c00;
}

.pill.selected {
  outline: 3px solid var(--blue);
  outline-offset: 3px;
}

.pill.nudge {
  animation: nudge 0.3s ease;
}

@keyframes nudge {
  40% {
    scale: 1.12;
  }
}

/* ---- the word being typed ---- */

.ghost {
  position: absolute;
  left: 0;
  top: 0;
  transform: translate(-50%, -50%);
}

.ghost.smooth {
  transition: translate 0.16s ease;
}

.ghost[hidden] {
  display: none;
}

.entry {
  display: block;
  height: 44px;
  min-width: 132px;
  padding: 0 18px;
  border: 2px dashed var(--ink-3);
  border-radius: 999px;
  outline: none;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font);
  font-weight: 600;
  font-size: 18px;
  letter-spacing: -0.005em;
  text-align: center;
  caret-color: var(--blue);
}

.entry::placeholder {
  color: var(--ink-3);
  font-weight: 500;
}

.entry:focus {
  border-color: var(--ink-2);
}

.ghost.valid .entry {
  border: 2px solid var(--green);
  background: var(--green-bg);
  box-shadow: 0 3px 0 var(--green);
  color: var(--green-ink);
}

.ghost.shake {
  animation: shake 0.32s ease;
}

.ghost.shake .entry {
  border-color: var(--red);
}

@keyframes shake {
  20% {
    margin-left: -7px;
  }
  45% {
    margin-left: 6px;
  }
  70% {
    margin-left: -4px;
  }
  90% {
    margin-left: 2px;
  }
}

.ghost-hint.muted {
  color: var(--ink-2);
  font-weight: 500;
}

.ghost-hint {
  position: absolute;
  left: 50%;
  top: 52px;
  margin: 0;
  translate: -50% 0;
  color: var(--green-ink);
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  pointer-events: none;
}

@media (prefers-color-scheme: dark) {
  .ghost-hint {
    color: var(--green);
  }
}

/* ---- board furniture ---- */

.tools {
  position: absolute;
  right: 16px;
  bottom: 14px;
  display: flex;
  gap: 8px;
}

.tools.modes {
  right: auto;
  left: 16px;
}

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

.tool[aria-pressed="true"]:hover {
  color: var(--paper);
}

.board.switching .world {
  visibility: hidden;
}

.tool {
  padding: 7px 14px;
  border: 1.5px solid var(--wire);
  border-radius: 999px;
  background: var(--paper);
  color: var(--ink-2);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

.tool:hover:not(:disabled) {
  border-color: var(--ink-2);
  color: var(--ink);
}

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

.loading {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  margin: 0;
  padding: 24px;
  color: var(--ink-2);
  text-align: center;
}

.loading[hidden] {
  display: none;
}

/* ---- status line ---- */

.status {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px 24px;
  flex-wrap: wrap;
  padding: 12px 20px calc(14px + env(safe-area-inset-bottom));
  border-top: 1.5px solid var(--paper-2);
}

.status p {
  margin: 0;
}

.status-main {
  max-width: 68ch;
}

.status-main b {
  font-weight: 700;
}

.status-main.warn {
  color: var(--red);
}

.status-world {
  color: var(--ink-2);
  font-variant-numeric: tabular-nums;
}

/* ---- dialogs ---- */

.sheet {
  width: min(520px, calc(100vw - 32px));
  max-height: calc(100dvh - 48px);
  padding: 28px 28px 24px;
  border: 2px solid var(--ink);
  border-radius: 24px;
  background: var(--paper);
  box-shadow: 0 6px 0 var(--ink);
  color: var(--ink);
  overflow-y: auto;
}

.sheet::backdrop {
  background: color-mix(in srgb, var(--ink) 38%, transparent);
}

@media (prefers-color-scheme: dark) {
  .sheet::backdrop {
    background: rgb(0 0 0 / 0.6);
  }
}

.sheet h2 {
  margin: 0 0 12px;
  font-size: 28px;
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1.15;
}

.sheet h2:focus {
  outline: none;
}

.sheet p {
  margin: 0 0 14px;
}

.sheet .close {
  float: right;
  width: 36px;
  height: 36px;
  margin: -10px -10px 0 8px;
  border: 0;
  border-radius: 999px;
  background: none;
  font-size: 26px;
  line-height: 1;
  cursor: pointer;
}

.sheet .close:hover {
  background: var(--paper-2);
}

.demo,
.chain {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px 0;
  margin: 18px 0 10px;
}

.demo .pill,
.chain .pill {
  height: 34px;
  padding: 0 13px;
  font-size: 15px;
  box-shadow: 0 2px 0 var(--ink);
}

.demo .pill.end,
.chain .pill.end {
  box-shadow: 0 2px 0 var(--gold-ink);
}

.demo i,
.chain i {
  width: 14px;
  height: 2.5px;
  background: var(--wire);
}

.chain i {
  background: var(--gold);
}

.demo-caption {
  color: var(--ink-2);
  font-size: 15px;
}

.how {
  margin: 0 0 16px;
  padding-left: 20px;
}

.how li {
  margin-bottom: 6px;
}

.fine {
  color: var(--ink-2);
  font-size: 15px;
}

.phrases {
  color: var(--ink-2);
}

.histogram {
  display: flex;
  align-items: stretch;
  gap: 8px;
  height: 150px;
  margin: 14px 0 2px;
  font-variant-numeric: tabular-nums;
}

.histogram .col {
  flex: 1 1 0;
  max-width: 64px;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: center;
  gap: 4px;
  min-width: 0;
}

.histogram .hbar {
  display: block;
  width: 100%;
  border-radius: 8px 8px 3px 3px;
  background: var(--ink-3);
}

.histogram .gap {
  flex: 0 0 18px;
  min-width: 0;
}

.histogram .gap-dots {
  display: block;
  margin-bottom: 18px;
  color: var(--ink-3);
  font-weight: 700;
  line-height: 1;
}

.histogram .mine .hbar {
  background: var(--gold);
}

.histogram .count,
.histogram .label {
  font-size: 13px;
  font-weight: 600;
  line-height: 1.2;
  min-height: 1.2em;
}

.histogram .label {
  color: var(--ink-2);
}

.histogram-title {
  margin: 18px 0 0;
}

.histogram-caption {
  margin: 0 0 14px;
  text-align: center;
}

.sheet h3 {
  margin: 20px 0 4px;
  font-size: 16px;
  font-weight: 700;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 20px;
}

.button {
  height: 44px;
  padding: 0 20px;
  border: 2px solid var(--ink);
  border-radius: 999px;
  background: var(--pill);
  box-shadow: 0 3px 0 var(--ink);
  font-weight: 700;
  cursor: pointer;
}

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

.button:active {
  translate: 0 2px;
  box-shadow: 0 1px 0 var(--ink);
}

.link-button {
  padding: 0;
  border: 0;
  background: none;
  color: var(--blue);
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}

/* ---- small screens ---- */

@media (max-width: 620px) {
  .bar {
    gap: 10px;
    padding: 10px 14px;
  }

  .brand-name {
    font-size: 19px;
  }

  .text-button {
    padding: 8px 9px;
    font-size: 15px;
  }

  .pill,
  .entry {
    height: 40px;
    font-size: 17px;
  }

  .pill {
    padding: 0 16px;
  }

  .entry {
    min-width: 118px;
  }

  .status {
    padding: 10px 14px calc(12px + env(safe-area-inset-bottom));
    font-size: 15px;
  }

  .tools {
    right: 12px;
    bottom: 10px;
  }

  .tools.modes {
    left: 12px;
  }

  .sheet {
    padding: 22px 20px 20px;
  }

  .sheet h2 {
    font-size: 24px;
  }
}

@media (max-width: 400px) {
  .puzzle-no {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .pills .pill.fresh,
  .pill.nudge,
  .ghost.shake {
    animation: none;
  }

  .ghost.smooth {
    transition: none;
  }
}

.custom-form {
  display: grid;
  gap: 12px;
  margin-top: 12px;
}

.custom-form label {
  display: grid;
  gap: 4px;
  font-size: 14px;
  font-weight: 600;
  color: var(--ink-2);
}

.custom-form input {
  padding: 9px 12px;
  border: 1.5px solid var(--wire);
  border-radius: 10px;
  background: var(--paper);
  color: var(--ink);
  font: inherit;
  font-size: 16px;
}

.custom-error {
  min-height: 1.3em;
  margin: 0;
  color: #b3261e;
  font-size: 14px;
}
