:root {
  --bg-primary: #0f172a;
  --bg-surface: #1e293b;
  --bg-surface-active: #283548;
  --bg-input: #0b1120;
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --accent-blue: #38bdf8;
  --accent-emerald: #34d399;
  --accent-amber: #fbbf24;
  --border-subtle: rgba(255, 255, 255, 0.08);
  --border-focus: #38bdf8;
  --card-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.4), 0 8px 10px -6px rgba(0, 0, 0, 0.3);
  --radius-lg: 18px;
  --radius-md: 12px;
  --radius-sm: 8px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  min-height: 100%;
  height: 100%;
  background-color: var(--bg-primary);
  color: var(--text-main);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  overscroll-behavior-y: contain;
}

body {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 0;
}

/* App Outer Shell - Optimized for mobile screen bounds */
.app-wrapper {
  width: 100%;
  max-width: 480px;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: env(safe-area-inset-top, 1rem) 1.25rem env(safe-area-inset-bottom, 1.25rem);
  box-sizing: border-box;
}

/* Header */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 0;
  margin-bottom: 0.5rem;
}

.nav-back {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.95rem;
  font-weight: 500;
  padding: 0.4rem 0.6rem;
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.05);
  transition: all 0.2s ease;
}

.nav-back:hover, .nav-back:active {
  color: var(--text-main);
  background: rgba(255, 255, 255, 0.1);
}

.app-title {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.text-accent {
  color: var(--accent-blue);
}

.header-right {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.icon-btn {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-subtle);
  color: var(--text-muted);
  width: 38px;
  height: 38px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  transition: all 0.2s ease;
}

.icon-btn:active {
  transform: scale(0.94);
  background: rgba(255, 255, 255, 0.12);
  color: var(--accent-blue);
}

.icon-btn.spinning i {
  animation: spin 0.8s linear infinite;
}

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

.btn-install {
  background: linear-gradient(135deg, #0284c7, #2563eb);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  padding: 0.45rem 0.75rem;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  transition: all 0.2s ease;
}

.btn-install:active {
  transform: scale(0.96);
  opacity: 0.9;
}

/* Status Banner */
.status-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.4rem 0.75rem;
  background: rgba(30, 41, 59, 0.6);
  border-radius: var(--radius-sm);
  margin-bottom: 1.25rem;
  font-size: 0.8rem;
  border: 1px solid var(--border-subtle);
}

.status-pill {
  display: flex;
  align-items: center;
  gap: 0.45rem;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: var(--accent-amber);
  display: inline-block;
}

.status-dot.online {
  background-color: var(--accent-emerald);
  box-shadow: 0 0 8px rgba(52, 211, 153, 0.6);
}

.status-dot.offline {
  background-color: var(--accent-amber);
}

.status-text {
  color: var(--text-muted);
  font-weight: 500;
}

.rates-date {
  color: var(--text-muted);
  font-size: 0.75rem;
}

/* Currency Cards */
.cards-container {
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
}

.currency-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 1rem 1.15rem;
  box-shadow: var(--card-shadow);
  transition: border-color 0.2s ease, transform 0.15s ease;
}

.currency-card:focus-within {
  border-color: var(--accent-blue);
  box-shadow: 0 0 0 1px var(--accent-blue), var(--card-shadow);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.6rem;
}

.currency-meta {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.flag {
  font-size: 1.5rem;
  line-height: 1;
}

.currency-titles {
  display: flex;
  flex-direction: column;
}

.currency-titles .code {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-main);
  letter-spacing: 0.02em;
}

.currency-titles .name {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.symbol-badge {
  background: rgba(255, 255, 255, 0.07);
  color: var(--accent-blue);
  font-weight: 700;
  font-size: 1rem;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Input Area */
.input-wrapper {
  position: relative;
  display: flex;
  align-items: center;
  background: var(--bg-input);
  border-radius: var(--radius-md);
  padding: 0.4rem 0.75rem;
  border: 1px solid var(--border-subtle);
}

.symbol-prefix {
  font-size: 1.35rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-right: 0.5rem;
  user-select: none;
}

.currency-input {
  width: 100%;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text-main);
  font-size: 1.75rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}

.currency-input::placeholder {
  color: rgba(255, 255, 255, 0.15);
}

.clear-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 1.1rem;
  padding: 0.3rem;
  cursor: pointer;
  display: none;
  transition: color 0.15s ease;
}

.clear-btn.visible {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.clear-btn:active {
  color: var(--text-main);
}

/* Quick Presets */
.quick-presets {
  margin-top: 1.25rem;
  padding: 0 0.25rem;
}

.presets-label {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
}

.presets-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 0.45rem;
}

.preset-btn {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  color: var(--text-main);
  border-radius: var(--radius-sm);
  padding: 0.55rem 0.2rem;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  text-align: center;
  transition: all 0.15s ease;
}

.preset-btn:hover {
  background: var(--bg-surface-active);
  border-color: rgba(255, 255, 255, 0.15);
}

.preset-btn:active {
  transform: scale(0.95);
  background: var(--accent-blue);
  color: #0f172a;
}

.preset-btn.reset-all {
  color: #f87171;
  background: rgba(239, 68, 68, 0.1);
  border-color: rgba(239, 68, 68, 0.2);
}

.preset-btn.reset-all:hover {
  background: rgba(239, 68, 68, 0.2);
}

/* Rates Footer & Ticker */
.rates-footer {
  margin-top: auto;
  padding-top: 1.5rem;
  text-align: center;
}

.rates-ticker {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 0.75rem 0.5rem;
  display: flex;
  align-items: center;
  justify-content: space-around;
  margin-bottom: 0.6rem;
}

.rate-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.15rem;
}

.rate-label {
  font-size: 0.7rem;
  color: var(--text-muted);
}

.rate-val {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--accent-emerald);
}

.rate-unit {
  font-size: 0.65rem;
  color: var(--text-muted);
}

.rate-divider {
  width: 1px;
  height: 28px;
  background-color: var(--border-subtle);
}

.data-source-note {
  font-size: 0.7rem;
  color: var(--text-muted);
  opacity: 0.8;
}

/* iOS Prompt Modal */
.ios-prompt {
  position: fixed;
  bottom: 1.5rem;
  left: 1.25rem;
  right: 1.25rem;
  max-width: 440px;
  margin: 0 auto;
  background: #1e293b;
  border: 1px solid var(--accent-blue);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  box-shadow: 0 20px 35px rgba(0, 0, 0, 0.6);
  z-index: 1000;
}

.ios-prompt-content {
  position: relative;
}

.ios-prompt h3 {
  font-size: 1rem;
  margin-bottom: 0.6rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--accent-blue);
}

.ios-prompt ol {
  padding-left: 1.25rem;
  font-size: 0.85rem;
  line-height: 1.5;
  color: var(--text-muted);
}

.ios-prompt strong {
  color: var(--text-main);
}

.close-ios {
  position: absolute;
  top: -4px;
  right: 0;
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 1rem;
  cursor: pointer;
}

/* Utility */
.hidden {
  display: none !important;
}
