:root {
  --bg: #f6ead6;
  --bg-pattern: rgba(158, 28, 35, .06);
  --surface: #fffaf0;
  --surface-2: #fbefd8;
  --surface-3: #fffdf8;
  --border: #d0a85d;
  --border-soft: #ead1a0;
  --text: #2f2018;
  --muted: #745d45;
  --accent: #a3262d;
  --accent-deep: #7f1821;
  --accent-2: #c68a2e;
  --gold-soft: #e9c982;
  --danger: #9f1f1f;
  --shadow: 0 8px 26px rgba(96, 54, 20, .12);
  --shadow-soft: 0 3px 12px rgba(96, 54, 20, .09);
  --focus: rgba(163, 38, 45, .16);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: Arial, Helvetica, sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at 12% 0%, rgba(163, 38, 45, .10), transparent 28%),
    radial-gradient(circle at 85% 12%, rgba(198, 138, 46, .13), transparent 26%),
    linear-gradient(135deg, rgba(163, 38, 45, .035) 25%, transparent 25%) 0 0 / 34px 34px,
    linear-gradient(180deg, #fff8ec 0%, var(--bg) 100%);
  min-height: 100vh;
}

body.drawer-active { overflow: hidden; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }

.app-shell {
  width: min(1220px, 100%);
  margin: 0 auto;
  padding: 14px 10px 30px;
}

.hero-card,
.toolbar-card,
.result-card,
.measurement-card {
  background: linear-gradient(180deg, var(--surface), #fff6e6);
  border: 1px solid var(--border-soft);
  border-radius: 10px;
  box-shadow: var(--shadow-soft);
}

.hero-card {
  position: relative;
  overflow: hidden;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
  padding: 16px;
  margin-bottom: 10px;
  border-top: 4px solid var(--accent);
}

.hero-card::after {
  content: "";
  position: absolute;
  right: -36px;
  top: -42px;
  width: 135px;
  height: 135px;
  border: 18px double rgba(198, 138, 46, .22);
  border-radius: 50%;
  pointer-events: none;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent);
  font-size: .76rem;
  letter-spacing: .08em;
  text-transform: uppercase;
  font-weight: 800;
}

h1, h2, h3 { margin: 0; line-height: 1.2; }
h1 { font-size: 1.7rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1rem; }

.hero-copy,
small,
.help-text,
.drawer-copy { color: var(--muted); }
.hero-copy { margin: 8px 0 0; }

.toolbar-card {
  padding: 10px;
  display: grid;
  gap: 10px;
  margin-bottom: 10px;
  border-left: 4px solid var(--gold-soft);
}

.toggle-row,
.card-top,
.section-heading {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.toggle-row span { display: grid; gap: 2px; }

input[type="checkbox"] {
  width: 20px;
  height: 20px;
  accent-color: var(--accent);
  flex: 0 0 auto;
}

.measurement-list,
.config-list { display: grid; gap: 10px; }

.measurement-card {
  padding: 12px;
  border-left: 4px solid var(--accent-2);
}

.measurement-card:nth-child(3n + 1) { border-left-color: var(--accent); }
.measurement-card:nth-child(3n + 2) { border-left-color: var(--accent-2); }
.measurement-card:nth-child(3n + 3) { border-left-color: #b65f2a; }
.measurement-card.disabled { opacity: .62; }
.card-top { margin-bottom: 10px; }

.card-title {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.card-title h3 { overflow-wrap: anywhere; }

.input-grid { display: grid; gap: 10px; }
.field-row { display: grid; gap: 5px; min-width: 0; }

.field-row label {
  color: var(--text);
  font-size: .9rem;
  font-weight: 700;
}

.unit-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 78px;
  gap: 8px;
}

input[type="text"],
input[type="number"],
select,
textarea {
  width: 100%;
  min-width: 0;
  min-height: 42px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface-3);
  color: var(--text);
  padding: 9px 10px;
  outline: none;
}

textarea { min-height: 82px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--focus); }
input:disabled, select:disabled, textarea:disabled { background: #efe5d3; color: #8a7b68; cursor: not-allowed; }

.primary-button,
.secondary-button,
.ghost-button,
.danger-button {
  border-radius: 6px;
  min-height: 42px;
  padding: 9px 14px;
  font-weight: 700;
}

.primary-button {
  background: linear-gradient(180deg, #b62c34, var(--accent-deep));
  color: #fffaf1;
  border: 1px solid var(--accent-deep);
  width: 100%;
}
.primary-button:hover { filter: brightness(.96); }
.secondary-button,
.ghost-button { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); }
.secondary-button:hover, .ghost-button:hover { border-color: var(--accent); background: #fff4dc; }
.danger-button { background: #fff2ed; color: var(--danger); border: 1px solid #e0a9a1; }
.compact { min-height: 38px; padding: 7px 12px; }
.sticky-action { margin: 12px 0; }

.result-card { padding: 14px; margin-top: 12px; border-top: 3px solid var(--accent); }
.section-heading { margin-bottom: 12px; }

#result-text {
  margin: 0;
  white-space: pre-wrap;
  overflow-x: auto;
  color: var(--text);
  background: var(--surface-3);
  border: 1px solid var(--border-soft);
  border-radius: 6px;
  padding: 12px;
  font-family: Consolas, Monaco, "Courier New", monospace;
  line-height: 1.45;
}

.drawer-overlay {
  position: fixed;
  inset: 0;
  background: rgba(47, 32, 24, .34);
  opacity: 0;
  transition: opacity .18s ease;
  z-index: 30;
}
.drawer-overlay.open { opacity: 1; }

.config-drawer {
  position: fixed;
  top: 0;
  right: 0;
  width: min(92vw, 430px);
  height: 100vh;
  height: 100dvh;
  max-height: 100dvh;
  z-index: 40;
  background: linear-gradient(180deg, #fffaf0, #f9ead0);
  border-left: 4px solid var(--accent);
  box-shadow: -12px 0 30px rgba(47, 32, 24, .22);
  padding: 14px;
  padding-bottom: calc(14px + env(safe-area-inset-bottom, 0px) + 88px);
  transform: translateX(105%);
  transition: transform .2s ease;
  overflow-y: auto;
}
.config-drawer.open { transform: translateX(0); }
.drawer-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 8px; }
.drawer-copy { margin: 0 0 12px; font-size: .94rem; }
.drawer-tools { margin-bottom: 10px; }
.drawer-form { display: grid; gap: 12px; padding-bottom: calc(22px + env(safe-area-inset-bottom, 0px)); }

.config-item {
  background: var(--surface-2);
  border: 1px solid var(--border-soft);
  border-radius: 9px;
  padding: 12px;
  display: grid;
  gap: 10px;
}
.config-actions,
.check-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.check-pill {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  color: var(--text);
  background: var(--surface-3);
  border: 1px solid var(--border-soft);
  border-radius: 6px;
  padding: 9px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%) translateY(150%);
  opacity: 0;
  transition: .2s ease;
  z-index: 60;
  width: min(92vw, 420px);
  background: var(--surface-3);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 11px 14px;
  text-align: center;
  box-shadow: var(--shadow);
}
.toast.show { transform: translateX(-50%) translateY(0); opacity: 1; }

@media (min-width: 720px) {
  .app-shell { padding: 20px 16px 34px; }
  .toolbar-card { grid-template-columns: 1fr auto; align-items: center; }
  .input-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (min-width: 980px) {
  .app-shell { padding-top: 18px; }
  .hero-card { align-items: center; padding: 14px 16px; }
  h1 { font-size: 1.55rem; }
  .hero-copy { margin-top: 4px; }

  .measurement-list { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; align-items: start; }
  .measurement-card { padding: 10px; min-height: 142px; }
  .card-top { margin-bottom: 8px; }
  .card-title h3 { font-size: .95rem; }
  .field-row label { font-size: .82rem; }
  .input-grid { gap: 10px; grid-template-columns: minmax(0, 1fr) minmax(132px, .95fr); }
  .unit-row { grid-template-columns: minmax(0, 1fr) 66px; }

  input[type="text"], input[type="number"], select, textarea { min-height: 36px; padding: 7px 9px; }
  textarea { min-height: 68px; }
  input[type="checkbox"] { width: 18px; height: 18px; }
  .primary-button, .secondary-button, .ghost-button, .danger-button { min-height: 38px; padding: 7px 12px; }
  .sticky-action { max-width: 360px; margin: 14px auto 0; }
  .config-drawer { width: min(440px, 36vw); }
}

@media (min-width: 1220px) {
  .measurement-list { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .unit-row { grid-template-columns: minmax(0, 1fr) 68px; }
}

@media (min-width: 1540px) {
  .app-shell { width: min(1480px, 100%); }
  .measurement-list { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .input-grid { grid-template-columns: minmax(0, 1fr) minmax(130px, .9fr); }
  .unit-row { grid-template-columns: minmax(0, 1fr) 64px; }
}

/* Museum catalog upgrade */
.hero-card {
  background:
    linear-gradient(90deg, rgba(127, 24, 33, .08), transparent 42%),
    linear-gradient(180deg, #fffdf7, #fff2dc);
  border-color: #d2a763;
}

.hero-card::before {
  content: "劍  刀";
  position: absolute;
  right: 92px;
  bottom: -18px;
  color: rgba(127, 24, 33, .10);
  font-family: Georgia, "Times New Roman", serif;
  font-size: 6rem;
  font-weight: 700;
  line-height: 1;
  transform: rotate(-8deg);
  pointer-events: none;
}

.hero-card h1 {
  font-family: Georgia, "Times New Roman", serif;
  letter-spacing: .01em;
}

.profiles-card {
  position: relative;
  overflow: hidden;
  padding: 14px;
  margin-bottom: 12px;
  background:
    linear-gradient(180deg, rgba(255,255,255,.7), rgba(255,248,235,.94)),
    repeating-linear-gradient(90deg, rgba(198, 138, 46, .08) 0 1px, transparent 1px 13px);
  border: 1px solid var(--border-soft);
  border-top: 4px solid var(--accent);
  border-radius: 10px;
  box-shadow: var(--shadow-soft);
}

.profiles-card::after {
  content: "REGISTER";
  position: absolute;
  right: 12px;
  bottom: 8px;
  color: rgba(163, 38, 45, .055);
  font-size: 2.4rem;
  font-weight: 900;
  letter-spacing: .12em;
  pointer-events: none;
}

.profile-save-row {
  display: grid;
  gap: 10px;
  margin-bottom: 12px;
}

.profile-name-field span {
  color: var(--text);
  font-size: .9rem;
  font-weight: 700;
}

.profile-transfer-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 12px;
}

.profiles-list {
  display: grid;
  gap: 10px;
}

.profile-item {
  display: grid;
  gap: 10px;
  align-items: center;
  padding: 12px;
  background: rgba(255, 253, 248, .88);
  border: 1px solid var(--border-soft);
  border-left: 4px solid var(--accent-2);
  border-radius: 9px;
}

.profile-item h3 {
  font-family: Georgia, "Times New Roman", serif;
  color: var(--accent-deep);
}

.profile-item p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: .86rem;
}

.profile-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.measurement-card {
  position: relative;
  overflow: hidden;
  background:
    linear-gradient(180deg, rgba(255,253,248,.96), rgba(255,244,221,.96)),
    radial-gradient(circle at right bottom, rgba(198, 138, 46, .11), transparent 42%);
}

.result-card {
  background:
    linear-gradient(180deg, rgba(255,253,248,.96), rgba(255,244,221,.96)),
    repeating-linear-gradient(0deg, rgba(198, 138, 46, .06) 0 1px, transparent 1px 28px);
}

#result-text {
  background:
    linear-gradient(180deg, rgba(255,253,248,.92), rgba(255,250,240,.92));
  border-left: 4px solid var(--accent-2);
}

@media (min-width: 720px) {
  .toolbar-card { grid-template-columns: 1fr auto auto; }
  .profile-save-row { grid-template-columns: minmax(260px, 1fr) auto; align-items: end; }
  .profile-save-button { width: auto; min-width: 170px; }
  .profile-item { grid-template-columns: 1fr auto; }
  .profile-actions { width: 180px; }
}

@media (min-width: 980px) {
  .profiles-card { padding: 12px 14px; }
  .profiles-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}


/* Version 2.7 refinements */
.profiles-card:not([hidden]) {
  background:
    linear-gradient(180deg, rgba(255, 246, 223, .98), rgba(248, 226, 184, .98)),
    repeating-linear-gradient(90deg, rgba(127, 24, 33, .08) 0 1px, transparent 1px 14px);
  border-color: #c4923e;
  border-top-color: var(--accent-deep);
  box-shadow: 0 10px 28px rgba(96, 54, 20, .16);
}

.profiles-card:not([hidden]) .section-heading {
  background: rgba(255, 253, 248, .55);
  border: 1px solid rgba(208, 168, 93, .55);
  border-radius: 8px;
  padding: 10px;
}

.profile-actions {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.drawer-top-actions,
.drawer-bottom-actions {
  display: grid;
  gap: 8px;
}

.drawer-top-actions {
  position: sticky;
  top: -18px;
  z-index: 3;
  grid-template-columns: 1.25fr .9fr .9fr;
  margin: 0 -14px 14px;
  padding: 12px 14px;
  background: linear-gradient(180deg, #f9ead0 0%, rgba(249, 234, 208, .96) 72%, rgba(249, 234, 208, .72) 100%);
  border-bottom: 1px solid var(--border-soft);
  box-shadow: 0 10px 20px rgba(82, 45, 28, .08);
}

.drawer-top-actions .primary-button {
  width: 100%;
}

.drawer-bottom-actions {
  margin: 8px 0 0;
  padding: 8px 0 calc(18px + env(safe-area-inset-bottom, 0px));
}

.app-footer {
  margin-top: 22px;
  text-align: center;
  color: rgba(47, 32, 24, .42);
  font-size: .78rem;
  letter-spacing: .04em;
}

@media (min-width: 720px) {
  .profile-actions { width: 280px; }
}

/* Export selector menu */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(47, 32, 24, .34);
  opacity: 0;
  transition: opacity .16s ease;
  z-index: 55;
}

.modal-overlay.open { opacity: 1; }

.export-modal {
  position: fixed;
  left: 50%;
  top: 50%;
  width: min(520px, calc(100vw - 24px));
  max-height: min(680px, calc(100vh - 32px));
  overflow: auto;
  transform: translate(-50%, -46%) scale(.98);
  opacity: 0;
  z-index: 60;
  padding: 16px;
  background:
    linear-gradient(180deg, rgba(255, 250, 240, .98), rgba(248, 226, 184, .98)),
    repeating-linear-gradient(90deg, rgba(127, 24, 33, .08) 0 1px, transparent 1px 14px);
  border: 1px solid #c4923e;
  border-top: 4px solid var(--accent-deep);
  border-radius: 12px;
  box-shadow: 0 18px 44px rgba(47, 32, 24, .28);
  transition: transform .16s ease, opacity .16s ease;
}

.export-modal.open {
  transform: translate(-50%, -50%) scale(1);
  opacity: 1;
}

.modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
  padding-bottom: 10px;
  border-bottom: 1px solid rgba(208, 168, 93, .55);
}

.export-options-list {
  display: grid;
  gap: 9px;
  margin-top: 12px;
}

.export-option {
  display: grid;
  gap: 4px;
  width: 100%;
  padding: 12px;
  text-align: left;
  color: var(--text);
  background: rgba(255, 253, 248, .82);
  border: 1px solid var(--border-soft);
  border-left: 4px solid var(--accent-2);
  border-radius: 9px;
  box-shadow: var(--shadow-soft);
}

.export-option:hover,
.export-option:focus-visible {
  border-left-color: var(--accent);
  background: #fffdf8;
  outline: none;
}

.export-option strong {
  font-family: Georgia, "Times New Roman", serif;
  color: var(--accent-deep);
}

.export-option span {
  color: var(--muted);
  font-size: .86rem;
}

/* v2.7 export multi-select refinements */
.export-modal-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 12px;
}

.export-modal-actions.top-actions {
  justify-content: flex-start;
  margin-top: 10px;
}

.export-modal-actions.bottom-actions {
  position: sticky;
  bottom: -16px;
  padding: 12px 0 0;
  background: linear-gradient(180deg, rgba(255, 250, 240, .2), rgba(248, 226, 184, .98) 30%);
}

.selection-count {
  color: var(--muted);
  font-size: .88rem;
  font-weight: 700;
}

.export-option {
  grid-template-columns: 24px 1fr;
  align-items: center;
}

.export-option .selection-mark {
  width: 18px;
  height: 18px;
  border-radius: 5px;
  border: 2px solid rgba(127, 24, 33, .35);
  background: rgba(255, 253, 248, .9);
  box-shadow: inset 0 1px 2px rgba(47, 32, 24, .12);
}

.export-option.selected {
  border-left-color: var(--accent-deep);
  background: linear-gradient(180deg, rgba(255, 253, 248, .98), rgba(248, 238, 214, .98));
  box-shadow: 0 10px 24px rgba(127, 24, 33, .14);
}

.export-option.selected .selection-mark {
  border-color: var(--accent-deep);
  background: var(--accent-deep);
  position: relative;
}

.export-option.selected .selection-mark::after {
  content: "";
  position: absolute;
  left: 5px;
  top: 1px;
  width: 5px;
  height: 10px;
  border: solid #fffaf0;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}

.export-option-text {
  display: grid;
  gap: 4px;
}

.primary-button:disabled,
.secondary-button:disabled {
  cursor: not-allowed;
  opacity: .52;
  box-shadow: none;
}


/* Mobile drawer spacing: top sticky controls stay visible and the final Jump to top button clears browser chrome. */
@media (max-width: 719px) {
  .config-drawer {
    width: 100vw;
    padding-bottom: calc(24px + env(safe-area-inset-bottom, 0px));
  }

  .drawer-top-actions {
    top: -14px;
    grid-template-columns: 1fr 1fr;
  }

  .drawer-top-actions .primary-button {
    grid-column: 1 / -1;
  }

  .drawer-bottom-actions {
    padding-bottom: calc(34px + env(safe-area-inset-bottom, 0px));
  }
}

/* Saved Profiles left drawer */
.profiles-drawer {
  position: fixed;
  top: 0;
  left: 0;
  width: min(92vw, 430px);
  height: 100vh;
  height: 100dvh;
  max-height: 100dvh;
  z-index: 40;
  margin: 0;
  border-radius: 0;
  border: 0;
  border-right: 4px solid var(--accent-2);
  border-top: 0;
  box-shadow: 12px 0 30px rgba(47, 32, 24, .22);
  padding: 14px;
  padding-bottom: calc(24px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-105%);
  transition: transform .2s ease;
  overflow-y: auto;
  background:
    linear-gradient(180deg, rgba(255, 246, 223, .98), rgba(248, 226, 184, .98)),
    repeating-linear-gradient(90deg, rgba(127, 24, 33, .08) 0 1px, transparent 1px 14px);
}

.profiles-drawer.open {
  transform: translateX(0);
}

.profiles-drawer .section-heading {
  position: sticky;
  top: -14px;
  z-index: 3;
  margin: -14px -14px 12px;
  padding: 14px;
  background: linear-gradient(180deg, #f8e2b8 0%, rgba(248, 226, 184, .98) 78%, rgba(248, 226, 184, .72) 100%);
  border: 0;
  border-bottom: 1px solid rgba(208, 168, 93, .66);
  border-radius: 0;
  box-shadow: 0 10px 20px rgba(82, 45, 28, .08);
}

.profiles-drawer .profile-save-row,
.profiles-drawer .profile-transfer-row,
.profiles-drawer .profiles-list {
  position: relative;
  z-index: 1;
}

.profiles-drawer .profile-save-row {
  grid-template-columns: 1fr;
}

.profiles-drawer .profile-save-button {
  width: 100%;
}

.profiles-drawer .profile-transfer-row {
  grid-template-columns: 1fr 1fr;
}

.profiles-drawer .profiles-list {
  grid-template-columns: 1fr;
  padding-bottom: calc(18px + env(safe-area-inset-bottom, 0px));
}

.profiles-drawer .profile-item {
  grid-template-columns: 1fr;
}

.profiles-drawer .profile-actions {
  width: 100%;
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

@media (min-width: 980px) {
  .profiles-drawer {
    width: min(440px, 36vw);
  }
}

@media (max-width: 719px) {
  .profiles-drawer {
    width: 100vw;
  }
}
