:root {
      color-scheme: light;
      --bg: #f5efe5;
      --paper: rgba(255, 250, 240, .88);
      --paper-strong: #fff8eb;
      --ink: #4f3527;
      --muted: #9a7a62;
      --line: rgba(143, 91, 45, .24);
      --gold: #d7a955;
      --red: #c96355;
      --red-dark: #a9483f;
      --brown: #785039;
      --shadow: 0 14px 36px rgba(73, 40, 20, .16);
      --radius: 14px;
      --glow: 0 0 0 1px rgba(255, 224, 155, .6), 0 0 24px rgba(255, 191, 97, .22);
    }

    * { box-sizing: border-box; }
    html, body { height: 100%; margin: 0; }
    body {
      font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
      color: var(--ink);
      background:
        radial-gradient(circle at 20% 8%, rgba(255, 238, 203, .9), transparent 34%),
        radial-gradient(circle at 90% 10%, rgba(245, 206, 190, .7), transparent 28%),
        linear-gradient(135deg, #f9f1e4, #eadfce);
      overflow: hidden;
    }

    .app {
      height: 100%;
      display: grid;
      grid-template-columns: 360px minmax(0, 1fr);
      grid-template-rows: 62px minmax(0, 1fr);
    }

    .topbar {
      grid-column: 1 / -1;
      display: flex;
      align-items: center;
      gap: 14px;
      padding: 10px 16px;
      border-bottom: 1px solid var(--line);
      background: linear-gradient(180deg, rgba(255, 249, 238, .92), rgba(245, 229, 207, .78));
      backdrop-filter: blur(16px);
      box-shadow: 0 3px 20px rgba(86, 52, 24, .08);
      z-index: 5;
    }

    .brand {
      min-width: 320px;
      display: flex;
      align-items: center;
      gap: 10px;
      font-weight: 750;
      letter-spacing: .02em;
    }

    .brand-mark {
      width: 34px;
      height: 34px;
      border-radius: 50%;
      display: grid;
      place-items: center;
      background: radial-gradient(circle at 35% 30%, #fff5d8, #d79a45);
      border: 2px solid #8f6335;
      box-shadow: inset 0 0 0 2px rgba(255,255,255,.45), 0 4px 10px rgba(109, 65, 25, .22);
      color: #fff8dc;
      animation: markPulse 4s ease-in-out infinite;
    }

    .toolbar {
      flex: 1;
      display: flex;
      align-items: center;
      justify-content: space-between;
      gap: 12px;
      min-width: 0;
    }

    .lang-select {
      height: 34px;
      border: 1px solid rgba(139, 88, 45, .22);
      border-radius: 10px;
      padding: 0 10px;
      background: rgba(255, 249, 238, .72);
      color: var(--brown);
      font-weight: 700;
    }

    .tool-group {
      display: flex;
      align-items: center;
      gap: 8px;
      min-width: 0;
    }

    .sidebar {
      min-height: 0;
      padding: 14px;
      border-right: 1px solid var(--line);
      background: rgba(255, 248, 235, .56);
      overflow: auto;
    }

    .main {
      min-width: 0;
      min-height: 0;
      display: grid;
      grid-template-rows: 42px auto minmax(0, 1fr) 32px;
      background: rgba(255,255,255,.18);
    }

    .tabs {
      display: flex;
      align-items: end;
      gap: 6px;
      padding: 7px 12px 0;
      border-bottom: 1px solid var(--line);
      overflow-x: auto;
      background: rgba(255, 249, 239, .45);
    }

    .view-toolbar {
      display: flex;
      align-items: center;
      justify-content: space-between;
      gap: 12px;
      min-height: 44px;
      padding: 6px 12px;
      border-bottom: 1px solid var(--line);
      background: linear-gradient(180deg, rgba(255, 250, 241, .7), rgba(255, 241, 220, .42));
    }

    .view-title {
      min-width: 0;
      color: var(--brown);
      font-size: 13px;
      font-weight: 750;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
    }

    .view-tools {
      display: flex;
      align-items: center;
      justify-content: flex-end;
      gap: 7px;
      flex-wrap: wrap;
    }

    .tool-divider {
      width: 1px;
      height: 22px;
      background: rgba(143, 91, 45, .22);
      margin: 0 2px;
    }

    .toolbar-check {
      height: 30px;
      display: inline-flex;
      align-items: center;
      gap: 6px;
      border: 1px solid rgba(132, 77, 39, .18);
      border-radius: 10px;
      padding: 0 10px;
      background: rgba(255, 249, 238, .5);
      color: var(--brown);
      font-size: 12px;
      font-weight: 650;
      white-space: nowrap;
    }

    .toolbar-check input {
      margin: 0;
      accent-color: var(--red);
    }

    .tab {
      max-width: 210px;
      padding: 9px 12px 8px;
      border: 1px solid var(--line);
      border-bottom: none;
      border-radius: 12px 12px 0 0;
      background: rgba(255, 248, 235, .64);
      color: var(--muted);
      cursor: pointer;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
      font-size: 13px;
    }

    .tab.active {
      background: var(--paper-strong);
      color: var(--ink);
      box-shadow: 0 -4px 16px rgba(112, 70, 33, .08);
    }

    .viewport {
      position: relative;
      min-width: 0;
      min-height: 0;
      overflow: hidden;
    }

    .drop {
      position: absolute;
      inset: 18px;
      border: 1.5px dashed rgba(154, 99, 52, .38);
      border-radius: 18px;
      display: grid;
      place-items: center;
      text-align: center;
      color: var(--muted);
      background: rgba(255, 250, 241, .36);
      transition: border-color .18s ease, background .18s ease, transform .18s ease, box-shadow .18s ease;
    }

    .drop strong { display: block; color: var(--ink); font-size: 20px; margin-bottom: 8px; }
    .drop.dragover {
      border-color: var(--red);
      background: rgba(255, 234, 220, .68);
      transform: scale(.995);
      box-shadow: inset 0 0 40px rgba(255, 190, 92, .18);
    }

    canvas {
      position: absolute;
      inset: 0;
      width: 100%;
      height: 100%;
      cursor: crosshair;
    }

    .statusbar {
      display: flex;
      align-items: center;
      justify-content: space-between;
      gap: 12px;
      padding: 6px 12px;
      font-size: 12px;
      color: var(--muted);
      border-top: 1px solid var(--line);
      background: rgba(255, 248, 235, .55);
    }

    .panel {
      background: var(--paper);
      border: 1px solid var(--line);
      border-radius: var(--radius);
      box-shadow: var(--shadow);
      margin-bottom: 14px;
      overflow: hidden;
      transition: transform .18s ease, box-shadow .18s ease, border-color .18s ease;
    }

    .panel:hover {
      transform: translateY(-1px);
      box-shadow: 0 16px 38px rgba(73, 40, 20, .18);
    }

    .panel-head {
      display: flex;
      align-items: center;
      justify-content: space-between;
      gap: 10px;
      padding: 12px 14px 10px;
      background: linear-gradient(180deg, rgba(255,255,255,.55), rgba(255, 238, 211, .25));
      border-bottom: 1px solid var(--line);
    }

    .panel h2 {
      margin: 0;
      font-size: 14px;
      font-weight: 760;
    }

    .panel-kicker {
      font-size: 11px;
      color: var(--muted);
      border: 1px solid rgba(139, 88, 45, .16);
      border-radius: 999px;
      padding: 2px 8px;
      background: rgba(255,255,255,.38);
    }

    .panel-body { padding: 14px; }

    .row {
      display: grid;
      grid-template-columns: 92px minmax(0, 1fr);
      align-items: center;
      gap: 10px;
      margin-bottom: 11px;
      font-size: 13px;
    }

    .row.compact {
      grid-template-columns: 34px minmax(0, 1fr);
      margin-bottom: 8px;
    }

    .row:last-child { margin-bottom: 0; }
    label { color: var(--muted); }

    input[type="number"], input[type="text"], select {
      width: 100%;
      height: 32px;
      border: 1px solid rgba(139, 88, 45, .22);
      border-radius: 9px;
      padding: 0 10px;
      color: var(--ink);
      background: rgba(255,255,255,.72);
      outline: none;
    }

    input[type="color"] {
      width: 44px;
      height: 32px;
      border: 1px solid rgba(139, 88, 45, .22);
      border-radius: 9px;
      background: rgba(255,255,255,.72);
      padding: 3px;
    }

    input[type="range"] { width: 100%; accent-color: var(--red); }

    .checkrow {
      display: flex;
      align-items: center;
      gap: 8px;
      margin: 9px 0;
      font-size: 13px;
      color: var(--ink);
    }

    .btn {
      height: 34px;
      border: 1px solid rgba(132, 77, 39, .26);
      border-radius: 10px;
      padding: 0 13px;
      background: linear-gradient(180deg, #fff8ed, #efd8bb);
      color: var(--ink);
      font-weight: 650;
      cursor: pointer;
      box-shadow: 0 3px 8px rgba(96, 55, 24, .12), inset 0 1px 0 rgba(255,255,255,.65);
      white-space: nowrap;
      transition: transform .12s ease, filter .15s ease, box-shadow .18s ease;
    }

    .btn:hover { filter: brightness(1.03); box-shadow: var(--glow); }
    .btn:active { transform: translateY(1px); }
    .btn.primary {
      color: white;
      border-color: rgba(135, 56, 45, .42);
      background: linear-gradient(180deg, #dc7c66, #b64e44);
    }
    .btn.ghost {
      background: rgba(255, 249, 238, .55);
      box-shadow: none;
      color: var(--brown);
    }
    .btn.small { height: 30px; padding: 0 10px; font-size: 12px; }
    .btn:disabled { opacity: .48; cursor: default; transform: none; }

    .sparkle {
      position: relative;
      overflow: hidden;
    }

    .sparkle::after {
      content: "";
      position: absolute;
      inset: -40% auto -40% -55%;
      width: 42%;
      transform: rotate(18deg);
      background: linear-gradient(90deg, transparent, rgba(255,255,255,.55), transparent);
      animation: shimmer 3.2s ease-in-out infinite;
    }

    .button-grid {
      display: grid;
      grid-template-columns: 1fr 1fr;
      gap: 8px;
    }

    .button-row {
      display: flex;
      align-items: center;
      gap: 8px;
      margin-bottom: 8px;
      flex-wrap: wrap;
    }

    .button-row.emphasized {
      display: grid;
      grid-template-columns: 1fr 1fr;
    }

    .file-pick {
      display: block;
      width: 100%;
      padding: 16px 12px;
      border: 1px dashed rgba(154, 99, 52, .42);
      border-radius: 14px;
      text-align: center;
      background: rgba(255,255,255,.35);
      cursor: pointer;
      color: var(--brown);
      font-weight: 680;
      transition: transform .18s ease, border-color .18s ease, background .18s ease, box-shadow .18s ease;
    }
    .file-pick input { display: none; }
    .file-pick small {
      display: block;
      margin-top: 4px;
      color: var(--muted);
      font-weight: 500;
    }
    .file-pick-icon {
      display: grid;
      width: 34px;
      height: 34px;
      margin: 0 auto 8px;
      place-items: center;
      border-radius: 50%;
      background: radial-gradient(circle, #fff8dc, #e3ac5a);
      color: white;
      box-shadow: 0 4px 14px rgba(160, 91, 28, .22);
    }
    .upload-panel.dragover .file-pick,
    .file-pick.dragover {
      border-color: var(--red);
      background: rgba(255, 235, 221, .76);
      transform: translateY(-1px);
      box-shadow: var(--glow);
    }

    .hint {
      font-size: 12px;
      line-height: 1.55;
      color: var(--muted);
    }

    .mini-list {
      display: grid;
      gap: 6px;
      max-height: 180px;
      overflow: auto;
    }

    .history-body {
      padding-top: 10px;
    }

    .history-list {
      display: grid;
      gap: 6px;
      max-height: 230px;
      overflow: auto;
      padding-right: 2px;
    }

    .history-empty {
      padding: 22px 8px;
      text-align: center;
      color: var(--muted);
      font-size: 12px;
    }

    .history-row {
      width: 100%;
      min-height: 34px;
      display: flex;
      align-items: center;
      gap: 8px;
      border: 1px solid rgba(139, 88, 45, .14);
      border-radius: 10px;
      padding: 7px 9px;
      background: rgba(255,255,255,.36);
      color: var(--ink);
      cursor: pointer;
      text-align: left;
      transition: transform .12s ease, border-color .16s ease, background .16s ease, opacity .16s ease;
    }

    .history-row:hover {
      transform: translateX(1px);
      border-color: rgba(198, 99, 85, .38);
      background: rgba(255, 247, 234, .72);
    }

    .history-row.is-current {
      border-color: rgba(198, 99, 85, .74);
      background: linear-gradient(180deg, rgba(255, 238, 211, .85), rgba(255, 249, 238, .72));
      box-shadow: inset 0 0 0 1px rgba(198, 99, 85, .18), 0 0 18px rgba(255, 196, 99, .18);
    }

    .history-row.is-future {
      opacity: .55;
    }

    .history-dot {
      width: 8px;
      height: 8px;
      flex: 0 0 auto;
      border-radius: 50%;
      background: #c9a16a;
      box-shadow: 0 0 0 3px rgba(215, 169, 85, .14);
    }

    .history-row.is-current .history-dot {
      background: var(--red);
      box-shadow: 0 0 0 4px rgba(198, 99, 85, .18), 0 0 14px rgba(255, 198, 88, .32);
    }

    .history-content {
      min-width: 0;
      display: grid;
      grid-template-columns: minmax(0, 1fr) auto;
      gap: 8px;
      flex: 1 1 auto;
      align-items: baseline;
    }

    .history-label {
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
      font-size: 12px;
      font-weight: 680;
    }

    .history-time {
      color: var(--muted);
      font-size: 11px;
      font-variant-numeric: tabular-nums;
    }

    .box-item {
      display: flex;
      align-items: center;
      justify-content: space-between;
      gap: 8px;
      padding: 8px 9px;
      border: 1px solid rgba(139, 88, 45, .16);
      border-radius: 10px;
      background: rgba(255,255,255,.45);
      font-size: 12px;
      cursor: pointer;
    }
    .box-item.active {
      border-color: rgba(198, 99, 85, .7);
      box-shadow: inset 0 0 0 1px rgba(198, 99, 85, .28);
    }

    .box-editor {
      display: grid;
      grid-template-columns: 1fr 1fr;
      gap: 0 10px;
      margin-bottom: 10px;
    }

    .kbd {
      border: 1px solid rgba(139, 88, 45, .26);
      background: rgba(255,255,255,.55);
      border-radius: 6px;
      padding: 1px 5px;
      font-size: 11px;
      color: var(--brown);
    }

    .magic-toast {
      pointer-events: none;
      position: absolute;
      left: 50%;
      top: 20px;
      transform: translate(-50%, -10px);
      opacity: 0;
      padding: 9px 14px;
      border-radius: 999px;
      border: 1px solid rgba(213, 159, 77, .48);
      color: var(--brown);
      background: rgba(255, 248, 230, .92);
      box-shadow: 0 10px 30px rgba(102, 58, 24, .2), 0 0 28px rgba(255, 202, 105, .22);
      font-size: 13px;
      font-weight: 750;
      transition: opacity .22s ease, transform .22s ease;
    }

    .magic-toast.show {
      opacity: 1;
      transform: translate(-50%, 0);
    }

    body.burst::before {
      content: "";
      pointer-events: none;
      position: fixed;
      inset: 0;
      background:
        radial-gradient(circle at 22% 22%, rgba(255, 229, 148, .32), transparent 9%),
        radial-gradient(circle at 78% 16%, rgba(255, 190, 205, .22), transparent 8%),
        radial-gradient(circle at 54% 82%, rgba(255, 232, 173, .22), transparent 9%);
      animation: burst .55s ease-out;
      z-index: 20;
    }

    @keyframes shimmer {
      0%, 60% { left: -55%; }
      100% { left: 120%; }
    }

    @keyframes markPulse {
      0%, 100% { transform: scale(1); }
      50% { transform: scale(1.04); }
    }

    @keyframes burst {
      from { opacity: 0; }
      25% { opacity: 1; }
      to { opacity: 0; }
    }
