:root {
  color-scheme: light;
  --ink: #17302f;
  --muted: #637372;
  --paper: #f5f4ee;
  --surface: #ffffff;
  --line: #d9ded9;
  --brand: #123b3a;
  --brand-2: #1f6662;
  --accent: #e8b44f;
  --danger: #a43f36;
  --shadow: 0 18px 44px rgba(24, 54, 52, 0.12);
  font-family: Inter, "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", system-ui, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 10% 0%, rgba(232, 180, 79, 0.14), transparent 28rem),
    var(--paper);
  color: var(--ink);
}

button, input { font: inherit; }
button { touch-action: manipulation; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1.1rem clamp(1rem, 4vw, 3rem);
  background: var(--brand);
  color: #fff;
}

h1, h2, p { margin: 0; }
h1 { font-size: clamp(1.25rem, 3vw, 1.8rem); letter-spacing: 0.02em; }
h2 { font-size: clamp(1.15rem, 2.5vw, 1.45rem); }
.eyebrow, .label { color: var(--muted); font-size: 0.72rem; font-weight: 800; letter-spacing: 0.14em; text-transform: uppercase; }
.topbar .eyebrow { color: #a9cfca; margin-bottom: 0.2rem; }

.status-row { display: flex; align-items: center; gap: 0.55rem; font-size: 0.9rem; }
.status-dot { width: 0.62rem; height: 0.62rem; border-radius: 50%; background: #65d297; box-shadow: 0 0 0 4px rgba(101, 210, 151, 0.15); }
.status-dot.offline { background: var(--accent); box-shadow: 0 0 0 4px rgba(232, 180, 79, 0.16); }

.app-shell {
  display: grid;
  grid-template-columns: minmax(310px, 0.95fr) minmax(360px, 1.05fr);
  gap: clamp(1rem, 3vw, 2.2rem);
  max-width: 1180px;
  margin: 0 auto;
  padding: clamp(1rem, 3vw, 2.2rem);
}

.qr-panel, .control-panel, .log-panel {
  background: var(--surface);
  border: 1px solid rgba(23, 48, 47, 0.08);
  border-radius: 24px;
  box-shadow: var(--shadow);
}

.qr-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 590px;
  padding: clamp(1rem, 3vw, 2.2rem);
}

.qr-code {
  display: grid;
  place-items: center;
  width: min(100%, 420px);
  aspect-ratio: 1;
  padding: clamp(0.8rem, 2vw, 1.25rem);
  background: #fff;
  border: 2px solid var(--ink);
  border-radius: 18px;
}

.qr-code svg { width: 100%; height: 100%; display: block; }
.id-wrap { margin-top: 1.3rem; text-align: center; }
.sample-id { margin-top: 0.28rem; font: 800 clamp(1.45rem, 4vw, 2.35rem)/1.1 ui-monospace, SFMono-Regular, Consolas, monospace; letter-spacing: 0.035em; }
.retake-badge { display: inline-block; margin-top: 0.75rem; padding: 0.42rem 0.7rem; border-radius: 999px; background: #fff1d1; color: #6d4a00; font-size: 0.85rem; font-weight: 750; }

.control-panel { padding: clamp(1.2rem, 3vw, 2rem); }
.section-heading { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1.25rem; }
.section-heading .label { margin-bottom: 0.25rem; }

.lock-button, .outline-button, .text-button, .utility-button, .action-button { cursor: pointer; border: 0; }
.lock-button { display: inline-flex; align-items: center; gap: 0.45rem; padding: 0.72rem 0.9rem; border-radius: 12px; background: #e7efed; color: var(--brand); font-weight: 800; }
.lock-button[aria-pressed="true"] { background: var(--brand); color: #fff; }

.field-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0.85rem; }
label span { display: block; margin-bottom: 0.4rem; font-size: 0.82rem; font-weight: 750; color: var(--muted); }
input { width: 100%; border: 1.5px solid var(--line); border-radius: 12px; padding: 0.86rem 0.9rem; background: #fff; color: var(--ink); font-size: 1.05rem; font-weight: 700; }
input:focus { outline: 3px solid rgba(31, 102, 98, 0.18); border-color: var(--brand-2); }
input:disabled { background: #eef1ed; color: #50605f; }
.field-error { display: block; min-height: 1.1rem; margin-top: 0.25rem; color: var(--danger); font-size: 0.75rem; }

.sequence-card { display: flex; justify-content: space-between; align-items: center; margin: 0.65rem 0 1rem; padding: 1rem 1.1rem; border-radius: 14px; background: #edf2ef; }
.sequence-card span { font-weight: 750; color: var(--muted); }
.sequence-card strong { font: 900 2.15rem/1 ui-monospace, SFMono-Regular, Consolas, monospace; }

.primary-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 0.85rem; }
.action-button { min-height: 88px; border-radius: 16px; font-size: 1.05rem; font-weight: 850; }
.action-button span { display: block; }
.action-button.primary { background: var(--brand); color: #fff; box-shadow: 0 10px 20px rgba(18, 59, 58, 0.2); }
.action-button.secondary { background: #dfe9e5; color: var(--brand); }
.action-button:disabled { opacity: 0.38; cursor: not-allowed; box-shadow: none; }
.action-symbol { font-size: 1.65rem; line-height: 1; margin-bottom: 0.2rem; }

.secondary-actions { display: grid; grid-template-columns: 0.7fr 1.3fr; gap: 0.85rem; margin-top: 0.85rem; }
.utility-button { min-height: 54px; padding: 0.7rem 1rem; border-radius: 13px; background: #eef0ed; color: var(--ink); font-weight: 800; }
.utility-button.retake { background: #fff1d1; color: #6d4a00; }
.message { min-height: 2.6rem; margin-top: 1rem; padding: 0.75rem 0.9rem; border-left: 4px solid var(--accent); background: #faf8f0; border-radius: 0 10px 10px 0; color: #4b5c5b; font-size: 0.86rem; }

.log-panel { display: flex; align-items: center; justify-content: space-between; gap: 1rem; max-width: calc(1180px - clamp(2rem, 6vw, 4.4rem)); margin: 0 auto clamp(1rem, 3vw, 2.2rem); padding: 1rem 1.25rem; box-shadow: none; }
.log-panel .label { margin-bottom: 0.25rem; }
.log-actions { display: flex; gap: 0.55rem; }
.outline-button { padding: 0.72rem 0.95rem; border: 1.5px solid var(--brand); border-radius: 11px; background: #fff; color: var(--brand); font-weight: 800; }
.text-button { padding: 0.5rem 0.6rem; background: transparent; color: inherit; font-weight: 750; }
.text-button.danger { color: var(--danger); }

dialog { width: min(92vw, 420px); border: 0; border-radius: 20px; padding: 0; box-shadow: 0 28px 80px rgba(0,0,0,0.28); }
dialog::backdrop { background: rgba(9, 27, 26, 0.64); backdrop-filter: blur(3px); }
dialog form { padding: 1.4rem; }
dialog h2 { margin: 0.25rem 0 1rem; }
.dialog-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 0.7rem; margin-top: 1rem; }
.action-button.compact { min-height: 50px; }

@media (max-width: 800px) {
  .topbar { align-items: flex-start; }
  .status-row { flex-wrap: wrap; justify-content: flex-end; }
  .app-shell { grid-template-columns: 1fr; }
  .qr-panel { min-height: 0; }
  .qr-code { width: min(78vw, 430px); }
  .log-panel { margin-left: 1rem; margin-right: 1rem; }
}

@media (max-width: 520px) {
  .topbar { padding: 0.85rem 1rem; }
  .status-row > span:not(.status-dot) { display: none; }
  .app-shell { padding: 0.75rem; gap: 0.75rem; }
  .qr-panel, .control-panel, .log-panel { border-radius: 18px; }
  .qr-panel { padding: 0.8rem; }
  .qr-code { width: min(76vw, 330px); border-radius: 13px; }
  .sample-id { font-size: clamp(1.35rem, 6vw, 1.8rem); }
  .control-panel { padding: 1rem; }
  .field-grid { grid-template-columns: 1fr; gap: 0.15rem; }
  .action-button { min-height: 76px; }
  .log-panel { align-items: flex-start; flex-direction: column; margin: 0 0.75rem 0.75rem; }
  .log-actions { width: 100%; }
  .log-actions > * { flex: 1; }
}

@media (prefers-reduced-motion: no-preference) {
  button { transition: transform 120ms ease, background 120ms ease, opacity 120ms ease; }
  button:active { transform: translateY(1px) scale(0.985); }
}
