:root {
  color-scheme: light dark;
  --bg: #fff;
  --fg: #111;
  --muted: #737373;
  --line: #e2e2e2;
  --soft: #f4f4f4;
  --err: #c4302b;
  --ring: rgba(17, 17, 17, 0.14);
  --radius: 10px;
  --mono: ui-monospace, 'SF Mono', SFMono-Regular, Menlo, Consolas, 'Liberation Mono', monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f0f0f;
    --fg: #f2f2f2;
    --muted: #9a9a9a;
    --line: #2e2e2e;
    --soft: #1c1c1c;
    --err: #ff7a70;
    --ring: rgba(242, 242, 242, 0.18);
  }
}

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

[hidden] {
  display: none !important;
}

html {
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 16px/1.5 system-ui, -apple-system, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
}

#app {
  max-width: 420px;
  margin: 0 auto;
  padding: 0 16px;
}

.mono {
  font-family: var(--mono);
}

.strong {
  font-weight: 600;
}

/* ---------- layout ---------- */

.page {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 8px 0 96px;
}

/* Fixed top offset instead of vertical centering: results grow downward without the
   code boxes jumping around. */
.page.center {
  padding-top: max(56px, 20vh);
}

.page.center > .warn {
  position: absolute;
  top: 12px;
  left: 0;
  right: 0;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.stack.sm {
  gap: 10px;
}

.row {
  display: flex;
  gap: 8px;
}

.row > * {
  flex: 1 1 0;
  min-width: 0;
}

.row > .sq {
  flex: 0 0 48px;
}

.row > .btn:not(.sq) {
  flex: 0 0 auto;
}

.row > .btn.primary {
  flex: 1 1 0;
}

.stage {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.stage:empty {
  display: none;
}

/* ---------- header ---------- */

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 56px;
}

.top a {
  color: var(--fg);
  text-decoration: none;
  font-weight: 600;
  padding: 8px 4px;
  border-radius: 6px;
}

.top .brand-sm {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.brand {
  margin: 0 0 8px;
  text-align: center;
  font-size: 30px;
  font-weight: 700;
  letter-spacing: -0.03em;
}

/* ---------- messages ---------- */

.err {
  margin: 0;
  color: var(--err);
  font-size: 14px;
  text-align: center;
}

.err.left {
  text-align: left;
}

.err:empty {
  display: none;
}

.warn {
  margin: 0;
  padding: 10px 12px;
  border-radius: var(--radius);
  background: var(--soft);
  font-size: 14px;
  text-align: center;
}

/* ---------- buttons ---------- */

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

.btn {
  position: relative;
  appearance: none;
  min-height: 48px;
  padding: 0 18px;
  border: 1.5px solid var(--fg);
  border-radius: var(--radius);
  background: transparent;
  color: var(--fg);
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
  touch-action: manipulation;
  transition: transform 0.08s ease, opacity 0.15s ease, background-color 0.15s ease;
}

.btn.primary {
  background: var(--fg);
  color: var(--bg);
}

.btn.ghost {
  border-color: var(--line);
  color: var(--muted);
}

.btn.sm {
  min-height: 36px;
  padding: 0 12px;
  font-size: 14px;
  border-color: var(--line);
}

.btn.sm.armed {
  border-color: var(--err);
  color: var(--err);
}

.btn.sq {
  padding: 0;
  font-size: 20px;
}

.btn.quiet {
  border-color: var(--line);
}

.btn:active:not(:disabled) {
  transform: scale(0.97);
}

.btn:disabled {
  opacity: 0.35;
  cursor: default;
}

.btn.busy {
  color: transparent !important;
  opacity: 1;
}

.btn.busy::after {
  content: '';
  position: absolute;
  inset: 0;
  margin: auto;
  width: 18px;
  height: 18px;
  border: 2px solid var(--fg);
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

.btn.primary.busy::after {
  border-color: var(--bg);
  border-right-color: transparent;
}

:focus-visible {
  outline: 2px solid var(--fg);
  outline-offset: 2px;
}

/* ---------- code boxes ---------- */

.code {
  display: flex;
  justify-content: center;
  gap: 8px;
}

.digit {
  flex: 1 1 0;
  min-width: 0;
  max-width: 52px;
  height: 60px;
  padding: 0;
  border: 1.5px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg);
  font: 600 28px/1 var(--mono);
  text-align: center;
  caret-color: transparent;
  transition: border-color 0.12s ease, box-shadow 0.12s ease;
}

.digit:focus {
  outline: none;
  border-color: var(--fg);
  box-shadow: 0 0 0 3px var(--ring);
}

.code.busy .digit {
  opacity: 0.5;
}

.code.shake {
  animation: shake 0.4s ease;
}

.code.shake .digit {
  border-color: var(--err);
}

/* ---------- fields ---------- */

.field {
  width: 100%;
  min-height: 48px;
  padding: 0 14px;
  border: 1.5px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg);
  font-size: 16px;
}

.field:focus {
  outline: none;
  border-color: var(--fg);
  box-shadow: 0 0 0 3px var(--ring);
}

select.field {
  appearance: none;
  padding-right: 34px;
  background: var(--bg) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M1 1l5 5 5-5' fill='none' stroke='%23888' stroke-width='1.6'/%3E%3C/svg%3E") no-repeat right 14px center;
  cursor: pointer;
}

/* ---------- send: zone ---------- */

.zone {
  position: relative;
  border: 1.5px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg);
  transition: border-color 0.12s ease, background-color 0.12s ease;
}

.zone:focus-within {
  border-color: var(--fg);
}

.zone.over {
  border-color: var(--fg);
  border-style: dashed;
  background: var(--soft);
}

.zone-text {
  display: block;
  width: 100%;
  min-height: 180px;
  padding: 14px 14px 52px;
  border: 0;
  border-radius: var(--radius);
  background: transparent;
  resize: vertical;
  line-height: 1.5;
}

.zone-text:focus {
  outline: none;
}

.pick {
  position: absolute;
  right: 8px;
  bottom: 8px;
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 8px;
  background: var(--soft);
  color: var(--fg);
  cursor: pointer;
}

.pick:active {
  transform: scale(0.94);
}

.zone.has-file .zone-text,
.zone.has-file .pick {
  display: none;
}

.zone-file:empty {
  display: none;
}

.zone .file {
  border: 0;
}

/* ---------- file card ---------- */

.file {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border: 1.5px solid var(--line);
  border-radius: var(--radius);
}

.ficon {
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  width: 40px;
  height: 48px;
  border-radius: 6px;
  background: var(--soft);
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
}

.fmeta {
  flex: 1;
  min-width: 0;
}

.fname {
  font-weight: 600;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.fsize {
  color: var(--muted);
  font-size: 13px;
}

.x {
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.x:hover {
  background: var(--soft);
  color: var(--fg);
}

/* ---------- send: tier switch ---------- */

.seg {
  display: flex;
  gap: 3px;
  padding: 3px;
  border: 1.5px solid var(--line);
  border-radius: var(--radius);
}

.seg button {
  flex: 1;
  min-height: 40px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.seg button[aria-checked='true'] {
  background: var(--fg);
  color: var(--bg);
}

.stack.locked .zone,
.stack.locked .seg,
.stack.locked .stack {
  pointer-events: none;
  opacity: 0.6;
}

/* ---------- progress ---------- */

.bar {
  display: block;
  width: 100%;
  height: 4px;
  appearance: none;
  border: 0;
  border-radius: 2px;
  background: var(--line);
  color: var(--fg);
  overflow: hidden;
}

.bar::-webkit-progress-bar {
  background: var(--line);
}

.bar::-webkit-progress-value {
  background: var(--fg);
  transition: width 0.15s linear;
}

.bar::-moz-progress-bar {
  background: var(--fg);
}

.bar:not([value]) {
  background: linear-gradient(90deg, var(--line) 0 35%, var(--fg) 35% 65%, var(--line) 65%) 0 0 / 300% 100%;
  animation: slide 1.1s linear infinite;
}

.bar:not([value])::-webkit-progress-bar {
  background: transparent;
}

.bar:not([value])::-moz-progress-bar {
  background: transparent;
}

/* ---------- pickup result ---------- */

.text {
  margin: 0;
  max-height: 55vh;
  overflow: auto;
  padding: 14px;
  border: 1.5px solid var(--line);
  border-radius: var(--radius);
  font: 14px/1.6 var(--mono);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.preview {
  display: block;
  max-width: 100%;
  max-height: 55vh;
  margin: 0 auto;
  border-radius: var(--radius);
}

/* ---------- send result ---------- */

.result {
  padding-top: 24px;
  text-align: center;
}

.big {
  display: flex;
  justify-content: center;
  gap: 0.35em;
  font-size: 48px;
  font-weight: 700;
  line-height: 1;
  letter-spacing: 0.06em;
  user-select: all;
}

.qr {
  display: block;
  width: 200px;
  height: 200px;
  margin: 0 auto;
  border-radius: var(--radius);
}

/* ---------- manage ---------- */

.list {
  margin: 0 0 16px;
  padding: 0;
  list-style: none;
}

.list:empty {
  display: none;
}

.list li {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 0;
  border-bottom: 1px solid var(--line);
  transition: opacity 0.2s ease;
}

.list li.gone {
  opacity: 0;
}

.li-main {
  flex: 1;
  min-width: 0;
}

.li-top {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.li-top .mono {
  font-size: 18px;
}

.meta {
  margin-top: 2px;
  color: var(--muted);
  font-size: 13px;
}

.tag {
  padding: 1px 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  font-size: 12px;
}

.tag.solid {
  border-color: var(--fg);
  background: var(--fg);
  color: var(--bg);
}

.actions {
  display: flex;
  flex: 0 0 auto;
  gap: 6px;
}

/* ---------- floating send ---------- */

.fab {
  position: fixed;
  right: 16px;
  bottom: max(16px, env(safe-area-inset-bottom));
  padding: 12px 18px;
  border-radius: 999px;
  background: var(--fg);
  color: var(--bg);
  font-weight: 600;
  text-decoration: none;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.18);
}

.fab:active {
  transform: scale(0.97);
}

/* ---------- motion ---------- */

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

@keyframes slide {
  from {
    background-position: 100% 0;
  }
  to {
    background-position: 0 0;
  }
}

@keyframes shake {
  10%, 90% { transform: translateX(-1px); }
  20%, 80% { transform: translateX(3px); }
  30%, 50%, 70% { transform: translateX(-6px); }
  40%, 60% { transform: translateX(6px); }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition: none !important;
  }
  .code.shake {
    animation: none;
  }
  .bar:not([value]) {
    animation: none;
  }
  .btn.busy::after {
    animation-duration: 1.6s;
  }
}
