:root {
  --bg: #010a13;
  --bg2: #0a1428;
  --panel: #0f1b2b;
  --line: #1e2d3d;
  --gold: #c8aa6e;
  --gold2: #f0e6d2;
  --teal: #0ac8b9;
  --text: #e8e2d4;
  --muted: #8d97a3;
  --radius: 10px;
  color-scheme: dark;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: radial-gradient(1200px 600px at 70% -10%, #0d2a3f 0%, transparent 60%), var(--bg);
  color: var(--text);
  font-family: "M PLUS 1p", "Hiragino Sans", "Yu Gothic", sans-serif;
  line-height: 1.6;
  -webkit-text-size-adjust: 100%;
}

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

.inapp-banner {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  background: #3a2a0a;
  border-bottom: 1px solid var(--gold);
  font-size: 13px;
  color: var(--gold2);
}
.inapp-banner p { margin: 0; flex: 1; }
.inapp-banner .btn { flex-shrink: 0; white-space: nowrap; }

dialog#save-dialog {
  width: min(900px, calc(100vw - 24px));
  padding: 16px;
  border: 1px solid var(--gold);
  border-radius: 12px;
  background: var(--bg2);
  color: var(--text);
}
dialog#save-dialog::backdrop { background: rgba(0, 0, 0, 0.8); }
.save-hint { margin: 0 0 12px; font-size: 14px; }
.save-hint strong { color: var(--gold); }
.save-hint a { color: var(--gold); font-weight: 700; }
#save-img { display: block; width: 100%; height: auto; border-radius: 8px; -webkit-touch-callout: default; user-select: auto; }

.site-header {
  padding: 18px 24px;
  border-bottom: 1px solid var(--line);
}
.logo {
  margin: 0;
  font-family: "Cinzel", serif;
  font-size: 24px;
  color: var(--gold);
  letter-spacing: 0.08em;
}
.logo span {
  margin-left: 10px;
  font-family: "M PLUS 1p", sans-serif;
  font-size: 14px;
  font-weight: 500;
  color: var(--muted);
  letter-spacing: 0;
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(360px, 1fr);
  gap: 28px;
  max-width: 1400px;
  margin: 0 auto;
  padding: 24px;
  align-items: start;
}

.preview {
  position: sticky;
  top: 20px;
}
.canvas-wrap {
  position: relative;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.55), 0 0 0 1px var(--line);
  background: var(--bg2);
}
#card {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 1200 / 675;
}
#card.draggable { cursor: grab; touch-action: none; }
#card.draggable:active { cursor: grabbing; }
.bg-tools { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 10px; }
.bg-tools .hint { margin: 0; }
.bg-tools .btn { white-space: nowrap; flex-shrink: 0; }
.loading {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--muted);
  background: var(--bg2);
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 16px;
}
.actions.sub { margin-top: 10px; }

.btn {
  border: 1px solid var(--gold);
  background: transparent;
  color: var(--gold2);
  padding: 10px 18px;
  border-radius: 6px;
  font-weight: 700;
  transition: background 0.15s, transform 0.05s;
}
.btn:hover { background: rgba(200, 170, 110, 0.12); }
.btn:active { transform: translateY(1px); }
.btn.primary {
  background: linear-gradient(180deg, #c8aa6e, #a0824a);
  color: #10161e;
  border-color: #e4c98f;
}
.btn.primary:hover { background: linear-gradient(180deg, #d8ba7e, #b0925a); }
.btn.x { border-color: #e7e9ea; color: #e7e9ea; }
.btn.ghost { border-color: var(--line); color: var(--muted); font-weight: 500; }
.btn.small { padding: 6px 12px; font-size: 14px; }

.editor {
  display: flex;
  flex-direction: column;
  gap: 16px;
}
fieldset {
  position: relative;
  margin: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(15, 27, 43, 0.7);
  padding: 14px 18px 18px;
  min-width: 0;
}
legend {
  padding: 0 8px;
  margin-left: -8px;
  color: var(--gold);
  font-weight: 800;
}
legend small { color: var(--muted); font-weight: 500; margin-left: 6px; }
.section-clear {
  position: absolute;
  top: -12px;
  right: 12px;
  border: 1px solid var(--line);
  background: var(--bg2);
  border-radius: 4px;
  padding: 2px 10px;
  font-size: 12px;
  color: var(--muted);
}
.section-clear:hover { border-color: var(--gold); color: var(--gold2); }
.form-footer { display: flex; justify-content: flex-end; }
.credit-toggle { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); cursor: pointer; }
.credit-toggle input { width: 16px; height: 16px; accent-color: var(--gold); }

.spread {
  position: relative;
  margin-top: 14px;
  padding: 14px 40px 14px 16px;
  border: 1px solid var(--gold);
  border-radius: var(--radius);
  background: rgba(200, 170, 110, 0.1);
  font-size: 14px;
}
.spread p { margin: 0 0 10px; }
.spread-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.spread-close {
  position: absolute;
  top: 6px;
  right: 8px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 18px;
}

dialog#cropper {
  width: min(640px, calc(100vw - 24px));
  padding: 16px;
  border: 1px solid var(--gold);
  border-radius: 12px;
  background: var(--bg2);
  color: var(--text);
}
.crop-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 12px; margin-bottom: 12px; }
.crop-head strong { color: var(--gold); }
.crop-head .hint { margin: 0; }
.crop-stage {
  position: relative;
  width: 100%;
  margin: 0 auto;
  overflow: hidden;
  border-radius: 8px;
  background: #000;
  touch-action: none;
  cursor: grab;
  user-select: none;
}
.crop-stage:active { cursor: grabbing; }
.crop-stage img {
  position: absolute;
  top: 0;
  left: 0;
  max-width: none;
  transform-origin: 0 0;
  pointer-events: none;
}
.crop-mask {
  position: absolute;
  inset: 0;
  pointer-events: none;
  box-shadow: inset 0 0 0 2px var(--gold);
  border-radius: 8px;
}
.crop-mask.round {
  border-radius: 0;
  box-shadow: none;
  background: radial-gradient(circle closest-side, transparent 98%, var(--gold) 98.5%, rgba(0, 0, 0, 0.6) 100%);
}
.crop-zoom { margin-top: 12px; }
.hint { margin: 0 0 10px; font-size: 13px; color: var(--muted); }

.row { display: flex; gap: 12px; flex-wrap: wrap; }
.grow { flex: 1 1 180px; min-width: 0; }
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
  margin-top: 10px;
  position: relative;
}
.field.small { flex: 0 0 120px; }
.field.tag { flex: 0 0 120px; }

input:not([type=range]), select, textarea {
  width: 100%;
  background: #061019;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px 12px;
  color: var(--text);
  font-size: 16px;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(200, 170, 110, 0.15);
}
textarea { resize: vertical; }
input[type=range] { width: 100%; accent-color: var(--gold); }

.prefix { position: relative; display: block; }
.prefix::before {
  content: "#";
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
  font-size: 16px;
}
.prefix.at::before { content: "@"; }
.prefix input { padding-left: 28px; }

.counter { position: absolute; right: 10px; bottom: 8px; font-size: 12px; }

.picker-row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.picker-row select { flex: 1 1 160px; width: auto; }

.champ-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 48px;
  padding: 4px 14px 4px 4px;
  border: 1px dashed var(--gold);
  background: #061019;
  border-radius: 8px;
  color: var(--text);
}
.champ-btn img { width: 40px; height: 40px; border-radius: 6px; object-fit: cover; }
.champ-btn img.wide { width: 72px; }
.btn.upload { display: inline-flex; align-items: center; cursor: pointer; }
.btn.upload:focus-within { outline: 2px solid var(--gold); }
.field .picker-row + .picker-row { margin-top: 8px; }
.champ-btn .empty { padding-left: 10px; color: var(--gold); }

.segmented { display: inline-flex; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; align-self: flex-start; }
.segmented button { border: 0; background: transparent; padding: 8px 18px; color: var(--muted); }
.segmented button.on { background: rgba(200, 170, 110, 0.18); color: var(--gold2); }

.roles { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 8px; }
.role {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 10px 4px 8px;
  border: 1px solid var(--line);
  background: #061019;
  border-radius: 8px;
}
.role img { width: 32px; height: 32px; opacity: 0.55; }
.role span { font-weight: 700; font-size: 13px; opacity: 0.55; }
.role.sub img, .role.sub span, .role.main img, .role.main span { opacity: 1; }
.role.sub { border-color: rgba(200, 170, 110, 0.5); }
.role.main { border-color: var(--gold); background: rgba(200, 170, 110, 0.15); }
.role-btns { display: flex; flex-direction: column; gap: 4px; width: 100%; margin-top: 6px; }
.role-btns button {
  border: 1px solid var(--line);
  background: transparent;
  border-radius: 4px;
  padding: 3px 0;
  font-size: 12px;
  color: var(--muted);
}
.role-btns button:hover { border-color: rgba(200, 170, 110, 0.6); }
.role-btns button.on { border-color: var(--gold); background: rgba(200, 170, 110, 0.22); color: var(--gold2); font-weight: 700; }
.role-btns button { font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.role-btns button[data-setrole="normal"].on { border-color: #8d97a3; background: rgba(141, 151, 163, 0.18); color: var(--text); }
.role-btns button[data-setrole="ng"].on { border-color: #d9605a; background: rgba(217, 96, 90, 0.2); color: #ffb3ae; }
.role.normal img, .role.normal span { opacity: 0.8; }
.role.ng { border-color: rgba(217, 96, 90, 0.5); }

.champ-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 10px; }
.champ-item, .champ-add {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 8px 6px;
  border: 1px solid var(--line);
  background: #061019;
  border-radius: 8px;
  font-size: 12px;
  text-align: center;
}
.champ-item img { width: 60px; height: 60px; border-radius: 8px; border: 1px solid var(--gold); }
.champ-item span { width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.editor .champ-role { padding: 4px 6px; font-size: 13px; }
.champ-ops { display: flex; gap: 4px; }
.champ-ops button {
  border: 1px solid var(--line);
  background: transparent;
  border-radius: 4px;
  width: 28px;
  height: 24px;
  padding: 0;
  color: var(--muted);
}
.champ-ops button:disabled { opacity: 0.3; cursor: default; }
.champ-add { justify-content: center; min-height: 120px; border-style: dashed; border-color: var(--gold); color: var(--gold); font-size: 14px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  border: 1px solid var(--line);
  background: #061019;
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 14px;
  color: var(--muted);
}
.chip.on { border-color: var(--gold); background: rgba(200, 170, 110, 0.18); color: var(--gold2); }
.chip.custom { padding-right: 8px; }
.name-presets { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 8px; margin-top: 8px; font-size: 12px; color: var(--muted); }
.name-presets .chip { padding: 3px 10px; font-size: 12px; }
.chip-del {
  display: inline-block;
  margin-left: 6px;
  padding: 0 4px;
  border-radius: 50%;
  color: var(--muted);
}
.chip-del:hover { color: var(--gold2); background: rgba(255, 255, 255, 0.08); }
.chip.add { border-style: dashed; border-color: var(--gold); color: var(--gold); }
.editor .chip-input {
  width: 150px;
  padding: 6px 14px;
  border-radius: 999px;
  border-color: var(--gold);
  font-size: 14px;
}

.themes { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 8px; }
.theme {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 6px;
  border: 1px solid var(--line);
  background: #061019;
  border-radius: 8px;
  font-size: 12px;
  color: var(--muted);
}
.theme i {
  display: block;
  height: 34px;
  border-radius: 5px;
  background: linear-gradient(135deg, var(--b), var(--c));
  border: 2px solid var(--a);
}
.theme.on { border-color: var(--gold); color: var(--gold2); }

dialog#skin-picker {
  width: min(760px, calc(100vw - 32px));
  max-height: min(80vh, 720px);
  padding: 0;
  border: 1px solid var(--gold);
  border-radius: 12px;
  background: var(--bg2);
  color: var(--text);
}
#skin-picker .picker-head { align-items: center; justify-content: space-between; }
#skin-picker .picker-head strong { color: var(--gold); }
.skin-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 10px;
  padding: 14px;
}
.skin-grid button {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  background: #061019;
  border-radius: 8px;
  font-size: 12px;
  text-align: center;
}
.skin-grid button:hover { border-color: var(--gold); }
.skin-grid img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 6px; }
.champ-img-btn {
  border: 1px solid var(--line);
  background: transparent;
  border-radius: 4px;
  padding: 2px 6px;
  font-size: 11px;
  color: var(--muted);
  width: 100%;
}
.champ-img-btn:hover { border-color: var(--gold); color: var(--gold2); }
.champ-item img { object-fit: cover; }

dialog#picker {
  width: min(760px, calc(100vw - 32px));
  max-height: min(80vh, 720px);
  padding: 0;
  border: 1px solid var(--gold);
  border-radius: 12px;
  background: var(--bg2);
  color: var(--text);
}
dialog::backdrop { background: rgba(0, 0, 0, 0.7); }
.picker-head {
  position: sticky;
  top: 0;
  display: flex;
  gap: 10px;
  padding: 14px;
  background: var(--bg2);
  border-bottom: 1px solid var(--line);
  z-index: 1;
}
.picker-head .btn { white-space: nowrap; }
.picker-roles { display: flex; align-items: center; gap: 10px; padding: 10px 14px 0; font-size: 13px; color: var(--muted); flex-wrap: wrap; }
.picker-roles .segmented button { padding: 6px 12px; font-weight: 700; }
.picker-tabs { display: flex; gap: 4px; padding: 10px 14px 0; }
.picker-tabs button {
  flex: 1;
  border: 1px solid var(--line);
  background: #061019;
  border-radius: 6px;
  padding: 8px;
  color: var(--muted);
  font-weight: 700;
}
.picker-tabs button.on { border-color: var(--gold); background: rgba(200, 170, 110, 0.18); color: var(--gold2); }
.picker-status { margin: 8px 14px 0; font-size: 13px; color: var(--muted); }
.picker-status:empty { display: none; }
.picker-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(84px, 1fr));
  gap: 8px;
  padding: 14px;
}
.picker-grid button {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 6px 2px;
  border: 1px solid transparent;
  background: transparent;
  border-radius: 8px;
  font-size: 12px;
}
.picker-grid button:hover { background: rgba(200, 170, 110, 0.1); }
.picker-grid button.on { border-color: var(--gold); background: rgba(200, 170, 110, 0.18); }
.picker-grid button.partial { border-color: rgba(200, 170, 110, 0.45); border-style: dashed; }
.picker-grid em { font-style: normal; font-size: 10px; color: var(--gold); line-height: 1.2; }
.picker-grid img { width: 60px; height: 60px; border-radius: 8px; background: #061019; }
.picker-grid span { width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; text-align: center; }
.picker-empty { grid-column: 1 / -1; color: var(--muted); text-align: center; }
.picker-grid .picker-more {
  grid-column: 1 / -1;
  padding: 12px;
  border: 1px dashed var(--line);
  color: var(--muted);
  font-size: 14px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translate(-50%, 20px);
  max-width: calc(100vw - 32px);
  padding: 12px 20px;
  border-radius: 8px;
  border: 1px solid var(--gold);
  background: #0a1428f2;
  color: var(--gold2);
  font-size: 14px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 10;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.guide {
  max-width: 1000px;
  margin: 40px auto 0;
  padding: 0 24px;
  line-height: 1.8;
}
.guide section { margin-bottom: 40px; }
.guide h2 {
  margin: 0 0 12px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--line);
  color: var(--gold);
  font-size: 20px;
}
.guide p { margin: 0 0 10px; }
.guide strong { color: var(--gold2); }
.steps { margin: 0; padding-left: 1.4em; }
.steps li { margin-bottom: 12px; }
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; margin-top: 16px; }
.gallery figure { margin: 0; }
.gallery img { display: block; width: 100%; height: auto; border-radius: 8px; border: 1px solid var(--line); }
.gallery figcaption { margin-top: 6px; font-size: 13px; color: var(--muted); text-align: center; }
.faq dt { margin-top: 14px; font-weight: 700; color: var(--gold2); }
.faq dt::before { content: "Q. "; color: var(--gold); }
.faq dd { margin: 4px 0 0; color: var(--text); }
.faq dd::before { content: "A. "; color: var(--muted); }

.site-footer {
  max-width: 1400px;
  margin: 20px auto 0;
  padding: 20px 24px 40px;
  border-top: 1px solid var(--line);
  font-size: 13px;
  color: var(--muted);
}
.site-footer .legal { font-size: 11px; opacity: 0.8; }
.site-footer a { color: var(--gold); }

@media (max-width: 900px) {
  .layout { grid-template-columns: minmax(0, 1fr); padding: 16px; gap: 18px; }
  .actions.sub .btn { padding: 4px 10px; font-size: 13px; }
  .preview {
    top: 0;
    z-index: 5;
    margin: -16px -16px 0;
    padding: 12px 16px;
    background: rgba(1, 10, 19, 0.95);
    border-bottom: 1px solid var(--line);
  }
  .actions { margin-top: 10px; }
  .actions .btn { flex: 1 1 auto; padding: 8px 10px; font-size: 14px; }
  .site-header { padding: 14px 16px; }
  .logo { font-size: 20px; }
  .logo span { display: block; margin: 2px 0 0; }
  .site-footer { padding: 20px 16px 40px; }
}
