:root {
  color-scheme: dark;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", sans-serif;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

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

body {
  min-height: 100dvh;
  overflow: hidden;
  background: #17131c;
  color: #fff;
}

button, input, select, textarea { font: inherit; }
button { border: 0; color: inherit; cursor: pointer; -webkit-tap-highlight-color: transparent; }

.app {
  --bg-a: #4b1775;
  --bg-b: #8f1f75;
  --bg-c: #b72b64;
  --accent: #f23cb4;
  --accent-2: #ff466d;
  --nav: rgba(48, 7, 57, .9);
  --panel: rgba(49, 13, 61, .72);
  --panel-strong: rgba(31, 8, 39, .78);
  --control: rgba(20, 7, 27, .62);
  --control-border: rgba(255, 155, 227, .22);
  position: relative;
  width: min(100%, 430px);
  height: 100dvh;
  margin: 0 auto;
  overflow: hidden;
  background:
    radial-gradient(circle at 82% 11%, rgba(255,255,255,.12), transparent 24%),
    linear-gradient(150deg, var(--bg-a), var(--bg-b) 55%, var(--bg-c));
  transition: background .25s ease;
}

.app[data-tool="processor"] {
  --bg-a: #064d68;
  --bg-b: #08716f;
  --bg-c: #0a906f;
  --accent: #17b9dc;
  --accent-2: #35d9bf;
  --nav: rgba(2, 52, 59, .92);
  --panel: rgba(5, 65, 72, .75);
  --panel-strong: rgba(2, 43, 50, .8);
  --control: rgba(1, 35, 42, .67);
  --control-border: rgba(114, 239, 226, .22);
}

.app[data-tool="id"] {
  --bg-a: #741208;
  --bg-b: #bd3511;
  --bg-c: #d37c18;
  --accent: #f35b20;
  --accent-2: #ff9b2e;
  --nav: rgba(83, 25, 4, .92);
  --panel: rgba(111, 31, 10, .74);
  --panel-strong: rgba(72, 19, 5, .8);
  --control: rgba(58, 14, 4, .68);
  --control-border: rgba(255, 184, 91, .24);
}

.topbar {
  position: absolute;
  z-index: 5;
  top: 0;
  right: 0;
  left: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: calc(70px + var(--safe-top));
  padding: calc(10px + var(--safe-top)) 16px 8px;
}

.brand { display: flex; align-items: center; min-width: 0; gap: 9px; }
.apple-mark {
  display: grid;
  flex: 0 0 36px;
  width: 36px;
  height: 36px;
  place-items: center;
  border-radius: 50%;
  background: rgba(13, 7, 20, .38);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.13);
}
.apple-mark svg { width: 20px; fill: #fff; }
.brand-label { display: block; color: rgba(255,255,255,.58); font-size: 8px; font-weight: 800; letter-spacing: 1.1px; }
h1 { margin: 1px 0 0; overflow: hidden; font-size: 18px; line-height: 1.08; letter-spacing: 0; text-overflow: ellipsis; white-space: nowrap; }

.language-button {
  display: grid;
  grid-template-columns: 1fr 1fr;
  flex: 0 0 64px;
  height: 32px;
  padding: 3px;
  border-radius: 17px;
  background: rgba(14, 8, 19, .43);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.13);
  font-size: 9px;
  font-weight: 800;
}
.language-button span { display: grid; place-items: center; border-radius: 14px; }
.language-button .active-language { background: rgba(255,255,255,.2); }

.screen {
  position: absolute;
  top: calc(70px + var(--safe-top));
  right: 0;
  bottom: calc(70px + var(--safe-bottom));
  left: 0;
  display: none;
  overflow-x: hidden;
  overflow-y: auto;
  padding: 6px 16px 24px;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
.screen::-webkit-scrollbar { display: none; }
.screen.active { display: block; animation: enter .18s ease-out; }

.field-row { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 8px; margin-bottom: 9px; }
.field {
  display: block;
  margin-bottom: 10px;
  padding: 10px;
  border-radius: 8px;
  border: 1px solid rgba(255,255,255,.1);
  background: linear-gradient(145deg, rgba(255,255,255,.08), transparent 60%), var(--panel);
  box-shadow: 0 9px 25px rgba(13, 5, 18, .22), inset 0 1px 0 rgba(255,255,255,.08);
  backdrop-filter: blur(18px);
}
.field > span:first-child,
.result-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 0 2px 6px;
  color: rgba(255,255,255,.82);
  font-size: 10px;
  font-weight: 800;
}
.result-label small {
  min-width: 27px;
  padding: 2px 7px;
  border-radius: 10px;
  background: rgba(255,255,255,.12);
  color: rgba(255,255,255,.78);
  text-align: center;
}

textarea, input, select {
  width: 100%;
  border: 1px solid var(--control-border);
  border-radius: 7px;
  outline: 0;
  background-color: var(--control);
  color: #fff;
  box-shadow: inset 0 1px 6px rgba(0,0,0,.15);
}
textarea:focus, input:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 16%, transparent); }
textarea::placeholder, input::placeholder { color: rgba(255,255,255,.38); }
textarea { min-height: 146px; padding: 10px; resize: vertical; font-family: "SFMono-Regular", Consolas, monospace; font-size: 12px; line-height: 1.42; }
input, select { height: 36px; padding: 0 9px; font-size: 11px; }
select { appearance: none; background-image: linear-gradient(45deg, transparent 50%, rgba(255,255,255,.7) 50%), linear-gradient(135deg, rgba(255,255,255,.7) 50%, transparent 50%); background-position: calc(100% - 13px) 15px, calc(100% - 8px) 15px; background-repeat: no-repeat; background-size: 5px 5px; padding-right: 24px; }
select option { background: #24142a; color: #fff; }

.switch-field {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 62px;
  padding: 9px 10px;
  border-radius: 8px;
  border: 1px solid rgba(255,255,255,.1);
  background: linear-gradient(145deg, rgba(255,255,255,.08), transparent 60%), var(--panel);
  box-shadow: 0 9px 25px rgba(13,5,18,.22), inset 0 1px 0 rgba(255,255,255,.08);
  color: rgba(255,255,255,.82);
  backdrop-filter: blur(18px);
  font-size: 9px;
  font-weight: 800;
}
.switch-field input { position: absolute; opacity: 0; pointer-events: none; }
.switch-track { position: relative; flex: 0 0 36px; width: 36px; height: 21px; margin-left: 6px; border-radius: 12px; background: rgba(255,255,255,.18); transition: .2s; }
.switch-track::after { content: ""; position: absolute; top: 3px; left: 3px; width: 15px; height: 15px; border-radius: 50%; background: #fff; box-shadow: 0 2px 5px rgba(0,0,0,.2); transition: .2s; }
.switch-field input:checked + .switch-track { background: var(--accent); }
.switch-field input:checked + .switch-track::after { transform: translateX(15px); }

.action-row { display: grid; grid-template-columns: 1fr 1.4fr; gap: 10px; margin: 1px 0 10px; }
.soft-button, .primary-button, .full-button {
  position: relative;
  overflow: hidden;
  min-height: 40px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 820;
  transition: transform .15s ease, filter .15s ease, background .15s ease;
}
.soft-button {
  border: 1px solid color-mix(in srgb, var(--accent) 54%, rgba(255,255,255,.16));
  background: rgba(17,7,22,.28);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.08);
  color: rgba(255,255,255,.9);
}
.primary-button, .full-button {
  border: 1px solid rgba(255,255,255,.12);
  background: linear-gradient(105deg, var(--accent), var(--accent-2));
  box-shadow: 0 8px 18px rgba(31,8,31,.2), inset 0 1px 0 rgba(255,255,255,.2);
}
.primary-button::after,
.full-button::after {
  content: "";
  position: absolute;
  top: 0;
  right: 12%;
  left: 12%;
  height: 1px;
  background: rgba(255,255,255,.48);
}
.soft-button:active,
.primary-button:active,
.full-button:active {
  transform: scale(.98);
  filter: brightness(.92);
}
.full-button { width: 100%; margin-bottom: 11px; }
.result-field textarea { min-height: 122px; }

.screen[data-page="gift"] {
  display: none;
  grid-template-rows: 74px minmax(104px, 1fr) 40px minmax(96px, .82fr) 40px;
  gap: 8px;
  padding-bottom: 10px;
  overflow: hidden;
}

.screen[data-page="gift"].active {
  display: grid;
}

.screen[data-page="gift"] .field-row,
.screen[data-page="gift"] .field,
.screen[data-page="gift"] .action-row,
.screen[data-page="gift"] .full-button {
  margin: 0;
}

.screen[data-page="gift"] .field {
  min-height: 0;
  padding: 10px;
}

.screen[data-page="gift"] .field textarea {
  height: calc(100% - 21px);
  min-height: 0;
  resize: none;
}

.screen[data-page="gift"] .switch-field {
  height: 74px;
  padding: 8px 9px;
}

.screen[data-page="gift"] .action-row {
  height: 40px;
}

.screen[data-page="gift"] .full-button {
  height: 40px;
  min-height: 40px;
}

.screen[data-page="gift"] .field-row {
  grid-template-columns: minmax(0, 1.3fr) minmax(112px, .7fr);
}

.screen[data-page="gift"] .field-row .field {
  overflow: hidden;
}

.screen[data-page="gift"] .switch-field > span:first-child {
  min-width: 0;
  line-height: 1.15;
  white-space: normal;
}

.screen[data-page="id"] {
  display: none;
  grid-template-rows: 78px 68px minmax(68px, 1fr) 38px minmax(64px, .78fr) 38px;
  gap: 8px;
  padding-bottom: 9px;
  overflow: hidden;
}

.screen[data-page="id"].active {
  display: grid;
}

.screen[data-page="id"] > .field-row,
.screen[data-page="id"] > .field,
.screen[data-page="id"] > .security-fields,
.screen[data-page="id"] > .action-row,
.screen[data-page="id"] > .full-button {
  margin: 0;
}

.screen[data-page="id"] .field {
  min-height: 0;
  height: 100%;
  padding: 9px;
  overflow: hidden;
}

.screen[data-page="id"] .field > span:first-child {
  margin-bottom: 7px;
  line-height: 1.2;
}

.screen[data-page="id"] input,
.screen[data-page="id"] select {
  display: block;
  height: 38px;
  min-height: 38px;
  font-size: 11px;
}

.screen[data-page="id"] select {
  background-position: calc(100% - 14px) 16px, calc(100% - 9px) 16px;
}

.screen[data-page="id"] .security-fields {
  height: 68px;
}

.screen[data-page="id"] .security-fields .field {
  margin: 0;
  padding: 8px;
}

.screen[data-page="id"] .security-fields input {
  height: 32px;
  min-height: 32px;
  font-size: 10px;
}

.screen[data-page="id"] > .field textarea {
  height: calc(100% - 19px);
  min-height: 0;
  padding: 9px;
  resize: none;
  font-size: 11px;
}

.screen[data-page="id"] .action-row,
.screen[data-page="id"] .full-button {
  height: 38px;
  min-height: 38px;
}

.screen[data-page="id"]:has(.custom-country.show) {
  grid-template-rows: 78px 66px 68px minmax(58px, 1fr) 38px minmax(54px, .7fr) 38px;
}

.result-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  margin: 2px 0 10px;
  padding: 4px;
  border-radius: 8px;
  border: 1px solid rgba(255,255,255,.09);
  background: var(--panel-strong);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.06);
}
.result-tabs button { min-height: 38px; border-radius: 6px; background: transparent; font-size: 12px; font-weight: 800; }
.result-tabs button.active { background: rgba(255,255,255,.2); }
.processor-result { display: none; }
.processor-result.active { display: block; }

.security-fields { display: grid; grid-template-columns: repeat(3, 1fr); gap: 7px; }
.security-fields .field { padding: 9px; }
.security-fields input { height: 38px; padding: 0 7px; font-size: 11px; }
.custom-country { display: none; }
.custom-country.show { display: block; }
.security-fields.hidden { display: none; }

.bottom-nav {
  position: absolute;
  z-index: 6;
  right: 24px;
  bottom: calc(9px + var(--safe-bottom));
  left: 24px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  height: 54px;
  padding: 3px;
  border-radius: 28px;
  background: var(--nav);
  box-shadow: 0 12px 28px rgba(0,0,0,.3), inset 0 0 0 1px rgba(255,255,255,.11);
  backdrop-filter: blur(16px);
}
.nav-item { display: grid; grid-template-rows: 23px 12px; align-content: center; justify-items: center; gap: 1px; min-width: 0; border-radius: 24px; background: transparent; }
.nav-item.active { background: rgba(255,255,255,.16); }
.nav-item svg { width: 21px; height: 21px; fill: none; stroke: #fff; stroke-linecap: round; stroke-linejoin: round; stroke-width: 2; }
.nav-item span { overflow: hidden; width: 100%; font-size: 9px; font-weight: 800; text-align: center; text-overflow: ellipsis; white-space: nowrap; }

.toast {
  position: fixed;
  z-index: 20;
  bottom: calc(75px + var(--safe-bottom));
  left: 50%;
  max-width: calc(100% - 40px);
  padding: 10px 18px;
  border-radius: 22px;
  background: #161119;
  color: #fff;
  box-shadow: 0 10px 30px rgba(0,0,0,.32);
  font-size: 12px;
  font-weight: 750;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 12px);
  transition: .2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: #a92929; }

@keyframes enter {
  from { opacity: .4; transform: translateY(5px); }
  to { opacity: 1; transform: translateY(0); }
}

@media (min-width: 431px) {
  body { display: grid; place-items: center; padding: 12px; }
  .app { height: min(900px, calc(100dvh - 24px)); border-radius: 18px; box-shadow: 0 28px 70px rgba(0,0,0,.45); }
}

@media (max-width: 350px) {
  .topbar { padding-right: 12px; padding-left: 12px; }
  .language-button { flex-basis: 68px; }
  .screen { padding-right: 11px; padding-left: 11px; }
  .security-fields { grid-template-columns: 1fr; }
}
