:root {
  color-scheme: light;
  --ink: #20142e;
  --muted: #62536f;
  --night: #130922;
  --brand: #8000ff;
  --brand-deep: #6200c6;
  --paper: #f7f4fb;
  --white: #fff;
  --line: #ded4e8;
  --control-line: #a993b9;
  --tint: #f2e7ff;
  font: 100%/1.5 system-ui, sans-serif;
  color: var(--ink);
  background: var(--paper);
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}
* { box-sizing: border-box; }
body { margin: 0; }
[hidden] { display: none !important; }
body {
  --left-gutter: max(.875rem, env(safe-area-inset-left));
  --right-gutter: max(.875rem, env(safe-area-inset-right));
}
.wrap {
  width: min(42rem, calc(100% - var(--left-gutter) - var(--right-gutter)));
  margin-inline: auto;
}
@media (orientation: landscape) {
  body {
    --left-gutter: max(.875rem, env(safe-area-inset-left), env(safe-area-inset-right));
    --right-gutter: var(--left-gutter);
  }
}
header {
  background: radial-gradient(ellipse at 85% 10%, #37016c, transparent 65%), var(--night);
  color: var(--white);
  padding: calc(.8rem + env(safe-area-inset-top)) 0 1.8rem;
}
header p { margin: 0; color: #e2d2f2; font-size: .9375rem; }
.brand { display: block; width: clamp(5.5rem, 26vw, 7.875rem); height: auto; }
h1, h2 { line-height: 1.12; letter-spacing: -.035em; margin: 0 0 .45rem; }
h1 { font-size: clamp(1.75rem, 6.7vw, 3.5rem); font-weight: 750; overflow-wrap: anywhere; }
h2 { font-size: 1.5rem; }
.workspace {
  position: relative;
  margin-top: -.85rem;
  padding: 0 clamp(.8rem, 4vw, 1.65rem) 1.25rem;
  border-radius: 1rem;
  background: var(--white);
  box-shadow: 0 12px 38px #32124c13;
}
nav {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: .2rem;
  margin-bottom: 1rem;
  border-bottom: 1px solid var(--line);
}
nav button {
  display: flex;
  flex-wrap: wrap;
  align-content: center;
  align-items: center;
  justify-content: center;
  gap: .15rem .25rem;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--muted);
  padding: .4rem .2rem;
  min-height: 3.1rem;
  font-size: .875rem;
  line-height: 1.2;
}
nav button[aria-current] { color: var(--brand-deep); box-shadow: inset 0 -2px var(--brand); }
#count {
  display: inline-block;
  min-width: 1.4rem;
  padding: 0 .3rem;
  color: var(--brand-deep);
  background: var(--tint);
  border-radius: 1rem;
  font-variant-numeric: tabular-nums;
}
label, legend { font-weight: 650; }
label span, .hint { color: var(--muted); font-weight: 400; }
input, textarea, select, button { font: inherit; color: inherit; }
input:not([type=radio]), textarea, select {
  border: 1px solid var(--control-line);
  border-radius: .65rem;
  background: var(--white);
  min-width: 0;
  max-width: 100%;
  min-height: 3rem;
  padding: .55rem .75rem;
  font-size: max(1rem, 16px);
}
input:not([type=radio]), textarea {
  display: block;
  width: 100%;
  margin-top: .3rem;
  caret-color: var(--brand-deep);
}
select {
  appearance: none;
  padding-inline-end: 2rem;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%),
    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 15px) center, calc(100% - 10px) center;
  background-size: 5px 5px;
  background-repeat: no-repeat;
}
input::placeholder, textarea::placeholder { color: var(--muted); }
#phone { font-size: 1.25rem; font-variant-numeric: tabular-nums; }
textarea { resize: vertical; }
.hint { font-size: .875rem; margin: .45rem 0 1.1rem; }
.fields, .actions { display: grid; grid-template-columns: minmax(0, 1fr); gap: .65rem; }
.fields > div { min-width: 0; }
fieldset { min-inline-size: 0; border: 0; padding: 0; margin: 1rem 0 1.15rem; }
.languages { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .55rem; margin-top: .35rem; }
.languages label {
  display: flex;
  align-items: center;
  gap: .45rem;
  min-height: 48px;
  padding: .4rem .75rem;
  border: 1px solid var(--control-line);
  border-radius: .65rem;
  cursor: pointer;
}
.languages label:has(input:checked) { background: var(--tint); border-color: var(--brand); }
.languages label:has(input:checked) span { color: var(--brand-deep); font-weight: 650; }
input[type=radio] { accent-color: var(--brand-deep); margin: 0; }
button {
  cursor: pointer;
  background: var(--white);
  border: 1px solid var(--control-line);
  border-radius: .65rem;
  font-weight: 700;
  min-height: 48px;
  padding: .55rem .7rem;
}
button.primary { background: var(--brand-deep); border-color: var(--brand-deep); color: var(--white); }
button:hover { background: var(--tint); }
button.primary:hover { background: #5100a4; }
.actions button { min-height: 3rem; }
:focus-visible { outline: 3px solid var(--brand); outline-offset: 3px; }
::selection { background: #e7cdff; color: var(--night); }
details { margin-top: 1.1rem; border-top: 1px solid var(--line); padding-top: .45rem; }
summary { cursor: pointer; font-weight: 650; min-height: 44px; padding: .6rem 0; color: var(--brand-deep); }
#preview { white-space: pre-wrap; overflow-wrap: anywhere; margin: .35rem 0; }
footer { padding: 1rem 0 max(1.5rem, env(safe-area-inset-bottom)); color: var(--muted); font-size: .875rem; }
#status { background: var(--tint); color: var(--ink); padding: .65rem .8rem; border-radius: .65rem; overflow-wrap: anywhere; }
.section-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .65rem; }
.filter { display: flex; align-items: center; gap: .45rem; font-size: .875rem; }
#empty { color: var(--muted); margin-bottom: 0; }
#contacts { list-style: none; padding: 0; margin-bottom: 0; }
#contacts li { border-top: 1px solid var(--line); padding: .8rem 0; overflow-wrap: anywhere; }
#contacts li:last-child { padding-bottom: 0; }
.contact-copy { margin: 0 0 .55rem; }
.contact-copy span { display: block; color: var(--muted); }
.contact-actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .45rem; }
.contact-actions .primary, .contact-actions button:only-child { grid-column: 1 / -1; }
#invalid { overflow-wrap: anywhere; }
#scanner {
  margin: 0 0 1.1rem;
  padding: .1rem .75rem;
  border: 1px solid var(--line);
  border-radius: .65rem;
  background: var(--tint);
}
#scanner[open] { padding-bottom: .75rem; }
#scanner summary { min-height: 44px; padding: .62rem 0; }
#scanner .hint { margin: 0 0 .65rem; }
.scan-actions { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 7rem), 1fr)); gap: .45rem; }
#scan-status { margin: .65rem 0 0; overflow-wrap: anywhere; }
#scan-choices { margin-top: .7rem; }
#scan-number { display: block; width: 100%; margin: .25rem 0 .45rem; }
#scan-prepare { margin-top: .6rem; }
#scan-prepare, #scan-use, #import .primary { width: 100%; }
button:disabled { cursor: default; opacity: .65; }
.brand-row { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: .55rem; margin-bottom: .55rem; }
#edit-profile { min-height: 44px; padding-inline: .6rem; font-size: .875rem; background: transparent; border-color: #a993b9; color: var(--white); }
#edit-profile:hover { background: #37016c; }
#profile { padding-top: 1.35rem; }
.profile-lead { color: var(--muted); margin: 0 0 1.1rem; }
.profile-field { margin-top: .85rem; }
.profile-actions { display: grid; grid-template-columns: minmax(0, 1fr); gap: .55rem; margin-top: 1.15rem; }
#draft-editor textarea { margin-bottom: .75rem; }
#draft-editor code { font-size: .9em; }
#profile-status { margin: .65rem 0 0; }
footer { display: grid; gap: .25rem; }
footer a { color: var(--brand-deep); text-underline-offset: .18em; }
footer a[download] { display: inline-flex; align-items: center; min-height: 44px; }

@media (min-width: 36rem) {
  header { padding: calc(1.4rem + env(safe-area-inset-top)) 0 3rem; }
  header p { font-size: 1rem; }
  .brand-row { margin-bottom: 1rem; }
  .workspace { margin-top: -1.3rem; }
  nav { margin-bottom: 1.25rem; }
  nav button { min-height: 3.35rem; font-size: .9375rem; }
  .fields, .actions { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .fields { align-items: end; }
  .languages, .scan-actions, .contact-actions, .profile-actions { display: flex; flex-wrap: wrap; }
  #scan-prepare, #scan-use, #import .primary { width: auto; }
}
