:root {
  color-scheme: dark;
  --bg: #171b18;
  --surface: #222824;
  --tile: #f3f1e8;
  --tile-text: #171a17;
  --muted: #9da69e;
  --line: #465048;
  --accent: #c8f970;
  --accent-ink: #16200d;
  --accent-2: #ff8264;
  --yellow: #f7d35c;
  --green: #77b65d;
  --blue: #5587ef;
  --purple: #a264b1;
  --focus: #c8f970;
  --tile-size: 116px;
}

* { box-sizing: border-box; }

html,
body { width: 100%; height: 100%; }

body {
  margin: 0;
  min-width: 320px;
  overflow: hidden;
  background: var(--bg);
  color: #f7f7f4;
  font-family: "Avenir Next", Avenir, Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

a { color: #b9ccff; }

.privacy-link {
  position: fixed;
  top: 18px;
  right: 20px;
  z-index: 20;
  color: #8b8b87;
  font-size: .66rem;
  text-decoration: none;
}

.privacy-link:hover,
.privacy-link:focus-visible { color: #f7f7f4; }

button,
input,
textarea { font: inherit; }

button { cursor: pointer; }

button:focus-visible,
input:focus-visible,
textarea:focus-visible,
.drop-zone:focus-within {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
}

[hidden] { display: none !important; }

.masthead {
  position: fixed;
  top: clamp(18px, 4vh, 40px);
  left: 50%;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 12px;
  transform: translateX(-50%);
  pointer-events: none;
  white-space: nowrap;
  transition:
    top 420ms cubic-bezier(.2,.8,.2,1),
    left 420ms cubic-bezier(.2,.8,.2,1),
    transform 420ms cubic-bezier(.2,.8,.2,1);
}

.masthead-copy {
  opacity: 1;
  transform: translateX(0) scale(1);
  transform-origin: left center;
  visibility: visible;
  transition:
    opacity 180ms ease,
    transform 300ms cubic-bezier(.2,.8,.2,1),
    visibility 0s linear;
}

body.is-workspace-active .masthead {
  top: max(18px, env(safe-area-inset-top));
  left: max(18px, env(safe-area-inset-left));
  transform: translate3d(0, 0, 0);
}

body.is-workspace-active .masthead-copy {
  opacity: 0;
  transform: translateX(-8px) scale(.96);
  visibility: hidden;
  transition:
    opacity 150ms ease,
    transform 240ms cubic-bezier(.2,.8,.2,1),
    visibility 0s linear 240ms;
}

.solver-mark {
  width: 29px;
  height: 29px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 2px;
  transform: rotate(0) scale(1);
  transition: transform 420ms cubic-bezier(.2,.8,.2,1);
}

body.is-workspace-active .masthead .solver-mark { transform: rotate(-4deg) scale(.92); }

.solver-mark i {
  display: block;
  border: 1px solid rgba(240,245,239,.2);
  border-radius: 2px;
  background: rgba(240,245,239,.045);
}

.solver-mark i:nth-child(1),
.solver-mark i:nth-child(2),
.solver-mark i:nth-child(5),
.solver-mark i:nth-child(8) {
  border-color: var(--accent);
  background: var(--accent);
}

.solver-mark i:nth-child(9) {
  border-color: var(--accent-2);
  background: var(--accent-2);
}

.masthead h1 {
  margin: 0;
  font-size: clamp(1.05rem, 2vw, 1.35rem);
  font-weight: 750;
  letter-spacing: -0.055em;
}

.masthead p {
  max-width: 260px;
  margin: 2px 0 0;
  overflow: hidden;
  color: #758078;
  font-size: 0.65rem;
  letter-spacing: 0.04em;
  text-overflow: ellipsis;
}

.canvas {
  position: fixed;
  inset: 0;
  overflow: hidden;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  background:
    radial-gradient(circle at 50% 44%, rgba(200,249,112,.035), transparent 46%),
    var(--bg);
}

.canvas-hint {
  position: absolute;
  left: 50%;
  bottom: 102px;
  margin: 0;
  transform: translateX(-50%);
  color: #696969;
  font-size: 0.68rem;
  letter-spacing: 0.04em;
  pointer-events: none;
  transition: opacity 200ms ease;
}

.canvas-hint.is-hidden { opacity: 0; }

.tile {
  width: var(--tile-size);
  height: var(--tile-size);
  position: absolute;
  top: 0;
  left: 0;
  z-index: 1;
  border: 0;
  border-radius: 9px;
  padding: 10px 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background: var(--tile);
  color: var(--tile-text);
  box-shadow: 0 1px 0 rgba(255,255,255,.28) inset, 0 3px 12px rgba(0,0,0,.18);
  font-size: clamp(0.63rem, 1.2vw, 0.88rem);
  font-weight: 850;
  line-height: 1.12;
  letter-spacing: 0.01em;
  text-align: center;
  text-transform: uppercase;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  backface-visibility: hidden;
  transform-origin: top left;
  contain: layout style;
  will-change: transform;
  cursor: grab;
  transition: box-shadow 130ms ease, filter 130ms ease;
}

@media (hover: hover) {
  .tile:hover { filter: brightness(1.025); }
}
.tile:active,
.tile.is-dragging { cursor: grabbing; }
.tile.is-dragging { z-index: 50; box-shadow: 0 18px 45px rgba(0,0,0,.46); transition: none; }
.tile.is-selected { box-shadow: 0 0 0 4px var(--focus), 0 15px 34px rgba(0,0,0,.33); }
.tile[data-group="yellow"] { background: var(--yellow); }
.tile[data-group="green"] { background: var(--green); }
.tile[data-group="blue"] { background: var(--blue); color: #fff; }
.tile[data-group="purple"] { background: var(--purple); color: #fff; }

.tile.has-visual {
  padding: 0;
  background: var(--tile);
}

.tile-crop {
  position: relative;
  display: block;
  flex: 0 0 auto;
  overflow: hidden;
  pointer-events: none;
}

.tile-crop img {
  max-width: none;
  position: absolute;
  display: block;
  pointer-events: none;
  user-select: none;
  -webkit-user-drag: none;
}

.tile.has-visual[data-group="yellow"] { background: var(--yellow); box-shadow: 0 0 0 4px var(--yellow), 0 3px 12px rgba(0,0,0,.18); }
.tile.has-visual[data-group="green"] { background: var(--green); box-shadow: 0 0 0 4px var(--green), 0 3px 12px rgba(0,0,0,.18); }
.tile.has-visual[data-group="blue"] { background: var(--blue); box-shadow: 0 0 0 4px var(--blue), 0 3px 12px rgba(0,0,0,.18); }
.tile.has-visual[data-group="purple"] { background: var(--purple); box-shadow: 0 0 0 4px var(--purple), 0 3px 12px rgba(0,0,0,.18); }
.tile.has-visual.is-selected { box-shadow: 0 0 0 4px var(--focus), 0 15px 34px rgba(0,0,0,.33); }
.tile.has-visual.is-dragging { box-shadow: 0 18px 45px rgba(0,0,0,.46); }

.tile[data-has-note="true"]::after {
  content: "";
  width: 7px;
  height: 7px;
  position: absolute;
  top: 8px;
  right: 8px;
  border-radius: 50%;
  background: currentColor;
  opacity: .52;
}

.toolbar {
  max-width: calc(100% - 24px);
  min-height: 66px;
  position: fixed;
  left: 50%;
  bottom: max(16px, env(safe-area-inset-bottom));
  z-index: 100;
  padding: 8px;
  display: flex;
  align-items: center;
  gap: 6px;
  overflow-x: auto;
  transform: translateX(-50%);
  border: 1px solid rgba(255,255,255,.15);
  border-radius: 18px;
  background: rgba(31,37,33,.92);
  box-shadow: 0 18px 55px rgba(0,0,0,.46);
  backdrop-filter: blur(18px);
  scrollbar-width: none;
}

.toolbar::-webkit-scrollbar { display: none; }

.tool {
  min-width: 58px;
  height: 48px;
  padding: 4px 10px;
  border: 0;
  border-radius: 11px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  background: transparent;
  color: #d9d8d3;
  font-size: 0.61rem;
  font-weight: 750;
}

.tool:hover:not(:disabled) { background: rgba(255,255,255,.07); }
.tool.primary { background: var(--accent); color: var(--accent-ink); }
.tool.primary:hover { background: #d7ff8f; }
.tool:disabled { opacity: .3; cursor: default; }
.tool-icon { font-size: 1.1rem; line-height: 1; }
.tool.icon-only { min-width: 48px; font-size: .9rem; letter-spacing: .08em; }

.zoom-tools {
  display: none;
  flex: 0 0 auto;
  align-items: center;
  overflow: hidden;
  border: 1px solid #4c4c4c;
  border-radius: 11px;
  background: rgba(0,0,0,.16);
}

.zoom-tools button {
  width: 36px;
  height: 42px;
  padding: 0;
  border: 0;
  background: transparent;
  color: #f1f0e8;
  font-size: 1.2rem;
  font-weight: 650;
  line-height: 1;
}

.zoom-tools button:active:not(:disabled) { background: rgba(255,255,255,.1); }
.zoom-tools button:disabled { opacity: .3; cursor: default; }

.zoom-tools output {
  min-width: 42px;
  color: #9c9b96;
  font-size: .58rem;
  font-variant-numeric: tabular-nums;
  font-weight: 750;
  text-align: center;
}

.toolbar-rule {
  width: 1px;
  height: 34px;
  flex: 0 0 1px;
  margin: 0 3px;
  background: #494949;
}

.color-tools {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 7px;
}

.color-tools button {
  width: 23px;
  height: 23px;
  flex: 0 0 auto;
  padding: 0;
  border: 2px solid transparent;
  border-radius: 50%;
  background: var(--tile);
}

.color-tools button[data-group="yellow"] { background: var(--yellow); }
.color-tools button[data-group="green"] { background: var(--green); }
.color-tools button[data-group="blue"] { background: var(--blue); }
.color-tools button[data-group="purple"] { background: var(--purple); }
.color-tools button:disabled { opacity: .24; cursor: default; }
.color-tools button.is-active { border-color: #fff; box-shadow: 0 0 0 2px #222; }

dialog {
  width: min(560px, calc(100% - 24px));
  max-height: calc(100dvh - 130px);
  inset: auto 12px 92px;
  margin: auto;
  padding: 0;
  overflow: auto;
  border: 1px solid #4b574e;
  border-radius: 18px;
  background: var(--surface);
  color: #fff;
  box-shadow: 0 30px 90px rgba(0,0,0,.62);
}

dialog::backdrop { background: rgba(0,0,0,.46); backdrop-filter: blur(3px); }
.upload-sheet {
  width: min(620px, calc(100% - 24px));
  max-height: calc(100dvh - 48px);
  bottom: 24px;
}
.sheet-shell { padding: 25px; }

.sheet-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 22px;
}

.sheet-header h2 { margin: 6px 0 0; font-size: 1.45rem; letter-spacing: -0.04em; }
.eyebrow { margin: 0; color: var(--muted); font-size: .62rem; font-weight: 850; letter-spacing: .15em; text-transform: uppercase; }

.close-button {
  width: 36px;
  height: 36px;
  flex: 0 0 auto;
  border: 1px solid #525252;
  border-radius: 50%;
  background: transparent;
  color: #ddd;
  font-size: 1.35rem;
}

.drop-zone {
  min-height: 250px;
  border: 1px dashed #626262;
  border-radius: 13px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background: #1c1c1c;
  text-align: center;
  cursor: pointer;
}

.drop-zone.is-over { border-color: var(--focus); background: #252f24; }
.drop-zone img { width: 100%; max-height: 330px; object-fit: contain; }
.upload-prompt strong { display: block; margin-bottom: 7px; }
.upload-prompt small { color: var(--muted); }

.paste-controls {
  margin-top: 10px;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 9px;
}

.paste-target {
  min-height: 42px;
  padding: 0 12px;
  border: 1px solid #535353;
  border-radius: 9px;
  display: flex;
  align-items: center;
  overflow: hidden;
  background: #222;
  color: #aaa;
  font-size: .7rem;
  line-height: 1.3;
  white-space: nowrap;
  cursor: text;
}

.paste-target:empty::before { content: attr(data-placeholder); }
.paste-target:focus { border-color: var(--focus); color: #ddd; }

.import-mode {
  margin: 14px 0 0;
  padding: 0;
  border: 0;
}

.import-mode legend {
  margin-bottom: 7px;
  color: #aaa9a4;
  font-size: .66rem;
  font-weight: 750;
}

.import-mode-row {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 8px;
}

.mode-toggle {
  padding: 3px;
  border: 1px solid #505050;
  border-radius: 10px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  background: #1c1c1c;
}

.mode-choice { position: relative; }
.mode-choice input { position: absolute; opacity: 0; pointer-events: none; }

.mode-choice span {
  min-height: 36px;
  border-radius: 7px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #aaa9a4;
  font-size: .72rem;
  font-weight: 800;
  cursor: pointer;
}

.mode-choice input:checked + span { background: var(--accent); color: var(--accent-ink); }
.mode-choice input:focus-visible + span { outline: 3px solid var(--focus); outline-offset: 2px; }

.info-button {
  width: 32px;
  height: 32px;
  padding: 0;
  border: 1px solid #565656;
  border-radius: 50%;
  background: #292929;
  color: #bbb;
  font-family: Georgia, serif;
  font-size: .86rem;
  font-weight: 700;
}

.rebus-help {
  margin: 8px 0 0;
  padding: 10px 12px;
  border-radius: 8px;
  background: #202020;
  color: #aaa9a4;
  font-size: .68rem;
  line-height: 1.45;
}

.sheet-status {
  min-height: 46px;
  margin: 0;
  padding: 13px 2px;
  color: var(--muted);
  font-size: .76rem;
  line-height: 1.4;
}

.sheet-status.is-error { color: #ff9d90; }
.sheet-status.is-working { color: var(--accent); }

.turnstile-container { min-height: 0; margin: -2px 0 14px; }

.upload-privacy {
  margin: -3px 0 16px;
  padding: 11px 12px;
  border: 1px solid #454545;
  border-radius: 9px;
  background: #222;
  color: #aaa9a4;
  font-size: .66rem;
  line-height: 1.5;
}

.upload-privacy a { white-space: nowrap; }

.privacy-page {
  height: auto;
  min-height: 100%;
  overflow: auto;
  overscroll-behavior: auto;
}

.privacy-shell {
  width: min(720px, calc(100% - 40px));
  margin: 0 auto;
  padding: 56px 0 90px;
}

.privacy-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 52px;
}

.privacy-brand {
  display: flex;
  align-items: center;
  gap: 11px;
  color: #fff;
  font-weight: 850;
  letter-spacing: -.03em;
  text-decoration: none;
}

.privacy-header > a:last-child { color: #aaa9a4; font-size: .75rem; }
.privacy-content h1 { margin: 0 0 10px; font-size: clamp(2rem, 7vw, 3.6rem); letter-spacing: -.065em; }
.privacy-updated { margin: 0 0 42px; color: #777; font-size: .7rem; }
.privacy-content h2 { margin: 36px 0 10px; font-size: 1.05rem; }
.privacy-content p,
.privacy-content li { color: #c2c1bc; font-size: .88rem; line-height: 1.7; }
.privacy-content ul { padding-left: 1.25rem; }
.privacy-callout { padding: 16px 18px; border: 1px solid #555; border-radius: 10px; background: #252525; }

.sheet-actions,
.board-utilities {
  display: flex;
  justify-content: flex-end;
  gap: 9px;
}

.button {
  min-height: 42px;
  padding: 0 15px;
  border: 1px solid transparent;
  border-radius: 9px;
  font-size: .75rem;
  font-weight: 800;
}

.button.primary { background: var(--accent); color: var(--accent-ink); }
.button.secondary { border-color: #535353; background: #333; color: #e7e6e1; }
.button.danger { border-color: #6a4545; background: transparent; color: #f1a6a0; }

.field {
  display: block;
  margin: 0 0 18px;
  color: #c5c4bf;
  font-size: .69rem;
  font-weight: 750;
}

.field input,
.field textarea {
  width: 100%;
  margin-top: 7px;
  border: 1px solid #505050;
  border-radius: 8px;
  background: #1c1c1c;
  color: #fff;
}

.field input { height: 42px; padding: 0 11px; }
.field textarea { padding: 11px; resize: vertical; line-height: 1.4; }
.field-help { margin: -10px 0 18px; color: #8f8e89; font-size: .66rem; line-height: 1.4; }

.color-field { margin: 0 0 18px; padding: 0; border: 0; }
.color-field legend { margin-bottom: 8px; color: #c5c4bf; font-size: .69rem; font-weight: 750; }
.editor-colors { display: flex; flex-wrap: wrap; gap: 7px; }

.editor-colors button {
  min-height: 34px;
  padding: 0 11px;
  border: 1px solid #505050;
  border-radius: 7px;
  background: #333;
  color: #ddd;
  font-size: .68rem;
}

.editor-colors button.is-active { border-color: #fff; box-shadow: 0 0 0 1px #fff inset; }

.dimensions {
  display: grid;
  grid-template-columns: 1fr auto 1fr auto;
  gap: 9px;
  align-items: end;
  margin-bottom: 18px;
}

.dimensions .field { margin: 0; }
.dimensions > span { padding-bottom: 12px; color: #777; }
.board-utilities { justify-content: space-between; padding-top: 3px; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 102px;
  z-index: 200;
  transform: translateX(-50%);
  padding: 11px 15px;
  border: 1px solid #565656;
  border-radius: 9px;
  background: #0f0f0f;
  color: #fff;
  box-shadow: 0 12px 30px rgba(0,0,0,.35);
  font-size: .75rem;
  white-space: nowrap;
}

@media (max-width: 600px) {
  .masthead { top: 16px; }
  .masthead p { display: none; }
  .canvas-hint { bottom: 96px; }
  .toolbar { min-height: 62px; border-radius: 16px; }
  .tool { min-width: 52px; height: 44px; }
  .color-tools { gap: 6px; padding-inline: 4px; }
  .color-tools button { width: 21px; height: 21px; }
  dialog { bottom: 86px; }
  .upload-sheet { bottom: 16px; max-height: calc(100dvh - 32px); }
  .sheet-shell { padding: 20px; }
  .drop-zone { min-height: 210px; }
  .paste-controls { grid-template-columns: 1fr; }
  .paste-controls .button { width: 100%; }
  .paste-target { justify-content: center; text-align: center; }
  .privacy-link { top: 20px; right: 14px; }
  .privacy-shell { width: min(100% - 30px, 720px); padding-top: 32px; }
  .privacy-header { margin-bottom: 38px; }
}

@media (pointer: coarse), (max-width: 700px) {
  .zoom-tools { display: flex; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: .01ms !important; }
}
