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

:root {
  --page-bg: #1a1d21;
  --chrome-border: #2a2e34;
  --text-primary: #eef0f3;
  --text-secondary: #9aa3ad;
  --accent: #4c9eea;
  --panel-bg: #5c626b;
  --panel-row: #5c626b;
  --code-text: #f2f4f6;
  --field-inactive: #d9dde2;
  --field-active: #9ad4f0;
  --field-text: #1c1e21;
  --chart-stroke: #8a9199;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

html,
body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: var(--page-bg);
  color: var(--text-primary);
  -webkit-tap-highlight-color: transparent;
}

body {
  display: flex;
  flex-direction: column;
  max-width: 480px;
  margin: 0 auto;
}

.banner {
  display: block;
  padding: 0.35rem 0.75rem;
  font-size: 0.75rem;
  text-align: center;
  border-bottom: 1px solid var(--chrome-border);
}

.banner--hidden {
  display: none !important;
}

#offline-banner:not(.banner--hidden) {
  background: #2a1818;
  color: #f85149;
}

#stale-banner.banner--warning:not(.banner--hidden) {
  background: #2a2412;
  color: #e3c66a;
}

.install-banner {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin: 0;
  padding: 0.45rem 0.5rem 0.45rem 0.65rem;
  background: #23272d;
  border-bottom: 1px solid var(--chrome-border);
}

.install-banner[hidden] {
  display: none !important;
}

.install-banner__icon {
  width: 2rem;
  height: 2rem;
  border-radius: 8px;
  flex-shrink: 0;
}

.install-banner__copy {
  flex: 1;
  min-width: 0;
}

.install-banner__title {
  margin: 0;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-primary);
  line-height: 1.25;
}

.install-banner__hint {
  margin: 0.15rem 0 0;
  font-size: 0.68rem;
  color: var(--text-secondary);
  line-height: 1.2;
}

.install-banner__cta {
  flex-shrink: 0;
  padding: 0.35rem 0.65rem;
  border: none;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-size: 0.75rem;
  font-weight: 700;
  cursor: pointer;
}

.install-banner__close {
  flex-shrink: 0;
  width: 1.75rem;
  height: 1.75rem;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--text-secondary);
  font-size: 1.25rem;
  line-height: 1;
  cursor: pointer;
}

.top-bar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-height: 48px;
  padding: 0.5rem 0.75rem 0.5rem 0.5rem;
  background: linear-gradient(180deg, #1e2228 0%, var(--page-bg) 100%);
  border-bottom: 1px solid var(--chrome-border);
}

.top-bar__menu {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2.25rem;
  height: 2.25rem;
  padding: 0;
  border: none;
  background: transparent;
  opacity: 0.9;
}

.top-bar__menu-lines {
  display: block;
  width: 1.05rem;
  height: 0.72rem;
  background:
    linear-gradient(#e8eaed, #e8eaed) 0 0 / 100% 2px no-repeat,
    linear-gradient(#e8eaed, #e8eaed) 0 50% / 80% 2px no-repeat,
    linear-gradient(#e8eaed, #e8eaed) 0 100% / 100% 2px no-repeat;
}

.top-bar__brand {
  flex: 1;
  margin: 0;
  font-size: 0.92rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--text-primary);
}

.updated-strip {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  min-height: 34px;
  padding: 0.35rem 0.75rem;
  background: var(--page-bg);
  border-bottom: 1px solid var(--chrome-border);
}

.updated-strip__refresh {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 1.75rem;
  height: 1.75rem;
  padding: 0;
  border: none;
  border-radius: 4px;
  background: transparent;
  color: var(--text-secondary);
}

.updated-strip__refresh:disabled {
  opacity: 0.45;
}

.updated-strip__text {
  margin: 0;
  font-size: 0.78rem;
  color: var(--text-secondary);
  font-weight: 400;
}

.list-panel {
  flex: 1;
  background: var(--page-bg);
  padding: 0.35rem 0.5rem 4.25rem;
}

.currency-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.currency-row {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin-bottom: 3px;
  padding: 0.15rem 0.2rem;
  background: var(--panel-row);
  touch-action: pan-y;
}

.currency-row:last-child {
  margin-bottom: 0;
}

.currency-row--dragging {
  opacity: 0.5;
}

.currency-row--over {
  outline: 2px dashed #9ad4f0;
  outline-offset: -1px;
}

.row-drag {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
}

.row-flag {
  flex-shrink: 0;
  width: 2rem;
  height: 1.45rem;
  border-radius: 4px;
  overflow: hidden;
  background: #2a2e35;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.25);
}

.row-flag img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.row-flag--btc {
  background: linear-gradient(180deg, #f6a623 0%, #f7931a 100%);
  color: #fff;
  font-size: 1rem;
  font-weight: 700;
}

.row-code {
  flex-shrink: 0;
  position: relative;
  min-width: 3.6rem;
}

.row-code select,
.row-code .row-code-btn {
  appearance: none;
  border: none;
  background: transparent;
  color: var(--code-text);
  font-size: 1rem;
  font-weight: 700;
  line-height: 1.1;
  padding: 0.35rem 1rem 0.35rem 0;
  letter-spacing: 0.02em;
  cursor: pointer;
  font-family: inherit;
  text-align: left;
}

.row-code .row-code-btn {
  display: block;
  width: 100%;
}

.row-code::after {
  content: "";
  position: absolute;
  right: 0.15rem;
  top: 50%;
  margin-top: -2px;
  border: 4px solid transparent;
  border-top-color: #d0d5db;
  pointer-events: none;
}

.row-right {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 0.35rem;
  min-width: 0;
}

.row-amount-wrap {
  flex: 1;
  min-width: 0;
  border-radius: 5px;
  min-height: 2.05rem;
  display: flex;
  align-items: center;
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.12);
}

.row-amount-wrap--inactive {
  background: var(--field-inactive);
}

.row-amount-wrap--active {
  background: var(--field-active);
}

.row-amount {
  width: 100%;
  border: none;
  background: transparent;
  color: var(--field-text);
  font-size: 1.05rem;
  font-weight: 500;
  text-align: right;
  padding: 0.35rem 0.45rem;
  line-height: 1.2;
  min-width: 0;
}

.row-amount:focus {
  outline: none;
}

.row-chart {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  color: var(--chart-stroke);
  opacity: 0.95;
  padding: 0.15rem 0.1rem;
  border: none;
  background: transparent;
  cursor: pointer;
}

.bottom-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  max-width: 480px;
  margin: 0 auto;
  padding: 0.5rem 0.75rem calc(0.5rem + var(--safe-bottom));
  background: var(--page-bg);
  border-top: 1px solid var(--chrome-border);
}

.manage-btn {
  width: 100%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.7rem 0.75rem;
  border: 1px solid var(--chrome-border);
  border-radius: 10px;
  background: #23272d;
  color: var(--text-primary);
  font-size: 0.9rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  cursor: pointer;
}

.manage-btn:active {
  opacity: 0.92;
}

.manage-btn--dialog {
  margin-top: 0.75rem;
}

.dialog {
  margin: auto;
  padding: 0;
  border: none;
  border-radius: 12px;
  background: #23272d;
  color: var(--text-primary);
  width: min(100% - 1.5rem, 420px);
  max-height: min(85vh, 560px);
  border: 1px solid var(--chrome-border);
}

.dialog--sheet {
  margin: auto 0 0;
  width: 100%;
  max-width: 480px;
  border-radius: 14px 14px 0 0;
  max-height: min(70vh, 520px);
}

.dialog::backdrop {
  background: rgba(0, 0, 0, 0.65);
}

.dialog__inner {
  padding: 0.85rem;
  display: flex;
  flex-direction: column;
  max-height: inherit;
}

.dialog__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.dialog__header h2 {
  margin: 0;
  font-size: 1rem;
}

.dialog__close {
  width: 2rem;
  height: 2rem;
  border: none;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.25);
  color: #fff;
  font-size: 1.35rem;
  line-height: 1;
}

.dialog__hint {
  margin: 0.45rem 0 0.75rem;
  font-size: 0.78rem;
  color: #c5cad1;
}

.picker-list {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  flex: 1;
}

.picker-item {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.55rem 0;
  border-bottom: 1px solid #5a6069;
}

.picker-item:last-child {
  border-bottom: none;
}

.picker-flag {
  font-size: 1.25rem;
}

.picker-meta {
  flex: 1;
  min-width: 0;
}

.picker-code {
  font-weight: 700;
}

.picker-name {
  font-size: 0.72rem;
  color: #c5cad1;
}

.toggle {
  position: relative;
  width: 2.65rem;
  height: 1.55rem;
  flex-shrink: 0;
}

.toggle input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle__slider {
  position: absolute;
  inset: 0;
  background: #353a42;
  border-radius: 999px;
  cursor: pointer;
}

.toggle__slider::before {
  content: "";
  position: absolute;
  width: 1.15rem;
  height: 1.15rem;
  left: 0.2rem;
  top: 0.2rem;
  background: #fff;
  border-radius: 50%;
  transition: transform 0.15s;
}

.toggle input:checked + .toggle__slider {
  background: var(--accent);
}

.row-picker-error {
  margin: 0 0 0.5rem;
  padding: 0.5rem 0.65rem;
  font-size: 0.8rem;
  color: #fecaca;
  background: rgba(127, 29, 29, 0.35);
  border-radius: 8px;
  border: 1px solid rgba(248, 113, 113, 0.35);
}

.row-currency-list {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  max-height: min(55vh, 420px);
}

.row-currency-option {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  width: 100%;
  padding: 0.65rem 0.25rem;
  border: none;
  border-bottom: 1px solid var(--chrome-border);
  background: transparent;
  color: var(--text-primary);
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.row-currency-option:last-child {
  border-bottom: none;
}

.row-currency-option:active:not(:disabled) {
  background: rgba(255, 255, 255, 0.04);
}

.row-currency-option--disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.row-currency-option__flag {
  font-size: 1.25rem;
  width: 1.5rem;
  text-align: center;
}

.row-currency-option__code {
  font-weight: 700;
  min-width: 2.75rem;
}

.row-currency-option__name {
  flex: 1;
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.toggle input:checked + .toggle__slider::before {
  transform: translateX(1.05rem);
}

.history-view {
  min-height: 100vh;
  background: var(--page-bg);
  display: flex;
  flex-direction: column;
}

.history-header {
  position: sticky;
  top: 0;
  z-index: 5;
}

.history-back {
  width: 2.25rem;
  height: 2.25rem;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--text-primary);
  font-size: 1.75rem;
  line-height: 1;
  padding: 0;
  cursor: pointer;
}

.history-title {
  font-size: 0.85rem;
}

.history-body {
  padding: 0.75rem;
  flex: 1;
}

.history-swap {
  display: flex;
  align-items: stretch;
  gap: 0.45rem;
  margin-bottom: 0.55rem;
}

.history-side {
  flex: 1;
  background: #252a30;
  border: 1px solid var(--chrome-border);
  border-radius: 10px;
  padding: 0.5rem;
  text-align: center;
}

.history-flag .row-flag {
  margin: 0 auto 0.35rem;
}

.history-code-select {
  width: 100%;
  margin: 0.25rem 0;
  padding: 0.35rem;
  border-radius: 6px;
  border: 1px solid var(--chrome-border);
  background: #1a1d21;
  color: var(--text-primary);
  font-weight: 700;
  text-align: center;
}

.history-amount {
  margin: 0.35rem 0 0;
  font-size: 1.05rem;
  font-weight: 600;
}

.history-today-label {
  margin: 0.2rem 0 0;
  font-size: 0.7rem;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.history-swap-btn {
  align-self: center;
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 50%;
  border: 1px solid var(--chrome-border);
  background: #23272d;
  color: var(--text-primary);
  font-size: 1.1rem;
  cursor: pointer;
}

.history-range-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.25rem;
}

.history-range-label {
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.history-range-select {
  flex: 1;
  padding: 0.45rem 0.5rem;
  border-radius: 8px;
  border: 1px solid var(--chrome-border);
  background: #252a30;
  color: var(--text-primary);
}

.history-range-caption {
  margin: 0 0 0.6rem;
  font-size: 0.75rem;
  color: var(--text-secondary);
}

.history-chart-section {
  margin-top: 0.25rem;
}

.history-chart-panel {
  background: linear-gradient(180deg, #1a7f8c 0%, #125e68 100%);
  border-radius: 12px;
  padding: 0.7rem 0.55rem 0.5rem;
  border: 1px solid #0e4a52;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

.history-chart-panel--loading {
  opacity: 0.88;
}

.history-chart-head {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-bottom: 0.35rem;
}

.history-chart-stats {
  margin: 0;
  font-size: 0.8rem;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.95);
}

.history-chart-bounds {
  display: grid;
  grid-template-columns: auto 1fr auto 1fr;
  gap: 0.25rem 0.5rem;
  align-items: center;
  font-size: 0.68rem;
  color: rgba(255, 255, 255, 0.8);
}

.history-chart-bound-label {
  text-transform: uppercase;
  letter-spacing: 0.04em;
  opacity: 0.85;
}

.history-chart-bound-value {
  font-weight: 600;
  color: #fff;
}

.history-chart-stage {
  position: relative;
  touch-action: manipulation;
}

.history-chart-loading,
.history-chart-empty {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0;
  font-size: 0.8rem;
  color: rgba(255, 255, 255, 0.9);
  z-index: 2;
  pointer-events: none;
}

.history-chart-loading[hidden],
.history-chart-empty[hidden] {
  display: none !important;
}

.history-chart {
  width: 100%;
  height: auto;
  display: block;
  min-height: 188px;
}

.history-chart-tooltip {
  position: absolute;
  z-index: 3;
  min-width: 7.5rem;
  padding: 0.35rem 0.5rem;
  border-radius: 6px;
  background: rgba(10, 18, 22, 0.92);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: #fff;
  font-size: 0.68rem;
  line-height: 1.25;
  pointer-events: none;
  white-space: nowrap;
}

.history-chart-tooltip[hidden] {
  display: none !important;
}

.chart-point.chart-point--active {
  r: 5;
  fill: #fff;
}

.history-chart-axis {
  display: flex;
  justify-content: space-between;
  font-size: 0.68rem;
  color: rgba(255, 255, 255, 0.78);
  padding: 0.3rem 0.35rem 0;
}

.history-note {
  margin: 0.55rem 0 0;
  font-size: 0.76rem;
  color: var(--text-secondary);
  line-height: 1.35;
}

.history-note--error {
  color: #fecaca;
}

:where(button, select, input, .row-code-btn):focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

@media (min-width: 481px) {
  body {
    border-left: 1px solid var(--chrome-border);
    border-right: 1px solid var(--chrome-border);
  }
}