:root {
  --bg: #eef1f6;
  --card: #ffffff;
  --text: #1c1c1e;
  --text-soft: #8a8a90;
  --line: #e6e8ee;
  --blue: #0a84ff;
  --blue-dark: #0066e0;
  --red: #ff3b30;
  --green: #34c759;
  --radius-lg: 26px;
  --radius-md: 18px;
  --radius-sm: 12px;
  --shadow: 0 14px 34px rgba(20, 30, 60, 0.08), 0 2px 8px rgba(20, 30, 60, 0.04);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Vazirmatn', sans-serif;
  -webkit-font-smoothing: antialiased;
}

body {
  min-height: 100vh;
  background:
    radial-gradient(1200px 500px at 20% -10%, #ffffff 0%, transparent 60%),
    radial-gradient(1000px 600px at 100% 0%, #dfe9ff 0%, transparent 55%),
    var(--bg);
}

/* ---------- Login screen ---------- */

.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.login-card {
  width: 100%;
  max-width: 360px;
  background: var(--card);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 40px 28px 32px;
  text-align: center;
}

.login-logo {
  width: 74px;
  height: 74px;
  margin: 0 auto 18px;
  border-radius: 22px;
  background: linear-gradient(145deg, var(--blue), var(--blue-dark));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 30px;
  color: #fff;
  box-shadow: 0 10px 24px rgba(10, 132, 255, 0.35);
}

.login-card h1 {
  font-size: 1.5rem;
  font-weight: 800;
  margin: 0 0 26px;
  letter-spacing: 0.2px;
}

.login-error {
  background: #fff1f0;
  color: var(--red);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 0.9rem;
  margin-bottom: 16px;
  font-weight: 600;
}

.login-form { display: flex; flex-direction: column; gap: 14px; }

.input-group {
  display: flex;
  align-items: center;
  gap: 10px;
  background: #f5f6fa;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
}

.input-group i { color: var(--text-soft); font-size: 0.95rem; width: 18px; text-align: center; }

.input-group input {
  border: none;
  background: transparent;
  outline: none;
  flex: 1;
  font-size: 1rem;
  color: var(--text);
  font-family: inherit;
}

.input-group input::placeholder { color: #b8b9c2; }

.login-btn {
  margin-top: 6px;
  border: none;
  border-radius: var(--radius-sm);
  padding: 15px;
  font-size: 1.02rem;
  font-weight: 700;
  color: #fff;
  background: linear-gradient(135deg, var(--blue), var(--blue-dark));
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  box-shadow: 0 10px 22px rgba(10, 132, 255, 0.3);
}

.login-btn:active { transform: scale(0.97); }

/* ---------- Top bar ---------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px;
  max-width: 640px;
  margin: 0 auto;
}

.brand {
  font-weight: 800;
  font-size: 1.1rem;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
}

.brand i { color: var(--blue); }

.logout-btn {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: var(--card);
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--red);
  text-decoration: none;
  font-size: 0.95rem;
}

/* ---------- Layout ---------- */

.container {
  max-width: 640px;
  margin: 0 auto;
  padding: 0 20px 120px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.card {
  background: var(--card);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 22px;
}

.field { margin-bottom: 20px; }
.field:last-child { margin-bottom: 0; }

label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 10px;
}

label i { color: var(--blue); width: 16px; text-align: center; }

input[type="text"] {
  width: 100%;
  padding: 14px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: #f5f6fa;
  font-size: 1rem;
  color: var(--text);
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

input[type="text"]:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 4px rgba(10, 132, 255, 0.12);
  background: #fff;
}

/* ---------- Continents ---------- */

.continent-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.continent-btn {
  border: 1px solid var(--line);
  background: #f5f6fa;
  border-radius: var(--radius-sm);
  padding: 14px 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--text);
  font-family: inherit;
  transition: all 0.18s ease;
}

.continent-btn i { font-size: 1.15rem; color: var(--text-soft); transition: color 0.18s; }

.continent-btn:active { transform: scale(0.96); }

.continent-btn.active {
  background: linear-gradient(135deg, var(--blue), var(--blue-dark));
  border-color: transparent;
  color: #fff;
  box-shadow: 0 8px 18px rgba(10, 132, 255, 0.3);
}

.continent-btn.active i { color: #fff; }

/* ---------- Countries ---------- */

.country-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  gap: 10px;
}

.country-btn {
  border: 1px solid var(--line);
  background: #f5f6fa;
  border-radius: var(--radius-sm);
  padding: 12px 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text);
  font-family: inherit;
  transition: all 0.18s ease;
}

.country-btn .flag { font-size: 1.3rem; }

.country-btn:active { transform: scale(0.96); }

.country-btn.selected {
  background: linear-gradient(135deg, var(--blue), var(--blue-dark));
  border-color: transparent;
  color: #fff;
  box-shadow: 0 8px 18px rgba(10, 132, 255, 0.3);
}

/* ---------- Error ---------- */

.error-msg {
  color: var(--red);
  font-size: 0.88rem;
  font-weight: 700;
  text-align: center;
  max-height: 0;
  overflow: hidden;
  opacity: 0;
  transition: all 0.25s ease;
}

.error-msg.show { max-height: 40px; opacity: 1; margin-top: 4px; margin-bottom: 4px; }

/* ---------- Build button ---------- */

.btn-build {
  width: 100%;
  border: none;
  border-radius: var(--radius-sm);
  padding: 16px;
  font-size: 1.02rem;
  font-weight: 800;
  color: #fff;
  background: linear-gradient(135deg, var(--blue), var(--blue-dark));
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-top: 6px;
  box-shadow: 0 12px 26px rgba(10, 132, 255, 0.32);
  transition: transform 0.15s ease;
}

.btn-build:active { transform: scale(0.98); }
.btn-build:disabled { opacity: 0.7; }

.btn-build.loading i { animation: spin 0.8s linear infinite; }

@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Output ---------- */

.output-box {
  margin-top: 20px;
  background: #0c0c0e;
  border-radius: var(--radius-md);
  padding: 18px;
  animation: rise 0.35s ease;
}

@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

#outputText {
  margin: 0;
  color: #7fd0ff;
  font-family: 'SF Mono', 'Consolas', monospace;
  font-size: 0.86rem;
  white-space: pre-wrap;
  direction: ltr;
  text-align: left;
  line-height: 1.6;
}

.output-actions {
  display: flex;
  gap: 10px;
  margin-top: 16px;
}

.btn-copy, .btn-download {
  flex: 1;
  border: none;
  border-radius: var(--radius-sm);
  padding: 13px;
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  font-family: inherit;
  transition: transform 0.15s ease;
}

.btn-copy:active, .btn-download:active { transform: scale(0.97); }

.btn-copy { background: #1c1c1e; color: #7fd0ff; }
.btn-download { background: var(--green); color: #fff; }

/* ---------- History ---------- */

.history-title {
  font-weight: 800;
  font-size: 1rem;
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 16px;
}

.history-title i { color: var(--blue); }

.empty-history {
  text-align: center;
  padding: 30px 0;
  color: #c3c4cc;
  font-size: 2rem;
}

.history-item {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 14px;
  margin-bottom: 12px;
}

.history-item:last-child { margin-bottom: 0; }

.history-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.history-name { font-weight: 700; font-size: 0.95rem; }
.history-date { font-size: 0.78rem; color: var(--text-soft); direction: ltr; }
.history-country { font-size: 0.82rem; color: var(--text-soft); margin-top: 4px; }

.history-actions {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

.mini-btn {
  flex: 1;
  border: none;
  border-radius: 10px;
  padding: 9px;
  font-size: 0.85rem;
  cursor: pointer;
  background: #f5f6fa;
  color: var(--text);
  transition: transform 0.15s ease;
}

.mini-btn:active { transform: scale(0.95); }
.mini-btn.copy { color: var(--blue); }
.mini-btn.download { color: var(--green); }
.mini-btn.delete { color: var(--red); }

/* ---------- Telegram floating badge ---------- */

.tg-float {
  position: fixed;
  bottom: 26px;
  left: 22px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: linear-gradient(135deg, #2aabee, #229ed9);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 1.6rem;
  cursor: pointer;
  box-shadow: 0 10px 24px rgba(34, 158, 217, 0.45);
  z-index: 50;
  animation: pulse 2.6s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { box-shadow: 0 10px 24px rgba(34, 158, 217, 0.45); }
  50% { box-shadow: 0 10px 30px rgba(34, 158, 217, 0.75), 0 0 0 8px rgba(34, 158, 217, 0.12); }
}

.tg-tip {
  position: absolute;
  bottom: 66px;
  left: 0;
  background: #1c1c1e;
  color: #fff;
  font-size: 0.78rem;
  font-weight: 600;
  padding: 8px 12px;
  border-radius: 10px;
  white-space: nowrap;
  direction: ltr;
  opacity: 0;
  transform: translateY(6px);
  transition: all 0.25s ease;
  pointer-events: none;
}

.tg-tip::after {
  content: "";
  position: absolute;
  bottom: -5px;
  left: 18px;
  width: 10px;
  height: 10px;
  background: #1c1c1e;
  transform: rotate(45deg);
}

.tg-tip.show { opacity: 1; transform: translateY(0); }

/* ---------- Responsive ---------- */

@media (max-width: 420px) {
  .continent-row { grid-template-columns: repeat(3, 1fr); }
  .login-card { padding: 32px 22px 26px; }
}
