:root {
  --bg: #f5f2eb;
  --panel: #f4f1e9;
  --panel-strong: #f1ede4;
  --line: #c9c1b4;
  --text: #222222;
  --muted: #857d70;
  --shadow: 0 10px 24px rgba(44, 34, 20, 0.06);
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }

body {
  background: linear-gradient(180deg, #f8f5ee 0%, #f2eee6 100%);
  color: var(--text);
  font-family: "PingFang SC", "Microsoft YaHei", "Segoe UI", sans-serif;
}

.shell {
  width: min(540px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 18px 0 40px;
}

.top-switch,
.sub-switch {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.sub-switch {
  margin: 8px 0 22px;
}

.top-tab,
.sub-tab,
.main-button {
  appearance: none;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.44);
  color: var(--text);
  border-radius: 14px;
  font-size: 18px;
  font-weight: 600;
  padding: 14px 18px;
}

.top-tab.active,
.sub-tab.active {
  background: #fffdfa;
  box-shadow: inset 0 0 0 1px rgba(34, 34, 34, 0.02);
}

.send-view,
.receive-view {
  margin-top: 28px;
}

.block-label {
  display: block;
  margin: 0 0 12px;
  font-size: 16px;
  color: #37312a;
}

.text-box {
  width: 100%;
  min-height: 166px;
  border: 1px solid #d8d2c7;
  border-radius: 12px;
  padding: 14px;
  background: rgba(255, 255, 255, 0.72);
  font-size: 20px;
  line-height: 1.45;
  color: var(--text);
  resize: none;
}

.text-box.masked {
  -webkit-text-security: disc;
}

.toggle-line {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  margin-top: 12px;
  font-size: 15px;
  color: var(--muted);
}

.main-button {
  width: 100%;
  margin-top: 14px;
  background: rgba(255, 255, 255, 0.5);
}

.result-card {
  margin-top: 30px;
  border-radius: 16px;
  background: rgba(244, 241, 233, 0.82);
  box-shadow: var(--shadow);
  padding: 20px 16px 18px;
}

.code-wrap {
  text-align: center;
}

.code-wrap strong {
  display: block;
  font-size: clamp(42px, 10vw, 62px);
  font-weight: 500;
  letter-spacing: 0.26em;
  text-indent: 0.26em;
  line-height: 1.05;
}

.status-text {
  margin: 10px 0 0;
  text-align: center;
  font-size: 15px;
  color: var(--muted);
}

.qr-divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 22px 0 18px;
  color: var(--muted);
  font-size: 14px;
}

.qr-divider::before,
.qr-divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: #ddd6c9;
}

.qr-panel {
  display: grid;
  place-items: center;
  gap: 14px;
  min-height: 220px;
}

#qr-image {
  width: 220px;
  height: 220px;
  border-radius: 12px;
  background: white;
  object-fit: contain;
}

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

.code-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 8px;
}

.code-cell {
  width: 100%;
  border: 1px solid #bfb7aa;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.48);
  text-align: center;
  text-transform: uppercase;
  font-size: 32px;
  padding: 12px 0;
  color: var(--text);
}

.code-cell:focus,
.text-box:focus {
  outline: none;
  border-color: #1d1d1d;
}

.scan-box {
  position: relative;
  min-height: 260px;
  border: 1px dashed #c8c0b3;
  border-radius: 16px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.4);
}

#scanner-video {
  width: 100%;
  height: 260px;
  object-fit: cover;
  display: block;
  background: #e8e1d5;
}

.scan-placeholder {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  text-align: center;
  color: var(--muted);
  padding: 18px;
  font-size: 15px;
}

.receive-state {
  min-height: 56px;
  display: grid;
  align-items: center;
}

#received-text {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.66);
  border: 1px solid #d8d1c4;
  padding: 14px;
  font-size: 16px;
  line-height: 1.6;
}

.footer {
  margin-top: 34px;
  padding-top: 28px;
  border-top: 1px solid #d8d1c4;
  text-align: center;
  color: var(--muted);
}

.footer h1 {
  margin: 0 0 10px;
  color: var(--text);
  font-size: 24px;
  font-weight: 700;
}

.footer p {
  margin: 4px 0;
  font-size: 14px;
}

.hidden {
  display: none !important;
}

@media (max-width: 520px) {
  .shell {
    width: min(100vw - 24px, 540px);
  }

  .top-tab,
  .sub-tab,
  .main-button {
    font-size: 16px;
  }

  .code-wrap strong {
    font-size: 46px;
  }

  #qr-canvas {
    width: 196px;
    height: 196px;
  }
}
