:root {
  --bg: #f5f7fb;
  --card: #ffffff;
  --text: #1f2937;
  --muted: #6b7280;
  --accent: #2563eb;
  --accent-soft: #dbeafe;
  --border: #e5e7eb;
  --error: #dc2626;
  --shadow: 0 16px 40px rgba(31, 41, 55, 0.08);
}

body.dark {
  --bg: #0f172a;
  --card: #111827;
  --text: #f9fafb;
  --muted: #9ca3af;
  --accent: #60a5fa;
  --accent-soft: #1e3a8a;
  --border: #374151;
  --error: #f87171;
  --shadow: 0 16px 40px rgba(2, 6, 23, 0.45);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Inter", "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
}

.app {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: clamp(8px, 3vw, 20px);
}

.converter-card {
  width: min(100%, 520px);
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 22px;
  box-shadow: var(--shadow);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

h1 {
  margin: 0;
  font-size: clamp(1.2rem, 2.6vw, 1.6rem);
}

.theme-btn,
.swap-btn {
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  border-radius: 12px;
  cursor: pointer;
}

.theme-btn {
  width: 44px;
  height: 44px;
  font-size: 1rem;
}

.subtitle {
  margin: 8px 0 20px;
  color: var(--muted);
  font-size: clamp(0.85rem, 2vw, 1rem);
}

.label {
  display: block;
  margin-bottom: 8px;
  font-size: 0.95rem;
  color: var(--muted);
}

.amount-input,
.currency-select {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  background: var(--card);
  color: var(--text);
  font-size: 1rem;
}

.selectors {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: end;
  gap: 12px;
  margin-top: 16px;
}

.currency-block {
  min-width: 0;
}

.custom-select {
  position: relative;
  min-width: 0;
}

.cs-trigger {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 12px;
  background: var(--card);
  color: var(--text);
  font-size: 1rem;
  cursor: pointer;
  text-align: left;
  outline: none;
}

.cs-trigger:focus-visible,
.cs-trigger[aria-expanded="true"] {
  border-color: var(--accent);
}

.cs-value {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 600;
}

.cs-search {
  flex: 1;
  min-width: 0;
  border: 0;
  background: transparent;
  color: var(--text);
  font-size: 1rem;
  padding: 0;
  outline: none;
}

.cs-caret {
  color: var(--muted);
  font-size: 0.8rem;
  transition: transform 0.15s ease;
}

.cs-trigger[aria-expanded="true"] .cs-caret {
  transform: rotate(180deg);
}

.cs-panel {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  z-index: 20;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 6px;
  display: flex;
  flex-direction: column;
  max-height: min(60vh, 320px);
  overflow: hidden;
}

.cs-panel[hidden] {
  display: none;
}

.cs-list {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  flex: 1;
}

.cs-list li {
  padding: 10px 12px;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 500;
  color: var(--text);
}

.cs-list li:hover,
.cs-list li[aria-selected="true"] {
  background: var(--accent-soft);
}

.cs-list li.is-active {
  background: var(--accent);
  color: #fff;
}

.cs-empty {
  margin: 8px 0 4px;
  text-align: center;
  color: var(--muted);
  font-size: 0.9rem;
}

.flag {
  flex-shrink: 0;
  min-width: 22px;
  border-radius: 3px;
  object-fit: cover;
  border: 1px solid var(--border);
  background: var(--accent-soft);
}

.swap-btn {
  width: 44px;
  height: 44px;
  font-size: 1.2rem;
  background: var(--accent-soft);
}

.result-box {
  margin-top: 18px;
  border-radius: 12px;
  padding: 14px;
  background: color-mix(in srgb, var(--card), var(--accent-soft) 25%);
  border: 1px solid var(--border);
}

.result-text {
  margin: 0;
  font-size: clamp(1.1rem, 3vw, 1.5rem);
  font-weight: 700;
}

.rate-info {
  margin: 6px 0 0;
  color: var(--muted);
}

.error-message {
  margin: 12px 0 0;
  color: var(--error);
  min-height: 1.2em;
}

@media (max-width: 768px) {
  .converter-card {
    padding: 20px;
    border-radius: 18px;
  }

  .selectors {
    gap: 10px;
  }
}

@media (max-width: 640px) {
  .converter-card {
    padding: 16px;
  }

  .selectors {
    gap: 8px;
  }

  .cs-trigger {
    gap: 6px;
    padding: 10px;
    font-size: 0.95rem;
    min-height: 44px;
  }

  .swap-btn {
    width: 44px;
    height: 44px;
    font-size: 1.1rem;
  }
}

@media (max-width: 360px) {
  .converter-card {
    padding: 14px;
    border-radius: 16px;
  }

  .amount-input {
    padding: 10px;
  }

  .theme-btn {
    width: 40px;
    height: 40px;
  }

  .selectors {
    gap: 6px;
  }

  .cs-trigger {
    gap: 4px;
    padding: 10px 8px;
    font-size: 0.9rem;
    min-height: 44px;
  }

  .flag {
    width: 18px;
    height: 13px;
    min-width: 18px;
  }

  .swap-btn {
    width: 40px;
    height: 40px;
  }
}

@media (max-height: 480px) and (orientation: landscape) {
  .app {
    min-height: auto;
    padding: 12px;
  }
}
