*,
*::before,
*::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --color-bg-1: #071410;
  --color-bg-2: #0f2320;
  --color-card: rgba(255, 255, 255, 0.045);
  --color-card-solid: #12201c;
  --color-surface-strong: rgba(255, 255, 255, 0.09);
  --color-border: rgba(255, 255, 255, 0.1);
  --color-border-strong: rgba(255, 255, 255, 0.18);
  --color-text: #f3f6f4;
  --color-text-muted: #93a8a1;
  --color-accent: #25d366;
  --color-accent-strong: #4ceb87;
  --color-accent-deep: #128c7e;
  --color-danger: #ff9d7a;
  --radius: 14px;
  --radius-lg: 22px;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.35), 0 12px 40px rgba(0, 0, 0, 0.4);
  --shadow-glow: 0 0 0 1px rgba(37, 211, 102, 0.35), 0 10px 34px rgba(37, 211, 102, 0.22);
  --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: radial-gradient(ellipse at top, var(--color-bg-2), var(--color-bg-1) 70%);
  background-attachment: fixed;
  color: var(--color-text);
  line-height: 1.5;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
}

main {
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
  padding: clamp(1.75rem, 6vw, 3.5rem) 1.25rem 3rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* --- Intro --- */

.intro {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.25rem;
}

.intro-icon {
  display: grid;
  place-items: center;
  width: 3rem;
  height: 3rem;
  border-radius: 50%;
  color: var(--color-accent);
  background: rgba(37, 211, 102, 0.12);
  border: 1px solid rgba(37, 211, 102, 0.3);
}

.intro-icon svg {
  width: 1.6rem;
  height: 1.6rem;
}

.intro h1 {
  font-size: clamp(1.5rem, 5.5vw, 2rem);
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.2;
  background: linear-gradient(135deg, #ffffff 0%, #8ff0b4 110%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.subtitle {
  color: var(--color-text-muted);
  font-size: 0.95rem;
  max-width: 24rem;
}

/* --- Cards --- */

.card {
  background: var(--color-card);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
  padding: 1.5rem 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  /* Every card needs a place in the paint order. `backdrop-filter` creates a
     stacking context, which traps the country panel inside the card that holds
     it: the panel's own z-index then counts only against its siblings in that
     card, never against a later card. Without this, the "Recent numbers" card
     painted over the open panel and hid half the country list. Do not remove
     these two rules while the cards keep `backdrop-filter`. */
  position: relative;
  z-index: 1;
}

/* The card that holds the country panel has to sit above the cards below it,
   because the panel drops out of the card and over them. */
#dial-form {
  z-index: 2;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.field label {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--color-text-muted);
}

/* --- Number row: country selector + phone field --- */

.number-row {
  position: relative;
  display: flex;
  gap: 0.5rem;
  align-items: stretch;
}

.country-trigger,
#phone-input {
  font: inherit;
  color: var(--color-text);
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  min-height: 3.25rem;
  transition: border-color var(--transition), box-shadow var(--transition), background var(--transition);
}

.country-trigger {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0 0.7rem;
  cursor: pointer;
  flex: 0 0 auto;
  font-variant-numeric: tabular-nums;
}

.country-trigger:hover {
  background: rgba(0, 0, 0, 0.18);
  border-color: var(--color-border-strong);
}

.country-trigger .flag {
  font-size: 1.35rem;
  line-height: 1;
}

.country-trigger .dial {
  font-weight: 600;
  font-size: 0.98rem;
}

.chevron {
  width: 1rem;
  height: 1rem;
  color: var(--color-text-muted);
  flex: 0 0 auto;
  transition: transform var(--transition);
}

.country-trigger[aria-expanded="true"] .chevron {
  transform: rotate(180deg);
}

#phone-input {
  flex: 1 1 auto;
  min-width: 0;
  padding: 0 0.9rem;
  font-size: 1.05rem;
  letter-spacing: 0.02em;
}

#phone-input::placeholder {
  color: rgba(147, 168, 161, 0.55);
}

.country-trigger:focus-visible,
#phone-input:focus {
  outline: none;
  border-color: var(--color-accent);
  box-shadow: 0 0 0 3px rgba(37, 211, 102, 0.18);
}

/* --- Country panel --- */

.country-panel {
  position: absolute;
  z-index: 20;
  top: calc(100% + 0.5rem);
  left: 0;
  right: 0;
  background: var(--color-card-solid);
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius);
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.55);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.country-panel[hidden] {
  display: none;
}

.country-search-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.65rem 0.8rem;
  border-bottom: 1px solid var(--color-border);
}

.search-icon {
  width: 1.05rem;
  height: 1.05rem;
  color: var(--color-text-muted);
  flex: 0 0 auto;
}

#country-search {
  font: inherit;
  flex: 1 1 auto;
  min-width: 0;
  background: none;
  border: none;
  color: var(--color-text);
  padding: 0.2rem 0;
}

#country-search:focus {
  outline: none;
}

#country-search::placeholder {
  color: rgba(147, 168, 161, 0.55);
}

.country-list {
  list-style: none;
  max-height: min(19rem, 45vh);
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

.country-option {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.6rem 0.85rem;
  cursor: pointer;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
  color: inherit;
  font: inherit;
}

.country-option .flag {
  font-size: 1.25rem;
  line-height: 1;
  flex: 0 0 auto;
}

.country-option .name {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.95rem;
}

.country-option .dial {
  color: var(--color-text-muted);
  font-size: 0.9rem;
  font-variant-numeric: tabular-nums;
  flex: 0 0 auto;
}

.country-option.active,
.country-option:hover {
  background: rgba(37, 211, 102, 0.14);
}

.country-option[aria-selected="true"] {
  color: var(--color-accent-strong);
}

.country-option[aria-selected="true"] .dial {
  color: var(--color-accent-strong);
}

.country-empty {
  padding: 0.9rem;
  color: var(--color-text-muted);
  font-size: 0.9rem;
  text-align: center;
}

.country-empty[hidden] {
  display: none;
}

/* --- Hint line --- */

.hint {
  font-size: 0.88rem;
  color: var(--color-text-muted);
  min-height: 1.3em;
  font-variant-numeric: tabular-nums;
}

.hint.is-ready {
  color: var(--color-accent-strong);
  font-weight: 600;
  letter-spacing: 0.01em;
}

.hint.is-problem {
  color: var(--color-danger);
}

/* --- Buttons --- */

.open-button {
  font: inherit;
  text-decoration: none;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.55rem;
  width: 100%;
  min-height: 3.25rem;
  padding: 0 1.5rem;
  border: none;
  border-radius: 999px;
  background: linear-gradient(135deg, var(--color-accent), var(--color-accent-deep));
  color: #04150d;
  font-size: 1.02rem;
  font-weight: 700;
  letter-spacing: 0.01em;
  cursor: pointer;
  box-shadow: var(--shadow-glow);
  transition: transform var(--transition), box-shadow var(--transition), opacity var(--transition);
}

.open-button svg {
  width: 1.2rem;
  height: 1.2rem;
}

.open-button:hover:not([aria-disabled="true"]) {
  transform: translateY(-1px);
  box-shadow: 0 0 0 1px rgba(76, 235, 135, 0.6), 0 14px 42px rgba(37, 211, 102, 0.34);
}

.open-button:active:not([aria-disabled="true"]) {
  transform: translateY(0);
}

.open-button[aria-disabled="true"] {
  opacity: 0.4;
  cursor: not-allowed;
  box-shadow: none;
}

.open-button:focus-visible {
  outline: 2px solid var(--color-accent-strong);
  outline-offset: 3px;
}

.ghost-button {
  font: inherit;
  background: var(--color-surface-strong);
  color: var(--color-text);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 0.5rem 0.85rem;
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: background var(--transition), border-color var(--transition), color var(--transition), opacity var(--transition);
}

.ghost-button:hover:not(:disabled) {
  background: rgba(37, 211, 102, 0.16);
  border-color: rgba(37, 211, 102, 0.42);
  color: var(--color-accent-strong);
}

.ghost-button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.ghost-button:focus-visible {
  outline: 2px solid var(--color-accent-strong);
  outline-offset: 2px;
}

.ghost-button.small {
  padding: 0.3rem 0.6rem;
  font-size: 0.82rem;
}

.share-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.share-status {
  color: var(--color-accent-strong);
  font-size: 0.88rem;
  min-height: 1.2em;
}

/* --- Recent numbers --- */

.recents[hidden] {
  display: none;
}

.recents-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.recents-head h2 {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--color-text-muted);
}

.recents-list {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.recent-chip {
  font: inherit;
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  background: rgba(0, 0, 0, 0.28);
  border: 1px solid var(--color-border);
  border-radius: 999px;
  padding: 0.4rem 0.8rem;
  color: var(--color-text);
  font-size: 0.9rem;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition), color var(--transition);
}

.recent-chip .flag {
  font-size: 1.1rem;
  line-height: 1;
}

.recent-chip:hover {
  background: rgba(37, 211, 102, 0.16);
  border-color: rgba(37, 211, 102, 0.42);
  color: var(--color-accent-strong);
}

.recent-chip:focus-visible {
  outline: 2px solid var(--color-accent-strong);
  outline-offset: 2px;
}

.recents-note {
  font-size: 0.8rem;
  color: var(--color-text-muted);
}

/* --- Footer --- */

.page-footer {
  text-align: center;
  color: var(--color-text-muted);
  font-size: 0.8rem;
  padding: 0 0.5rem;
}

.page-footer code {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.95em;
  color: var(--color-text);
  background: rgba(255, 255, 255, 0.07);
  border-radius: 5px;
  padding: 0.05em 0.35em;
}

/* --- Small screens --- */

@media (max-width: 400px) {
  main {
    padding-left: 0.9rem;
    padding-right: 0.9rem;
  }
  .card {
    padding: 1.25rem 1rem;
  }
  .country-trigger {
    padding: 0 0.55rem;
    gap: 0.3rem;
  }
  #phone-input {
    font-size: 1rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
  }
  .open-button:hover:not([aria-disabled="true"]) {
    transform: none;
  }
}
