:root {
      --bg: #0c0116;
      --bg-soft: #1f0b3a;
      --panel: #dce6e7;
      --ink: #0c0116;
      --accent: #8400ff;
      --accent-2: #4cd275;
      --danger: #ff8360;
      --line: #b9c8cc;
      --muted: #546a76;
      --surface: #ffffff;
      --alt-yellow: #e8e288;
      --alt-cyan: #3cdbd3;
      --alt-lilac: #b298dc;
      --alt-blue: #006BA6;
    }

    * { box-sizing: border-box; }

    body {
      margin: 0;
      font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
      color: var(--ink);
      background:
        radial-gradient(circle at 12% 18%, #8400ff66 0%, transparent 34%),
        radial-gradient(circle at 88% 2%, #3cdbd355 0%, transparent 28%),
        linear-gradient(160deg, #0c0116, #17042f 55%, #120225);
      min-height: 100vh;
    }

    .app {
      display: grid;
      grid-template-columns: 300px 1fr 420px;
      min-height: 100vh;
      gap: 14px;
      padding: 14px;
    }

    .panel {
      background: var(--panel);
      border-radius: 16px;
      border: 1px solid var(--line);
      box-shadow: 0 14px 28px rgba(2, 8, 20, 0.25);
      overflow: hidden;
    }

    .panel-head {
      padding: 14px 16px;
      border-bottom: 1px solid var(--line);
      display: flex;
      align-items: center;
      justify-content: space-between;
      gap: 10px;
      background: linear-gradient(140deg, #ffffff, #dce6e7);
    }

    .title {
      margin: 0;
      font-size: 1.05rem;
      font-weight: 700;
      letter-spacing: .2px;
    }

    .sub {
      margin: 4px 0 0;
      color: var(--muted);
      font-size: .82rem;
    }

    .content { padding: 14px 16px; }

    .stack { display: grid; gap: 10px; }

    .field { display: grid; gap: 6px; }

    .sidebar-group {
      display: grid;
      gap: 10px;
      padding: 12px;
      border: 1px solid #bfd0d4;
      border-radius: 12px;
      background: linear-gradient(165deg, #f8fcfc, #eef5f6);
      box-shadow: inset 0 1px 0 #ffffff;
    }

    .sidebar-group-title {
      margin: 0;
      display: flex;
      align-items: center;
      gap: 8px;
      font-size: .78rem;
      text-transform: uppercase;
      letter-spacing: .08em;
      color: #344d57;
      font-weight: 700;
      padding-bottom: 8px;
      border-bottom: 1px solid #ccdadf;
    }

    .sidebar-group-icon {
      display: inline-flex;
      align-items: center;
      justify-content: center;
      min-width: 22px;
      height: 22px;
      border-radius: 7px;
      background: linear-gradient(140deg, #e6dbf7, #d0e7ed);
      border: 1px solid #b5c7cc;
      color: #2f4752;
      font-size: .66rem;
      font-weight: 700;
      letter-spacing: .02em;
      line-height: 1;
      font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
      padding: 0 6px;
    }

    .sidebar-divider {
      border: 0;
      border-top: 1px dashed #c4d3d7;
      margin: 2px 0;
    }

    .field label {
      font-size: .74rem;
      text-transform: uppercase;
      letter-spacing: .08em;
      color: var(--muted);
      font-weight: 600;
    }

    input, select, textarea {
      width: 100%;
      border: 1px solid #a6bbc1;
      background: var(--surface);
      border-radius: 10px;
      padding: 10px 11px;
      font: inherit;
      color: var(--ink);
    }

    textarea {
      min-height: 80px;
      resize: vertical;
    }

    input:focus, select:focus, textarea:focus {
      outline: 2px solid #b298dc;
      border-color: var(--accent);
    }

    .row {
      display: flex;
      gap: 8px;
      flex-wrap: wrap;
    }

    .btn {
      border: 0;
      border-radius: 10px;
      padding: 9px 11px;
      font: inherit;
      font-weight: 600;
      cursor: pointer;
      transition: transform .15s ease, filter .15s ease;
    }

    .btn:hover { filter: brightness(1.04); transform: translateY(-1px); }

    .btn:active { transform: translateY(0); }

    .btn-primary { background: var(--accent); color: #fff; }
    .btn-soft { background: #cfdde0; color: #0c0116; }
    .btn-success { background: var(--accent-2); color: #0c0116; }
    .btn-danger { background: #ffd5cb; color: #6f241b; }

    .list {
      display: grid;
      gap: 8px;
      max-height: 36vh;
      overflow: auto;
      padding-right: 4px;
    }

    .item {
      border: 1px solid #adc0c5;
      background: var(--surface);
      border-radius: 12px;
      padding: 10px;
      display: grid;
      gap: 6px;
      cursor: pointer;
    }

    .item.active {
      border-color: var(--accent);
      box-shadow: inset 0 0 0 1px var(--accent);
      background: #efe5fb;
    }

    .item .meta {
      color: var(--muted);
      font-size: .78rem;
    }

    .main-grid {
      padding: 14px;
      overflow: auto;
      display: grid;
      gap: 12px;
      align-content: start;
      background: repeating-linear-gradient(
        -45deg,
        #edf3f4,
        #edf3f4 20px,
        #e3ecee 20px,
        #e3ecee 40px
      );
    }

    .rcg-card {
      border: 1px solid #b7c8cc;
      background: rgba(255, 255, 255, .95);
      border-radius: 16px;
      overflow: hidden;
      animation: popIn .22s ease;
      position: relative;
      box-shadow: 0 10px 20px rgba(12, 1, 22, 0.08);
    }

    .rcg-card::before {
      content: "";
      position: absolute;
      inset: 0 auto 0 0;
      width: 8px;
      background: var(--rcg-accent, #7d68b3);
    }

    .rcg-card[data-tone="0"] {
      --rcg-accent: #7d68b3;
      --rcg-head-start: #f2ebff;
      --rcg-head-end: #e6f0f7;
      --rcg-lane: #f8f4ff;
    }

    .rcg-card[data-tone="1"] {
      --rcg-accent: #0f8f8f;
      --rcg-head-start: #e7fbfa;
      --rcg-head-end: #eef8f3;
      --rcg-lane: #f1fbfa;
    }

    .rcg-card[data-tone="2"] {
      --rcg-accent: #b66b2f;
      --rcg-head-start: #fff3e7;
      --rcg-head-end: #fff8ef;
      --rcg-lane: #fffaf4;
    }

    .rcg-card[data-tone="3"] {
      --rcg-accent: #2b6cb0;
      --rcg-head-start: #eaf4ff;
      --rcg-head-end: #eef7fb;
      --rcg-lane: #f4f9ff;
    }

    .rcg-head {
      display: flex;
      justify-content: space-between;
      align-items: center;
      padding: 11px 12px;
      padding-left: 18px;
      background: linear-gradient(125deg, var(--rcg-head-start, #f2f7f8), var(--rcg-head-end, #e7eff1));
      border-bottom: 1px solid #c7d5d9;
      gap: 8px;
    }

    .rcg-kicker {
      margin: 0 0 3px;
      font-size: .67rem;
      text-transform: uppercase;
      letter-spacing: .11em;
      font-weight: 700;
      color: var(--rcg-accent, #546a76);
    }

    .rcg-name { font-weight: 700; }

    .pill {
      display: inline-flex;
      align-items: center;
      justify-content: center;
      border-radius: 999px;
      min-width: 26px;
      min-height: 26px;
      padding: 0 8px;
      line-height: 1;
      font-size: .72rem;
      font-weight: 700;
      background: #e3d7f6;
      color: #3e0c7a;
    }

    .rcg-body {
      display: grid;
      grid-template-columns: 1fr 1fr;
      gap: 10px;
      padding: 10px;
      background: linear-gradient(180deg, rgba(255, 255, 255, 0.6), rgba(255, 255, 255, 0.92));
    }

    .lane {
      border: 1px dashed #b8c9ce;
      border-radius: 12px;
      background: var(--rcg-lane, #f5f9fa);
      min-height: 90px;
      padding: 8px;
      display: grid;
      gap: 8px;
      align-content: start;
    }

    .lane h4 {
      margin: 0;
      font-size: .78rem;
      text-transform: uppercase;
      letter-spacing: .07em;
      color: #546a76;
    }

    .rc-card {
      border: 1px solid #c0d0d4;
      border-radius: 12px;
      padding: 8px;
      background: white;
      display: grid;
      gap: 7px;
    }

    .rc-title {
      font-weight: 700;
      font-size: .88rem;
      display: flex;
      align-items: center;
      justify-content: space-between;
      gap: 8px;
    }

    .small {
      font-size: .75rem;
      color: var(--muted);
    }

    .rule-list {
      display: grid;
      gap: 6px;
      min-height: 24px;
    }

    .rule {
      border: 1px solid #c6d4d8;
      border-radius: 9px;
      background: #ffffff;
      padding: 7px;
      display: flex;
      align-items: center;
      justify-content: space-between;
      gap: 8px;
      font-size: .8rem;
    }

    .rule-name { font-weight: 600; }

    .mono {
      font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
      white-space: pre;
      overflow: auto;
      margin: 0;
      padding: 12px;
      background: #130025;
      color: #d7fff2;
      height: calc(100vh - 190px);
      font-size: .77rem;
      line-height: 1.45;
    }

    .hint {
      font-size: .76rem;
      color: var(--muted);
      margin: 0;
    }

    .drop-ghost {
      opacity: .5;
      background: #e8e288;
      border: 1px dashed #8400ff;
    }

    .footer-actions {
      border-top: 1px solid var(--line);
      background: #dce6e7;
      padding: 10px;
      display: flex;
      gap: 8px;
      flex-wrap: wrap;
    }

    .app-footer {
      grid-column: 1 / -1;
      width: 100%;
      justify-self: stretch;
      margin: 10px 16px 18px;
      padding-top: 10px;
      border-top: 1px solid #bfd0d4;
      color: #3a5360;
      font-size: .8rem;
      display: flex;
      align-items: center;
      justify-content: center;
      gap: 6px;
      flex-wrap: nowrap;
      text-align: center;
      white-space: nowrap;
    }

    .footer-link {
      color: #0d4f5f;
      font-weight: 700;
      text-decoration: underline;
      text-underline-offset: 2px;
      cursor: pointer;
    }

    .privacy-banner {
      display: grid;
      grid-template-columns: 1fr auto;
      gap: 12px;
      align-items: start;
      position: sticky;
      top: 0;
      z-index: 900;
      margin: 0;
      padding: 14px 18px;
      background: linear-gradient(135deg, #fff8df, #f6efd1);
      border-bottom: 1px solid #d6c48d;
      color: #4e4725;
      box-shadow: 0 2px 10px rgba(25, 25, 25, 0.08);
    }

    .privacy-banner[hidden] {
      display: none !important;
    }

    .privacy-banner-copy {
      display: grid;
      gap: 6px;
      max-width: 96ch;
    }

    .privacy-banner-title {
      margin: 0;
      font-size: .88rem;
      font-weight: 800;
      letter-spacing: .02em;
    }

    .privacy-banner-copy p {
      margin: 0;
      font-size: .82rem;
      line-height: 1.5;
    }

    .privacy-banner-close {
      align-self: center;
      white-space: nowrap;
    }

    .modal-overlay {
      position: fixed;
      inset: 0;
      background: rgba(3, 10, 20, 0.62);
      display: none;
      align-items: center;
      justify-content: center;
      padding: 20px;
      z-index: 1000;
    }

    .modal-overlay.open {
      display: flex;
    }

    .modal-card {
      width: min(720px, 100%);
      max-height: 90vh;
      overflow: auto;
      background: #eef4f5;
      border: 1px solid #bfd0d4;
      border-radius: 16px;
      box-shadow: 0 20px 44px rgba(2, 8, 20, 0.45);
    }

    .modal-head {
      padding: 14px 16px;
      border-bottom: 1px solid #c7d8dc;
      background: linear-gradient(145deg, #ffffff, #e5edef);
    }

    .modal-title {
      margin: 0;
      font-size: 1.02rem;
      font-weight: 700;
    }

    .modal-body {
      padding: 14px 16px;
      display: grid;
      gap: 10px;
    }

    .modal-grid {
      display: grid;
      gap: 10px;
      grid-template-columns: 1fr 1fr;
    }

    .modal-grid .span-2 {
      grid-column: span 2;
    }

    .modal-actions {
      border-top: 1px solid #c7d8dc;
      padding: 12px 16px;
      background: #dfe9ea;
      display: flex;
      justify-content: flex-end;
      gap: 8px;
    }

    .modal-error {
      border: 1px solid #ffb6a3;
      background: #ffe3dc;
      color: #7f2e22;
      border-radius: 10px;
      padding: 9px 10px;
      font-size: .82rem;
      font-weight: 600;
    }

    @media (max-width: 840px) {
      .modal-grid {
        grid-template-columns: 1fr;
      }

      .modal-grid .span-2 {
        grid-column: span 1;
      }
    }

    @keyframes popIn {
      from { opacity: 0; transform: translateY(6px); }
      to { opacity: 1; transform: translateY(0); }
    }

    .ipg-row {
      display: flex;
      gap: 6px;
      align-items: center;
    }

    .ipg-name-tag {
      flex-shrink: 0;
      width: 150px;
      font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
      font-size: .7rem;
      color: #3f1978;
      background: #e8ddf7;
      border-radius: 6px;
      padding: 5px 7px;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
      cursor: default;
    }

    .ipg-value-input {
      flex: 1;
      min-width: 0;
      font-size: .7rem;
      font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
      padding: 5px 7px;
      border-radius: 8px;
    }

    .ipg-remove-btn {
      flex-shrink: 0;
      background: #ffd5cb;
      color: #6f241b;
      border: none;
      border-radius: 6px;
      padding: 4px 8px;
      cursor: pointer;
      font-size: .72rem;
      font-weight: 700;
    }

    .ipg-remove-btn:hover { background: #ffb49f; }

    .hint-support-formats {
      display: block;
      margin-bottom: 8px;
      color: var(--muted);
    }

    .hint-no-margin {
      margin: 0;
    }

    .ip-group-params-list {
      max-height: 28vh;
      overflow: auto;
      padding-right: 4px;
    }

    .hint-italic {
      font-style: italic;
    }

    @media (max-width: 1400px) {
      .app { grid-template-columns: 280px 1fr; }
      .preview-panel { grid-column: span 2; }
      .mono { height: 300px; }
    }

    @media (max-width: 960px) {
      .app { grid-template-columns: 1fr; }
      .preview-panel { grid-column: auto; }
      .rcg-body { grid-template-columns: 1fr; }
    }
