/* ============ StringGen Mini App — dark, glowing, mesmerizing ============ */
* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

:root {
  --bg: #07070f;
  --surface: rgba(255, 255, 255, 0.045);
  --surface-2: rgba(255, 255, 255, 0.08);
  --border: rgba(255, 255, 255, 0.09);
  --text: #f2f2f7;
  --text-dim: #9a9ab0;
  --accent: #7c5cff;
  --accent-2: #00d4ff;
  --accent-glow: rgba(124, 92, 255, 0.55);
  --success: #2ee6a8;
  --danger: #ff5470;
  --radius: 20px;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: 'Sora', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  overflow-x: hidden;
}

/* ---- animated background ---- */
.bg-glow {
  position: fixed; border-radius: 50%; filter: blur(90px);
  opacity: 0.5; z-index: 0; pointer-events: none;
}
.glow-1 { width: 420px; height: 420px; background: #5b3fff; top: -140px; left: -120px; animation: drift1 14s ease-in-out infinite alternate; }
.glow-2 { width: 380px; height: 380px; background: #00a2ff; bottom: -120px; right: -110px; animation: drift2 17s ease-in-out infinite alternate; }
.glow-3 { width: 300px; height: 300px; background: #ff2ea6; top: 45%; left: 60%; opacity: 0.22; animation: drift3 20s ease-in-out infinite alternate; }

@keyframes drift1 { to { transform: translate(60px, 80px) scale(1.1); } }
@keyframes drift2 { to { transform: translate(-70px, -60px) scale(1.15); } }
@keyframes drift3 { to { transform: translate(-120px, -90px) scale(0.9); } }

.stars { position: fixed; inset: 0; z-index: 0; pointer-events: none; opacity: 0.55; }
.star {
  position: absolute; width: 2px; height: 2px; border-radius: 50%;
  background: #fff; animation: twinkle 3s ease-in-out infinite;
}
@keyframes twinkle { 0%,100% { opacity: 0.1; transform: scale(0.7);} 50% { opacity: 0.9; transform: scale(1.2);} }

/* ---- loader ---- */
.loader {
  position: fixed; inset: 0; z-index: 100;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 18px; background: var(--bg);
  transition: opacity 0.4s ease, visibility 0.4s;
}
.loader.hidden { opacity: 0; visibility: hidden; }

.loader-ring {
  width: 54px; height: 54px; border-radius: 50%;
  border: 3px solid rgba(124,92,255,0.15);
  border-top-color: var(--accent);
  border-right-color: var(--accent-2);
  animation: spin 0.9s linear infinite;
}
.loader-ring.small { width: 38px; height: 38px; border-width: 2.5px; }
@keyframes spin { to { transform: rotate(360deg); } }
.loader-text { color: var(--text-dim); font-size: 14px; }

/* ---- locked ---- */
.locked-screen {
  position: fixed; inset: 0; z-index: 90;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; padding: 32px; gap: 12px;
}
.locked-screen.hidden { display: none; }
.locked-icon { font-size: 58px; }
.locked-screen h2 { font-weight: 800; }
.locked-screen p { color: var(--text-dim); font-size: 14px; }

/* ---- app shell ---- */
.app { position: relative; z-index: 2; max-width: 480px; margin: 0 auto; padding: 20px 18px 60px; }
body.tg-embedded .app { padding-top: calc(96px + env(safe-area-inset-top, 0px)); }
body.tg-embedded .app { padding-left: max(18px, calc(env(safe-area-inset-left, 0px) + 4px)); padding-right: max(18px, calc(env(safe-area-inset-right, 0px) + 4px)); }
body.tg-embedded .steps-bar { margin-top: 6px; }
.app.hidden { display: none; }

/* ---- header ---- */
.header { margin-bottom: 8px; }
.header-top { display: flex; align-items: center; justify-content: space-between; }
.header-brand { display: flex; align-items: center; gap: 12px; }
.brand-logo {
  width: 48px; height: 48px; border-radius: 16px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  display: flex; align-items: center; justify-content: center;
  font-size: 24px; box-shadow: 0 0 24px var(--accent-glow);
  animation: floaty 3s ease-in-out infinite;
}
@keyframes floaty { 0%,100% { transform: translateY(0);} 50% { transform: translateY(-4px);} }
.header-brand h1 { font-size: 20px; font-weight: 800; letter-spacing: -0.3px; }
.header-sub { font-size: 12px; color: var(--text-dim); }

.user-avatar {
  width: 42px; height: 42px; border-radius: 50%;
  background: var(--surface-2); border: 1.5px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  font-size: 18px; font-weight: 700; color: var(--accent-2);
  overflow: hidden;
}
.user-avatar img { width: 100%; height: 100%; object-fit: cover; border-radius: 50%; }

/* ---- steps bar ---- */
.steps-bar { display: flex; align-items: center; margin: 22px 0 24px; }
.step-dot { display: flex; flex-direction: column; align-items: center; gap: 6px; flex-shrink: 0; }
.step-dot span {
  width: 34px; height: 34px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; font-weight: 700;
  background: var(--surface); border: 1.5px solid var(--border);
  color: var(--text-dim); transition: all 0.4s cubic-bezier(.4,0,.2,1);
}
.step-dot i { font-style: normal; font-size: 10px; color: var(--text-dim); }
.step-dot.active span {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff; border-color: transparent;
  box-shadow: 0 0 18px var(--accent-glow);
}
.step-dot.done span { background: var(--success); color: #04301f; border-color: transparent; }
.step-line { flex: 1; height: 2px; background: var(--surface-2); margin: 0 6px 18px; border-radius: 1px; }
.step-line.active { background: linear-gradient(90deg, var(--accent), var(--accent-2)); }

/* ---- panels ---- */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 26px 22px;
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  animation: slideUp 0.5s cubic-bezier(.3,.8,.3,1) both;
}
.panel.hidden { display: none; }
@keyframes slideUp { from { opacity: 0; transform: translateY(22px);} to { opacity: 1; transform: translateY(0);} }

.panel-title { font-size: 22px; font-weight: 800; letter-spacing: -0.4px; margin-bottom: 6px; }
.panel-desc { font-size: 13px; color: var(--text-dim); line-height: 1.5; margin-bottom: 22px; }

/* ---- type grid ---- */
.type-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.type-card {
  position: relative; overflow: hidden;
  background: var(--surface-2);
  border: 1.5px solid var(--border);
  border-radius: 18px;
  padding: 22px 16px;
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  cursor: pointer; transition: transform 0.25s cubic-bezier(.3,.8,.3,1), border-color 0.25s, box-shadow 0.25s;
  color: var(--text); font-family: inherit;
}
.type-card:active { transform: scale(0.96); }
.type-card::before {
  content: ''; position: absolute; inset: 0;
  background: radial-gradient(circle at 30% 20%, rgba(124,92,255,0.16), transparent 60%);
  opacity: 0; transition: opacity 0.3s;
}
.type-card:hover::before, .type-card.selected::before { opacity: 1; }
.type-card.selected { border-color: var(--accent); box-shadow: 0 0 22px var(--accent-glow); }
.type-icon { font-size: 32px; filter: drop-shadow(0 4px 12px rgba(0,0,0,0.4)); }
.type-name { font-weight: 700; font-size: 15px; }
.type-tag { font-size: 11px; color: var(--text-dim); background: var(--surface); padding: 3px 10px; border-radius: 999px; }

/* ---- fields ---- */
.field { margin-bottom: 18px; }
.field label { display: block; font-size: 12px; font-weight: 600; color: var(--text-dim); margin-bottom: 8px; letter-spacing: 0.4px; text-transform: uppercase; }
.field input, input#apiIdInput {
  width: 100%; padding: 15px 16px;
  background: var(--surface-2);
  border: 1.5px solid var(--border);
  border-radius: 14px;
  color: var(--text); font-size: 15px; font-family: inherit;
  transition: border-color 0.25s, box-shadow 0.25s;
  outline: none;
}
.field input:focus { border-color: var(--accent); box-shadow: 0 0 0 4px rgba(124,92,255,0.15); }
.field input::placeholder { color: rgba(154,154,176,0.5); }
input[type=number]::-webkit-outer-spin-button, input[type=number]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

.field-error {
  background: rgba(255,84,112,0.12); border: 1px solid rgba(255,84,112,0.3);
  color: #ffa4b4; font-size: 13px; padding: 12px 14px; border-radius: 12px; margin-bottom: 16px;
}
.field-error.hidden { display: none; }

/* ---- buttons ---- */
.btn {
  width: 100%; padding: 16px;
  border-radius: 15px; border: none;
  font-family: inherit; font-size: 15px; font-weight: 700;
  cursor: pointer; transition: transform 0.2s cubic-bezier(.3,.8,.3,1), box-shadow 0.25s, opacity 0.2s;
  display: flex; align-items: center; justify-content: center; gap: 8px;
}
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.55; pointer-events: none; }

.btn-primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff; box-shadow: 0 8px 24px var(--accent-glow);
}
.btn-primary:hover { box-shadow: 0 10px 32px var(--accent-glow); }
.btn-pulse { animation: btnPulse 2.4s ease-in-out infinite; }
@keyframes btnPulse { 0%,100% { box-shadow: 0 8px 24px var(--accent-glow);} 50% { box-shadow: 0 8px 38px var(--accent-glow), 0 0 0 6px rgba(124,92,255,0.08);} }

.btn-ghost {
  background: var(--surface-2); color: var(--text);
  border: 1.5px solid var(--border); margin-top: 12px;
}
.btn-ghost:hover { background: rgba(255,255,255,0.12); }

.back-btn {
  background: none; border: none; color: var(--text-dim);
  font-family: inherit; font-size: 13px; font-weight: 600;
  cursor: pointer; margin-bottom: 16px; padding: 6px 0;
}
.back-btn:hover { color: var(--text); }

/* ---- OTP inputs ---- */
.otp-row { display: flex; gap: 10px; justify-content: center; margin-bottom: 20px; }
.otp-row input {
  width: 50px; height: 60px;
  text-align: center; font-size: 26px; font-weight: 800;
  background: var(--surface-2); border: 1.5px solid var(--border);
  border-radius: 14px; color: var(--accent-2); outline: none;
  transition: border-color 0.2s, box-shadow 0.2s, transform 0.15s;
}
.otp-row input:focus { border-color: var(--accent); box-shadow: 0 0 0 4px rgba(124,92,255,0.18); transform: translateY(-2px); }

/* ---- success ---- */
.success-ring {
  width: 110px; height: 110px; margin: 0 auto 22px;
  border-radius: 50%;
  background: linear-gradient(135deg, rgba(46,230,168,0.15), rgba(0,212,255,0.1));
  display: flex; align-items: center; justify-content: center;
  animation: popIn 0.6s cubic-bezier(.3,1.6,.5,1) both;
  border: 1.5px solid rgba(46,230,168,0.3);
}
.success-check {
  width: 72px; height: 72px; border-radius: 50%;
  background: linear-gradient(135deg, var(--success), #00d4a0);
  color: #fff; font-size: 38px; font-weight: 800;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 0 40px rgba(46,230,168,0.5);
}
@keyframes popIn { from { transform: scale(0.3); opacity: 0;} to { transform: scale(1); opacity: 1;} }

.session-box {
  background: rgba(0,0,0,0.45);
  border: 1px solid var(--border);
  border-radius: 14px; padding: 16px;
  font-family: 'SF Mono', ui-monospace, monospace; font-size: 12px;
  line-height: 1.6; color: #9ff5dd; word-break: break-all;
  max-height: 180px; overflow-y: auto; margin-bottom: 20px;
  white-space: pre-wrap;
}
.result-actions { display: flex; gap: 10px; flex-direction: column; }
.result-note { text-align: center; font-size: 12px; color: var(--success); margin-top: 18px; }

#step4 { text-align: center; }

/* ---- busy overlay ---- */
.busy-overlay {
  position: fixed; inset: 0; z-index: 110;
  background: rgba(5,5,12,0.75); backdrop-filter: blur(6px);
  display: flex; align-items: center; justify-content: center;
}
.busy-overlay.hidden { display: none; }
.busy-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 20px; padding: 30px 40px;
  display: flex; flex-direction: column; align-items: center; gap: 16px;
  backdrop-filter: blur(20px);
}
.busy-text { font-size: 14px; color: var(--text-dim); }

/* ---- toast ---- */
.toast {
  position: fixed; bottom: 32px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: rgba(20,20,35,0.95); border: 1px solid var(--border);
  color: var(--text); padding: 13px 22px; border-radius: 999px;
  font-size: 13px; font-weight: 600; z-index: 200;
  opacity: 0; transition: all 0.35s cubic-bezier(.3,.8,.3,1);
  backdrop-filter: blur(12px); max-width: 86%;
  box-shadow: 0 10px 30px rgba(0,0,0,0.4);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.hidden { display: block; }

::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(124,92,255,0.35); border-radius: 3px; }

@media (max-width: 380px) {
  .otp-row input { width: 44px; height: 54px; font-size: 22px; }
}
