:root {
  color-scheme: light;
  --bg: #edf4f1;
  --bg-2: #f8fbf7;
  --panel: rgba(255, 255, 252, 0.9);
  --panel-strong: rgba(255, 255, 250, 0.98);
  --line: #cbded8;
  --line-strong: #a9c9c0;
  --ink: #173433;
  --muted: #60736f;
  --teal: #0b7d77;
  --teal-soft: #e4f5f0;
  --amber: #c7872d;
  --danger: #a64941;
  --shadow: 0 18px 45px rgba(22, 58, 55, 0.13);
  --inner-shadow: inset 0 1px 0 rgba(255,255,255,.72);
}

body[data-ui-theme="dark"] {
  color-scheme: dark;
  --bg: #071616;
  --bg-2: #0d2220;
  --panel: rgba(10, 31, 30, 0.86);
  --panel-strong: rgba(12, 37, 35, 0.98);
  --line: #244a47;
  --line-strong: #35716b;
  --ink: #e6f2ec;
  --muted: #9fb8b0;
  --teal: #42c7b7;
  --teal-soft: rgba(66, 199, 183, .14);
  --amber: #d59a45;
  --danger: #ff958c;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.32);
  --inner-shadow: inset 0 1px 0 rgba(255,255,255,.08);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

body {
  font-family: "Hiragino Sans GB", "PingFang SC", system-ui, sans-serif;
  background:
    radial-gradient(circle at 12% 0%, rgba(199, 135, 45, 0.16), transparent 28%),
    radial-gradient(circle at 90% 12%, rgba(11, 125, 119, 0.16), transparent 30%),
    linear-gradient(135deg, var(--bg-2), var(--bg));
  color: var(--ink);
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    linear-gradient(90deg, rgba(23,52,51,.045) 1px, transparent 1px),
    linear-gradient(180deg, rgba(23,52,51,.04) 1px, transparent 1px);
  background-size: 44px 44px;
  mask-image: radial-gradient(circle at 50% 35%, black, transparent 82%);
}

button, input, textarea, select { font: inherit; }

button {
  border: 0;
  border-radius: 8px;
  padding: 10px 14px;
  cursor: pointer;
  color: var(--ink);
  transition: transform .16s ease, border-color .16s ease, background .16s ease;
}

button:hover { transform: translateY(-1px); }

button.primary {
  background: linear-gradient(135deg, var(--teal), #0a625f);
  color: #fff;
  box-shadow: 0 10px 22px rgba(11, 125, 119, 0.18);
}

button.ghost {
  background: var(--teal-soft);
  border: 1px solid var(--line);
}

.shell {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: minmax(640px, 1fr) minmax(430px, 40vw);
  gap: 18px;
  height: 100vh;
  padding: 18px;
  overflow: hidden;
}

.workspace, .preview {
  min-height: 0;
  min-width: 0;
}

.workspace {
  display: grid;
  grid-template-rows: auto minmax(190px, 27vh) minmax(0, 1fr);
  gap: 14px;
}

.preview {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 14px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  min-height: 70px;
  padding: 0 2px;
}

.brand-block {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

.seal {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  flex: 0 0 auto;
  border-radius: 10px;
  color: #fff;
  background: linear-gradient(145deg, var(--teal), #064a48);
  box-shadow: 0 10px 24px rgba(11, 125, 119, .22);
  font-family: "Songti SC", "Hiragino Mincho ProN", serif;
  font-size: 24px;
  font-weight: 700;
}

h1, h2, p { margin: 0; }

h1 {
  font-family: "Songti SC", "Hiragino Mincho ProN", serif;
  font-size: 32px;
  line-height: 1.05;
  letter-spacing: 0;
}

h2 {
  font-size: 17px;
  font-weight: 700;
}

.topbar p, .status {
  margin-top: 7px;
  color: var(--muted);
  font-size: 14px;
}

.actions, .inline {
  display: flex;
  align-items: end;
  gap: 10px;
}

.panel {
  min-height: 0;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow), var(--inner-shadow);
  backdrop-filter: blur(14px);
}

.input-panel, .result-panel, .controls {
  padding: 16px;
}

.input-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
}

.result-panel {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.compact-head {
  margin-bottom: 10px;
}

select, input, textarea {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-strong);
  color: var(--ink);
  outline: none;
}

select:focus, input:focus, textarea:focus {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--teal) 18%, transparent);
}

select {
  min-width: 150px;
  padding: 9px 10px;
}

textarea {
  width: 100%;
  min-height: 0;
  padding: 13px;
  resize: none;
  line-height: 1.7;
}

.title-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 12px;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}

input {
  width: 100%;
  padding: 10px 11px;
}

.items-editor {
  display: grid;
  align-content: start;
  gap: 10px;
  overflow: auto;
  padding: 2px 6px 2px 1px;
}

.items-editor::-webkit-scrollbar,
.canvas-wrap::-webkit-scrollbar {
  width: 10px;
}

.items-editor::-webkit-scrollbar-thumb,
.canvas-wrap::-webkit-scrollbar-thumb {
  background: color-mix(in srgb, var(--teal) 38%, transparent);
  border-radius: 999px;
}

.item-row {
  display: grid;
  grid-template-columns: 44px minmax(160px, .9fr) minmax(220px, 1.55fr) 36px;
  gap: 10px;
  align-items: center;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: color-mix(in srgb, var(--panel-strong) 88%, var(--teal-soft));
}

.item-index {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  color: var(--teal);
  background: var(--teal-soft);
  font-size: 13px;
  font-weight: 700;
}

.delete {
  width: 36px;
  height: 36px;
  padding: 0;
  background: color-mix(in srgb, var(--danger) 10%, transparent);
  color: var(--danger);
}

.controls {
  position: static;
  z-index: auto;
}

.style-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.style-button {
  display: grid;
  gap: 4px;
  min-height: 62px;
  border: 1px solid var(--line);
  background: var(--panel-strong);
  text-align: left;
}

.style-button span {
  font-weight: 700;
}

.style-button small {
  color: var(--muted);
  font-size: 12px;
}

.style-button.active {
  color: #fff;
  background: linear-gradient(135deg, var(--teal), #0a615e);
  border-color: transparent;
}

.style-button.active small {
  color: rgba(255,255,255,.74);
}

.check {
  display: flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
  margin: 0;
}

.check input { width: auto; }

.canvas-wrap {
  overflow: auto;
  display: grid;
  place-items: start center;
  padding: 16px;
  background:
    linear-gradient(135deg, color-mix(in srgb, var(--panel) 70%, transparent), color-mix(in srgb, var(--teal-soft) 42%, transparent));
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow), var(--inner-shadow);
}

canvas {
  width: min(100%, 390px);
  height: auto;
  display: block;
  border-radius: 8px;
  box-shadow: 0 18px 50px rgba(5, 31, 36, 0.25);
  background: #fff;
}

@media (max-width: 1180px) {
  .shell {
    grid-template-columns: 1fr;
    overflow: auto;
    height: auto;
    min-height: 100vh;
  }

  html, body {
    overflow: auto;
  }

  .workspace, .preview {
    min-height: 780px;
  }
}

@media (max-width: 760px) {
  .shell { padding: 12px; }
  .topbar, .panel-head, .actions, .inline {
    align-items: stretch;
    flex-direction: column;
  }
  .title-grid, .item-row, .style-grid {
    grid-template-columns: 1fr;
  }
}
