:root {
  --paper: #fdf8f4;
  --paper-deep: #f8efe6;
  --card: #ffffff;
  --ink: #4a3f3a;
  --ink-soft: #8a7a72;
  --line: #efe3d8;
  --rose: #e79ab5;
  --rose-deep: #d97a9a;
  --sage: #7fa060;
  --sage-deep: #5f7f47;
  --lilac: #b49ad8;
  --sun: #f0c75e;
  --sky: #8fbce0;
  --radius: 18px;
  --shadow: 0 10px 30px rgba(122, 90, 70, 0.09);
  --font-body: "Nunito Sans", "Segoe UI", system-ui, -apple-system, sans-serif;
  --font-display: "Caveat", "Segoe Print", "Comic Sans MS", cursive;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-body);
  color: var(--ink);
  background:
    radial-gradient(900px 480px at 12% -6%, rgba(231, 154, 181, 0.14), transparent 60%),
    radial-gradient(820px 460px at 96% 0%, rgba(180, 154, 216, 0.13), transparent 55%),
    radial-gradient(700px 500px at 50% 110%, rgba(127, 160, 96, 0.12), transparent 60%),
    var(--paper);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  line-height: 1.5;
}

.page {
  width: min(1080px, 100% - 2rem);
  margin: 0 auto;
  padding: 1.4rem 0 2.5rem;
}

.back-btn {
  position: fixed;
  top: 0.9rem;
  left: 0.9rem;
  z-index: 60;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font: inherit;
  font-size: 0.88rem;
  font-weight: 700;
  color: #5b4a44;
  background: #ffffff;
  border: 1.5px solid var(--line);
  border-radius: 999px;
  padding: 0.42rem 0.9rem;
  text-decoration: none;
  box-shadow: 0 4px 14px rgba(122, 90, 70, 0.12);
  transition: border-color 0.15s ease, transform 0.12s ease;
}

.back-btn:hover { border-color: var(--rose); transform: translateY(-1px); }
.back-btn:focus-visible { outline: none; box-shadow: 0 0 0 4px rgba(143, 188, 224, 0.45); }
.back-btn-arrow { font-size: 1.05em; line-height: 1; }

@media (max-width: 480px) {
  .back-btn { top: 0.55rem; left: 0.55rem; padding: 0.34rem 0.75rem; font-size: 0.82rem; }
}

.seo-article {
  display: grid;
  gap: 1.6rem;
}

.article-header {
  text-align: center;
  padding: 0.4rem 0 0.4rem;
}

.article-kicker {
  display: inline-block;
  margin: 0 0 0.6rem;
  font-size: 0.74rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--rose-deep);
  background: #fdf0f5;
  border: 1px solid #f6dbe4;
  border-radius: 999px;
  padding: 0.22rem 0.75rem;
}

.article-header h1 {
  font-family: var(--font-display);
  font-size: clamp(2.05rem, 5.4vw, 3rem);
  font-weight: 700;
  margin: 0;
  color: #5b4a44;
  letter-spacing: 0.4px;
  line-height: 1.12;
}

.lede {
  margin: 0.8rem auto 0;
  max-width: 44rem;
  color: var(--ink-soft);
  font-size: clamp(0.98rem, 2.6vw, 1.08rem);
}

.article-section {
  text-align: center;
}

.article-section h2 {
  font-family: var(--font-display);
  font-size: clamp(1.55rem, 3.8vw, 2.05rem);
  font-weight: 700;
  color: #5b4a44;
  margin: 0 auto 0.7rem;
  line-height: 1.2;
}

.article-section p {
  margin: 0 auto 0.85rem;
  max-width: 44rem;
  color: var(--ink);
  font-size: clamp(0.95rem, 2.4vw, 1.02rem);
  line-height: 1.65;
}

.article-section p:last-child { margin-bottom: 0; }

.tool-section { scroll-margin-top: 1rem; }

.tool-section .app {
  margin-top: 1.2rem;
  text-align: left;
}

.conclusion {
  background: linear-gradient(180deg, rgba(253, 240, 245, 0.75), rgba(255, 255, 255, 0.9));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.4rem 1.2rem 1.5rem;
  box-shadow: var(--shadow);
}

.cta-btn {
  display: inline-flex;
  width: auto;
  margin-top: 0.5rem;
  text-decoration: none;
  padding: 0.72rem 1.5rem;
  font-size: 1rem;
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.1rem 1.2rem;
}

.app { display: grid; gap: 1rem; }

.name-card .name-row {
  display: flex;
  gap: 0.8rem;
  align-items: flex-end;
  flex-wrap: wrap;
}

.field { display: flex; flex-direction: column; gap: 0.3rem; }
.field.grow { flex: 1 1 240px; min-width: 0; }

.field label, .group-title {
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-soft);
  margin: 0 0 0.1rem;
}

#nameInput {
  width: 100%;
  font: inherit;
  font-size: clamp(1.15rem, 3.6vw, 1.5rem);
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink);
  background: #fffcfa;
  border: 1.5px solid var(--line);
  border-radius: 12px;
  padding: 0.62rem 0.9rem;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

#nameInput:focus {
  border-color: var(--rose);
  box-shadow: 0 0 0 4px rgba(231, 154, 181, 0.22);
}

.btn-col {
  display: flex;
  gap: 0.5rem;
  flex: 0 0 auto;
}

.btn {
  font: inherit;
  font-weight: 700;
  font-size: 0.92rem;
  border-radius: 12px;
  border: 1.5px solid transparent;
  padding: 0.6rem 1rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  transition: transform 0.12s ease, box-shadow 0.15s ease, background 0.15s ease, border-color 0.15s ease;
  color: var(--ink);
  background: #fff;
  white-space: nowrap;
}

.btn:active { transform: translateY(1px) scale(0.99); }
.btn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 4px rgba(143, 188, 224, 0.4);
}

.btn-icon { font-size: 1.05em; line-height: 1; }

.btn-primary {
  background: linear-gradient(180deg, #f0a8c0, #e79ab5);
  border-color: #e290ad;
  color: #5c2738;
  width: 100%;
  box-shadow: 0 4px 14px rgba(231, 154, 181, 0.45);
}

.btn-primary:hover { background: linear-gradient(180deg, #f4b3c8, #eb9fbe); }

.btn-secondary {
  background: #fff;
  border-color: var(--line);
  width: 100%;
}

.btn-secondary:hover { border-color: #e2cdbd; background: #fffaf6; }

.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--ink-soft);
  width: 100%;
}

.btn-ghost:hover { color: var(--ink); background: var(--paper-deep); }

.btn[disabled] { opacity: 0.45; cursor: not-allowed; }

.hint {
  margin: 0.55rem 0 0;
  font-size: 0.82rem;
  color: var(--ink-soft);
}

.app-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 1rem;
  align-items: start;
}

.preview-card { padding: 1rem; }

.preview-wrap {
  position: relative;
  width: min(100%, 430px);
  margin: 0 auto;
  aspect-ratio: 3 / 4;
  border-radius: 14px;
  overflow: hidden;
  background-color: var(--preview-bg, #fbf6ef);
  border: 1px solid var(--line);
}

.preview-wrap.is-transparent {
  background-color: #ffffff;
  background-image:
    conic-gradient(#e9e4de 90deg, #ffffff 90deg 180deg, #e9e4de 180deg 270deg, #ffffff 270deg);
  background-size: 22px 22px;
  background-position: 0 0;
}

#previewCanvas {
  display: block;
  width: 100%;
  height: 100%;
}

.empty-hint {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  margin: 0;
  padding: 1rem;
  text-align: center;
  font-family: var(--font-display);
  font-size: 1.6rem;
  color: #b7a49a;
  pointer-events: none;
}

.empty-hint[hidden] { display: none; }

.legend-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  justify-content: center;
  margin-top: 0.85rem;
  min-height: 0.5rem;
}

.chip {
  font-size: 0.78rem;
  font-weight: 700;
  border-radius: 999px;
  padding: 0.18rem 0.6rem;
  background: #fdf3f6;
  border: 1px solid #f6dbe4;
  color: #96506a;
  display: inline-flex;
  gap: 0.35rem;
  align-items: baseline;
}

.chip .chip-letter { font-family: var(--font-display); font-size: 1.05rem; color: #7c3f56; }

.controls-card { display: grid; gap: 1.15rem; }

.control-group { display: grid; gap: 0.55rem; }
.group-title { margin: 0; }

.swatch-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}

.swatch {
  width: 2.1rem;
  height: 2.1rem;
  border-radius: 50%;
  border: 2px solid rgba(0, 0, 0, 0.08);
  cursor: pointer;
  padding: 0;
  position: relative;
  transition: transform 0.12s ease, box-shadow 0.15s ease;
  background-clip: padding-box;
}

.swatch:hover { transform: scale(1.08); }
.swatch:focus-visible { outline: none; box-shadow: 0 0 0 4px rgba(143, 188, 224, 0.45); }

.swatch.is-active {
  box-shadow: 0 0 0 2.5px #fff, 0 0 0 5px var(--rose-deep);
}

.swatch.swatch-transparent {
  background-image:
    conic-gradient(#d9d4ce 90deg, #ffffff 90deg 180deg, #d9d4ce 180deg 270deg, #ffffff 270deg);
  background-size: 10px 10px;
  border-color: #cfc8c0;
}

.swatch.swatch-transparent::after {
  content: "";
  position: absolute;
  inset: -1px;
  border-radius: 50%;
  background: linear-gradient(45deg, transparent 45%, #e2574c 45%, #e2574c 55%, transparent 55%);
}

.color-field {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--ink-soft);
}

.color-field input[type="color"] {
  -webkit-appearance: none;
  appearance: none;
  width: 2.6rem;
  height: 1.9rem;
  border: 1.5px solid var(--line);
  border-radius: 8px;
  background: none;
  padding: 2px;
  cursor: pointer;
}

.color-field input[type="color"]::-webkit-color-swatch-wrapper { padding: 0; }
.color-field input[type="color"]::-webkit-color-swatch { border: none; border-radius: 5px; }

.controls-card .btn + .btn { margin-top: 0.1rem; }

.mapping-card summary {
  cursor: pointer;
  font-weight: 700;
  color: var(--ink-soft);
  font-size: 0.95rem;
  padding: 0.1rem 0.2rem;
}

.mapping-card summary:focus-visible { outline: 2px solid var(--sky); border-radius: 6px; }

.mapping-list {
  list-style: none;
  margin: 0.8rem 0 0.2rem;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 0.35rem 0.8rem;
}

.mapping-list li {
  display: flex;
  gap: 0.5rem;
  align-items: baseline;
  font-size: 0.86rem;
  color: var(--ink);
  padding: 0.18rem 0.3rem;
  border-radius: 8px;
}

.mapping-list li.is-used { background: #fdf3f6; }

.mapping-list .map-letter {
  font-family: var(--font-display);
  font-size: 1.25rem;
  color: var(--rose-deep);
  min-width: 1.1rem;
  text-align: center;
}

.mapping-list .map-name { color: var(--ink-soft); }

.site-footer {
  text-align: center;
  color: var(--ink-soft);
  font-size: 0.82rem;
  padding: 1.2rem 0 0;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 1.2rem;
  transform: translateX(-50%) translateY(120%);
  background: #43372f;
  color: #fff8f1;
  font-size: 0.9rem;
  font-weight: 600;
  padding: 0.65rem 1.1rem;
  border-radius: 999px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25);
  z-index: 50;
  max-width: min(92vw, 420px);
  text-align: center;
  transition: transform 0.28s ease;
}

.toast.is-visible { transform: translateX(-50%) translateY(0); }

@media (min-width: 880px) {
  .app-grid {
    grid-template-columns: minmax(0, 1.05fr) minmax(300px, 0.95fr);
  }

  .preview-card { order: 0; position: sticky; top: 1rem; }
  .controls-card { order: 1; }

  .page { padding-top: 2rem; }
}

@media (max-width: 879px) {
  .name-card { order: 0; }
  .app-grid { display: contents; }

  .preview-card { order: 1; }
  .controls-card { order: 2; }
  .mapping-card { order: 3; }

  .btn-col { flex: 1 1 100%; }
  .btn-col .btn { flex: 1; }

  .page {
    width: min(1080px, 100% - 1.2rem);
    padding-top: 1rem;
  }

  .card { padding: 0.95rem 1rem; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
