:root {
  --bg: #eef2f4;
  --surface: #ffffff;
  --surface-2: #f4f8f9;
  --line: #dde6ea;
  --ink: #1a2b33;
  --muted: #6b7f88;
  --brand: #0d7a84;
  --brand-dark: #0a5f67;
  --brand-soft: #e6f5f7;
  --brand-mid: #11939b;
  --ok: #1a9d6a;
  --down: #d64545;
  --nav: var(--header);
  --nav-ink: rgba(255, 255, 255, 0.62);
  --nav-active: #ffffff;
  --shadow: 0 4px 18px rgba(18, 49, 58, 0.07);
  --radius: 16px;
  --nav-h: 4.5rem;
  --header: #0d7a84;
}

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

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--bg);
  color: var(--ink);
  font-family: "Noto Sans Khmer", "Inter", sans-serif;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

button,
input {
  font: inherit;
}

body {
  display: grid;
  place-items: center;
}

.app {
  position: relative;
  width: min(100%, 430px);
  height: 100svh;
  max-height: 100svh;
  overflow: hidden;
  display: grid;
  grid-template-rows: auto 1fr auto;
  background: var(--bg);
}

.topbar {
  display: grid;
  grid-template-columns: 2.5rem 1fr 2.5rem;
  align-items: center;
  min-height: 3.65rem;
  padding:
    max(0.55rem, env(safe-area-inset-top))
    0.75rem
    0.65rem;
  background: var(--header);
  color: #fff;
}

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

.topbar-title {
  margin: 0;
  font-size: 1.02rem;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.topbar-sub {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  margin: 0.15rem 0 0;
  font-size: 0.68rem;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.82);
}

.topbar-sub[hidden] {
  display: none;
}

.topbar-side {
  width: 2.5rem;
  height: 2.4rem;
  position: relative;
}

.topbar-side .icon-btn {
  position: absolute;
  inset: 0;
}

.icon-btn {
  width: 2.4rem;
  height: 2.4rem;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: #fff;
  display: grid;
  place-items: center;
  cursor: pointer;
  padding: 0;
}

.icon-btn[hidden] {
  display: none;
}

.topbar-spacer {
  width: 2.4rem;
  height: 2.4rem;
}

.live-dot {
  width: 0.42rem;
  height: 0.42rem;
  border-radius: 50%;
  background: var(--ok);
  flex-shrink: 0;
}

.live-dot.offline,
.live-dot.stale {
  background: #e8a838;
}

.screens {
  position: relative;
  min-height: 0;
  overflow: hidden;
}

.screen {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  gap: 0.65rem;
  padding: 0.85rem 1rem 0.75rem;
  overflow: hidden;
}

#screen-home {
  padding: 0;
  gap: 0;
  overflow: hidden;
}

#screen-home.is-active {
  display: flex;
  flex-direction: column;
}

.home-scroll {
  flex: 1;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  padding: 0.6rem 0.85rem 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.home-scroll::-webkit-scrollbar {
  display: none;
}

#screen-home .pair-bar {
  flex-shrink: 0;
  padding: 0.5rem 0.65rem;
}

#screen-home .input-card,
#screen-home .result-input-card {
  flex-shrink: 0;
  padding: 0.6rem 0.75rem;
}

#screen-home .field-label {
  margin-bottom: 0.3rem;
  font-size: 0.68rem;
}

#screen-home .amount-field {
  padding: 0.4rem 0.65rem;
}

#screen-home #amount,
#screen-home #toAmount {
  font-size: clamp(1.2rem, 5vw, 1.5rem);
}

#screen-home .summary-card {
  display: none;
}

#screen-home .also-section {
  flex-shrink: 0;
  margin-top: 0;
}

#screen-home .also-head {
  margin-bottom: 0.35rem;
}

#screen-home .also-title {
  font-size: 0.75rem;
}

#screen-home .also-card {
  width: 8.25rem;
  padding: 0.55rem 0.6rem;
}

#screen-home .also-card-value {
  font-size: 0.85rem;
}

#screen-home .home-actions {
  flex-shrink: 0;
  margin-top: 0;
  padding: 0.4rem 0.85rem 0.5rem;
  background: var(--bg);
  border-top: 1px solid var(--line);
}

#screen-home .action-btn {
  min-height: 2.45rem;
  font-size: 0.72rem;
}

.screen.is-active {
  display: flex;
}

.screen-currency {
  padding: 0;
  background: var(--surface);
  gap: 0;
}

.currency-search-wrap {
  flex: 0 0 auto;
  padding: 0.65rem 0.85rem;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.currency-search {
  width: 100%;
  min-height: 2.5rem;
  padding: 0 0.85rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface-2);
  color: var(--ink);
  font-size: 0.9rem;
  font-weight: 600;
  outline: none;
}

.currency-search:focus {
  border-color: var(--brand);
}

.currency-empty {
  margin: 2rem 1rem 0;
  text-align: center;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 600;
}

.screen-currency .currency-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

.app.picking-currency .bottom-nav {
  display: none;
}

.pair-bar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 0.4rem;
  padding: 0.65rem 0.75rem;
  border-radius: 14px;
  background: #2d3a40;
  color: #fff;
}

.pair-side {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  border: 0;
  background: transparent;
  color: #fff;
  text-align: left;
  cursor: pointer;
  padding: 0.2rem;
  min-width: 0;
}

.pair-side:last-of-type {
  flex-direction: row-reverse;
  text-align: right;
}

.pair-side:last-of-type .pair-text {
  align-items: flex-end;
}

.pair-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.pair-code {
  display: block;
  font-family: "Inter", sans-serif;
  font-size: 1rem;
  font-weight: 800;
}

.pair-name {
  display: block;
  margin-top: 0.1rem;
  font-size: 0.68rem;
  color: rgba(255, 255, 255, 0.7);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.swap-circle {
  width: 2.4rem;
  height: 2.4rem;
  border: 0;
  border-radius: 50%;
  background: linear-gradient(180deg, var(--brand-mid), var(--brand-dark));
  color: #fff;
  display: grid;
  place-items: center;
  cursor: pointer;
  flex-shrink: 0;
}

.swap-circle:active {
  transform: scale(0.92);
}

.input-card,
.result-input-card {
  padding: 0.9rem 0.95rem;
}

.field-label {
  display: block;
  margin: 0 0 0.4rem;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--muted);
}

.amount-field {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  padding: 0.55rem 0.75rem;
}

.money-symbol {
  flex: 0 0 auto;
  min-width: 1.15rem;
  font-family: "Inter", sans-serif;
  font-size: 1.35rem;
  font-weight: 800;
  color: var(--brand);
  text-align: center;
}

.money-code {
  flex: 0 0 auto;
  padding: 0.28rem 0.48rem;
  border-radius: 8px;
  background: var(--brand-soft);
  color: var(--brand-dark);
  font-family: "Inter", sans-serif;
  font-size: 0.66rem;
  font-weight: 800;
  letter-spacing: 0.04em;
}

.to-field .money-code {
  background: rgba(255, 255, 255, 0.7);
}

.amount-field.to-field {
  background: var(--brand-soft);
  border-color: #b8dde2;
}

.amount-field.bump {
  animation: bump 0.3s ease;
}

#amount,
#toAmount {
  width: 100%;
  min-width: 0;
  border: 0;
  outline: none;
  background: transparent;
  font-family: "Inter", sans-serif;
  font-size: clamp(1.45rem, 6vw, 1.85rem);
  font-weight: 800;
  letter-spacing: -0.03em;
  color: var(--ink);
}

#toAmount {
  color: var(--brand-dark);
}

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.flag {
  flex: 0 0 auto;
  width: 28px;
  height: 20px;
  object-fit: cover;
  border-radius: 3px;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.08);
  background: #ddd;
}

#amount {
  flex: 1;
  min-width: 0;
  border: 0;
  outline: none;
  background: transparent;
  font-family: "Inter", sans-serif;
  font-size: clamp(1.5rem, 6.5vw, 2rem);
  font-weight: 800;
  letter-spacing: -0.03em;
  color: var(--ink);
}

.summary-card {
  padding: 0.95rem 1rem 0.85rem;
}

.summary-label {
  margin: 0;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--muted);
}

.summary-main {
  margin: 0.25rem 0 0;
  font-family: "Inter", "Noto Sans Khmer", sans-serif;
  font-size: clamp(1.5rem, 6.5vw, 1.85rem);
  font-weight: 800;
  letter-spacing: -0.03em;
  color: var(--brand);
}

.summary-main.bump {
  animation: bump 0.3s ease;
}

.summary-desc {
  margin: 0.35rem 0 0;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--muted);
  line-height: 1.35;
}

.also-section {
  margin-top: 0.1rem;
}

.also-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.55rem;
}

.also-title {
  margin: 0;
  font-size: 0.82rem;
  font-weight: 800;
  color: var(--ink);
}

.also-scroll {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.55rem;
  overflow: hidden;
  padding-bottom: 0.15rem;
}

.also-scroll::-webkit-scrollbar {
  display: none;
}

.also-card {
  width: 100%;
  min-width: 0;
  padding: 0.75rem 0.8rem;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  box-shadow: var(--shadow);
  cursor: pointer;
  text-align: left;
  animation: also-card-in 0.24s ease both;
}

.also-card:nth-child(2) { animation-delay: 0.04s; }
.also-card:nth-child(3) { animation-delay: 0.08s; }

@keyframes also-card-in {
  from { opacity: 0; transform: translateY(5px); }
  to { opacity: 1; transform: translateY(0); }
}

.also-card-head {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin-bottom: 0.45rem;
}

.also-card-code {
  font-family: "Inter", sans-serif;
  font-size: 0.82rem;
  font-weight: 800;
}

.also-card-name {
  font-size: 0.62rem;
  font-weight: 600;
  color: var(--muted);
}

.also-card-value {
  font-family: "Inter", sans-serif;
  font-size: 0.95rem;
  font-weight: 800;
  color: var(--ink);
}

.also-card-rate {
  margin-top: 0.35rem;
  font-size: 0.62rem;
  font-weight: 600;
  color: var(--muted);
}

.disclaimer,
.settings-disclaimer {
  margin: 0.55rem 0 0;
  padding: 0 1rem 0.85rem;
  font-size: 0.62rem;
  font-weight: 600;
  line-height: 1.35;
  color: var(--muted);
}

.summary-card .disclaimer {
  padding: 0;
  margin-top: 0.55rem;
}

.settings-disclaimer {
  padding: 0.75rem 1rem 1rem;
  border-top: 1px solid var(--line);
}

.home-actions {
  display: grid;
  grid-template-columns: 1fr 1fr 1.2fr;
  gap: 0.45rem;
  margin-top: 0.15rem;
  padding-bottom: 0.25rem;
}

.action-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  min-height: 2.75rem;
  border-radius: 12px;
  font-size: 0.78rem;
  font-weight: 800;
  cursor: pointer;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
}

.action-btn.primary {
  border: 0;
  background: linear-gradient(180deg, var(--brand-mid), var(--brand-dark));
  color: #fff;
}

.screen-hint {
  margin: 0;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--muted);
}

.fav-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  min-height: 0;
  overflow: hidden;
}

.fav-item {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 0.5rem;
  padding: 0.85rem 0.95rem;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  box-shadow: var(--shadow);
  cursor: pointer;
  text-align: left;
}

.fav-item strong {
  display: block;
  font-family: "Inter", sans-serif;
  font-size: 1rem;
  font-weight: 800;
}

.fav-item small {
  display: block;
  margin-top: 0.15rem;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 600;
}

.fav-item .use-label {
  font-size: 0.72rem;
  font-weight: 800;
  color: var(--brand);
}

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
  margin: 2rem 0.5rem 0;
  text-align: center;
}

.empty-state p {
  margin: 0;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 600;
  line-height: 1.4;
}

.empty-state .btn {
  min-width: 10rem;
  padding: 0 1rem;
}

.onboard {
  position: absolute;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: 1.25rem;
  background:
    radial-gradient(ellipse at 30% 20%, rgba(13, 122, 132, 0.18), transparent 55%),
    radial-gradient(ellipse at 80% 80%, rgba(240, 197, 106, 0.22), transparent 50%),
    var(--bg);
}

.onboard[hidden] {
  display: none;
}

.onboard-card {
  width: min(100%, 22rem);
  padding: 1.75rem 1.35rem 1.5rem;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: var(--surface);
  box-shadow: var(--shadow);
  text-align: center;
}

.onboard-brand {
  margin: 0;
  font-size: 1.35rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  color: var(--brand);
}

.onboard-title {
  margin: 0.65rem 0 0;
  font-size: 1.15rem;
  font-weight: 800;
  line-height: 1.35;
  color: var(--ink);
}

.onboard-body {
  margin: 0.55rem 0 0;
  font-size: 0.88rem;
  font-weight: 600;
  line-height: 1.45;
  color: var(--muted);
}

.onboard-cta {
  width: 100%;
  margin-top: 1.35rem;
  border: 0;
  background: var(--brand);
  color: #fff;
}

.onboard-cta:active {
  background: var(--brand-dark);
}

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

.history-head .screen-hint {
  margin: 0;
}

.history-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
}

.history-item {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 0.5rem;
  padding: 0.85rem 0.95rem;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  box-shadow: var(--shadow);
  cursor: pointer;
  text-align: left;
}

.history-item strong {
  display: block;
  font-family: "Inter", "Noto Sans Khmer", sans-serif;
  font-size: 0.95rem;
  font-weight: 800;
}

.history-item small {
  display: block;
  margin-top: 0.15rem;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 600;
}

.history-item .use-label {
  font-size: 0.72rem;
  font-weight: 800;
  color: var(--brand);
}

.settings-card {
  display: flex;
  flex-direction: column;
  gap: 0;
  padding: 0;
  overflow: hidden;
}

.btn {
  min-height: 2.75rem;
  border-radius: 12px;
  font-size: 0.84rem;
  font-weight: 800;
  cursor: pointer;
}

.btn.primary {
  border: 0;
  background: linear-gradient(180deg, var(--brand-mid), var(--brand-dark));
  color: #fff;
}

.btn:active,
.action-btn:active {
  transform: translateY(1px);
}

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.95rem 1rem;
  border-bottom: 1px solid var(--line);
}

.setting-row:last-child {
  border-bottom: 0;
}

.setting-title {
  margin: 0;
  font-size: 0.9rem;
  font-weight: 800;
}

.setting-desc {
  margin: 0.2rem 0 0;
  font-size: 0.72rem;
  color: var(--muted);
  font-weight: 600;
}

.lang-btn {
  min-width: 4rem;
  min-height: 2.3rem;
  padding: 0 0.8rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--ink);
  font-size: 0.8rem;
  font-weight: 700;
  cursor: pointer;
}

.text-btn {
  border: 0;
  background: transparent;
  color: var(--brand);
  font-size: 0.78rem;
  font-weight: 800;
  cursor: pointer;
  white-space: nowrap;
}

.bottom-nav {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  min-height: var(--nav-h);
  padding: 0.4rem 0.5rem max(0.4rem, env(safe-area-inset-bottom));
  background: var(--header);
  color: var(--nav-ink);
  border-top: 1px solid rgba(255, 255, 255, 0.12);
  box-shadow: none;
}

.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.12rem;
  border: 0;
  background: transparent;
  color: inherit;
  cursor: pointer;
  padding: 0.2rem;
  border-radius: 12px;
}

.nav-item.is-active {
  color: var(--nav-active);
}

.nav-item.is-active .nav-icon {
  background: rgba(255, 255, 255, 0.16);
}

.nav-icon {
  display: grid;
  place-items: center;
  width: 2.35rem;
  height: 1.85rem;
  border-radius: 999px;
  color: inherit;
}

.nav-label {
  font-size: 0.65rem;
  font-weight: 700;
}

.toast {
  position: absolute;
  left: 50%;
  bottom: calc(var(--nav-h) + 0.75rem);
  transform: translate(-50%, 12px);
  z-index: 20;
  padding: 0.55rem 1rem;
  border-radius: 999px;
  background: rgba(18, 49, 58, 0.92);
  color: #fff;
  font-size: 0.75rem;
  font-weight: 700;
  opacity: 0;
  pointer-events: none;
  transition: 0.2s ease;
  white-space: nowrap;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

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

.currency-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 0.75rem;
  width: 100%;
  min-height: 3.35rem;
  padding: 0.7rem 1rem;
  border: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  background: var(--surface);
  text-align: left;
  cursor: pointer;
  outline: none;
  -webkit-tap-highlight-color: transparent;
}

.currency-row:focus,
.currency-row:focus-visible {
  outline: none;
  box-shadow: none;
}

.currency-row:active {
  background: var(--surface-2);
}

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

.currency-row .flag {
  width: 32px;
  height: 22px;
  border-radius: 0;
}

.currency-meta {
  display: flex;
  flex-direction: row;
  align-items: baseline;
  gap: 0.45rem;
  min-width: 0;
}

.currency-meta strong {
  font-family: "Inter", sans-serif;
  font-size: 0.95rem;
  font-weight: 800;
  color: var(--ink);
}

.currency-meta small {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.currency-row .radio {
  width: 1.25rem;
  height: 1.25rem;
  border: 2px solid #c5d0d5;
  border-radius: 50%;
  background: #fff;
}

.currency-row.selected .currency-meta strong,
.currency-row.selected .currency-meta small {
  color: var(--brand);
}

.currency-row.selected .radio {
  border-color: var(--brand);
  background:
    radial-gradient(circle at center, #fff 0 35%, var(--brand) 36% 100%);
}

@keyframes bump {
  0% { transform: scale(1); }
  45% { transform: scale(1.04); }
  100% { transform: scale(1); }
}

@media (max-height: 700px) {
  .screen { gap: 0.45rem; padding-top: 0.65rem; }
  #screen-home .home-scroll { padding-top: 0.5rem; gap: 0.35rem; }
  #screen-home .summary-main { font-size: 1.45rem; }
  #screen-home .action-btn { min-height: 2.2rem; }
  #screen-home .pair-name { display: none; }
  #screen-home .also-card { width: 100%; padding: 0.45rem 0.5rem; }
}

@media (min-width: 700px) {
  .app {
    height: min(100svh, 860px);
    max-height: min(100svh, 860px);
    border-radius: 0;
    border: 1px solid var(--line);
    box-shadow: 0 20px 50px rgba(18, 49, 58, 0.12);
    overflow: hidden;
  }

  .topbar,
  .bottom-nav {
    border-radius: 0;
  }
}
