:root {
  --ink: #101426;
  --muted: #687084;
  --soft: #f4f7fb;
  --line: #e8edf5;
  --blue: #0f6dd0;
  --blue-deep: #2563eb;
  --blue-soft: #dbeafe;
}

* {
  box-sizing: border-box;
}

html {
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
  background: var(--blue);
}

body {
  margin: 0;
  min-width: 320px;
  width: 100%;
  max-width: 100%;
  min-height: 100vh;
  overflow-x: hidden;
  color: var(--ink);
  background: var(--blue);
  font-family: "Inter", ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
label {
  font: inherit;
}

button,
label {
  -webkit-tap-highlight-color: transparent;
}

.app {
  display: grid;
  grid-template-columns: minmax(680px, 1fr) 504px;
  width: 100%;
  max-width: 100%;
  min-height: 100vh;
  overflow: hidden;
  background:
    radial-gradient(circle at 8% 14%, rgba(255, 255, 255, 0.12), transparent 16rem),
    linear-gradient(135deg, #0f6dd0 0%, #0f6dd0 58%, #2f9bff 100%);
}

.stage {
  position: relative;
  display: grid;
  grid-template-rows: auto 1fr auto;
  min-height: 100vh;
  padding: 54px 56px 36px;
  color: #fff;
}

.ambient {
  position: absolute;
  border-radius: 50%;
  pointer-events: none;
  filter: blur(120px);
}

.ambient-one {
  top: -10%;
  left: -10%;
  width: 500px;
  height: 500px;
  background: rgba(255, 255, 255, 0.2);
}

.ambient-two {
  bottom: -20%;
  left: 20%;
  width: 600px;
  height: 600px;
  background: rgba(34, 211, 238, 0.3);
  filter: blur(150px);
}

.ambient-three {
  top: 20%;
  right: 18%;
  width: 400px;
  height: 400px;
  background: rgba(99, 102, 241, 0.3);
  filter: blur(100px);
}

.brand {
  display: grid;
  grid-template-columns: 50px minmax(0, 560px);
  gap: 14px;
  align-items: start;
  z-index: 2;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 50px;
  height: 50px;
  color: #146ddd;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.2);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
  color: #fff;
  font-size: 30px;
  font-weight: 800;
  backdrop-filter: blur(14px);
  margin-top: -6px;
}

.brand-mark img {
  display: block;
  width: 32px;
  height: 32px;
  filter: invert(1);
}

h1 {
  margin: 0;
  font-size: clamp(32px, 2.5vw, 38px);
  line-height: 0.95;
  letter-spacing: 0;
  font-weight: 900;
  text-shadow: 0 1px 2px rgba(0, 55, 140, 0.16);
}

.brand p {
  margin: 10px 0 0;
  max-width: 390px;
  color: #dbeafe;
  font-size: 14px;
  line-height: 1.45;
  font-weight: 650;
}

.decor {
  position: absolute;
  color: rgba(255, 255, 255, 0.1);
  pointer-events: none;
}

.decor-plane {
  top: 15%;
  left: 25%;
  font-size: 64px;
  transform: rotate(12deg);
}

.decor-sun {
  left: 11%;
  bottom: 30%;
  font-size: 96px;
}

.preview-card {
  align-self: center;
  justify-self: center;
  width: min(66vh, 520px);
  padding: 48px 48px 28px;
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 48px;
  background: rgba(255, 255, 255, 0.1);
  box-shadow: 0 32px 64px rgba(0, 0, 0, 0.25), inset 0 1px 0 rgba(255, 255, 255, 0.18);
  backdrop-filter: blur(28px);
  cursor: pointer;
  transition: transform 500ms cubic-bezier(0.22, 1, 0.36, 1), box-shadow 500ms ease;
}

.preview-card:hover {
  transform: scale(1.02);
  box-shadow: 0 36px 78px rgba(0, 0, 0, 0.28), inset 0 1px 0 rgba(255, 255, 255, 0.2);
}

.preview-card.dragging {
  transform: scale(1.02);
  border-color: rgba(255, 255, 255, 0.72);
  background: rgba(255, 255, 255, 0.18);
}

.preview-card:focus-visible {
  outline: 3px solid rgba(255, 255, 255, 0.78);
  outline-offset: 4px;
}

.preview-shell {
  display: grid;
  place-items: center;
}

#avatarCanvas {
  display: block;
  width: 100%;
  aspect-ratio: 1;
  height: auto;
  border-radius: 50%;
  box-shadow: inset 0 0 40px rgba(15, 23, 42, 0.12), 0 18px 42px rgba(0, 76, 163, 0.16);
  outline: 12px solid rgba(255, 255, 255, 0.2);
  outline-offset: -12px;
}

.caption {
  width: max-content;
  max-width: 100%;
  display: flex;
  align-items: center;
  gap: 8px;
  margin: -28px auto 0;
  padding: 8px 16px;
  color: rgba(255, 255, 255, 0.82);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.2);
  text-align: center;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.08em;
  backdrop-filter: blur(10px);
}

.credits {
  display: flex;
  gap: 26px;
  align-items: center;
  flex-wrap: wrap;
  color: rgba(255, 255, 255, 0.62);
  font-size: 17px;
  font-weight: 750;
  z-index: 2;
}

.credits a {
  display: inline-flex;
  gap: 5px;
  align-items: center;
  color: rgba(255, 255, 255, 0.82);
  text-decoration: none;
  transition: color 180ms ease;
}

.credits a:hover {
  color: #fff;
}

.controls {
  position: relative;
  align-self: center;
  justify-self: end;
  display: grid;
  grid-template-rows: 1fr auto;
  width: 480px;
  height: calc(100vh - 48px);
  margin-right: 24px;
  overflow: hidden;
  border-radius: 40px;
  background: #fff;
  box-shadow: 0 28px 80px rgba(0, 62, 140, 0.28);
}

.controls-scroll {
  overflow: auto;
  padding: 32px 32px 128px;
}

.controls-scroll::-webkit-scrollbar {
  width: 6px;
}

.controls-scroll::-webkit-scrollbar-track {
  background: transparent;
}

.controls-scroll::-webkit-scrollbar-thumb {
  border-radius: 20px;
  background-color: #e2e8f0;
}

.controls-scroll:hover::-webkit-scrollbar-thumb {
  background-color: #cbd5e1;
}

.panel {
  margin: 0 0 40px;
}

.panel h2,
.section-title {
  display: flex;
  align-items: center;
  gap: 14px;
  margin: 0 0 20px;
  color: #9aa3b4;
  font-size: 14px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.panel h2 span,
.section-title span {
  margin: 0;
}

.panel h2 b,
.section-title b {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  color: #2563eb;
  border-radius: 50%;
  background: #dbeafe;
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.08);
  font-size: 12px;
  font-weight: 800;
  font-style: normal;
  letter-spacing: 0;
}

#photoInput {
  display: none;
}

.template-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.template-option {
  position: relative;
  min-height: 148px;
  padding: 16px;
  border: 2px solid #f3f4f6;
  border-radius: 20px;
  background: #fff;
  cursor: pointer;
  text-align: left;
  box-shadow: 0 1px 0 rgba(16, 20, 38, 0.02);
  transition: transform 160ms ease, border-color 160ms ease, box-shadow 160ms ease, background 160ms ease;
}

.template-option:hover {
  transform: translateY(-2px);
  box-shadow: 0 18px 36px rgba(19, 97, 191, 0.08);
}

.template-preview {
  display: block;
  width: 92px;
  height: 92px;
  margin-bottom: 16px;
  object-fit: contain;
  border-radius: 14px;
  background: #f8fbff;
}

.template-option strong {
  display: block;
  margin-bottom: 6px;
  font-size: 14px;
  line-height: 1;
  font-weight: 800;
}

.template-option small {
  display: block;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.25;
  font-weight: 680;
}

.template-option.active {
  border-color: #3b82f6;
  background: rgba(239, 246, 255, 0.3);
  box-shadow: inset 0 0 0 1px #3b82f6, 0 1px 3px rgba(15, 23, 42, 0.08);
}

.template-option.active::after {
  content: "✓";
  position: absolute;
  top: 26px;
  right: 20px;
  display: grid;
  place-items: center;
  width: 20px;
  height: 20px;
  color: #fff;
  border-radius: 50%;
  background: #3b82f6;
  font-size: 13px;
  font-weight: 800;
}

.text-panel {
  padding: 20px;
  border: 1px solid #f3f4f6;
  border-radius: 24px;
  background: #f9fafb;
}

.text-panel label {
  display: block;
  margin-bottom: 18px;
}

.input-wrap {
  position: relative;
}

.text-panel input[type="text"] {
  width: 100%;
  height: 50px;
  padding: 0 84px 0 20px;
  color: var(--ink);
  border: 1px solid #dfe5ee;
  border-radius: 12px;
  outline: none;
  background: #fff;
  box-shadow: 0 7px 18px rgba(16, 20, 38, 0.07);
  font-size: 14px;
  font-weight: 800;
}

.text-panel input[type="text"]:focus {
  border-color: #3b82f6;
}

.input-wrap em {
  position: absolute;
  top: 50%;
  right: 16px;
  transform: translateY(-50%);
  padding: 5px 9px;
  color: #9ca3af;
  border-radius: 8px;
  background: #f0f3f8;
  font-style: normal;
  font-size: 13px;
  font-weight: 850;
}

.control-card {
  margin-bottom: 18px;
  padding: 18px 18px 20px;
  border: 1px solid #e5eaf2;
  border-radius: 18px;
  background: #f8fafc;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.7);
}

.control-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.control-head span {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  margin: 0;
  color: #64748b;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.control-head i {
  color: #64748b;
  font-size: 20px;
}

.control-head em {
  flex: 0 0 auto;
  min-width: 44px;
  padding: 7px 10px;
  color: #1d4ed8;
  border-radius: 10px;
  background: #dbeafe;
  text-align: center;
  font-style: normal;
  font-size: 14px;
  font-weight: 800;
}

.head-actions {
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 8px;
}

.icon-toggle {
  display: none;
  place-items: center;
  width: 38px;
  height: 38px;
  color: #3b82f6;
  border: 0;
  border-radius: 10px;
  background: #eff6ff;
  cursor: pointer;
  font-size: 22px;
  box-shadow: 0 8px 16px rgba(37, 99, 235, 0.08);
  transition: transform 160ms ease, background 160ms ease, color 160ms ease;
}

.icon-toggle:hover {
  transform: translateY(-1px);
  background: #dbeafe;
}

.icon-toggle[aria-pressed="false"] {
  color: #94a3b8;
  background: #f1f5f9;
}

.range-scale {
  display: grid;
  grid-template-columns: 24px 1fr 24px;
  gap: 12px;
  align-items: center;
}

.range-scale b,
.range-scale strong {
  color: #94a3b8;
  font-size: 18px;
  line-height: 1;
  font-weight: 800;
}

.range-scale strong {
  text-align: right;
  font-size: 28px;
}

.range-scale.compact {
  grid-template-columns: 16px 1fr 16px;
  gap: 8px;
}

.range-scale.compact b,
.range-scale.compact strong {
  color: #cbd5e1;
  font-size: 13px;
}

.position-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.axis-control {
  min-width: 0;
}

.axis-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
  color: #94a3b8;
  font-size: 12px;
  font-weight: 850;
}

.axis-head span {
  margin: 0;
  color: inherit;
  font-size: inherit;
  font-weight: inherit;
  letter-spacing: 0;
  text-transform: none;
}

.axis-head strong {
  color: #64748b;
  font-size: 13px;
  font-weight: 800;
}

input[type="range"] {
  width: 100%;
  height: 28px;
  accent-color: #3b82f6;
  cursor: pointer;
  background: transparent;
  -webkit-appearance: none;
  appearance: none;
}

input[type="range"]::-webkit-slider-runnable-track {
  height: 6px;
  border-radius: 999px;
  background: linear-gradient(to right, #3b82f6 0 var(--fill, 50%), #dbe3ee var(--fill, 50%) 100%);
}

input[type="range"]::-webkit-slider-thumb {
  width: 28px;
  height: 28px;
  margin-top: -11px;
  border: 5px solid #eff6ff;
  border-radius: 50%;
  background: #3b82f6;
  box-shadow: 0 8px 18px rgba(37, 99, 235, 0.28);
  -webkit-appearance: none;
  appearance: none;
}

input[type="range"]::-moz-range-track {
  height: 6px;
  border-radius: 999px;
  background: #dbe3ee;
}

input[type="range"]::-moz-range-progress {
  height: 6px;
  border-radius: 999px;
  background: #3b82f6;
}

input[type="range"]::-moz-range-thumb {
  width: 20px;
  height: 20px;
  border: 5px solid #eff6ff;
  border-radius: 50%;
  background: #3b82f6;
  box-shadow: 0 8px 18px rgba(37, 99, 235, 0.28);
}

.color-row {
  margin-top: 8px;
}

.color-control {
  display: grid;
  grid-template-columns: 54px 1fr;
  gap: 12px;
  align-items: center;
}

#colorInput {
  width: 54px;
  height: 54px;
  padding: 4px;
  border: 1px solid #dfe5ee;
  border-radius: 14px;
  background: #fff;
}

.action-bar {
  display: grid;
  gap: 16px;
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  padding: 24px;
  border-top: 1px solid #f3f4f6;
  background: rgba(255, 255, 255, 0.95);
  box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.05);
  backdrop-filter: blur(16px);
}

.download-button,
.fun-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  min-height: 56px;
  border: 0;
  border-radius: 16px;
  cursor: pointer;
  font-size: 16px;
  font-weight: 800;
  letter-spacing: 0;
  transition: transform 160ms ease, box-shadow 160ms ease;
}

.download-button {
  color: #fff;
  background: #2563eb;
  box-shadow: 0 12px 24px rgba(37, 99, 235, 0.3);
}

.download-button:hover {
  background: #1d4ed8;
}

.fun-button {
  color: var(--ink);
  background: #f3f4f6;
}

.fun-button:hover {
  background: #e5e7eb;
}

.fun-button i {
  color: #f59e0b;
}

.download-button:hover,
.fun-button:hover {
  transform: translateY(-1px);
}

@media (max-width: 1180px) {
  html,
  body {
    height: 100%;
    overflow: hidden;
  }

  body {
    padding-bottom: 0;
  }

  .app {
    display: flex;
    flex-direction: column;
    width: 100%;
    max-width: 100%;
    height: 100dvh;
    min-height: 0;
    overflow: hidden;
  }

  .stage {
    flex: 0 0 auto;
    width: 100%;
    max-width: 100%;
    min-height: auto;
    padding: 22px 22px 14px;
    grid-template-rows: auto auto auto;
    gap: 12px;
  }

  .brand {
    grid-template-columns: 48px minmax(0, 1fr);
    gap: 14px;
    width: 100%;
    max-width: 100%;
  }

  .brand-mark {
    width: 48px;
    height: 48px;
    border-radius: 15px;
    font-size: 28px;
  }

  h1 {
    font-size: 38px;
  }

  .brand p {
    max-width: 520px;
    font-size: 14px;
    line-height: 1.32;
  }

  .preview-card {
    width: min(40vh, 430px, 58vw);
    padding: 18px 18px 12px;
    border-radius: 30px;
  }

  .caption {
    margin-top: -16px;
    padding: 6px 10px;
    font-size: 9px;
  }

  .decor {
    display: none;
  }

  .credits {
    justify-content: center;
    gap: 10px 18px;
    margin-top: -2px;
    font-size: 14px;
    line-height: 1;
  }

  .controls {
    flex: 1 1 auto;
    align-self: stretch;
    justify-self: stretch;
    width: 100%;
    max-width: 100%;
    min-height: 0;
    height: auto;
    margin: 0;
    overflow: hidden;
    border-radius: 34px 34px 0 0;
  }

  .controls-scroll {
    height: 100%;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    padding: 28px 28px calc(176px + env(safe-area-inset-bottom));
  }

  .action-bar {
    position: fixed;
    z-index: 50;
    right: 0;
    bottom: 0;
    left: 0;
    width: 100%;
    max-width: 100%;
    gap: 12px;
    grid-template-columns: minmax(0, 0.9fr) minmax(0, 1.1fr);
    padding: 16px 18px calc(18px + env(safe-area-inset-bottom));
    border-top: 1px solid rgba(226, 232, 240, 0.9);
    border-radius: 28px 28px 0 0;
    background: rgba(255, 255, 255, 0.96);
    box-shadow: 0 -18px 44px rgba(15, 23, 42, 0.14);
  }

  .download-button,
  .fun-button {
    min-height: 56px;
    border-radius: 18px;
    font-size: 14px;
  }

  .download-button {
    order: 2;
  }

  .fun-button {
    order: 1;
  }
}

@media (max-width: 620px) {
  .stage {
    padding: 22px max(16px, env(safe-area-inset-left)) 18px max(16px, env(safe-area-inset-left));
    gap: 18px;
  }

  .brand {
    grid-template-columns: 44px 1fr;
    gap: 12px;
  }

  .brand-mark {
    width: 44px;
    height: 44px;
    border-radius: 14px;
    font-size: 26px;
  }

  h1 {
    font-size: 34px;
  }

  .brand p {
    max-width: 300px;
    margin-top: 6px;
    font-size: 13px;
    line-height: 1.28;
  }

  .preview-card {
    width: min(74vw, 330px);
    padding: 18px 18px 12px;
    border-radius: 28px;
  }

  .caption {
    margin-top: -16px;
    padding: 6px 10px;
    font-size: 8px;
    letter-spacing: 0.04em;
  }

  .credits {
    gap: 8px 12px;
    font-size: 12px;
  }

  .credits a {
    gap: 4px;
  }

  .controls {
    margin-top: -2px;
    border-radius: 28px 28px 0 0;
  }

  .controls-scroll {
    padding: 22px max(18px, env(safe-area-inset-left)) calc(176px + env(safe-area-inset-bottom));
  }

  .panel {
    margin-bottom: 24px;
  }

  .template-grid {
    grid-template-columns: 1fr;
  }

  .position-grid {
    grid-template-columns: 1fr;
  }

  .action-bar {
    padding-inline: max(18px, env(safe-area-inset-left));
  }
}

@media (max-width: 420px) {
  .brand p {
    display: none;
  }

  .preview-card {
    width: min(68vw, 280px);
    padding: 14px 14px 10px;
  }

  .download-button,
  .fun-button {
    gap: 8px;
    font-size: 13px;
  }
}
