:root {
      color-scheme: light;
      --ink: #243044;
      --muted: #6b7280;
      --line: #d7dde8;
      --panel: #f8fafc;
      --accent: #2563eb;
      --bad: #dc2626;
      --ok: #15803d;
    }
    * { box-sizing: border-box; }
    body {
      margin: 0;
      font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
      color: var(--ink);
      background: #eef3f8;
    }
    main {
      max-width: 1180px;
      margin: 0 auto;
      padding: 24px;
      display: grid;
      grid-template-columns: minmax(320px, 680px) minmax(300px, 1fr);
      gap: 20px;
      align-items: start;
    }
    h1 {
      margin: 0 0 16px;
      font-size: 24px;
      font-weight: 750;
      letter-spacing: 0;
    }
    .aside-title {
      margin-top: 30px;
    }
    .panel {
      background: white;
      border: 1px solid var(--line);
      border-radius: 8px;
      padding: 16px;
      box-shadow: 0 10px 30px rgba(15, 23, 42, 0.07);
    }
    .controls {
      display: grid;
      grid-template-columns: repeat(3, minmax(0, 1fr));
      gap: 10px;
      margin-bottom: 14px;
    }
    .locked-control {
      display: grid;
      gap: 5px;
    }
    .input-tool {
      position: relative;
      display: flex;
      align-items: center;
      height: 38px;
      border: 1px solid var(--line);
      border-radius: 6px;
      background: white;
      overflow: hidden;
    }
    .input-tool input {
      height: 100%;
      min-width: 0;
      flex: 1;
      border: 0;
      border-radius: 0;
      padding-right: 8px;
      background: transparent;
    }
    .input-tool input:focus {
      outline: none;
    }
    .input-tool:focus-within {
      border-color: #94a3b8;
      box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.12);
    }
    .step-btn,
    .lock {
      height: 38px;
      width: 30px;
      padding: 0;
      display: grid;
      place-items: center;
      border: 0;
      border-radius: 0;
      background: transparent;
      color: var(--muted);
      font-size: 16px;
      font-weight: 700;
    }
    .step-btn {
      cursor: pointer;
    }
    .step-btn:hover {
      background: transparent;
      color: var(--muted);
    }
    .step-btn.is-hovered {
      background: rgba(15, 23, 42, 0.06);
      color: var(--ink);
    }
    .step-btn:focus:not(:hover) {
      background: transparent;
      color: var(--muted);
      outline: none;
    }
    .lock:hover {
      background: rgba(15, 23, 42, 0.06);
      color: var(--ink);
    }
    .lock {
      position: relative;
      cursor: pointer;
      user-select: none;
    }
    .lock.hidden {
      display: none;
    }
    .lock input {
      position: absolute;
      opacity: 0;
      pointer-events: none;
    }
    .lock-icon {
      position: relative;
      width: 14px;
      height: 12px;
      border: 2px solid currentColor;
      border-radius: 3px;
      display: block;
    }
    .lock-icon::before {
      content: "";
      position: absolute;
      left: 2px;
      top: -9px;
      width: 7px;
      height: 8px;
      border: 2px solid currentColor;
      border-bottom: 0;
      border-radius: 7px 7px 0 0;
      transform-origin: 1px 8px;
      transform: rotate(-34deg);
    }
    .lock input:checked + .lock-icon {
      color: var(--accent);
    }
    .lock input:checked + .lock-icon::before {
      transform: rotate(0deg);
    }
    .number-control {
      display: flex;
      align-items: center;
      height: 38px;
      border: 1px solid var(--line);
      border-radius: 6px;
      background: white;
      overflow: hidden;
      font-size: 16px;
    }
    .number-control input {
      height: 100%;
      min-width: 0;
      flex: 1;
      border: 0;
      border-radius: 0;
      text-align: center;
      background: transparent;
    }
    input[type="number"]::-webkit-outer-spin-button,
    input[type="number"]::-webkit-inner-spin-button {
      -webkit-appearance: none;
      margin: 0;
    }
    input[type="number"] {
      appearance: textfield;
      -moz-appearance: textfield;
    }
    .number-control input:focus {
      outline: none;
    }
    .number-control:focus-within {
      border-color: #94a3b8;
      box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.12);
    }
    .right-tools input {
      text-align: left;
      padding-left: 10px;
    }
    input::placeholder {
      color: #9ca3af;
    }
    label {
      display: grid;
      gap: 5px;
      font-size: 13px;
      color: var(--muted);
    }
    input, select, button {
      height: 38px;
      border-radius: 6px;
      border: 1px solid var(--line);
      padding: 0 10px;
      font: inherit;
      background: white;
      color: var(--ink);
    }
    button {
      cursor: pointer;
      border-color: transparent;
      background: var(--accent);
      color: white;
      font-weight: 650;
    }
    button.secondary {
      background: #e5eaf2;
      color: var(--ink);
      border-color: var(--line);
    }
    button.danger {
      background: #fee2e2;
      color: #991b1b;
      border-color: #fecaca;
    }
    .actions {
      display: flex;
      gap: 10px;
      flex-wrap: wrap;
      margin-top: 14px;
    }
    .palette {
      display: flex;
      gap: 8px;
      flex-wrap: wrap;
      margin: 12px 0 16px;
    }
    .swatch {
      width: 36px;
      height: 36px;
      border-radius: 6px;
      border: 3px solid transparent;
      display: grid;
      place-items: center;
      font-weight: 800;
      color: rgba(0, 0, 0, 0.58);
      cursor: pointer;
      user-select: none;
    }
    .swatch.active {
      border-color: #111827;
      box-shadow: 0 0 0 2px white inset;
    }
    .grid-wrap {
      overflow: auto;
      padding: 8px;
      background: #dbe4ef;
      border-radius: 8px;
      border: 1px solid var(--line);
    }
    .grid {
      display: grid;
      gap: 4px;
      width: min(100%, 620px);
      aspect-ratio: 1;
      min-width: 320px;
      margin: 0 auto;
      touch-action: none;
      user-select: none;
    }
    .cell {
      border: 1px solid rgba(15, 23, 42, 0.25);
      border-radius: 4px;
      display: grid;
      place-items: center;
      font-size: clamp(11px, 1.8vw, 18px);
      font-weight: 800;
      color: #0f172a;
      cursor: pointer;
      user-select: none;
      position: relative;
    }
    .cell.solution::after {
      content: "";
      width: 52%;
      height: 52%;
      border-radius: 999px;
      background: rgba(17, 24, 39, 0.84);
      box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.8);
    }
    .help {
      margin: 0;
      color: var(--muted);
      font-size: 14px;
      line-height: 1.55;
    }
    .result {
      margin-top: 12px;
      padding: 12px;
      border-radius: 8px;
      background: var(--panel);
      border: 1px solid var(--line);
      min-height: 92px;
      white-space: pre-wrap;
      line-height: 1.55;
    }
    .ok { color: var(--ok); font-weight: 750; }
    .bad { color: var(--bad); font-weight: 750; }
    .mono {
      font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
      font-size: 13px;
    }
    textarea {
      width: 100%;
      margin-top: 12px;
      min-height: 130px;
      resize: vertical;
      border: 1px solid var(--line);
      border-radius: 6px;
      padding: 10px;
      font: 13px/1.45 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    }
    .file-row {
      display: grid;
      gap: 10px;
      margin-top: 10px;
    }
    .image-crop-control {
      gap: 12px;
      margin-block: 8px;
    }
    input[type="file"] {
      height: auto;
      padding: 9px;
      background: var(--panel);
    }
    .preview-wrap {
      position: relative;
      display: none;
      margin-top: 10px;
      border-radius: 8px;
    }
    .preview-wrap:focus {
      outline: none;
    }
    .preview-wrap:focus-visible {
      box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.18);
    }
    canvas.preview {
      width: 100%;
      max-height: 220px;
      object-fit: contain;
      display: block;
      margin-top: 0;
      border: 1px solid var(--line);
      border-radius: 8px;
      background: #f8fafc;
    }
    .delete-preview {
      position: absolute;
      top: 8px;
      right: 8px;
      width: 30px;
      height: 30px;
      padding: 0;
      display: grid;
      place-items: center;
      border-radius: 999px;
      background: #dc2626;
      color: white;
      border: 2px solid rgba(255, 255, 255, 0.85);
      box-shadow: 0 8px 18px rgba(15, 23, 42, 0.22);
      font-size: 22px;
      line-height: 1;
      opacity: 0;
      transform: scale(0.92);
      transition: opacity 0.12s ease, transform 0.12s ease;
    }
    .preview-wrap:hover .delete-preview,
    .preview-wrap:focus-within .delete-preview {
      opacity: 1;
      transform: scale(1);
    }
    .delete-preview:hover {
      background: #b91c1c;
    }
    @media (max-width: 860px) {
      main { grid-template-columns: 1fr; padding: 14px; }
      .controls { grid-template-columns: 1fr 1fr; }
    }
