:root {
  --bg: #141210;
  --top: #1a1815;
  --panel: #1c1a17;
  --stage: #0e0d0b;
  --line: #34302a;
  --text: #f6f1e7;
  --muted: #a39888;
  --cinnabar: #c44536;
  --cinnabar-deep: #9d3226;
  --paper: #efe7d6;
  --ink: #211c16;
  color-scheme: dark;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  font-size: 14px;
}

button, input { font: inherit; color: inherit; }

button { cursor: pointer; }

:focus-visible {
  outline: 2px solid var(--paper);
  outline-offset: 2px;
}

.app {
  height: 100%;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px 24px;
  padding: 14px 18px;
  background: var(--top);
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.seal {
  width: 36px;
  height: 36px;
  flex: none;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: var(--cinnabar);
  color: white;
  font-family: "Songti SC", "STSong", "NSimSun", serif;
  font-size: 18px;
  line-height: 1;
}

.brand h1 {
  margin: 0;
  font-family: "Songti SC", "STSong", "NSimSun", serif;
  font-size: 20px;
  font-weight: 600;
  letter-spacing: 0.06em;
}

.brand p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0.01em;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.sep {
  width: 1px;
  height: 22px;
  background: var(--line);
  margin: 0 4px;
}

.btn {
  border: 1px solid var(--line);
  background: transparent;
  color: var(--text);
  border-radius: 8px;
  padding: 8px 12px;
  line-height: 1.2;
}

.btn:hover:not(:disabled) { background: #28241f; }

.btn:disabled {
  opacity: 0.38;
  cursor: not-allowed;
}

.btn.primary {
  background: var(--cinnabar);
  border-color: var(--cinnabar);
  color: white;
}

.btn.primary:hover:not(:disabled) { background: var(--cinnabar-deep); }

.btn.light {
  background: var(--paper);
  border-color: var(--paper);
  color: var(--ink);
}

.btn.light:hover:not(:disabled) { background: #f7f2e6; }

.btn.danger {
  width: 100%;
  margin-top: 6px;
  color: #ffd7d1;
  border-color: #6a332c;
}

.btn.danger:hover:not(:disabled) { background: #3a211e; }

.workspace {
  flex: 1;
  min-height: 0;
  display: flex;
}

.stage {
  position: relative;
  flex: 1;
  min-width: 0;
  min-height: 280px;
  display: grid;
  place-items: center;
  padding: 28px;
  background:
    radial-gradient(ellipse at center, rgba(255, 244, 220, 0.04), transparent 58%),
    var(--stage);
}

.empty {
  width: min(420px, 100%);
  text-align: center;
  padding: 12px;
}

.empty-kicker {
  margin: 0 0 10px;
  color: var(--cinnabar);
  font-size: 12px;
  letter-spacing: 0.16em;
}

.empty-title {
  margin: 0;
  font-family: "Songti SC", "STSong", "NSimSun", serif;
  font-size: 32px;
  letter-spacing: 0.04em;
}

.empty-copy {
  margin: 12px auto 22px;
  max-width: 28em;
  color: var(--muted);
  line-height: 1.6;
}

#view {
  display: block;
  background: #111;
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.38);
  cursor: crosshair;
  touch-action: none;
}

.dropmask {
  position: absolute;
  inset: 16px;
  display: none;
  place-items: center;
  pointer-events: none;
  border: 1.5px dashed rgba(196, 69, 54, 0.9);
  border-radius: 16px;
  background: rgba(196, 69, 54, 0.12);
  color: var(--text);
  font-size: 18px;
  letter-spacing: 0.06em;
}

.stage.dropping .dropmask { display: grid; }

.panel {
  width: 320px;
  flex: none;
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--panel);
  border-left: 1px solid var(--line);
  overflow: auto;
}

.panel-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: 16px 16px 10px;
}

.panel-head h2 {
  margin: 0;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.12em;
}

.panel-head span,
.hint,
.footnote {
  color: var(--muted);
}

.stamp-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 0 12px;
}

.stamp-list:empty { display: none; }

.stamp {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  text-align: left;
  padding: 7px;
  border-radius: 10px;
  border: 1px solid transparent;
  background: transparent;
}

.stamp small {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
}

.stamp:hover { background: #26231f; }

.stamp[aria-selected="true"] {
  background: #2c211e;
  border-color: #6a332c;
}

.thumb {
  width: 42px;
  height: 42px;
  flex: none;
  border-radius: 6px;
  object-fit: contain;
  background-color: #141210;
  background-image:
    linear-gradient(45deg, #2a2723 25%, transparent 25%),
    linear-gradient(-45deg, #2a2723 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #2a2723 75%),
    linear-gradient(-45deg, transparent 75%, #2a2723 75%);
  background-size: 10px 10px;
  background-position: 0 0, 0 5px, 5px -5px, -5px 0;
}

.hint, .footnote {
  margin: 0;
  padding: 8px 16px 0;
  line-height: 1.55;
  font-size: 13px;
}

.footnote {
  margin-top: auto;
  padding: 16px;
  font-size: 12px;
}

.inspector {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 14px 16px 8px;
}

.field span {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 13px;
}

.field b {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

input[type="range"] {
  width: 100%;
  margin: 8px 0 0;
  accent-color: var(--cinnabar);
}

.blends {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin-top: 8px;
}

.blends button {
  border: 1px solid var(--line);
  background: transparent;
  border-radius: 8px;
  padding: 8px 4px;
  font-size: 13px;
}

.blends button[aria-pressed="true"] {
  background: var(--cinnabar);
  border-color: var(--cinnabar);
  color: white;
}

.menu {
  position: fixed;
  z-index: 20;
  min-width: 132px;
  padding: 4px;
  background: #26231f;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.35);
}

.menu button {
  display: block;
  width: 100%;
  text-align: left;
  background: transparent;
  border: 0;
  border-radius: 6px;
  padding: 8px 10px;
}

.menu button:hover { background: #3a221f; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%);
  z-index: 30;
  max-width: min(440px, calc(100% - 32px));
  padding: 10px 14px;
  border-radius: 8px;
  background: var(--paper);
  color: var(--ink);
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.28);
}

.sheet-toggle,
.control-tabs { display: none; }

.grip {
  width: 28px;
  height: 4px;
  flex: none;
  border-radius: 999px;
  background: #5a5348;
}

.sheet-summary {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text);
  font-size: 13px;
}

.sheet-toggle-label {
  flex: none;
  color: var(--paper);
  font-size: 13px;
}

@media (max-width: 860px) {
  .top {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
    padding: 8px 12px;
  }
  .brand p { display: none; }
  .seal {
    width: 28px;
    height: 28px;
    font-size: 15px;
  }
  .brand h1 { font-size: 17px; }
  .toolbar {
    flex-wrap: nowrap;
    overflow-x: auto;
    scrollbar-width: none;
  }
  .toolbar::-webkit-scrollbar { display: none; }
  .btn {
    flex: none;
    padding: 7px 10px;
  }
  .sep { display: none; }
  .workspace {
    position: relative;
    display: block;
  }
  .stage {
    position: absolute;
    inset: 0;
    min-height: 0;
    height: auto;
    padding: 8px 8px 72px;
  }
  .empty-title { font-size: 26px; }
  .panel {
    position: absolute;
    left: 8px;
    right: 8px;
    bottom: 8px;
    z-index: 5;
    width: auto;
    max-height: none;
    border: 1px solid var(--line);
    border-radius: 16px;
    border-left: 1px solid var(--line);
    box-shadow: 0 16px 40px rgba(0, 0, 0, 0.4);
    overflow: hidden;
  }
  .panel.is-collapsed .panel-body { display: none; }
  .sheet-toggle {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 12px 14px;
    border: 0;
    background: transparent;
    text-align: left;
  }
  .control-tabs {
    display: flex;
    gap: 6px;
    overflow-x: auto;
    scrollbar-width: none;
  }
  .control-tabs::-webkit-scrollbar { display: none; }
  .control-tabs button {
    flex: none;
    border: 1px solid var(--line);
    background: transparent;
    border-radius: 999px;
    padding: 6px 10px;
    font-size: 13px;
  }
  .control-tabs button[aria-selected="true"] {
    background: var(--cinnabar);
    border-color: var(--cinnabar);
    color: white;
  }
  .inspector {
    gap: 10px;
    padding: 4px 12px 12px;
  }
  .inspector .field:not(.is-active) { display: none; }
  .btn.danger {
    width: auto;
    margin-top: 0;
  }
  .stamp-list {
    flex-direction: row;
    overflow-x: auto;
    padding-bottom: 8px;
  }
  .stamp { width: auto; flex: none; }
  .footnote { display: none; }
  .toast {
    top: 8px;
    bottom: auto;
  }
}
