:root {
      color-scheme: light;
      --bg: #f1f0ea;
      --ink: #202528;
      --muted: #5d676b;
      --line: #c9c8bd;
      --blue: #008ad8;
      --cyan: #00c7ff;
      --green: #20a85d;
      --paper: #fbfaf5;
      --shadow: rgba(28, 31, 34, 0.14);
    }

    * {
      box-sizing: border-box;
    }

    html,
    body {
      min-height: 100%;
    }

    body {
      margin: 0;
      background:
        linear-gradient(180deg, rgba(0, 199, 255, 0.10), transparent 210px),
        var(--bg);
      color: var(--ink);
      font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    }

    .shell {
      width: min(1500px, calc(100vw - 28px));
      margin: 0 auto;
      padding: 18px 0 28px;
    }

    .topbar {
      display: grid;
      grid-template-columns: minmax(280px, 520px) 1fr;
      gap: 14px;
      align-items: stretch;
      margin-bottom: 14px;
    }

    .panel {
      background: rgba(251, 250, 245, 0.94);
      border: 1px solid var(--line);
      border-radius: 8px;
      box-shadow: 0 14px 36px var(--shadow);
    }

    .controls {
      padding: 14px;
    }

    .code-row {
      display: grid;
      grid-template-columns: 1fr auto;
      gap: 10px;
      align-items: center;
    }

    label {
      display: block;
      color: var(--muted);
      font-size: 13px;
      font-weight: 700;
      letter-spacing: 0.02em;
      margin-bottom: 7px;
      text-transform: uppercase;
    }

    input[type="text"] {
      width: 100%;
      height: 54px;
      border: 2px solid #aab2b3;
      border-radius: 8px;
      background: white;
      color: var(--ink);
      font-size: 30px;
      font-weight: 900;
      letter-spacing: 0.12em;
      line-height: 1;
      padding: 0 16px;
      outline: none;
    }

    input[type="text"]:focus {
      border-color: var(--blue);
      box-shadow: 0 0 0 4px rgba(0, 138, 216, 0.16);
    }

    button,
    .file-label {
      display: inline-flex;
      align-items: center;
      justify-content: center;
      min-height: 44px;
      border: 0;
      border-radius: 8px;
      background: var(--blue);
      color: white;
      cursor: pointer;
      font-size: 15px;
      font-weight: 800;
      padding: 0 16px;
      text-decoration: none;
      white-space: nowrap;
    }

    button.secondary,
    .file-label {
      background: #343b3f;
    }

    button:disabled {
      cursor: wait;
      opacity: 0.62;
    }

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

    input[type="file"] {
      display: none;
    }

    .status {
      min-height: 22px;
      color: var(--muted);
      font-size: 14px;
      font-weight: 650;
      margin-top: 10px;
    }

    .summary {
      display: grid;
      grid-template-columns: repeat(5, minmax(92px, 1fr));
      gap: 10px;
      padding: 14px;
    }

    .stat {
      min-height: 74px;
      border: 1px solid var(--line);
      border-left: 6px solid var(--cyan);
      border-radius: 8px;
      background: white;
      padding: 10px 12px;
    }

    .stat strong {
      display: block;
      font-size: 24px;
      line-height: 1.05;
    }

    .stat span {
      color: var(--muted);
      display: block;
      font-size: 12px;
      font-weight: 800;
      margin-top: 5px;
      text-transform: uppercase;
    }

    .stage {
      overflow: hidden;
      padding: 10px;
      position: relative;
    }

    canvas,
    .fallback-image,
    .three-stage {
      display: block;
      width: 100%;
      border: 1px solid var(--line);
      border-radius: 8px;
      background: var(--paper);
    }

    canvas,
    .fallback-image {
      height: auto;
      object-fit: contain;
    }

    .three-stage {
      height: min(78vh, 920px);
      min-height: 520px;
      overflow: hidden;
      position: relative;
    }

    .three-stage canvas {
      border: 0;
      border-radius: 0;
      height: 100% !important;
      width: 100% !important;
    }

    .loading-overlay {
      align-items: center;
      background: rgba(251, 250, 245, 0.94);
      border: 1px solid var(--line);
      border-radius: 8px;
      color: var(--ink);
      display: flex;
      flex-direction: column;
      gap: 14px;
      inset: 10px;
      justify-content: center;
      position: absolute;
      text-align: center;
      z-index: 10;
    }

    .loading-spinner {
      animation: spin 0.85s linear infinite;
      border: 5px solid rgba(0, 138, 216, 0.18);
      border-radius: 999px;
      border-top-color: var(--blue);
      height: 52px;
      width: 52px;
    }

    .loading-title {
      color: var(--muted);
      font-size: 16px;
      font-weight: 850;
    }

    @keyframes spin {
      to {
        transform: rotate(360deg);
      }
    }

    .hidden {
      display: none !important;
    }

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

      .summary {
        grid-template-columns: repeat(2, minmax(120px, 1fr));
      }
    }

    @media (max-width: 520px) {
      .shell {
        width: min(100vw - 16px, 1500px);
        padding-top: 8px;
      }

      .code-row {
        grid-template-columns: 1fr;
      }

      input[type="text"] {
        height: 60px;
        font-size: 34px;
        text-align: center;
      }

      .summary {
        grid-template-columns: 1fr;
      }
    }