:root {
  --ink: #2c1b17;
  --muted: #7a6660;
  --line: #eadfd5;
  --panel: #fffaf5;
  --accent: #a91116;
  --accent-dark: #7d0d11;
  --gold: #bd761b;
  --stage: #1d1717;
  --poster-ratio: 1086 / 1448;
}

* { box-sizing: border-box; }

html, body { min-height: 100%; }

body {
  margin: 0;
  color: var(--ink);
  background: #f3ede8;
  font-family: system-ui, -apple-system, "Segoe UI", "Microsoft YaHei", sans-serif;
}

button, input, select { font: inherit; }

.topbar {
  min-height: 76px;
  padding: 14px clamp(18px, 4vw, 54px);
  display: flex;
  align-items: center;
  gap: 14px;
  background: #fffdfa;
  border-bottom: 1px solid var(--line);
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 46px;
  height: 34px;
  border-radius: 7px;
  color: #fff;
  background: var(--accent);
  font-size: 15px;
  font-weight: 800;
  letter-spacing: .04em;
}

h1, h2, p { margin: 0; }

h1 { font-size: 19px; line-height: 1.2; letter-spacing: .02em; }
.topbar p { margin-top: 4px; color: var(--muted); font-size: 12px; }

.top-actions { margin-left: auto; display: flex; gap: 10px; }

.button {
  border: 1px solid transparent;
  border-radius: 9px;
  min-height: 38px;
  padding: 8px 14px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 650;
  transition: transform .15s ease, box-shadow .15s ease, background .15s ease;
}
.button:hover { transform: translateY(-1px); }
.button:active { transform: translateY(0); }
.button:disabled { cursor: not-allowed; opacity: .65; transform: none; box-shadow: none; }
.button-primary { color: #fff; background: var(--accent); box-shadow: 0 4px 14px #a9111629; }
.button-primary:hover { background: var(--accent-dark); }
.button-quiet { color: #5e4a43; border-color: var(--line); background: #fff; }
.button-outline { display: inline-grid; place-items: center; color: var(--accent); border-color: #dca9a2; background: #fff9f7; }
.upload-button { width: 100%; cursor: pointer; }

.app-shell {
  width: min(1920px, 100%);
  margin: 0 auto;
  padding: 16px clamp(18px, 4vw, 54px) 4px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(280px, 320px);
  grid-template-areas: "preview controls";
  gap: 26px;
}

.control-panel {
  grid-area: controls;
  align-self: start;
  border: 1px solid var(--line);
  border-radius: 14px;
  overflow: hidden;
  background: var(--panel);
  box-shadow: 0 8px 28px #6d35250c;
}

.panel-section { padding: 20px; border-bottom: 1px solid var(--line); }
.panel-section:last-child { border-bottom: 0; }
.section-title-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
h2 { font-size: 14px; letter-spacing: .04em; }
.pill, .state { border-radius: 999px; padding: 3px 8px; font-size: 11px; white-space: nowrap; }
.pill { color: var(--accent); background: #f9e9e6; }
.state-warning { color: #8c591e; background: #fff0d9; }
.state-ok { color: #246348; background: #e5f5ea; }
.font-lock { display: flex; align-items: center; gap: 9px; margin-top: 12px; padding: 10px 11px; border: 1px solid #d9e9dc; border-radius: 9px; color: #305d42; background: #f3fbf4; font-size: 12px; }
.lock-icon { display: grid; place-items: center; width: 19px; height: 19px; flex: 0 0 auto; border-radius: 50%; color: #fff; background: #4b9467; font-size: 12px; font-weight: 800; }

.field { display: grid; grid-template-columns: 70px minmax(0, 1fr); align-items: center; gap: 10px; margin-top: 13px; }
.field span { color: var(--muted); font-size: 13px; }
.field input, .field select {
  width: 100%;
  min-width: 0;
  border: 1px solid #e0d2ca;
  border-radius: 8px;
  padding: 9px 10px;
  color: var(--ink);
  background: #fff;
  outline: none;
  appearance: auto;
  transition: border-color .15s ease, box-shadow .15s ease;
}
.field input:focus, .field select:focus { border-color: #c86b65; box-shadow: 0 0 0 3px #bb49411c; }

.help-text, .file-name, .font-note, .tips-section li { color: var(--muted); font-size: 12px; line-height: 1.65; }
.help-text { margin: 10px 0 13px; }
.layout-note { margin-bottom: 0; }
.layout-note.layout-warning { color: var(--accent); }
.template-help { margin-bottom: 0; }
.file-name { margin-top: 8px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.font-note { display: flex; gap: 7px; margin-top: 13px; padding: 9px 10px; border-radius: 8px; background: #fff6e9; }
.note-dot { flex: 0 0 auto; width: 7px; height: 7px; margin-top: 6px; border-radius: 50%; background: #c47a1d; }
code { font-size: 11px; color: #7d4e1b; }
.tips-section ul { margin: 12px 0 0; padding-left: 18px; }
.tips-section li + li { margin-top: 7px; }

.preview-panel { grid-area: preview; min-width: 0; }
.preview-toolbar { display: flex; justify-content: space-between; align-items: center; margin: 0 0 8px; }
.preview-toolbar strong { font-size: 15px; }
#previewHint { margin-left: 10px; color: var(--muted); font-size: 12px; }
.load-state { color: var(--muted); font-size: 12px; }
.load-state.loaded { color: #246348; }

.poster-layout { display: grid; grid-template-columns: minmax(156px, 184px) minmax(0, 1fr); gap: 14px; align-items: start; }
.template-switcher { padding: 16px; border: 1px solid var(--line); border-radius: 14px; background: var(--panel); box-shadow: 0 8px 28px #6d35250c; }
.template-options { display: grid; gap: 9px; margin-top: 15px; }
.template-card {
  display: grid;
  grid-template-columns: 58px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 7px;
  border: 1px solid #e0d2ca;
  border-radius: 10px;
  color: var(--ink);
  background: #fff;
  text-align: left;
  cursor: pointer;
  transition: border-color .15s ease, box-shadow .15s ease, background .15s ease, transform .15s ease;
}
.template-card:hover { border-color: #c86b65; transform: translateY(-1px); }
.template-card:focus-visible { outline: 3px solid #bb49414a; outline-offset: 1px; }
.template-card.is-active {
  border-color: var(--accent);
  background: #fff7f5;
  box-shadow: 0 0 0 2px #a9111622, 0 5px 14px #6d352512;
}
.template-thumb {
  display: block;
  width: 58px;
  overflow: hidden;
  border-radius: 6px;
  background: #24191a;
}
.template-thumb img { display: block; width: 100%; height: auto; object-fit: contain; }
.template-card-label { min-width: 0; font-size: 12px; line-height: 1.45; font-weight: 650; }
.template-switcher .template-help { margin: 12px 0 0; }

.poster-stage {
  display: grid;
  place-items: center;
  min-height: 0;
  padding: 8px;
  border: 1px solid #3d2b2b;
  border-radius: 14px;
  background: var(--stage);
  box-shadow: 0 18px 50px #3e191922;
}

.poster {
  position: relative;
  width: min(100%, var(--poster-max-width, 100%));
  max-width: 100%;
  aspect-ratio: var(--poster-ratio);
  overflow: hidden;
  isolation: isolate;
  background: #fff;
  box-shadow: 0 12px 38px #0008;
}
.poster-canvas { display: block; width: 100%; height: 100%; object-fit: contain; }

.poster-canvas { user-select: none; }

.toast { position: fixed; left: 50%; bottom: 24px; z-index: 10; max-width: min(90vw, 500px); padding: 10px 15px; border-radius: 999px; color: #fff; background: #2b211eeb; box-shadow: 0 8px 24px #0003; font-size: 13px; opacity: 0; transform: translate(-50%, 12px); pointer-events: none; transition: opacity .2s ease, transform .2s ease; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.save-modal[hidden] { display: none; }
.save-modal { position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; padding: 18px; background: #1d1717d9; }
.save-modal-card { position: relative; display: grid; justify-items: center; gap: 12px; width: min(100%, 520px); max-height: 92dvh; overflow: auto; padding: 22px; border-radius: 16px; background: #fffaf5; text-align: center; box-shadow: 0 18px 60px #0005; }
.save-modal-card > p { color: var(--muted); font-size: 14px; line-height: 1.6; }
.save-modal-close { position: absolute; top: 8px; right: 10px; width: 36px; height: 36px; border: 0; border-radius: 50%; color: var(--muted); background: #f3ede8; font-size: 24px; line-height: 1; cursor: pointer; }
.save-modal-image { display: block; max-width: 100%; max-height: 66dvh; width: auto; height: auto; object-fit: contain; border-radius: 6px; background: #fff; -webkit-touch-callout: default; user-select: auto; -webkit-user-select: auto; }
.save-modal-card > .save-modal-hint { font-size: 12px; }

@media (max-width: 780px) {
  .topbar { align-items: flex-start; flex-wrap: wrap; }
  .top-actions { width: 100%; margin-left: 60px; }
  .top-actions .button { flex: 1; }
  .app-shell {
    grid-template-columns: 1fr;
    grid-template-areas: "preview" "controls";
    padding-top: 18px;
  }
  .poster-stage { min-height: 0; padding: 12px; }
  .poster-layout { grid-template-columns: 1fr; gap: 12px; }
  .template-switcher { order: 1; }
  .template-options { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
  .template-card { grid-template-columns: 1fr; justify-items: center; gap: 4px; padding: 5px; }
  .template-thumb { width: 100%; max-width: 52px; border-radius: 5px; }
  .template-card-label { font-size: 11px; white-space: nowrap; }
  .poster-stage { order: 2; }
  .poster { width: 100%; height: auto; }
  #previewHint { display: none; }
  .save-modal { padding: 10px; }
  .save-modal-card { gap: 9px; padding: 17px 14px; }
  .save-modal-image { max-height: 66dvh; }
}
