:root {
  --bg: #0f1115;
  --card: #171a21;
  --border: #262b36;
  --text: #e8eaf0;
  --muted: #9aa3b2;
  --accent: #7c5cff;
  --accent2: #00d4ff;
}

* { box-sizing: border-box; }

/* the hidden attribute must beat explicit display rules (e.g. #gate's flex) */
[hidden] { display: none !important; }

body {
  margin: 0;
  padding: 0 16px 64px;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  line-height: 1.5;
}

header { max-width: 720px; margin: 28px auto 20px; text-align: center; }
header h1 { margin: 0; font-size: 1.9rem; }
header .sub { margin: 4px 0 0; color: var(--muted); }

main { max-width: 720px; margin: 0 auto; display: flex; flex-direction: column; gap: 16px; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 18px 20px;
}
.card h2 { margin: 0 0 12px; font-size: 1.1rem; display: flex; align-items: center; gap: 10px; }
.card h3 { margin: 18px 0 8px; font-size: .95rem; }
.step {
  display: inline-flex; align-items: center; justify-content: center;
  width: 24px; height: 24px; border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  color: #fff; font-size: .85rem; flex: none;
}
.muted { color: var(--muted); font-weight: normal; font-size: .85rem; }

/* photo drop zone */
#drop {
  border: 2px dashed var(--border);
  border-radius: 12px;
  min-height: 180px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  transition: border-color .15s;
  overflow: hidden;
}
#drop:hover, #drop.drag { border-color: var(--accent); }
#drop-hint { text-align: center; color: var(--muted); }
#drop-hint .big { font-size: 2.2rem; }
#drop-hint p { margin: 4px 0; }
#photo-preview { max-width: 100%; max-height: 320px; border-radius: 8px; display: block; }

/* style tiles */
.styles { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.style-tile {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 6px;
  text-align: center;
  cursor: pointer;
  display: flex; flex-direction: column; gap: 2px;
  transition: border-color .15s, background .15s;
}
.style-tile input { display: none; }
.style-tile .emoji { font-size: 1.6rem; }
.style-tile .name { font-weight: 600; font-size: .9rem; }
.style-tile .desc { color: var(--muted); font-size: .75rem; }
.style-tile:has(input:checked) {
  border-color: var(--accent);
  background: rgba(124, 92, 255, .12);
}

/* palette */
.palette { display: flex; flex-wrap: wrap; gap: 10px; }
.chip {
  position: relative;
  width: 52px; height: 52px;
  border-radius: 10px;
  border: 2px solid var(--border);
  cursor: pointer;
  opacity: .35;
  transition: opacity .15s, border-color .15s;
}
.chip.on { opacity: 1; border-color: #4a5364; }
.chip input[type=color] {
  position: absolute;
  width: 0; height: 0;
  opacity: 0;
  border: none; padding: 0;
  pointer-events: none;
}
.chip .edit {
  position: absolute; bottom: -7px; right: -7px;
  width: 20px; height: 20px; border-radius: 50%;
  background: #2a3040;
  border: 1px solid var(--border);
  color: var(--muted); font-size: .7rem;
  display: flex; align-items: center; justify-content: center;
}
.chip .edit:hover { color: #fff; border-color: var(--accent); }
.chip .tick {
  position: absolute; top: -7px; right: -7px;
  width: 20px; height: 20px; border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  color: #fff; font-size: .75rem;
  display: none; align-items: center; justify-content: center;
  pointer-events: none;
}
.chip.on .tick { display: flex; }

input[type=text], input[type=password] {
  width: 100%;
  background: #10131a;
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  padding: 10px 12px;
  font-size: .95rem;
}
input[type=text]:focus, input[type=password]:focus { outline: none; border-color: var(--accent); }

/* buttons */
button {
  font: inherit;
  border: none;
  border-radius: 10px;
  padding: 10px 18px;
  cursor: pointer;
  transition: filter .15s, opacity .15s;
}
button:disabled { opacity: .45; cursor: not-allowed; }
button.primary {
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  color: #fff; font-weight: 600;
}
button.primary:hover:not(:disabled) { filter: brightness(1.15); }
button.secondary {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
}
button.secondary:hover:not(:disabled) { border-color: var(--accent); }
.big-btn { padding: 14px; font-size: 1.05rem; }
.btn-row { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 12px; }
.btn-row a {
  display: inline-block;
  padding: 9px 16px;
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  text-decoration: none;
}
.btn-row a:hover { border-color: var(--accent2); }

.result-img {
  display: block;
  max-width: 100%;
  max-height: 480px;
  margin: 0 auto;
  border-radius: 10px;
  background: #10131a;
}

/* progress */
.bar {
  height: 10px;
  background: #10131a;
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
}
.bar .fill {
  height: 100%; width: 0%;
  background: linear-gradient(90deg, var(--accent), var(--accent2));
  transition: width .6s;
}
#model-status { margin: 8px 0 0; }

label.check {
  display: flex; align-items: center; gap: 8px;
  margin-top: 10px;
  color: var(--muted); font-size: .85rem;
  cursor: pointer;
}
label.check input { accent-color: var(--accent); }

/* generation progress */
#gen-progress { margin-top: -6px; }
#gen-progress .muted { margin: 6px 0 0; }

/* history */
#history-list { list-style: none; margin: 0; padding: 0; }
#history-list li {
  display: flex; align-items: center; gap: 12px;
  padding: 8px 4px;
  border-bottom: 1px solid var(--border);
  font-size: .9rem;
  cursor: pointer;
}
#history-list li:last-child { border-bottom: none; }
#history-list li:hover { background: rgba(124, 92, 255, .08); }
#history-list img {
  width: 44px; height: 44px;
  object-fit: cover;
  border-radius: 8px;
  background: #10131a;
  flex: none;
}
.hist-info .muted { font-size: .8rem; }

/* token gate */
#gate {
  position: fixed; inset: 0;
  background: rgba(10, 12, 16, .92);
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
  z-index: 10;
}
.gate-card { width: 100%; max-width: 380px; display: flex; flex-direction: column; gap: 12px; }

/* toast */
#toast {
  position: fixed; left: 50%; bottom: 24px;
  transform: translateX(-50%);
  background: #2a1520;
  border: 1px solid #7a2740;
  color: #ffb4c4;
  border-radius: 10px;
  padding: 10px 18px;
  max-width: 90vw;
  z-index: 20;
}

@media (max-width: 640px) {
  .styles { grid-template-columns: repeat(2, 1fr); }
}
