:root {
  --bg: #0b0b1d;
  --panel: #14142c;
  --panel-2: #1b1b38;
  --line: #2a2a4d;
  --text: #e9e7f7;
  --muted: #9a98bd;
  --accent: #ffc857;
  --accent-2: #a78bfa;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  background: radial-gradient(1200px 800px at 80% -10%, #231a52 0%, transparent 60%), var(--bg);
  color: var(--text);
  font: 14px/1.4 Inter, system-ui, sans-serif;
  min-height: 100vh;
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  border: 1px solid var(--line);
  background: var(--panel-2);
  border-radius: 10px;
  padding: 8px 14px;
  transition: background 0.15s, border-color 0.15s, opacity 0.15s;
}
button:hover {
  border-color: var(--accent-2);
}
button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
button.ghost {
  background: transparent;
}
button.small {
  padding: 5px 10px;
  font-size: 13px;
}
button.primary {
  background: linear-gradient(135deg, #ffc857, #ff8fb1);
  border: none;
  color: #1b1030;
  font-weight: 700;
  padding: 13px 22px;
  border-radius: 12px;
  width: 100%;
  max-width: 380px;
}

input[type='text'],
input[type='number'],
select,
textarea {
  width: 100%;
  background: #0f0f24;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 9px;
  outline: none;
}
input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent-2);
}
input:disabled,
select:disabled {
  opacity: 0.35;
}
textarea {
  resize: vertical;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 24px;
  border-bottom: 1px solid var(--line);
}
.brand {
  display: flex;
  align-items: baseline;
  gap: 10px;
  font-size: 20px;
  font-weight: 700;
}
.brand small {
  font-size: 13px;
  color: var(--muted);
  font-weight: 400;
}
.logo {
  color: var(--accent);
  text-shadow: 0 0 12px rgba(255, 200, 87, 0.8);
}
.top-actions {
  display: flex;
  gap: 8px;
}

.layout {
  display: grid;
  grid-template-columns: minmax(360px, 520px) 1fr;
  gap: 24px;
  padding: 20px 24px 40px;
  max-width: 1300px;
  margin: 0 auto;
}

.editor {
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 16px;
}
.panel h2 {
  margin: 0 0 12px;
  font-size: 15px;
  letter-spacing: 0.02em;
}
.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 4px;
}
.panel-head h2 {
  margin: 0;
}
.grid {
  display: grid;
  grid-template-columns: 1.4fr 1fr 1fr;
  gap: 10px;
}
label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  color: var(--muted);
  font-size: 12px;
}
label.full {
  margin-top: 10px;
}
label.row {
  flex-direction: row;
  align-items: center;
  gap: 12px;
}
label.row input {
  flex: 1;
}
.hint {
  color: var(--muted);
  font-size: 12px;
  margin: 10px 0 0;
}

.bg-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}
.bg-item {
  position: relative;
  padding: 0;
  aspect-ratio: 16 / 10;
  border-radius: 10px;
  overflow: hidden;
  border: 2px solid transparent;
  background: #000 center / cover no-repeat;
}
.bg-item span {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 3px 6px;
  font-size: 11px;
  text-align: left;
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.75));
}
.bg-item.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(255, 200, 87, 0.25);
}
.bg-item.upload {
  background: var(--panel-2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  color: var(--muted);
}

.people {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 12px;
}
.person {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-left: 4px solid var(--c, #fff);
  border-radius: 12px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.person.me {
  box-shadow: inset 0 0 0 1px rgba(255, 200, 87, 0.35);
}
.person .row1 {
  display: flex;
  gap: 8px;
  align-items: center;
}
.person input[type='color'] {
  width: 34px;
  height: 34px;
  padding: 0;
  border: none;
  background: none;
  cursor: pointer;
  flex: none;
}
.person .name {
  font-weight: 600;
}
.badge {
  font-size: 11px;
  background: rgba(255, 200, 87, 0.15);
  color: var(--accent);
  padding: 3px 8px;
  border-radius: 999px;
  flex: none;
}
.icons {
  display: flex;
  gap: 4px;
  flex: none;
}
.icons button {
  padding: 4px 8px;
  font-size: 12px;
  background: transparent;
}
.person .row2 {
  display: grid;
  grid-template-columns: 1fr 92px;
  gap: 8px;
}
.person .note {
  font-size: 12px;
  color: var(--accent);
  align-self: end;
  padding-bottom: 8px;
}
.person .warn {
  font-size: 12px;
  color: #ff9b9b;
}

.stage {
  position: sticky;
  top: 16px;
  align-self: start;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}
.phone {
  height: min(74vh, 820px);
  aspect-ratio: 9 / 16;
  border-radius: 26px;
  padding: 8px;
  background: #050510;
  border: 1px solid var(--line);
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.55), 0 0 60px rgba(120, 80, 220, 0.2);
}
.phone canvas {
  width: 100%;
  height: 100%;
  border-radius: 19px;
  display: block;
  background: #000;
}
.controls {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  max-width: 480px;
}
.controls input[type='range'] {
  flex: 1;
}
.round {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  padding: 0;
  flex: none;
}
.time {
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  font-size: 12px;
  min-width: 128px;
  text-align: right;
}
input[type='range'] {
  accent-color: var(--accent);
}

.export {
  width: 100%;
  max-width: 380px;
}
.bar {
  height: 8px;
  background: var(--panel-2);
  border-radius: 999px;
  overflow: hidden;
}
.bar div {
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, #ffc857, #ff8fb1);
  transition: width 0.1s;
}
.export-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 8px;
  color: var(--muted);
  font-size: 12px;
}
.download {
  color: var(--accent);
  font-size: 13px;
}

.music-row {
  display: flex;
  gap: 8px;
}
.music-row select {
  flex: 1;
}
.add-bottom {
  width: 100%;
  margin-top: 10px;
  border-style: dashed;
  background: transparent;
  color: var(--muted);
}
.share {
  width: 100%;
  max-width: 380px;
  background: var(--panel-2);
  font-weight: 600;
}
.person .note {
  font-size: 12px;
  color: var(--accent);
}
.person .row2.single {
  grid-template-columns: 1fr;
}
.person.me .badge {
  white-space: nowrap;
}
.fab {
  display: none;
}

@media (max-width: 900px) {
  html,
  body {
    font-size: 15px;
  }
  .topbar {
    padding: 10px 14px;
    padding-top: max(10px, env(safe-area-inset-top));
    position: sticky;
    top: 0;
    z-index: 20;
    background: rgba(11, 11, 29, 0.92);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
  }
  .brand {
    font-size: 18px;
  }
  .brand small {
    display: none;
  }
  .top-actions button {
    padding: 7px 10px;
    font-size: 13px;
  }
  .layout {
    grid-template-columns: 1fr;
    gap: 14px;
    padding: 12px 12px calc(90px + env(safe-area-inset-bottom));
  }
  .stage {
    position: static;
    order: -1;
    gap: 10px;
  }
  .phone {
    height: auto;
    width: min(100%, calc(62vh * 9 / 16));
    width: min(100%, calc(62svh * 9 / 16));
    border-radius: 22px;
    padding: 6px;
  }
  .phone canvas {
    border-radius: 17px;
  }
  .controls {
    max-width: none;
  }
  .time {
    min-width: 0;
    font-size: 11px;
  }
  button.primary,
  .share,
  .export {
    max-width: none;
  }
  .panel {
    padding: 14px 12px;
    border-radius: 12px;
  }
  /* 16px inputs stop iOS Safari from zooming in on focus. */
  input[type='text'],
  input[type='number'],
  select,
  textarea {
    font-size: 16px;
    padding: 9px 10px;
    min-height: 42px;
  }
  .grid {
    grid-template-columns: 1fr 1fr;
  }
  .grid label:first-child {
    grid-column: 1 / -1;
  }
  .bg-grid {
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
  }
  .person {
    padding: 10px;
  }
  .person .row1 {
    flex-wrap: wrap;
  }
  .person .name {
    flex: 1;
    min-width: 0;
  }
  .person.me .badge {
    order: 3;
    width: 100%;
    text-align: center;
  }
  .person .row2 {
    grid-template-columns: 1fr 86px;
  }
  .icons button {
    width: 36px;
    height: 36px;
    padding: 0;
  }
  input[type='range'] {
    height: 28px;
  }
  .round {
    width: 44px;
    height: 44px;
  }
  .fab {
    position: fixed;
    right: 14px;
    bottom: calc(14px + env(safe-area-inset-bottom));
    z-index: 30;
    border: none;
    border-radius: 999px;
    padding: 12px 18px;
    font-weight: 700;
    color: #1b1030;
    background: linear-gradient(135deg, #ffc857, #ff8fb1);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  }
  .fab.show {
    display: block;
  }
}
