:root {
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --key-gap: 8px;
  --key-size: 64px;
  --amount-size: 28px;
  --label-blue: #647fa3;
  --accent: var(--text);
  --accent-muted: var(--text-secondary);
  --text-on-emphasis: #ffffff;
  --warning: var(--text-secondary);
}

html[data-theme="light"] {
  color-scheme: light;
  --bg: #f2f2f2;
  --surface: #ffffff;
  --surface-secondary: #d4d4d2;
  --surface-fn: #d4d4d2;
  --surface-op: #505050;
  --text: #000000;
  --text-secondary: #6c6c70;
  --text-on-emphasis: #ffffff;
  --label-blue: #5a7fa3;
  --shadow: rgba(0, 0, 0, 0.06);
}

html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #000000;
  --surface: #333333;
  --surface-secondary: #1c1c1e;
  --surface-fn: #505050;
  --surface-op: #505050;
  --text: #ffffff;
  --text-secondary: #a5a5a5;
  --text-on-emphasis: #ffffff;
  --label-blue: #8aaed4;
  --shadow: rgba(0, 0, 0, 0.4);
}

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

html {
  touch-action: manipulation;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

html,
body {
  margin: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI",
    sans-serif;
  background: var(--bg);
  color: var(--text);
}

html[data-platform="ios"] body,
html[data-platform="android"] body {
  position: fixed;
  inset: 0;
}

body {
  display: flex;
  justify-content: center;
}

html[data-platform="ios"] .app,
html[data-platform="android"] .app {
  max-width: 100%;
  border-radius: 0;
  box-shadow: none;
}

html[data-platform="macos"] {
  --app-max-width: min(92vw, 720px);
}

html[data-platform="windows"] {
  --app-max-width: min(90vw, 680px);
}

html[data-platform="macos"] body,
html[data-platform="windows"] body {
  align-items: center;
  padding: 20px 16px;
}

html[data-platform="macos"] .app,
html[data-platform="windows"] .app {
  height: min(calc(100dvh - 40px), 920px);
  max-height: min(calc(100dvh - 40px), 920px);
  border-radius: 24px;
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--text-secondary) 12%, transparent);
}

html[data-platform="web"] body {
  align-items: center;
  padding: 20px 16px;
}

.app {
  width: 100%;
  max-width: min(100vw, var(--app-max-width, 520px));
  height: 100vh;
  height: 100dvh;
  height: 100svh;
  max-height: 100vh;
  max-height: 100dvh;
  max-height: 100svh;
  display: flex;
  flex-direction: column;
  padding-top: var(--safe-top);
  overflow: hidden;
  margin: 0 auto;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px 6px;
  flex-shrink: 0;
}

.app-header h1 {
  margin: 0;
  font-size: 17px;
  font-weight: 500;
  flex: 1;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.theme-toggle {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 2px;
  border-radius: 999px;
  background: var(--surface-fn);
}

.theme-btn {
  border: none;
  border-radius: 999px;
  padding: 6px 10px;
  font-size: 12px;
  font-weight: 600;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  line-height: 1;
}

.theme-btn[aria-pressed="true"] {
  background: var(--surface-op);
  color: var(--text-on-emphasis);
  box-shadow: none;
}

.mode-toggle {
  border: none;
  border-radius: 999px;
  padding: 7px 12px;
  font-size: 12px;
  font-weight: 600;
  background: var(--surface-fn);
  color: var(--text);
  cursor: pointer;
}

.mode-toggle[aria-pressed="true"] {
  background: var(--surface-op);
  color: var(--text-on-emphasis);
}

.mode-toggle-locked::after {
  content: " Pro";
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.pro-modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 20px;
}

.pro-modal[hidden] {
  display: none;
}

.pro-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
}

.pro-modal-card {
  position: relative;
  width: min(100%, 360px);
  background: var(--surface);
  border-radius: 20px;
  padding: 22px;
  box-shadow: 0 12px 40px var(--shadow);
}

.pro-modal-card h2 {
  margin: 0 0 8px;
  font-size: 20px;
}

.pro-modal-card p {
  margin: 0 0 12px;
  color: var(--text-secondary);
  line-height: 1.45;
  font-size: 15px;
}

.pro-modal-price {
  font-weight: 600;
  color: var(--text) !important;
}

.pro-modal-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 44px;
  margin-top: 8px;
  border: none;
  border-radius: 999px;
  font-size: 16px;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  background: var(--surface-fn);
  color: var(--text);
}

.pro-modal-btn-primary {
  background: var(--surface-op);
  color: var(--text-on-emphasis);
}

.pro-unlock-form {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 12px;
}

.pro-unlock-form label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
}

.pro-unlock-form input {
  width: 100%;
  border: none;
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 16px;
  background: var(--surface-secondary);
  color: var(--text);
}

.pro-modal-message {
  min-height: 18px;
  margin: 8px 0 0;
  font-size: 13px;
  color: var(--text-secondary);
}

.pro-modal-legal {
  margin: 12px 0 0;
  font-size: 12px;
  text-align: center;
  color: var(--text-secondary);
}

.pro-modal-legal a {
  color: var(--text-secondary);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.pro-modal-close {
  display: block;
  width: 100%;
  margin-top: 10px;
  border: none;
  background: none;
  color: var(--text-secondary);
  font-size: 15px;
  cursor: pointer;
}

.install-steps {
  margin: 0 0 14px;
  padding-left: 20px;
  color: var(--text-secondary);
  font-size: 14px;
  line-height: 1.55;
}

.install-steps li {
  margin-bottom: 10px;
}

.install-steps strong {
  color: var(--text);
  font-weight: 600;
}

body.install-modal-open {
  overflow: hidden;
}

.mode-panel[hidden] {
  display: none !important;
}

.icon-btn {
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 50%;
  background: var(--surface-fn);
  color: var(--text);
  font-size: 18px;
  cursor: pointer;
}

.icon-btn:disabled {
  opacity: 0.5;
}

.app-main {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#converter-panel {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  overflow: hidden;
}

#mix-panel {
  flex: 1;
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  padding-bottom: calc(8px + var(--safe-bottom));
}

.search-section {
  padding: 0 12px 6px;
  flex-shrink: 0;
}

.search-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 14px;
  background: var(--surface);
  border-radius: 13px;
}

.search-icon {
  color: var(--text-secondary);
  font-size: 16px;
}

#search-input {
  flex: 1;
  border: none;
  background: transparent;
  font-size: 16px;
  color: var(--text);
  outline: none;
}

#search-clear {
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-size: 18px;
  cursor: pointer;
  padding: 0;
}

#search-clear[hidden] {
  display: none;
}

.suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  overflow: hidden;
  max-height: 72px;
  padding: 8px 0 0;
}

.suggestions[hidden] {
  display: none;
}

.currency-section {
  padding: 4px 12px 0;
  align-self: start;
  min-height: 0;
  overflow: visible;
  width: 100%;
}

.suggestion-chip {
  border: none;
  border-radius: 999px;
  padding: 6px 12px;
  background: var(--surface-fn);
  color: var(--text);
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
}

.status-row {
  min-height: 18px;
  padding: 4px 12px 0;
  font-size: 11px;
  color: var(--text-secondary);
  flex-shrink: 0;
}

.status-row[hidden] {
  display: none;
}

#status-error {
  color: var(--warning);
}

.currency-card {
  width: 100%;
  text-align: left;
  background: transparent;
  border-radius: 0;
  padding: 8px 2px;
  box-shadow: none;
}

.currency-card-inner {
  display: block;
  min-width: 0;
}

.currency-meta {
  width: 100%;
  min-width: 0;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  column-gap: 10px;
  row-gap: 4px;
}

.currency-field-label {
  grid-column: 1;
  grid-row: 1;
  font-size: 12px;
  font-weight: 600;
  color: var(--label-blue);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  white-space: nowrap;
}

.currency-select-wrap {
  position: relative;
  grid-column: 2;
  grid-row: 1;
  min-width: 0;
}

.currency-select {
  width: 100%;
  max-width: 100%;
  border: none;
  border-radius: 10px;
  padding: 8px 36px 8px 10px;
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  background: var(--surface);
  box-shadow: none;
  appearance: none;
  -webkit-appearance: none;
  cursor: pointer;
}

html[data-theme="dark"] .currency-select {
  background: var(--surface);
}

input,
select,
textarea {
  font-size: 16px;
}

.currency-select-arrow {
  position: absolute;
  right: 14px;
  top: 50%;
  width: 8px;
  height: 8px;
  pointer-events: none;
  transform: translateY(-65%) rotate(45deg);
  border-right: 2px solid var(--text-secondary);
  border-bottom: 2px solid var(--text-secondary);
}

.currency-symbol,
.amount-label {
  display: block;
  font-size: 12px;
  color: var(--text-secondary);
}

.currency-symbol {
  grid-column: 2;
  grid-row: 2;
}

html[data-platform="ios"] .currency-symbol,
html[data-platform="android"] .currency-symbol {
  display: none;
}

.currency-amount-wrap {
  grid-column: 1 / -1;
  grid-row: 3;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  text-align: left;
  margin-top: 2px;
}

.currency-amount {
  display: block;
  width: 100%;
  max-width: 100%;
  font-size: var(--amount-size, clamp(18px, 5vmin, 34px));
  font-weight: 300;
  line-height: 1.05;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
  white-space: nowrap;
  overflow: hidden;
}

.currency-amount-stacked {
  display: inline-flex;
  flex-direction: column;
  align-items: flex-start;
  line-height: 1;
  max-width: 100%;
}

html[data-platform="macos"] .currency-symbol,
html[data-platform="windows"] .currency-symbol {
  grid-column: 1 / -1;
  grid-row: 2;
}

html[data-platform="ios"] .amount-label,
html[data-platform="android"] .amount-label {
  display: none;
}

html[data-platform="ios"] .currency-card,
html[data-platform="android"] .currency-card {
  padding: 4px 2px;
}

html[data-platform="ios"] .swap-row,
html[data-platform="android"] .swap-row {
  margin: 4px 0;
}

html[data-platform="ios"] .rate-info,
html[data-platform="android"] .rate-info {
  margin: 2px 0 0;
  font-size: 10px;
}

.amount-line {
  display: block;
  white-space: nowrap;
}

.amount-line-main {
  font-size: var(--amount-size, clamp(20px, 5.5vmin, 34px));
  font-weight: 300;
}

.amount-line-sub {
  margin-top: 2px;
  font-size: calc(var(--amount-size, clamp(20px, 5.5vmin, 34px)) * 0.82);
  font-weight: 300;
  letter-spacing: 0.02em;
}

.amount-result {
  color: var(--text);
  font-weight: 300;
}

.swap-row {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  height: clamp(28px, 6vmin, 42px);
  margin: 6px 0;
}

.swap-row::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: 50%;
  border-top: 1px solid color-mix(in srgb, var(--text-secondary) 25%, transparent);
}

#swap-btn {
  position: relative;
  z-index: 1;
  width: clamp(32px, 8vmin, 42px);
  height: clamp(32px, 8vmin, 42px);
  border: none;
  border-radius: 50%;
  background: color-mix(in srgb, var(--label-blue) 22%, var(--surface-fn));
  color: var(--label-blue);
  font-size: 15px;
  font-weight: 700;
  box-shadow: none;
  cursor: pointer;
}

.rate-info {
  text-align: center;
  font-size: 11px;
  color: var(--text-secondary);
  margin: 4px 0 0;
}

.keypad-section {
  flex-shrink: 0;
  align-self: end;
  width: 100%;
  padding: 8px 12px calc(10px + var(--safe-bottom));
  background: var(--bg);
  border-radius: 0;
  box-shadow: none;
}

#keypad {
  display: flex;
  flex-direction: column;
  width: 100%;
}

.keypad-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--key-gap, 8px);
  width: 100%;
  margin-bottom: var(--key-gap, 8px);
}

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

.key-btn {
  width: 100%;
  aspect-ratio: 1;
  height: auto;
  max-height: var(--key-size, none);
  min-width: 0;
  border: none;
  border-radius: 50%;
  background: var(--surface);
  color: var(--text);
  font-size: clamp(18px, calc(var(--key-size, 72px) * 0.38), 28px);
  font-weight: 400;
  box-shadow: none;
  cursor: pointer;
  padding: 0;
}

.key-btn.key-op,
.key-btn.key-equals {
  background: var(--surface-op);
  color: var(--text-on-emphasis);
  font-weight: 500;
  line-height: 1;
}

.key-btn.key-op {
  font-size: clamp(20px, calc(var(--key-size, 72px) * 0.44), 34px);
  font-weight: 300;
}

.key-btn.key-equals {
  font-size: clamp(18px, calc(var(--key-size, 72px) * 0.4), 30px);
  font-weight: 400;
}

.key-btn:active:not(:disabled) {
  filter: brightness(1.15);
  transform: scale(0.96);
}

.key-btn.key-delete,
.key-btn.key-clear {
  background: var(--surface-fn);
  color: var(--text);
}

.key-btn.key-delete {
  font-size: clamp(16px, calc(var(--key-size, 72px) * 0.3), 22px);
}

.key-btn.key-clear {
  font-size: clamp(14px, calc(var(--key-size, 72px) * 0.28), 20px);
  font-weight: 500;
}

.key-empty {
  opacity: 0;
  pointer-events: none;
}

.mix-card {
  margin: 0 16px 8px;
  padding: 12px 16px;
  background: var(--surface);
  border-radius: 12px;
  box-shadow: none;
  flex: 1 1 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

html[data-theme="dark"] .mix-card {
  background: var(--surface);
}

.mix-expression {
  width: 100%;
  margin-top: 6px;
  border: none;
  border-radius: 12px;
  padding: 12px;
  font-size: 16px;
  line-height: 1.45;
  color: var(--text);
  background: var(--bg);
  box-shadow: none;
  resize: none;
  flex: 1 1 auto;
  min-height: 56px;
  max-height: var(--mix-expr-max, 120px);
  font-family: inherit;
}

.mix-quick-ops {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.mix-op-btn {
  border: none;
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 600;
  background: var(--surface-fn);
  color: var(--text);
  cursor: pointer;
}

.mix-hint {
  margin: 8px 0 0;
  font-size: 11px;
  color: var(--text-secondary);
  overflow: hidden;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
}

.mix-result-card {
  margin: 8px auto 0;
  flex-shrink: 0;
  width: fit-content;
  max-width: calc(100% - 32px);
  min-width: min(100%, 260px);
  background: var(--surface);
  border-radius: 12px;
  padding: 12px;
}

html[data-theme="dark"] .mix-result-card {
  background: var(--surface);
}

.mix-result-card .currency-card-inner {
  flex-direction: column;
  align-items: center;
  gap: 14px;
}

.mix-result-card .currency-meta {
  width: 100%;
}

.mix-result-card .currency-amount-wrap {
  margin-left: 0;
  width: fit-content;
  max-width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

.mix-result-card .currency-amount,
.mix-result-card .currency-amount-stacked {
  align-items: center;
  text-align: center;
}

.mix-result-card .amount-label {
  text-align: center;
}

.mix-error {
  margin: 8px 16px 0;
  font-size: 13px;
  color: var(--warning);
  text-align: center;
}

.mix-error[hidden] {
  display: none;
}

@media (min-width: 768px) and (pointer: fine) {
  html[data-platform="web"] {
    --app-max-width: 580px;
  }

  html[data-platform="web"] .app {
    height: min(calc(100dvh - 40px), 920px);
    max-height: min(calc(100dvh - 40px), 920px);
    border-radius: 24px;
    box-shadow: 0 0 0 1px color-mix(in srgb, var(--text-secondary) 12%, transparent);
  }
}

html[data-platform="macos"] .app-header,
html[data-platform="windows"] .app-header {
  padding: 14px 16px 10px;
}

html[data-platform="macos"] .search-section,
html[data-platform="windows"] .search-section {
  padding: 0 16px 10px;
}

html[data-platform="macos"] .currency-section,
html[data-platform="windows"] .currency-section {
  padding: 8px 16px 0;
}

html[data-platform="macos"] .keypad-section,
html[data-platform="windows"] .keypad-section {
  padding: 16px 20px 24px;
}

@media (max-width: 390px) {
  .header-actions {
    gap: 4px;
  }

  .theme-btn {
    padding: 6px 7px;
    font-size: 11px;
  }

  .mode-toggle {
    padding: 6px 8px;
    font-size: 11px;
  }

  .icon-btn {
    width: 32px;
    height: 32px;
    font-size: 16px;
  }
}

@media (max-width: 340px) {
  .currency-field-label {
    font-size: 11px;
  }
}

@media (max-height: 640px) {
  .amount-label {
    display: none;
  }

  .search-section {
    padding-bottom: 4px;
  }

  .search-bar {
    padding: 8px 12px;
  }
}

@media (orientation: landscape) and (max-height: 500px) {
  .app-header h1 {
    font-size: 15px;
  }

  .search-section {
    display: none;
  }

  .status-row {
    min-height: 0;
    padding-top: 2px;
  }

  .currency-card {
    padding: 4px 2px;
  }

  .swap-row {
    margin: 2px 0;
  }

  .rate-info {
    display: none;
  }
}

@media (display-mode: standalone) {
  .app-header {
    padding-top: 8px;
  }
}
