:root {
  color-scheme: light dark;
  --bg: #0f172a;
  --card-bg: rgba(15, 23, 42, 0.75);
  --card-border: rgba(148, 163, 184, 0.1);
  --text: #e2e8f0;
  --muted: #94a3b8;
  --accent: #38bdf8;
  --accent-soft: rgba(56, 189, 248, 0.12);
  --success: #34d399;
  --danger: #f87171;
  font-family: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI',
    sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: radial-gradient(circle at top left, rgba(56, 189, 248, 0.18), transparent 45%),
    radial-gradient(circle at bottom right, rgba(129, 140, 248, 0.18), transparent 55%),
    var(--bg);
  color: var(--text);
  line-height: 1.6;
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

.container {
  width: min(1100px, 92vw);
  margin: 0 auto;
}

.page-header {
  padding: 2.5rem 0 2rem;
}

.page-header .container {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 2rem;
}

.branding {
  display: flex;
  align-items: center;
  gap: 1.5rem;
}

.branding h1 {
  margin: 0 0 0.2rem;
  font-size: clamp(2.1rem, 4vw, 2.6rem);
}

.branding p {
  margin: 0;
  color: var(--muted);
}

.logo {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.4rem;
}

.logo-circle {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: linear-gradient(135deg, rgba(56, 189, 248, 0.9), rgba(129, 140, 248, 0.6));
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.3);
}

.logo-circle:nth-child(2) {
  background: linear-gradient(135deg, rgba(59, 130, 246, 0.9), rgba(56, 189, 248, 0.5));
}

.logo-circle:nth-child(3) {
  grid-column: span 2;
  justify-self: center;
  width: 48px;
  height: 48px;
  background: linear-gradient(135deg, rgba(129, 140, 248, 0.9), rgba(59, 130, 246, 0.6));
}

.market-summary {
  text-align: right;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.35rem;
}

.market-summary .refresh-status {
  margin: 0;
  font-size: 0.85rem;
  color: var(--muted);
}

.refresh-button {
  margin: 0;
  padding: 0.55rem 1rem;
  border-radius: 999px;
  border: 1px solid rgba(148, 163, 184, 0.25);
  background: rgba(15, 23, 42, 0.4);
  color: inherit;
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition: border-color 0.2s ease, background 0.2s ease, transform 0.2s ease;
}

.refresh-button:hover,
.refresh-button:focus-visible {
  border-color: var(--accent);
  background: rgba(56, 189, 248, 0.12);
  transform: translateY(-1px);
}

.refresh-button:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.35);
}

.summary-title {
  margin: 0;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.summary-value {
  margin: 0.2rem 0 0;
  font-size: 1.1rem;
  font-weight: 600;
}

main.container {
  display: grid;
  grid-template-columns: 1.15fr 0.85fr;
  gap: 1.5rem;
}

.card {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 20px;
  padding: 1.75rem;
  backdrop-filter: blur(14px);
  box-shadow: 0 20px 60px rgba(15, 23, 42, 0.35);
}

.card-wide {
  grid-column: span 2;
}

.card-header h2 {
  margin: 0 0 0.4rem;
  font-size: 1.4rem;
}

.card-header p {
  margin: 0;
  color: var(--muted);
}

.favorites-editor {
  margin: 1.2rem 0 0;
  border: 1px solid rgba(148, 163, 184, 0.18);
  border-radius: 16px;
  background: rgba(15, 23, 42, 0.35);
  padding: 0.75rem 1rem;
}

.favorites-editor[open] {
  background: rgba(15, 23, 42, 0.5);
}

.favorites-editor summary {
  list-style: none;
  cursor: pointer;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.favorites-editor summary::-webkit-details-marker {
  display: none;
}

.favorites-editor summary::after {
  content: '▾';
  float: right;
  transition: transform 0.2s ease;
}

.favorites-editor[open] summary::after {
  transform: rotate(180deg);
}

.favorites-body {
  margin-top: 0.9rem;
  display: grid;
  gap: 0.75rem;
}

.favorites-body p {
  margin: 0;
  color: var(--muted);
  font-size: 0.85rem;
}

.favorites-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 0.55rem;
}

.favorite-option {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  background: rgba(148, 163, 184, 0.08);
  border-radius: 12px;
  padding: 0.45rem 0.65rem;
  font-size: 0.9rem;
}

.favorite-option input {
  width: 18px;
  height: 18px;
}

.reset-button {
  justify-self: start;
  padding: 0.45rem 0.85rem;
  border-radius: 999px;
  border: 1px solid rgba(148, 163, 184, 0.3);
  background: transparent;
  color: inherit;
  cursor: pointer;
  font-size: 0.85rem;
  transition: border-color 0.2s ease, background 0.2s ease;
}

.reset-button:hover,
.reset-button:focus-visible {
  border-color: var(--accent);
  background: rgba(56, 189, 248, 0.12);
}

.converter-form {
  margin-top: 1.5rem;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
  align-items: end;
}

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

.field span {
  font-size: 0.85rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

input,
select {
  background: rgba(15, 23, 42, 0.4);
  border: 1px solid rgba(148, 163, 184, 0.18);
  border-radius: 12px;
  padding: 0.85rem;
  font-size: 1rem;
  color: inherit;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

input:focus,
select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.25);
}

.swap {
  align-self: center;
  justify-self: center;
  width: 44px;
  height: 44px;
  border-radius: 12px;
  border: none;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 1.25rem;
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.swap:hover {
  transform: translateY(-2px);
  box-shadow: 0 12px 24px rgba(56, 189, 248, 0.25);
}

.swap:active {
  transform: translateY(0);
}

.result-field {
  grid-column: span 2;
  padding: 1rem;
  border-radius: 14px;
  background: rgba(148, 163, 184, 0.12);
  border: 1px solid rgba(148, 163, 184, 0.16);
}

.result-field p {
  margin: 0;
  font-size: clamp(1.6rem, 4vw, 2.2rem);
  font-weight: 600;
}

.result-field small {
  color: var(--muted);
}

.error {
  margin-top: 1.25rem;
  padding: 0.95rem 1.1rem;
  border-radius: 12px;
  border: 1px solid rgba(248, 113, 113, 0.35);
  background: rgba(248, 113, 113, 0.12);
  color: #fecaca;
  font-weight: 500;
}

.table-wrapper {
  margin-top: 1.5rem;
  border-radius: 16px;
  overflow: hidden;
  border: 1px solid rgba(148, 163, 184, 0.12);
}

.metals-grid {
  margin-top: 1.5rem;
  display: grid;
  gap: 1.2rem;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

.metal-card {
  padding: 1.4rem 1.5rem;
  border-radius: 18px;
  border: 1px solid rgba(148, 163, 184, 0.12);
  background: rgba(15, 23, 42, 0.45);
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  box-shadow: inset 0 0 0 1px rgba(148, 163, 184, 0.08);
}

.metal-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
}

.metal-card h3 {
  margin: 0;
  font-size: 1.1rem;
}

.metal-badge {
  padding: 0.25rem 0.6rem;
  border-radius: 999px;
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-weight: 600;
}

.metal-badge.gold {
  background: rgba(250, 204, 21, 0.15);
  color: #facc15;
}

.metal-badge.silver {
  background: rgba(203, 213, 225, 0.15);
  color: #e2e8f0;
}

.metal-price {
  margin: 0;
  font-size: clamp(1.3rem, 3.4vw, 1.9rem);
  font-weight: 600;
}

.metal-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  color: var(--muted);
}

.metal-meta .change {
  margin-left: auto;
}

.metal-card.placeholder {
  justify-content: center;
  text-align: center;
  color: var(--muted);
}

.metal-error {
  border-style: dashed;
  border-color: rgba(248, 113, 113, 0.4);
  background: rgba(248, 113, 113, 0.08);
  color: #fecaca;
  text-align: center;
}

table {
  width: 100%;
  border-collapse: collapse;
}

thead {
  background: rgba(148, 163, 184, 0.1);
  color: var(--muted);
  text-transform: uppercase;
  font-size: 0.75rem;
  letter-spacing: 0.08em;
}

thead th {
  padding: 0.85rem 1rem;
  text-align: left;
}

tbody tr {
  border-bottom: 1px solid rgba(148, 163, 184, 0.08);
}

tbody tr:last-child {
  border-bottom: none;
}

td {
  padding: 1rem;
}

.rate-value {
  font-weight: 600;
}

.change {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.35rem 0.6rem;
  border-radius: 999px;
  font-weight: 600;
  font-size: 0.9rem;
}

.change.positive {
  background: rgba(52, 211, 153, 0.14);
  color: var(--success);
}

.change.negative {
  background: rgba(248, 113, 113, 0.14);
  color: var(--danger);
}

.change.neutral {
  background: rgba(148, 163, 184, 0.14);
  color: var(--muted);
}

.placeholder td {
  text-align: center;
  color: var(--muted);
}

.insight-list {
  margin: 1.5rem 0 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 0.9rem;
}

.insight-list li {
  padding: 0.95rem 1.1rem;
  border-radius: 14px;
  background: rgba(15, 23, 42, 0.35);
  border: 1px solid rgba(148, 163, 184, 0.12);
  position: relative;
  padding-left: 2.6rem;
}

.insight-list li::before {
  content: '★';
  position: absolute;
  left: 1rem;
  top: 50%;
  transform: translateY(-50%);
  font-size: 1rem;
  color: var(--accent);
}

.insight-list li strong {
  display: block;
  font-size: 1rem;
  letter-spacing: 0.02em;
}

.insight-list li span {
  display: block;
  color: var(--muted);
}

.insight-list li .change {
  margin-top: 0.45rem;
  display: inline-flex;
}

.chart-controls {
  margin-top: 1.5rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 1rem;
}

.chart-controls .field {
  margin: 0;
  width: min(220px, 100%);
}

.chart-status {
  margin: 0;
  font-size: 0.85rem;
  color: var(--muted);
}

.chart-wrapper {
  margin-top: 1.5rem;
  width: 100%;
  min-height: 260px;
}

#trend-chart {
  width: 100%;
  max-height: 320px;
}

.page-footer {
  margin: 3rem 0 2rem;
  color: var(--muted);
  font-size: 0.95rem;
}

@media (max-width: 900px) {
  main.container {
    grid-template-columns: 1fr;
  }

  .card-wide {
    grid-column: span 1;
  }

  .page-header .container {
    flex-direction: column;
    align-items: flex-start;
  }

  .market-summary {
    text-align: left;
    align-self: stretch;
  }

  .market-summary {
    text-align: left;
    align-self: stretch;
    align-items: flex-start;
  }
}

@media (max-width: 600px) {
  .converter-form {
    grid-template-columns: 1fr;
  }

  .swap {
    width: 100%;
    height: 50px;
  }

  .result-field {
    grid-column: span 1;
  }

  .metals-grid {
    grid-template-columns: 1fr;
  }
}
