:root {
  --paper: #f6f4f0;
  --ink: #161513;
  --mute: #7a756c;
  --line: #e4dfd6;
  --accent: #9a3b1c;
  --soft: #f3e6df;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--paper);
  color: var(--ink);
  font-family: Tahoma, sans-serif;
}

html.fonts-ready,
html.fonts-ready body {
  font-family: "YekanBakhFaNum", Tahoma, sans-serif;
}

.app {
  min-height: 100vh;
}

.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.85rem 1rem;
  padding: 0.85rem 1.15rem;
  border-bottom: 1px solid var(--line);
  background: rgb(246 244 240 / 0.92);
  position: sticky;
  top: 0;
  z-index: 5;
  backdrop-filter: blur(12px);
}

.back {
  color: var(--mute);
  text-decoration: none;
  font-size: 0.85rem;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  flex: 1;
}

.mark {
  width: 2.1rem;
  height: 2.1rem;
  border-radius: 999px;
  background: var(--ink);
  color: var(--paper);
  display: grid;
  place-items: center;
  font-size: 0.62rem;
  font-weight: 800;
  letter-spacing: 0.04em;
}

.brand h1 {
  display: block;
  margin: 0;
  font-size: 0.95rem;
  font-weight: 800;
  line-height: 1.3;
}

.brand small {
  color: var(--mute);
  font-size: 0.72rem;
}

.crumbs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin: 0 0 0.85rem;
  padding: 0;
  font-size: 0.75rem;
  color: var(--mute);
  list-style: none;
}

.crumbs a {
  color: var(--accent);
  text-decoration: none;
}

.seo-block {
  padding: 0 1.15rem 2rem;
  max-width: 46rem;
}

.seo-block p {
  margin: 0;
  font-size: 0.88rem;
  line-height: 1.9;
  color: var(--mute);
}

.guide-list {
  margin: 0.85rem 0 0;
  padding: 0 1.1rem 0 0;
  color: var(--mute);
  font-size: 0.85rem;
  line-height: 1.9;
}

.guide-list li + li {
  margin-top: 0.4rem;
}

kbd.ink {
  background: var(--soft);
  color: var(--ink);
}

.seo-block h2 {
  margin: 1.75rem 0 0.7rem;
  font-size: 1.15rem;
}

.faq-list {
  margin: 0;
}

.faq-list dt {
  margin-top: 1rem;
  font-size: 0.9rem;
  font-weight: 800;
}

.faq-list dd {
  margin: 0.35rem 0 0;
  font-size: 0.85rem;
  line-height: 1.9;
  color: var(--mute);
}

.site-foot {
  padding: 1.1rem 1.15rem 1.4rem;
  border-top: 1px solid var(--line);
  text-align: center;
  font-size: 0.75rem;
  color: var(--mute);
}

.site-foot nav {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.75rem 1.1rem;
  margin-bottom: 0.65rem;
}

.site-foot a {
  color: var(--accent);
  text-decoration: none;
}

.top-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.28rem;
  min-width: 2.45rem;
  height: 2.45rem;
  padding: 0 0.7rem;
  border-radius: 999px;
}

.icon-btn svg {
  width: 1.15rem;
  height: 1.15rem;
  fill: currentColor;
  flex-shrink: 0;
}

.icon-btn span {
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.02em;
  line-height: 1;
}

.icon-btn.ghost {
  padding: 0;
}

button,
.file-btn {
  font: inherit;
  cursor: pointer;
}

.primary,
.accent,
.ghost,
.file-btn {
  border: 0;
  border-radius: 999px;
  padding: 0.55rem 0.95rem;
  font-size: 0.82rem;
  font-weight: 700;
}

.primary {
  background: var(--ink);
  color: var(--paper);
}

.accent {
  background: var(--accent);
  color: #fff;
}

.ghost {
  background: #fff;
  border: 1px solid var(--line);
}

.icon-btn.ghost {
  width: 2.45rem;
  padding: 0;
}

.icon-btn.primary,
.icon-btn.accent {
  padding: 0 0.75rem;
}

.file-btn {
  display: inline-flex;
  justify-content: center;
  background: #fff;
  border: 1px solid var(--line);
}

.file-btn.block {
  width: 100%;
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(280px, 340px);
  gap: 1rem;
  padding: 0.85rem 1.15rem 1.15rem;
  align-items: start;
}

.stage {
  min-width: 0;
}

.frame {
  position: relative;
  width: 100%;
  max-height: min(74vh, 860px);
  aspect-ratio: 16 / 9;
  border-radius: 1.1rem;
  overflow: hidden;
  border: 1px solid var(--line);
  background: #1a1916;
  box-shadow: 0 18px 40px rgb(22 21 19 / 0.08);
  margin-inline: auto;
}

.frame.is-portrait {
  width: min(100%, calc(min(74vh, 860px) * var(--ratio-w, 9) / var(--ratio-h, 16)));
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: center;
  cursor: grab;
}

canvas.is-drag {
  cursor: grabbing;
}

.drop {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  gap: 0.45rem;
  text-align: center;
  color: #f6f4f0;
  background: rgb(22 21 19 / 0.35);
  padding: 1rem;
}

.drop p {
  margin: 0;
  font-size: 0.92rem;
}

.drop .file-btn {
  margin: 0.7rem auto 0;
}

.drop.is-off {
  display: none;
}

.panel {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 1.1rem;
  padding: 0.15rem 0.85rem 0.7rem;
}

.panel section {
  padding: 0.7rem 0;
  border-bottom: 1px solid var(--line);
}

.panel section:last-child {
  border-bottom: 0;
}

.panel h2 {
  margin: 0 0 0.55rem;
  font-size: 0.74rem;
  letter-spacing: 0.04em;
  color: var(--accent);
}

label {
  display: grid;
  gap: 0.3rem;
  margin-bottom: 0.5rem;
  font-size: 0.76rem;
  color: var(--mute);
}

input[type="text"],
input[type="number"],
textarea,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 0.7rem;
  padding: 0.5rem 0.7rem;
  font: inherit;
  color: var(--ink);
  background: var(--paper);
}

textarea {
  resize: vertical;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}

.range-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.5rem;
}

.range-head b {
  color: var(--ink);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.6rem;
}

.check {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  color: var(--ink);
  font-size: 0.82rem;
}

.check input {
  accent-color: var(--accent);
}

.ratio-meta {
  margin: 0.4rem 0 0;
  font-size: 0.72rem;
  color: var(--mute);
}

.field-note {
  margin: 0 0 0.45rem;
  font-size: 0.7rem;
  line-height: 1.6;
  color: var(--mute);
}

.ghost.slim {
  width: 100%;
  margin-top: 0.35rem;
}

.frame-upload {
  margin-top: 0.65rem;
}

.color-row {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 0.55rem 0.75rem;
  margin-bottom: 0.15rem;
}

.hex-field {
  flex: 1;
  min-width: 7.2rem;
  margin: 0;
}

.hex-field input {
  font-family: ui-monospace, Consolas, monospace;
  letter-spacing: 0.04em;
  padding: 0.4rem 0.55rem;
}

.swatches {
  display: flex;
  gap: 0.45rem;
}

.swatches button {
  width: 1.7rem;
  height: 1.7rem;
  border-radius: 999px;
  border: 2px solid #fff;
  box-shadow: 0 0 0 1px var(--line);
  background: var(--c, #fff);
}

.swatches button.is-on {
  box-shadow: 0 0 0 2px var(--ink);
}

.swatches button:nth-child(1) { background: #f6f4f0; }
.swatches button:nth-child(2) { background: #fff; }
.swatches button:nth-child(3) { background: #161513; }
.swatches button:nth-child(4) { background: #9a3b1c; }

.swatch-custom {
  position: relative;
  width: 1.7rem;
  height: 1.7rem;
  border-radius: 999px;
  overflow: hidden;
  border: 2px solid #fff;
  box-shadow: 0 0 0 1px var(--line);
  background: conic-gradient(#e11d48, #f59e0b, #22c55e, #3b82f6, #a855f7, #e11d48);
  cursor: pointer;
}

.swatch-custom.is-on {
  box-shadow: 0 0 0 2px var(--ink);
}

.swatch-custom input {
  position: absolute;
  inset: -30%;
  width: 160%;
  height: 160%;
  padding: 0;
  border: 0;
  cursor: pointer;
  opacity: 0;
}

.swatch-label {
  margin: 0 0 0.4rem;
  font-size: 0.78rem;
  color: var(--mute);
}

.choice-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.4rem;
}

.choice-grid button {
  border: 1px solid var(--line);
  background: var(--paper);
  color: var(--ink);
  border-radius: 0.65rem;
  padding: 0.42rem 0.35rem;
  font-size: 0.7rem;
  font-weight: 700;
  line-height: 1.35;
}

.choice-grid button.is-on {
  background: var(--ink);
  color: var(--paper);
  border-color: var(--ink);
}

.is-hidden {
  display: none !important;
}

kbd {
  display: inline-block;
  padding: 0.05rem 0.35rem;
  border-radius: 0.3rem;
  background: rgb(255 255 255 / 0.16);
  font-size: 0.75rem;
}

@media (min-width: 961px) {
  .stage,
  .panel {
    position: sticky;
    top: 4.4rem;
  }

  .panel {
    max-height: calc(100vh - 5rem);
    overflow: auto;
  }
}

@media (max-width: 960px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .panel {
    order: 2;
  }
}
