:root {
  color-scheme: light;
  font-family: "Avenir Next", Avenir, "Segoe UI", sans-serif;
  background: #f4f0e5;
  color: #272521;
}

* {
  box-sizing: border-box;
}

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

body {
  background: #f4f0e5;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

button {
  font: inherit;
}

.artboard {
  position: relative;
  width: 100%;
  height: 100vh;
  height: 100svh;
  isolation: isolate;
  overflow: hidden;
}

.field {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  cursor: crosshair;
  outline: none;
  touch-action: none;
}

.field:focus-visible {
  box-shadow: inset 0 0 0 2px rgba(39, 37, 33, 0.65);
}

.field.is-dragging {
  cursor: grabbing;
}

.identity,
.readout,
.toolbar {
  position: absolute;
  z-index: 2;
}

.identity {
  top: max(28px, env(safe-area-inset-top));
  left: max(30px, env(safe-area-inset-left));
  pointer-events: none;
  text-shadow:
    -2px -2px 3px #f4f0e5,
    2px -2px 3px #f4f0e5,
    -2px 2px 3px #f4f0e5,
    2px 2px 3px #f4f0e5;
}

.identity h1,
.identity p {
  margin: 0;
  letter-spacing: 0;
}

.identity h1 {
  font-family: ui-monospace, "SFMono-Regular", Consolas, monospace;
  font-size: 1.08rem;
  font-weight: 650;
  line-height: 1.25;
}

.identity p {
  margin-top: 4px;
  color: rgba(39, 37, 33, 0.62);
  font-family: Georgia, "Times New Roman", serif;
  font-size: 0.92rem;
  line-height: 1.35;
}

.readout {
  top: max(30px, env(safe-area-inset-top));
  right: max(30px, env(safe-area-inset-right));
  display: flex;
  gap: 18px;
  color: rgba(39, 37, 33, 0.58);
  font-family: ui-monospace, "SFMono-Regular", Consolas, monospace;
  font-size: 0.7rem;
  line-height: 1.4;
  pointer-events: none;
  text-shadow: 0 0 4px #f4f0e5, 0 0 4px #f4f0e5;
}

.toolbar {
  right: max(24px, env(safe-area-inset-right));
  bottom: max(24px, env(safe-area-inset-bottom));
  display: grid;
  grid-template-columns: repeat(6, 44px);
  height: 44px;
  border: 1px solid rgba(39, 37, 33, 0.48);
  border-radius: 2px;
  background: rgba(244, 240, 229, 0.93);
  box-shadow: 3px 4px 0 rgba(39, 37, 33, 0.1);
}

.tool,
.close-info {
  position: relative;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: #272521;
  cursor: pointer;
}

.tool {
  width: 44px;
  height: 42px;
  border-right: 1px solid rgba(39, 37, 33, 0.2);
}

.tool:last-child {
  border-right: 0;
}

.tool:hover,
.tool:focus-visible,
.close-info:hover,
.close-info:focus-visible {
  background: rgba(39, 37, 33, 0.08);
  outline: none;
}

.tool:focus-visible,
.close-info:focus-visible {
  box-shadow: inset 0 0 0 2px #272521;
}

.tool:disabled {
  color: rgba(39, 37, 33, 0.27);
  cursor: default;
}

.tool:disabled:hover {
  background: transparent;
}

.tool::after {
  position: absolute;
  right: 50%;
  bottom: calc(100% + 9px);
  width: max-content;
  max-width: 160px;
  padding: 5px 7px;
  border: 1px solid rgba(39, 37, 33, 0.38);
  background: #f4f0e5;
  color: #272521;
  content: attr(data-tooltip);
  font-family: ui-monospace, "SFMono-Regular", Consolas, monospace;
  font-size: 0.66rem;
  line-height: 1.2;
  opacity: 0;
  pointer-events: none;
  transform: translate(50%, 3px);
  transition: opacity 120ms ease, transform 120ms ease;
}

.tool:hover::after,
.tool:focus-visible::after {
  opacity: 1;
  transform: translate(50%, 0);
}

.info-panel {
  position: fixed;
  inset: 0 0 0 auto;
  width: min(440px, 100%);
  max-width: none;
  height: 100vh;
  height: 100dvh;
  max-height: none;
  margin: 0;
  padding: 0;
  overflow: auto;
  border: 0;
  border-left: 1px solid rgba(39, 37, 33, 0.55);
  background: #f4f0e5;
  color: #272521;
  box-shadow: -12px 0 32px rgba(39, 37, 33, 0.13);
}

.info-panel::backdrop {
  background: rgba(39, 37, 33, 0.25);
}

.info-panel__content {
  width: 100%;
  padding: 76px 46px 48px;
}

.close-info {
  position: fixed;
  z-index: 1;
  top: 18px;
  right: 18px;
  width: 40px;
  height: 40px;
}

.info-panel__eyebrow,
.info-panel h2,
.info-panel p,
.algorithm {
  margin-top: 0;
  letter-spacing: 0;
}

.info-panel__eyebrow {
  margin-bottom: 12px;
  color: #8b4e43;
  font-family: ui-monospace, "SFMono-Regular", Consolas, monospace;
  font-size: 0.68rem;
  font-weight: 650;
  line-height: 1.4;
  text-transform: uppercase;
}

.info-panel h2 {
  margin-bottom: 30px;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 3rem;
  font-weight: 400;
  line-height: 1;
}

.info-panel p,
.algorithm {
  color: rgba(39, 37, 33, 0.82);
  font-size: 0.94rem;
  line-height: 1.62;
}

.info-panel__lead {
  color: #272521 !important;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.18rem !important;
  line-height: 1.48 !important;
}

.algorithm {
  margin-bottom: 24px;
  padding: 16px 0 16px 22px;
  border-top: 1px solid rgba(39, 37, 33, 0.25);
  border-bottom: 1px solid rgba(39, 37, 33, 0.25);
}

.algorithm li + li {
  margin-top: 6px;
}

.formula {
  font-family: ui-monospace, "SFMono-Regular", Consolas, monospace;
  font-size: 0.9em;
}

.references {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 18px;
  margin-top: 34px;
  padding-top: 16px;
  border-top: 1px solid rgba(39, 37, 33, 0.25);
}

.references a {
  color: #274f70;
  font-family: ui-monospace, "SFMono-Regular", Consolas, monospace;
  font-size: 0.72rem;
  line-height: 1.4;
  text-underline-offset: 3px;
}

.references a:hover,
.references a:focus-visible {
  color: #8b4e43;
}

.visually-hidden {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

noscript {
  position: fixed;
  inset: 50% auto auto 50%;
  transform: translate(-50%, -50%);
}

@media (max-width: 640px) {
  .identity {
    top: max(18px, env(safe-area-inset-top));
    left: max(18px, env(safe-area-inset-left));
  }

  .identity h1 {
    font-size: 0.96rem;
  }

  .identity p {
    font-size: 0.82rem;
  }

  .readout {
    top: max(20px, env(safe-area-inset-top));
    right: max(18px, env(safe-area-inset-right));
    flex-direction: column;
    align-items: flex-end;
    gap: 1px;
    font-size: 0.62rem;
  }

  .toolbar {
    right: auto;
    bottom: max(18px, env(safe-area-inset-bottom));
    left: 50%;
    transform: translateX(-50%);
  }

  .info-panel {
    border-left: 0;
  }

  .info-panel__content {
    padding: 72px 28px 38px;
  }

  .info-panel h2 {
    font-size: 2.5rem;
  }
}

@media (hover: none) {
  .tool::after {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .tool::after {
    transition: none;
  }
}
