:root {
  color-scheme: light;
  --bg: #f5f5f7;
  --surface: rgba(255, 255, 255, 0.82);
  --surface-strong: #ffffff;
  --ink: #1d1d1f;
  --muted: #6e6e73;
  --line: rgba(0, 0, 0, 0.09);
  --accent: #0071e3;
  --accent-soft: #f5faff;
  --warn: #b64d17;
  --warn-bg: #fff4ed;
  --ok: #168a48;
  --ok-bg: #effaf3;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background:
    radial-gradient(circle at 15% 0%, rgba(255, 255, 255, 0.95), transparent 28%),
    linear-gradient(180deg, #fbfbfd 0%, var(--bg) 42%, #ffffff 100%);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text", "Hiragino Sans", "Yu Gothic", sans-serif;
  font-size: 18px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

body.sex-male-theme {
  --bg: #f2f8ff;
  --surface: rgba(255, 255, 255, 0.84);
  background:
    radial-gradient(circle at 18% 0%, rgba(212, 234, 255, 0.95), transparent 30%),
    linear-gradient(180deg, #fbfdff 0%, #f2f8ff 44%, #ffffff 100%);
}

body.sex-female-theme {
  --bg: #fff6f9;
  --surface: rgba(255, 255, 255, 0.86);
  background:
    radial-gradient(circle at 18% 0%, rgba(255, 218, 232, 0.95), transparent 30%),
    linear-gradient(180deg, #fffbfd 0%, #fff6f9 44%, #ffffff 100%);
}

button,
input {
  font: inherit;
}

.app-shell {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 32px 0 48px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--accent);
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(42px, 5.4vw, 72px);
  line-height: 1.05;
  letter-spacing: 0;
  font-weight: 750;
}

h2 {
  margin-bottom: 0;
  font-size: 23px;
  letter-spacing: 0;
  font-weight: 700;
}

h3 {
  margin-bottom: 10px;
  font-size: 20px;
}

.action-buttons {
  display: flex;
  gap: 10px;
  align-items: center;
}

.print-button,
.secondary-button,
.clear-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 92px;
  height: 42px;
  border-radius: 999px;
  font-weight: 650;
  cursor: pointer;
}

.print-button {
  border: 1px solid rgba(0, 113, 227, 0.18);
  background: #0071e3;
  color: #fff;
  box-shadow: 0 10px 22px rgba(0, 113, 227, 0.24);
}

.print-button:hover {
  background: #0077ed;
}

.secondary-button {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.76);
  color: var(--ink);
}

.secondary-button:hover {
  background: #fff;
}

.clear-button {
  min-width: 106px;
  margin-right: 16px;
  border: 1px solid rgba(185, 28, 28, 0.2);
  background: rgba(255, 255, 255, 0.7);
  color: #b42318;
}

.clear-button:hover {
  background: #fff5f3;
}

.glass-panel {
  border: 1px solid var(--line);
  border-radius: 22px;
  background: var(--surface);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.patient-panel {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) auto;
  gap: 16px;
  align-items: end;
  padding: 18px;
  margin-bottom: 18px;
}

label span,
legend {
  display: block;
  margin-bottom: 7px;
  color: var(--muted);
  font-size: 17px;
  font-weight: 650;
}

fieldset {
  margin: 0;
  padding: 0;
  border: 0;
}

input[type="text"],
input[type="number"] {
  width: 100%;
  min-height: 54px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.74);
  color: var(--ink);
  padding: 12px 16px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.9);
}

.name-field {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
}

.name-field > span {
  margin: 0;
  color: var(--ink);
  font-size: 20px;
  font-weight: 700;
}

.name-input-wrap {
  position: relative;
  display: block;
}

.name-input-wrap input {
  padding-left: 104px;
}

.paste-button {
  position: absolute;
  top: 50%;
  left: 6px;
  transform: translateY(-50%);
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.78);
  color: var(--accent);
  padding: 0 14px;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
}

.paste-button:hover {
  background: #fff;
}

input:focus {
  outline: 4px solid rgba(0, 113, 227, 0.15);
  border-color: var(--accent);
}

.segmented-control {
  display: grid;
  grid-template-columns: 1fr 1fr;
  width: 180px;
  border: 1px solid var(--line);
  border-radius: 999px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.7);
  padding: 3px;
}

.segmented-control label {
  display: block;
  cursor: pointer;
}

.segmented-control input {
  position: absolute;
  opacity: 0;
}

.segmented-control span {
  display: grid;
  place-items: center;
  min-height: 46px;
  margin: 0;
  color: var(--ink);
  border-radius: 999px;
  background: transparent;
  transition: background 0.16s ease, color 0.16s ease, box-shadow 0.16s ease;
}

.segmented-control input:checked + span {
  background: var(--surface-strong);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.12);
}

.segmented-control input:checked + .sex-male {
  background: #eaf4ff;
  color: #0071e3;
}

.segmented-control input:checked + .sex-female {
  background: #fff0f5;
  color: #d63b75;
}

.workspace-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 18px;
  align-items: start;
}

.input-stack,
.result-stack {
  display: grid;
  gap: 18px;
}

.panel,
.result-panel {
  padding: 20px;
}

.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 16px;
}

output {
  color: var(--accent);
  font-weight: 800;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.tooth-row {
  display: grid;
  grid-template-columns: repeat(4, minmax(80px, 1fr));
  gap: 12px;
}

.tooth-input {
  display: grid;
}

.tooth-input small {
  margin-top: 5px;
  color: var(--muted);
  font-size: 16px;
}

.two-arch-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.arch-inputs {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 10px;
  align-items: end;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.55);
}

.arch-inputs h3 {
  grid-column: 1 / -1;
}

.crowding-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.primary-result {
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.9), rgba(245, 250, 255, 0.86));
}

.result-list,
.prediction-list {
  display: grid;
  gap: 12px;
  margin: 16px 0 0;
}

.result-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 15px 16px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.7);
}

.result-item strong {
  font-size: 34px;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.result-item.shortage {
  border-color: #f0c4ae;
  background: var(--warn-bg);
}

.result-item.shortage strong {
  color: var(--warn);
}

.result-item.room {
  border-color: #bfe3cd;
  background: var(--ok-bg);
}

.result-item.room strong {
  color: var(--ok);
}

.prediction-list div {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding-bottom: 11px;
  border-bottom: 1px solid var(--line);
}

.prediction-list div:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}

dt {
  color: var(--muted);
  font-weight: 700;
  font-size: 18px;
}

dd {
  margin: 0;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  font-size: 18px;
}

.note-panel p {
  margin: 10px 0 0;
  color: var(--muted);
}

body.image-exporting {
  background: #fff;
  font-size: 18px;
  line-height: 1.35;
}

body.image-exporting .app-shell {
  width: 1120px;
  padding: 0;
}

body.image-exporting .action-buttons {
  display: none;
}

body.image-exporting .paste-button {
  display: none;
}

body.image-exporting .name-input-wrap input {
  padding-left: 8px;
}

body.image-exporting .topbar {
  margin-bottom: 12px;
}

body.image-exporting h1 {
  font-size: 52px;
}

body.image-exporting h2 {
  font-size: 22px;
}

body.image-exporting .glass-panel {
  border-radius: 10px;
  background: #fff;
  box-shadow: none;
  backdrop-filter: none;
}

body.image-exporting .patient-panel {
  padding: 12px;
  margin-bottom: 12px;
}

body.image-exporting .workspace-grid {
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 12px;
}

body.image-exporting .input-stack,
body.image-exporting .result-stack {
  gap: 12px;
}

body.image-exporting .panel,
body.image-exporting .result-panel {
  padding: 13px;
}

body.image-exporting .panel-heading {
  margin-bottom: 10px;
}

body.image-exporting input[type="text"],
body.image-exporting input[type="number"] {
  min-height: 46px;
  border-radius: 7px;
  padding: 9px 10px;
  background: #fff;
  box-shadow: none;
}

body.image-exporting .arch-inputs,
body.image-exporting .result-item {
  border-radius: 8px;
}

body.image-exporting .result-item strong {
  font-size: 30px;
}

@media (max-width: 860px) {
  .workspace-grid,
  .patient-panel,
  .two-arch-grid {
    grid-template-columns: 1fr;
  }

  .segmented-control {
    width: 100%;
  }
}

@media (max-width: 560px) {
  .app-shell {
    width: min(100% - 20px, 1180px);
    padding-top: 16px;
  }

  .topbar {
    align-items: stretch;
    flex-direction: column;
  }

  .action-buttons {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .clear-button {
    grid-column: 1 / -1;
    margin-right: 0;
  }

  .name-field {
    grid-template-columns: minmax(0, 1fr) auto;
  }

  .name-input-wrap input {
    padding-left: 94px;
  }

  .tooth-row,
  .crowding-grid {
    grid-template-columns: 1fr 1fr;
  }

  .arch-inputs {
    grid-template-columns: 1fr 1fr;
  }

  .arch-inputs output {
    grid-column: 1 / -1;
  }
}

@media print {
  @page {
    size: A4 portrait;
    margin: 10mm 7mm 7mm;
  }

  * {
    print-color-adjust: exact;
    -webkit-print-color-adjust: exact;
  }

  body {
    background: #fff !important;
    font-size: 11.5px;
    line-height: 1.3;
  }

  .app-shell {
    width: 100%;
    background: #fff !important;
    padding-top: 8mm;
  }

  .topbar {
    align-items: end;
    gap: 10px;
    margin-bottom: 12px;
  }

  .eyebrow {
    margin-bottom: 2px;
    font-size: 9px;
  }

  h1 {
    font-size: 27px;
    line-height: 1;
  }

  h2 {
    font-size: 12.5px;
  }

  h3 {
    margin-bottom: 5px;
    font-size: 11px;
  }

  .action-buttons {
    display: none;
  }

  .paste-button {
    display: none;
  }

  .name-input-wrap input {
    padding-left: 6px;
  }

  .glass-panel {
    border-radius: 6px;
    background: #fff !important;
    box-shadow: none;
    backdrop-filter: none;
  }

  .primary-result,
  .result-item.shortage,
  .result-item.room {
    background: #fff !important;
  }

  .patient-panel {
    grid-template-columns: minmax(0, 1fr) 130px;
    gap: 9px;
    padding: 8px;
    margin-bottom: 11px;
  }

  .patient-panel,
  .panel,
  .result-panel {
    box-shadow: none;
    break-inside: avoid;
  }

  .workspace-grid {
    grid-template-columns: minmax(0, 1fr) 265px;
    gap: 8px;
  }

  .input-stack,
  .result-stack {
    gap: 8px;
  }

  .panel,
  .result-panel {
    padding: 9px;
  }

  .panel-heading {
    gap: 8px;
    margin-bottom: 8px;
  }

  label span,
  legend {
    margin-bottom: 3px;
    font-size: 9.5px;
  }

  input[type="text"],
  input[type="number"] {
    min-height: 22px;
    border-radius: 5px;
    padding: 4px 6px;
    background: #fff;
    box-shadow: none;
  }

  .name-field {
    gap: 5px;
    grid-template-columns: minmax(0, 1fr) auto;
  }

  .name-field > span {
    font-size: 11px;
  }

  .segmented-control {
    width: 120px;
    border-radius: 5px;
    padding: 1px;
  }

  .segmented-control span {
    min-height: 24px;
    border-radius: 4px;
  }

  .segmented-control input:checked + span {
    box-shadow: none;
  }

  .tooth-row {
    gap: 7px;
  }

  .tooth-input small {
    margin-top: 2px;
    font-size: 9px;
  }

  .two-arch-grid,
  .crowding-grid {
    gap: 8px;
  }

  .arch-inputs {
    gap: 6px;
    padding: 8px;
    border-radius: 5px;
  }

  .result-list,
  .prediction-list {
    gap: 6px;
    margin-top: 8px;
  }

  .result-item {
    gap: 7px;
    padding: 8px 9px;
    border-radius: 5px;
  }

  .result-item strong {
    font-size: 17px;
  }

  .prediction-list div {
    gap: 7px;
    padding-bottom: 6px;
  }

  .note-panel p {
    margin-top: 5px;
  }

  output,
  dd {
    font-size: 11.5px;
  }
}
