/* ---------------------------------------------------------------
   #สั่งฟ้องสว. — profile frame maker
   ธีมสีแดง–น้ำเงิน เก็บโทนจากงานอาร์ตของเฟรม
---------------------------------------------------------------- */

:root {
  --red: #f42f47;
  --red-dark: #cf1f36;
  --blue: #2400a5;
  --blue-dark: #1a0079;
  --ink: #14001f;
  --paper: #ffffff;
  --mist: #f4f2f8;
  --line: #14001f;
  --radius: 14px;
  --shadow: 6px 6px 0 var(--blue);
  --shadow-sm: 4px 4px 0 var(--blue);
  --font-display: 'Noto Sans Thai Looped', 'Noto Sans Thai', system-ui, sans-serif;
  --font-body: 'Noto Sans Thai', system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }

/* .btn / .controls กำหนด display เอง จึงต้องบังคับให้ hidden ชนะเสมอ */
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background:
    radial-gradient(90rem 40rem at 110% -10%, rgba(36, 0, 165, .10), transparent 60%),
    radial-gradient(70rem 36rem at -10% 0%, rgba(244, 47, 71, .12), transparent 60%),
    var(--paper);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.7;
  min-height: 100dvh;
}

.wrap { width: min(72rem, 100% - 2rem); margin-inline: auto; }

a { color: var(--blue); text-underline-offset: 3px; }
a:hover { color: var(--red); }

.skip-link {
  position: absolute; left: -9999px; top: 0;
  background: var(--ink); color: #fff; padding: .6rem 1rem; z-index: 50;
}
.skip-link:focus { left: .5rem; top: .5rem; }

/* ---------------- lucide icons ---------------- */

.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }

/* <use> ไม่รับค่า presentation attribute จาก <svg> ต้นทาง จึงกำหนดสไตล์เส้นที่นี่ */
.i {
  width: 1.15em; height: 1.15em;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  vertical-align: -.2em;
}

/* ---------------- hero ---------------- */

.hero { padding: clamp(1.75rem, 5vw, 3.5rem) 0 clamp(1rem, 3vw, 2rem); text-align: center; }

.badge {
  display: inline-flex;
  align-items: center;
  gap: .45em;
  margin: 0 0 1.25rem;
  padding: .35rem .9rem;
  border: 2px solid var(--line);
  border-radius: 999px;
  background: var(--paper);
  box-shadow: 3px 3px 0 var(--blue);
  font-size: .82rem;
  font-weight: 600;
  letter-spacing: .01em;
}

.hero__title { margin: 0; font-size: 0; }
.hero__title img {
  display: block;
  width: min(36rem, 92%);
  height: auto;
  margin-inline: auto;
}

.hero__lead {
  margin: 1.5rem auto 0;
  max-width: 40rem;
  font-size: clamp(1rem, 2.4vw, 1.2rem);
  text-wrap: balance;   /* กันไม่ให้บรรทัดสุดท้ายเหลือคำโดด ๆ */
}
.hero__lead strong { color: var(--red); font-weight: 700; }

/* ---------------- panels ---------------- */

.app { padding-bottom: 3rem; display: grid; gap: clamp(1rem, 3vw, 1.5rem); }

.panel {
  background: var(--paper);
  border: 3px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: clamp(1rem, 3vw, 1.6rem);
}

.step {
  display: flex; align-items: center; gap: .6rem;
  margin: 0 0 1rem;
  font-family: var(--font-display);
  font-size: clamp(1.15rem, 3.2vw, 1.45rem);
  font-weight: 700;
}
.step__i { color: var(--blue); width: 1.2em; height: 1.2em; }

.step__no {
  display: grid; place-items: center;
  width: 1.9rem; height: 1.9rem;
  background: var(--red); color: #fff;
  border-radius: 999px;
  font-size: 1rem; font-weight: 700;
  flex: none;
}

/* ---------------- frame picker ---------------- */

.frames {
  list-style: none; margin: 0 auto; padding: 0;
  max-width: 34rem;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: .6rem;
}
.frames button {
  width: 100%;
  display: block;
  padding: 0;
  border: 3px solid #e4e1ec;
  border-radius: 10px;
  background: var(--mist);
  cursor: pointer;
  transition: border-color .12s, transform .12s, box-shadow .12s;
}
.frames img { display: block; width: 100%; height: auto; aspect-ratio: 1; }
.frames button:hover { transform: translateY(-2px); border-color: var(--red); }
.frames button[aria-checked="true"] {
  border-color: var(--red);
  box-shadow: var(--shadow-sm);
}
.frames button:focus-visible { outline: 3px solid var(--blue); outline-offset: 3px; }

/* ---------------- stage ---------------- */

.stage-wrap { display: grid; place-items: center; }

.stage {
  position: relative;
  width: min(30rem, 100%);
  aspect-ratio: 1;
  border: 3px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
  background: #fff;
  touch-action: none;
}
.stage.is-drag { border-color: var(--red); box-shadow: inset 0 0 0 4px rgba(244, 47, 71, .25); }

#canvas {
  display: block; width: 100%; height: 100%;
  cursor: grab;
}
#canvas:active { cursor: grabbing; }
#canvas:focus-visible { outline: 3px solid var(--blue); outline-offset: -3px; }
.stage.is-empty #canvas { cursor: default; }

.drop {
  position: absolute; inset: 0;
  display: grid; place-items: center;
  padding: 1.25rem;
  text-align: center;
  background: rgba(255, 255, 255, .88);
  backdrop-filter: blur(2px);
}
.stage:not(.is-empty) .drop { display: none; }
.drop__icon {
  width: 2.75rem; height: 2.75rem;
  color: var(--blue);
  fill: none; stroke: currentColor; stroke-width: 1.6;
  stroke-linecap: round; stroke-linejoin: round;
}
.drop__title { margin: .6rem 0 .1rem; font-family: var(--font-display); font-weight: 700; font-size: 1.15rem; }
.drop__sub { margin: 0 0 1rem; font-size: .9rem; color: #5a5566; }
.drop__note {
  display: flex; align-items: center; justify-content: center; gap: .35em;
  margin: .9rem 0 0; font-size: .78rem; color: #5a5566;
}

.hint {
  list-style: none;
  margin: .9rem auto 0;
  padding: 0;
  max-width: 36rem;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: .25rem 1.1rem;
  font-size: .85rem;
  color: #5a5566;
}
.hint li { display: inline-flex; align-items: center; gap: .35em; }
.hint .i { color: var(--blue); }

/* ---------------- controls ---------------- */

.controls { margin-top: 1rem; display: grid; gap: .9rem; justify-items: center; }

.zoom {
  display: flex; align-items: center; gap: .6rem;
  width: min(30rem, 100%);
}
.zoom__label { font-weight: 600; font-size: .9rem; }

input[type="range"] {
  flex: 1;
  appearance: none;
  height: 8px;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--red), var(--blue));
  outline: none;
}
input[type="range"]::-webkit-slider-thumb {
  appearance: none;
  width: 24px; height: 24px;
  border-radius: 50%;
  background: #fff;
  border: 3px solid var(--ink);
  cursor: pointer;
}
input[type="range"]::-moz-range-thumb {
  width: 22px; height: 22px;
  border-radius: 50%;
  background: #fff;
  border: 3px solid var(--ink);
  cursor: pointer;
}
input[type="range"]:focus-visible { outline: 3px solid var(--blue); outline-offset: 4px; }

.controls__row { display: flex; flex-wrap: wrap; gap: .5rem; justify-content: center; }

/* ตัวเลือกว่าปุ่มลูกศรกำลังขยับอะไร — จะอัปเดตเองเมื่อลากชิ้นส่วนบนภาพ */
.targets {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: .35rem .6rem;
  font-size: .85rem;
}
.targets__label { display: inline-flex; align-items: center; gap: .35em; color: #5a5566; }
.targets__label .i { color: var(--blue); }
.targets__group { display: flex; gap: .35rem; }

.chip {
  font-family: var(--font-body);
  font-size: .85rem;
  font-weight: 600;
  padding: .18rem .7rem;
  border: 2px solid #d9d5e4;
  border-radius: 999px;
  background: var(--paper);
  color: #5a5566;
  cursor: pointer;
  transition: border-color .12s, background .12s, color .12s;
}
.chip:hover { border-color: var(--red); color: var(--ink); }
.chip[aria-checked="true"] {
  background: var(--blue);
  border-color: var(--blue);
  color: #fff;
}
.chip:focus-visible { outline: 3px solid var(--blue); outline-offset: 2px; }

/* ---------------- buttons ---------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .45em;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1rem;
  padding: .6rem 1.15rem;
  border: 3px solid var(--line);
  border-radius: 999px;
  background: var(--paper);
  color: var(--ink);
  cursor: pointer;
  transition: transform .1s, box-shadow .1s, background .12s;
}
.btn:hover { transform: translate(-1px, -1px); box-shadow: 3px 3px 0 var(--blue); }
.btn:active { transform: translate(1px, 1px); box-shadow: none; }
.btn:focus-visible { outline: 3px solid var(--blue); outline-offset: 3px; }
.btn--primary { background: var(--red); color: #fff; }
.btn--primary:hover { background: var(--red-dark); }
.btn--blue { background: var(--blue); color: #fff; }
.btn--blue:hover { background: var(--blue-dark); }
.btn--ghost { background: var(--mist); }
.btn--lg { font-size: 1.1rem; padding: .8rem 1.6rem; }
.btn[disabled] { opacity: .45; cursor: not-allowed; transform: none; box-shadow: none; }

.icon-btn {
  width: 2.1rem; height: 2.1rem;
  flex: none;
  display: grid; place-items: center;
  border: 3px solid var(--line);
  border-radius: 50%;
  background: var(--paper);
  color: var(--ink);
  cursor: pointer;
}
.icon-btn .i { width: 1.05rem; height: 1.05rem; vertical-align: 0; }
.icon-btn:hover { background: var(--mist); }
.icon-btn:focus-visible { outline: 3px solid var(--blue); outline-offset: 2px; }

/* ---------------- save ---------------- */

.save { display: flex; flex-wrap: wrap; gap: .6rem; }
.save__note { margin: .75rem 0 0; font-size: .9rem; color: var(--blue); font-weight: 600; min-height: 1.5rem; }
.save__hash { margin: .4rem 0 0; font-size: .95rem; }

.tag {
  display: inline-flex; align-items: center; gap: .4em;
  font-family: var(--font-display);
  font-weight: 700;
  border: 2px dashed var(--red);
  border-radius: 999px;
  background: #fff5f6;
  color: var(--red);
  padding: .2rem .8rem;
  cursor: pointer;
}
.tag:hover { background: var(--red); color: #fff; }
.tag:focus-visible { outline: 3px solid var(--blue); outline-offset: 3px; }

/* ---------------- sheet (fallback save) ---------------- */

.sheet {
  border: 3px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem;
  max-width: min(26rem, 92vw);
  box-shadow: var(--shadow);
}
.sheet::backdrop { background: rgba(20, 0, 31, .55); }
.sheet__title { margin: 0 0 .75rem; font-family: var(--font-display); font-size: 1.1rem; text-align: center; }
.sheet img { display: block; width: 100%; height: auto; border-radius: 8px; margin-bottom: .75rem; }
.sheet .btn { display: block; margin-inline: auto; }

/* ---------------- footer ---------------- */

.foot {
  border-top: 6px solid var(--red);
  background: var(--blue);
  color: #fff;
  padding: 1.75rem 0 2.5rem;
  font-size: .9rem;
}
.foot a { color: #fff; text-decoration: underline; }
.foot a:hover { color: #ff9aa8; }
.foot a .i { vertical-align: -.15em; }
.foot__grid { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(15rem, 1fr)); }
.foot__item { margin: 0; }
.foot__k {
  display: flex;
  align-items: center;
  gap: .4em;
  font-family: var(--font-display);
  font-weight: 700;
  color: #ff8fa0;
  font-size: .9rem;
  letter-spacing: .02em;
}

@media (max-width: 30rem) {
  /* ปุ่มหลักเต็มความกว้างบนจอแคบ เพื่อไม่ให้ข้อความตกบรรทัดกลางปุ่ม */
  .save { flex-direction: column; }
  .save .btn { width: 100%; }
  .btn--lg { font-size: .95rem; padding: .75rem 1rem; }
}

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