:root {
  --ink: #29241f;
  --muted: #756f68;
  --paper: #fffdf8;
  --edge: #d8cab8;
  --accent: #9b2f25;
  --wash: #f4efe6;
  color-scheme: light;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  color: var(--ink);
  background: linear-gradient(#f6f1e8, #e9dfd1);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans TC", sans-serif;
}

.advancedApp {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 320px 1fr;
}

.advancedPanel {
  padding: 22px;
  background: rgba(255, 253, 248, .96);
  border-right: 1px solid var(--edge);
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.seal {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  color: #fff;
  background: var(--accent);
  border: 2px solid #7f2119;
  font-family: "BiauKai", "DFKai-SB", serif;
  font-size: 30px;
}

h1,
h2,
p { margin: 0; }

h1 {
  font-size: 22px;
  line-height: 1.2;
}

h2 {
  font-size: 18px;
  line-height: 1.2;
}

p {
  color: var(--muted);
  font-size: 14px;
}

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

.modeNav a {
  height: 36px;
  display: grid;
  place-items: center;
  border: 1px solid var(--edge);
  border-radius: 6px;
  color: var(--ink);
  background: #fffaf0;
  text-decoration: none;
  font-size: 14px;
  font-weight: 700;
}

.modeNav a.is-active {
  border-color: #7f2119;
  color: #fff;
  background: var(--accent);
}

label {
  display: grid;
  gap: 7px;
  font-size: 14px;
  color: #4b443d;
}

textarea,
select,
button {
  width: 100%;
  border: 1px solid var(--edge);
  border-radius: 6px;
  font: inherit;
}

textarea,
select {
  background: #fffaf0;
  color: var(--ink);
}

textarea {
  min-height: 104px;
  padding: 10px;
  line-height: 1.55;
  resize: vertical;
}

select {
  height: 40px;
  padding: 0 10px;
}

.grid2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

button {
  height: 42px;
  border-color: #7f2119;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  cursor: pointer;
}

.workspace {
  min-width: 0;
  padding: 26px;
  display: grid;
  grid-template-rows: auto minmax(260px, 1fr) auto;
  gap: 18px;
}

.workspaceHeader,
.sectionTitle {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 14px;
}

.resultGrid {
  min-height: 260px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  align-content: start;
  gap: 14px;
}

.resultCard {
  overflow: hidden;
  border: 1px solid var(--edge);
  border-radius: 8px;
  background: var(--paper);
  box-shadow: 0 10px 30px rgba(56, 43, 29, .1);
}

.imageButton {
  height: 210px;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: #eee5d7;
  display: block;
}

.imageButton img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
}

.resultCard.is-selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(155, 47, 37, .22), 0 10px 30px rgba(56, 43, 29, .12);
}

.cardText {
  padding: 10px;
  display: grid;
  gap: 4px;
}

.cardText strong {
  font-size: 15px;
}

.cardText span,
.cardText small {
  color: var(--muted);
  font-size: 13px;
}

.selectButton {
  height: 34px;
  margin-top: 4px;
  font-size: 13px;
}

.collectionPanel {
  border-top: 1px solid var(--edge);
  padding-top: 18px;
  display: grid;
  gap: 12px;
}

.referenceSheet {
  min-height: 180px;
  padding: 12px;
  border: 1px solid var(--edge);
  background: var(--paper);
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 12px;
}

.referenceItem {
  border: 1px solid var(--edge);
  background: #fffaf0;
}

.referenceItem img {
  width: 100%;
  aspect-ratio: 1 / 1;
  display: block;
  object-fit: cover;
}

.referenceItem span {
  display: block;
  padding: 6px 8px;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.emptyState {
  color: var(--muted);
  font-size: 14px;
}

.lightbox[hidden] { display: none; }

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 22px;
}

.lightboxBackdrop {
  position: absolute;
  inset: 0;
  height: auto;
  border: 0;
  border-radius: 0;
  background: rgba(22, 19, 16, .72);
}

.lightboxPanel {
  position: relative;
  z-index: 1;
  width: min(1100px, 94vw);
  max-height: 92vh;
  border: 1px solid var(--edge);
  border-radius: 8px;
  background: var(--paper);
  box-shadow: 0 24px 80px rgba(0, 0, 0, .34);
  overflow: hidden;
  display: grid;
}

.lightboxPanel img {
  width: 100%;
  max-height: 74vh;
  display: block;
  object-fit: contain;
  background: #eee5d7;
}

.lightboxClose {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 38px;
  height: 38px;
  border-color: rgba(255, 255, 255, .74);
  border-radius: 50%;
  background: rgba(39, 35, 31, .78);
  font-size: 28px;
  line-height: 1;
}

.lightboxInfo {
  padding: 12px 14px;
  display: grid;
  gap: 5px;
}

.lightboxInfo span {
  color: var(--muted);
  font-size: 14px;
}

.lightboxInfo a {
  color: var(--accent);
  font-size: 14px;
  font-weight: 700;
}

@media (max-width: 820px) {
  .advancedApp { grid-template-columns: 1fr; }
  .advancedPanel { border-right: 0; border-bottom: 1px solid var(--edge); }
  .workspace { padding: 16px; }
}
