:root {
  --bg: #0b0d0f;
  --ink: #f4f6f8;
  --ink-dim: rgba(255, 255, 255, 0.56);
  --ink-faint: rgba(255, 255, 255, 0.34);
  --line: rgba(255, 255, 255, 0.1);
  --line-strong: rgba(255, 255, 255, 0.28);
  --glass: rgba(255, 255, 255, 0.07);
  --glass-strong: rgba(255, 255, 255, 0.14);
  --radius: 18px;
  --warn: #e8cd95;
  --ease: cubic-bezier(0.22, 0.61, 0.36, 1);
  --row-height: 62px;
}

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

[hidden] {
  display: none !important;
}

html,
body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Segoe UI', Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
  overscroll-behavior: none;
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
}

button:disabled {
  cursor: default;
}

:focus-visible {
  outline: 2px solid rgba(255, 255, 255, 0.55);
  outline-offset: 2px;
}

/* ---------- background ---------- */

.backdrop {
  position: fixed;
  inset: 0;
  z-index: -2;
  background:
    radial-gradient(125% 75% at 50% -10%, #3b4550 0%, #232930 34%, #11151a 68%, #08090b 100%),
    var(--bg);
}

.backdrop::before {
  content: '';
  position: absolute;
  inset: -12%;
  background:
    radial-gradient(28% 22% at 18% 12%, rgba(168, 190, 215, 0.26), transparent 72%),
    radial-gradient(24% 18% at 78% 28%, rgba(122, 138, 158, 0.22), transparent 72%),
    radial-gradient(42% 30% at 52% 92%, rgba(88, 100, 116, 0.24), transparent 72%);
  filter: blur(6px);
}

.backdrop::after {
  content: '';
  position: absolute;
  left: -15%;
  top: 16%;
  width: 130%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: radial-gradient(closest-side, transparent 60%, rgba(255, 255, 255, 0.055) 63%, transparent 74%);
  filter: blur(14px);
}

.grain {
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  opacity: 0.045;
  mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='3'/%3E%3C/filter%3E%3Crect width='140' height='140' filter='url(%23n)'/%3E%3C/svg%3E");
}

/* ---------- shell ---------- */

.app {
  position: relative;
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 430px;
  height: 100dvh;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top, 0px) + 6px) 14px max(env(safe-area-inset-bottom, 0px), 8px);
}

@media (min-width: 520px) {
  body {
    background: #060708;
  }
  .app {
    height: calc(100dvh - 28px);
    margin: 14px auto;
    border-radius: 30px;
    box-shadow: 0 40px 100px rgba(0, 0, 0, 0.7), inset 0 0 0 1px rgba(255, 255, 255, 0.06);
    overflow: hidden;
  }
}

/* ---------- top bar ---------- */

.topbar {
  display: grid;
  grid-template-columns: 44px 1fr 44px;
  align-items: center;
  padding: 2px 0 2px;
}

.icon-btn {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 14px;
  color: rgba(255, 255, 255, 0.66);
  transition: background 0.16s, color 0.16s, transform 0.12s;
}

.icon-btn svg {
  width: 22px;
  height: 22px;
}

.icon-btn:active {
  transform: scale(0.94);
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
}

.brand {
  text-align: center;
  min-width: 0;
}

.wordmark {
  margin: 0;
  font-size: 27px;
  font-weight: 600;
  letter-spacing: 0.2em;
  margin-left: 0.2em;
  line-height: 1;
  color: #fff;
  text-shadow: 0 2px 18px rgba(255, 255, 255, 0.16);
}

.tagline {
  margin: 6px 0 0;
  font-size: 8px;
  font-weight: 500;
  letter-spacing: 0.26em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.4);
  margin-left: 0.26em;
}

/* ---------- sync bar ---------- */

.syncbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 4px 8px;
  font-size: 11px;
  color: var(--ink-faint);
  font-variant-numeric: tabular-nums;
}

.sync-source {
  color: rgba(255, 255, 255, 0.74);
  font-weight: 500;
  letter-spacing: 0.01em;
}

.sync-time {
  margin-right: auto;
}

.refresh {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 10px;
  color: rgba(255, 255, 255, 0.6);
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.08);
  transition: background 0.16s;
}

.refresh svg {
  width: 15px;
  height: 15px;
}

.refresh:active {
  background: rgba(255, 255, 255, 0.14);
}

.refresh.is-busy svg {
  animation: spin 1s linear infinite;
  opacity: 0.7;
}

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

/* ---------- warnings ---------- */

.update-bar {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  padding: 9px 12px;
  border-radius: 13px;
  font-size: 11.5px;
  color: rgba(255, 255, 255, 0.82);
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.16);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
}

.update-btn {
  flex: 0 0 auto;
  margin-left: auto;
  padding: 5px 10px;
  border-radius: 9px;
  font-size: 11px;
  font-weight: 600;
  color: #0c0e10;
  background: rgba(255, 255, 255, 0.88);
}

.update-btn:active {
  background: #fff;
}

.warnings {
  display: flex;
  flex: 0 0 auto;
  flex-direction: column;
  gap: 6px;
  padding-bottom: 8px;
  max-height: 34dvh;
  overflow-y: auto;
}

.warning {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 8px;
  padding: 9px 12px;
  border-radius: 13px;
  font-size: 11.5px;
  line-height: 1.4;
  color: var(--warn);
  background: rgba(232, 205, 149, 0.09);
  border: 1px solid rgba(232, 205, 149, 0.24);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
}

.warning-action {
  flex: 0 0 auto;
  margin-left: auto;
  padding: 5px 9px;
  border-radius: 9px;
  font-size: 11px;
  font-weight: 600;
  color: var(--warn);
  border: 1px solid rgba(232, 205, 149, 0.3);
  background: rgba(232, 205, 149, 0.08);
}

/* ---------- currency list ---------- */

.list {
  position: relative;
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  gap: 8px;
  min-height: 0;
  padding: 0 0 4px;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
  scroll-padding: 20px 0 28px;
}

.list::-webkit-scrollbar {
  display: none;
}

.list.is-scrollable {
  mask-image: linear-gradient(180deg, #000 calc(100% - 24px), transparent 100%);
  -webkit-mask-image: linear-gradient(180deg, #000 calc(100% - 24px), transparent 100%);
}

.list.is-scrolled {
  mask-image: linear-gradient(180deg, transparent 0, #000 16px, #000 calc(100% - 24px), transparent 100%);
  -webkit-mask-image: linear-gradient(180deg, transparent 0, #000 16px, #000 calc(100% - 24px), transparent 100%);
}

.row {
  position: relative;
  display: flex;
  flex: 0 0 var(--row-height);
  align-items: center;
  gap: 10px;
  height: var(--row-height);
  padding: 0 15px 0 17px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.1), rgba(255, 255, 255, 0.052));
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.26), inset 0 1px 0 rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(20px) saturate(145%);
  -webkit-backdrop-filter: blur(20px) saturate(145%);
  cursor: pointer;
  touch-action: pan-y;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  transition: background 0.22s var(--ease), border-color 0.22s var(--ease), box-shadow 0.22s var(--ease),
    opacity 0.2s;
  animation: rise 0.42s var(--ease) both;
}

.row:nth-child(2) {
  animation-delay: 0.03s;
}
.row:nth-child(3) {
  animation-delay: 0.06s;
}
.row:nth-child(4) {
  animation-delay: 0.09s;
}
.row:nth-child(5) {
  animation-delay: 0.12s;
}
.row:nth-child(6) {
  animation-delay: 0.15s;
}
.row:nth-child(7) {
  animation-delay: 0.18s;
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
}

.row.is-active {
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.17), rgba(255, 255, 255, 0.1));
  border-color: var(--line-strong);
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.4), inset 0 1px 0 rgba(255, 255, 255, 0.26);
}

.row-accent {
  position: absolute;
  left: 6px;
  top: 50%;
  width: 3px;
  height: 0;
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 0 10px rgba(255, 255, 255, 0.5);
  transform: translateY(-50%);
  opacity: 0;
  transition: height 0.24s var(--ease), opacity 0.24s var(--ease);
}

.row.is-active .row-accent {
  height: 26px;
  opacity: 1;
}

.row-info {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
  max-width: 42%;
}

.row-code {
  font-size: 14.5px;
  font-weight: 600;
  letter-spacing: 0.055em;
  color: rgba(255, 255, 255, 0.94);
}

.row-name {
  overflow: hidden;
  max-width: 100%;
  font-size: 10px;
  line-height: 1.25;
  color: var(--ink-dim);
  white-space: nowrap;
  text-overflow: ellipsis;
}

.row-source {
  font-size: 8px;
  letter-spacing: 0.11em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.28);
}

.row-values {
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  align-items: flex-end;
  gap: 1px;
  min-width: 0;
}

.row-amount {
  max-width: 100%;
  overflow: hidden;
  font-size: 29px;
  font-weight: 300;
  letter-spacing: 0.005em;
  line-height: 1.08;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  color: rgba(255, 255, 255, 0.82);
  transition: color 0.2s;
}

.row.is-active .row-amount {
  color: #fff;
  font-weight: 400;
}

.row-amount.is-muted {
  color: rgba(255, 255, 255, 0.32);
}

.row-rate {
  max-width: 100%;
  overflow: hidden;
  font-size: 10px;
  color: rgba(255, 255, 255, 0.46);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.row.is-unavailable {
  opacity: 0.52;
}

.row.is-unavailable .row-rate {
  color: var(--warn);
}

.row.is-drag-origin {
  opacity: 0.12;
}

.list.is-dragging .row {
  transition: transform 220ms var(--ease);
}

.drag-proxy {
  z-index: 60;
  margin: 0;
  pointer-events: none;
  animation: none !important;
  transform-origin: center;
  will-change: transform;
  border-color: rgba(255, 255, 255, 0.32);
  box-shadow: 0 28px 64px rgba(0, 0, 0, 0.58), inset 0 1px 0 rgba(255, 255, 255, 0.28);
}

body.is-dragging,
body.is-dragging * {
  cursor: grabbing !important;
}

/* ---------- keypad ---------- */

.keypad {
  flex: 0 0 auto;
  padding-top: 10px;
  margin: 0 -2px;
  animation: keypad-in 0.24s var(--ease) both;
}

@keyframes keypad-in {
  from {
    opacity: 0;
    transform: translateY(14px);
  }
}

.keypad-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 2px 8px;
}

.tool-btn {
  min-height: 34px;
  padding: 7px 14px;
  border-radius: 11px;
  font-size: 12.5px;
  color: rgba(255, 255, 255, 0.68);
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.08);
  transition: background 0.16s;
}

.tool-btn.is-primary {
  color: #0c0e10;
  font-weight: 600;
  background: rgba(255, 255, 255, 0.88);
  border-color: transparent;
}

.tool-btn:active {
  background: rgba(255, 255, 255, 0.16);
}

.tool-btn.is-primary:active {
  background: #fff;
}

.keys {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 7px;
}

.key {
  display: grid;
  place-items: center;
  height: 46px;
  border-radius: 14px;
  font-size: 23px;
  font-weight: 300;
  color: #f2f4f6;
  background: rgba(255, 255, 255, 0.075);
  border: 1px solid rgba(255, 255, 255, 0.085);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.07);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  font-variant-numeric: tabular-nums;
  touch-action: manipulation;
  transition: transform 0.08s, background 0.14s;
}

.key:active {
  transform: scale(0.975);
  background: rgba(255, 255, 255, 0.17);
}

.key-icon svg {
  width: 22px;
  height: 22px;
  color: rgba(255, 255, 255, 0.8);
}

/* ---------- sheet ---------- */

.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 10;
  background: rgba(4, 6, 8, 0.55);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  animation: fade 0.2s ease both;
}

@keyframes fade {
  from {
    opacity: 0;
  }
}

.sheet {
  position: fixed;
  bottom: 0;
  left: 50%;
  z-index: 11;
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 430px;
  max-height: 88dvh;
  padding-bottom: max(env(safe-area-inset-bottom, 0px), 10px);
  border-radius: 26px 26px 0 0;
  border-top: 1px solid rgba(255, 255, 255, 0.16);
  background: linear-gradient(180deg, rgba(30, 34, 39, 0.92), rgba(16, 18, 21, 0.95));
  box-shadow: 0 -20px 70px rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(34px) saturate(150%);
  -webkit-backdrop-filter: blur(34px) saturate(150%);
  transform: translateX(-50%);
  animation: sheet-in 0.3s var(--ease) both;
}

@keyframes sheet-in {
  from {
    opacity: 0;
    transform: translate(-50%, 18px);
  }
}

.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 12px 6px 20px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.07);
}

.sheet-head h2 {
  margin: 0;
  font-size: 17px;
  font-weight: 600;
  letter-spacing: 0.16em;
}

.sheet-close {
  color: rgba(255, 255, 255, 0.55);
}

.sheet-body {
  padding: 6px 18px 28px;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.section-title {
  margin: 18px 0 8px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.42);
}

.hint {
  margin: 0 0 10px;
  font-size: 11.5px;
  line-height: 1.5;
  color: rgba(255, 255, 255, 0.42);
}

.hint.version {
  margin-top: 14px;
  letter-spacing: 0.1em;
  font-size: 10px;
  text-transform: uppercase;
}

.hint.version .author {
  text-transform: none;
}

.sheet-list,
.sheet-add-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.sheet-item,
.sheet-add {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 11px 13px;
  border-radius: 14px;
  border: 1px solid rgba(255, 255, 255, 0.075);
  background: rgba(255, 255, 255, 0.055);
  text-align: left;
}

.sheet-item-main {
  display: flex;
  align-items: baseline;
  gap: 9px;
  min-width: 0;
}

.sheet-item-main .row-name {
  font-size: 12px;
}

.sheet-remove {
  margin-left: auto;
  min-height: 32px;
  padding: 7px 12px;
  border-radius: 9px;
  font-size: 11.5px;
  color: #efb1b1;
  background: rgba(226, 122, 122, 0.12);
  border: 1px solid rgba(226, 122, 122, 0.2);
}

.sheet-remove:disabled {
  opacity: 0.35;
}

.sheet-add:active {
  background: rgba(255, 255, 255, 0.12);
}

.sheet-add .row-name {
  font-size: 12px;
}

.sheet-plus {
  margin-left: auto;
  font-size: 18px;
  color: rgba(255, 255, 255, 0.6);
}

.info-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  font-size: 12px;
  color: rgba(255, 255, 255, 0.44);
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.info-row span:last-child {
  color: rgba(255, 255, 255, 0.86);
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.sheet-error {
  margin: 10px 0 0;
  font-size: 11.5px;
  line-height: 1.45;
  color: var(--warn);
}

.wide-btn {
  width: 100%;
  margin-top: 14px;
  padding: 13px;
  border-radius: 14px;
  font-size: 13px;
  font-weight: 600;
  color: #0c0e10;
  background: rgba(255, 255, 255, 0.9);
  transition: transform 0.1s, background 0.16s;
}

.wide-btn:active {
  transform: scale(0.99);
  background: #fff;
}

/* ---------- compact screens ---------- */

@media (max-height: 720px) {
  :root {
    --row-height: 56px;
  }
  .key {
    height: 42px;
    font-size: 21px;
  }
  .row-amount {
    font-size: 26px;
  }
  .wordmark {
    font-size: 23px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
