:root {
  color-scheme: light;
  --ink-strong: #102236;
  --ink: #23384d;
  --ink-muted: #617489;
  --canvas: #eef3f7;
  --surface: #ffffff;
  --surface-soft: #f7fafc;
  --surface-muted: #edf3f7;
  --line: #d8e2ec;
  --line-strong: #c5d3e0;
  --teal: #0c7c7c;
  --teal-deep: #075d60;
  --teal-soft: #e1f3f1;
  --gold: #b7791f;
  --gold-soft: #fff4d6;
  --danger: #b84b3a;
  --success: #087557;
  --header-height: 76px;
  font-family: "Microsoft YaHei", "PingFang SC", Inter, system-ui, sans-serif;
}

* { box-sizing: border-box; }

html { min-width: 320px; }

body {
  margin: 0;
  min-width: 320px;
  background: var(--canvas);
  color: var(--ink-strong);
  font-family: inherit;
}

button,
input,
select { font: inherit; }

a { color: inherit; text-decoration: none; }

button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 3px solid rgba(12, 124, 124, 0.28);
  outline-offset: 2px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Home */

.home-page {
  min-height: 100vh;
  background: #06131e;
  color: #f2f8fa;
}

.home-page .home-header {
  position: absolute;
  inset: 0 0 auto;
  z-index: 10;
  height: 72px;
  display: flex;
  align-items: center;
  border-bottom: 1px solid rgba(210, 229, 235, 0.16);
  background: rgba(4, 14, 23, 0.56);
  backdrop-filter: blur(10px);
}

.home-page .home-header-inner,
.home-page .home-stage-inner {
  width: min(1440px, calc(100% - 72px));
  margin: 0 auto;
}

.home-page .home-header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
}

.home-page .home-brand {
  display: inline-flex;
  align-items: center;
  gap: 11px;
  color: #f7fbfc;
  font-weight: 800;
}

.home-page .home-brand-mark,
.brand-mark {
  width: 34px;
  height: 34px;
  display: inline-grid;
  place-items: center;
  border: 1px solid rgba(221, 185, 108, 0.62);
  border-radius: 7px;
  background: #0a696b;
  color: #fff2cb;
}

.home-page .home-brand-mark svg,
.brand-mark svg {
  width: 19px;
  height: 19px;
}

.home-page .home-brand-copy {
  display: grid;
  gap: 1px;
  line-height: 1.1;
}

.home-page .home-brand-copy strong { font-size: 15px; }
.home-page .home-brand-copy span { color: #9eb4bf; font-size: 11px; }
.home-page .home-header-note { color: #aec0c8; font-size: 12px; }

.home-page .home-main {
  min-height: 100vh;
  margin: 0;
  padding: 0;
}

.home-page .home-stage {
  position: relative;
  isolation: isolate;
  min-height: 100svh;
  display: flex;
  overflow: hidden;
  background: #06131e;
}

.home-page .home-stage-media,
.home-page .home-stage-shade {
  position: absolute;
  inset: 0;
}

.home-page .home-stage-media { z-index: -2; }

.home-page .home-stage-media img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
  object-position: 58% center;
}

.home-page .home-stage-shade {
  z-index: -1;
  background: rgba(2, 11, 19, 0.28);
}

.home-page .home-stage-inner {
  display: flex;
  align-items: center;
  padding: 108px 0 44px;
}

.home-page .home-hero-copy {
  width: min(760px, 100%);
}

.home-page .home-kicker {
  margin: 0 0 12px;
  color: #91ddd4;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.12em;
}

.home-page .home-stage h1 {
  margin: 0;
  color: #fffdf8;
  font-size: 52px;
  line-height: 1.08;
  letter-spacing: 0;
}

.home-page .home-summary {
  margin: 16px 0 0;
  color: #d0e0e6;
  font-size: 16px;
  line-height: 1.65;
}

.home-page .home-launcher {
  width: min(720px, 100%);
  margin-top: 42px;
}

.home-page .home-launcher-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 12px;
}

.home-page .home-launcher-heading h2 {
  margin: 0;
  color: #f5fafc;
  font-size: 15px;
  line-height: 1.2;
}

.home-page .home-launcher-heading span {
  color: #9bb1bc;
  font-size: 11px;
}

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

.home-page .tool-entry {
  min-height: 104px;
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) 18px;
  align-items: center;
  gap: 14px;
  padding: 18px;
  border: 1px solid rgba(148, 189, 201, 0.38);
  border-radius: 8px;
  background: rgba(5, 23, 35, 0.9);
  box-shadow: 0 16px 34px rgba(0, 6, 12, 0.28);
  transition: transform 150ms ease, border-color 150ms ease, background-color 150ms ease;
}

.home-page .tool-entry:hover {
  border-color: rgba(222, 184, 103, 0.78);
  background: rgba(7, 31, 45, 0.96);
  transform: translateY(-2px);
}

.home-page .tool-entry-icon {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(222, 184, 103, 0.62);
  border-radius: 7px;
  background: #0a6769;
  color: #fff0c6;
}

.home-page .tool-entry-icon svg { width: 22px; height: 22px; }
.home-page .tool-entry-copy { min-width: 0; }

.home-page .tool-entry-copy h3 {
  margin: 0;
  color: #f6fbfd;
  font-size: 18px;
  line-height: 1.25;
}

.home-page .tool-entry-arrow { color: #d8ad59; }
.home-page .tool-entry-arrow svg { width: 17px; height: 17px; }

@media (max-width: 760px) {
  .home-page .home-header { height: 64px; }
  .home-page .home-header-inner,
  .home-page .home-stage-inner { width: min(100% - 32px, 620px); }
  .home-page .home-header-note,
  .home-page .home-brand-copy span { display: none; }
  .home-page .home-stage-media img { object-position: 70% center; }
  .home-page .home-stage-shade { background: rgba(2, 11, 19, 0.48); }
  .home-page .home-stage-inner { align-items: flex-end; padding: 92px 0 34px; }
  .home-page .home-hero-copy { padding: 0; }
  .home-page .home-stage h1 { font-size: 38px; }
  .home-page .home-summary { font-size: 14px; }
  .home-page .home-launcher { margin-top: 30px; }
  .home-page .tool-directory-grid { grid-template-columns: 1fr; }
  .home-page .tool-entry { min-height: 104px; padding: 15px; }
}

/* Calculator shell */
.calculator-page {
  min-height: 100vh;
  background: var(--canvas);
}

.calculator-header {
  position: sticky;
  top: 0;
  z-index: 50;
  padding: 0;
  border: 0;
  border-bottom: 1px solid var(--line-strong);
  background: rgba(255, 255, 255, 0.97);
  box-shadow: 0 4px 14px rgba(25, 50, 72, 0.08);
}

.calculator-header-inner {
  width: min(1680px, calc(100% - 40px));
  min-height: var(--header-height);
  margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(220px, 1fr) auto minmax(360px, 1fr);
  align-items: center;
  gap: 20px;
}

.calculator-brand {
  min-width: 0;
  display: inline-flex;
  align-items: center;
  gap: 10px;
}

.calculator-brand-copy {
  display: grid;
  min-width: 0;
  gap: 2px;
}

.calculator-brand-copy strong {
  color: var(--ink-strong);
  font-size: 16px;
  line-height: 1.2;
}

.calculator-brand-copy span {
  color: var(--ink-muted);
  font-size: 12px;
  line-height: 1.2;
}

.calculator-tabs {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
}

.calculator-tab {
  min-height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 0 14px;
  border-radius: 5px;
  color: var(--ink-muted);
  font-size: 14px;
  font-weight: 700;
  white-space: nowrap;
}

.calculator-tab:hover { color: var(--teal-deep); }

.calculator-tab[aria-current="page"] {
  color: #ffffff;
  background: var(--teal);
  box-shadow: 0 1px 3px rgba(7, 93, 96, 0.28);
}

.calculator-tab svg { width: 16px; height: 16px; }

.calculator-header-actions {
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
}

.header-score {
  min-width: 176px;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
  padding-right: 4px;
  text-align: right;
}

.calculator-header .header-score {
  padding: 0 4px 0 0;
  border: 0;
  border-radius: 0;
  background: transparent;
}

.header-score .label {
  margin: 0;
  color: var(--ink-muted);
  font-size: 12px;
  font-weight: 700;
  line-height: 1.25;
  white-space: nowrap;
}

.header-score.active { display: flex; }

.header-score .value {
  color: var(--success);
  font-size: 26px;
  font-weight: 800;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.header-tools {
  display: flex;
  align-items: center;
  gap: 6px;
}

.header-tools button {
  min-height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 0 10px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: var(--surface);
  color: var(--ink);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}

.header-tools button:hover {
  border-color: #79aaa6;
  color: var(--teal-deep);
  background: #f7fbfb;
}

.header-tools button.clear-button { color: var(--danger); }
.header-tools button.clear-button:hover { border-color: #d9a096; background: #fff9f8; }
.header-tools svg { width: 16px; height: 16px; }

.calculator-main {
  width: min(1680px, calc(100% - 40px));
  margin: 0 auto;
  padding: 22px 0 64px;
}

.workspace-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 20px;
  margin: 0 0 14px;
}

.workspace-heading h1 {
  margin: 0;
  color: var(--ink-strong);
  font-size: 24px;
  line-height: 1.2;
  letter-spacing: 0;
}

.workspace-heading p {
  margin: 0;
  color: var(--ink-muted);
  font-size: 13px;
}

.calculator-main .view { display: none; }
.calculator-main .view.active { display: block; }

.calculator-main .layout {
  display: block;
}

.calculator-main .layout > div { display: block; }

.calculator-main .layout section,
.calculator-main section {
  min-width: 0;
  margin: 0;
  padding: 20px;
  overflow: visible;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 3px 10px rgba(24, 49, 72, 0.04);
}

.calculator-main section + section { margin-top: 14px; }

.calculator-main h2 {
  margin: 0 0 18px;
  padding: 0 0 10px;
  border-bottom: 1px solid var(--line);
  color: var(--ink-strong);
  font-size: 20px;
  line-height: 1.2;
  font-weight: 800;
}

.calculator-main h3 {
  margin: 20px 0 10px;
  color: var(--ink);
  font-size: 16px;
}

.calculator-main .subsections {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  align-items: start;
}

.calculator-main .subsections > .excel-block,
.calculator-main .subsections > .parameter-block {
  min-width: 0;
}

.calculator-main .subsections > .excel-block:has(.table-wrap),
.calculator-main .subsections > .excel-block:has([id$="BraceletStatRows"]),
.calculator-main .subsections > .excel-block:has(.bracelet-line-grid),
.calculator-main .subsections > .excel-block:has(.engraving-grid),
.calculator-main .subsections > .wide-block,
.calculator-main .subsections > .parameter-block {
  grid-column: 1 / -1;
}

.calculator-main .excel-block,
.calculator-main .parameter-block {
  padding: 16px;
  overflow: visible;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface-soft);
}

.calculator-main .excel-title,
.calculator-main .parameter-title {
  margin: 0 0 14px;
  padding: 0;
  border: 0;
  color: var(--ink);
  font-size: 16px;
  line-height: 1.3;
  font-weight: 800;
  text-align: left;
}

.calculator-main .grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(145px, 1fr));
  gap: 12px;
}

.calculator-main .excel-block .grid,
.calculator-main .parameter-block .grid {
  gap: 12px;
}

.calculator-main label,
.calculator-main .excel-block label,
.calculator-main .parameter-block label,
.calculator-main .bracelet-line-field,
.calculator-main .engraving-field {
  display: grid;
  gap: 6px;
  color: var(--ink-muted);
  font-size: 13px;
  line-height: 1.35;
}

.calculator-main input,
.calculator-main select,
.calculator-main .excel-input,
.calculator-main .excel-select,
.calculator-main .parameter-block input,
.calculator-main .parameter-block select,
.calculator-main .data-grid input,
.calculator-main .data-grid select,
.calculator-main .bracelet-line-field select,
.calculator-main .engraving-field select {
  width: 100%;
  height: 42px;
  min-width: 0;
  padding: 7px 10px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: #ffffff;
  color: var(--ink-strong);
  font-size: 15px;
  line-height: 1.2;
}

.calculator-main input[readonly] {
  background: var(--surface-muted);
  color: #607387;
}

.calculator-main input:focus,
.calculator-main select:focus {
  border-color: var(--teal);
  outline: 2px solid rgba(12, 124, 124, 0.16);
}

.calculator-main .table-wrap {
  width: 100%;
  overflow-x: auto;
  overscroll-behavior-inline: contain;
  scrollbar-color: #9ab0c3 transparent;
}

.calculator-main .data-grid {
  width: 100%;
  min-width: 940px;
  border-collapse: separate;
  border-spacing: 0 8px;
  font-size: 13px;
}

.calculator-main .data-grid th {
  padding: 0 8px 2px 0;
  color: var(--ink-muted);
  font-size: 12px;
  font-weight: 800;
  text-align: left;
  white-space: nowrap;
}

.calculator-main .data-grid td {
  padding: 0 8px 0 0;
  vertical-align: middle;
}

.calculator-main .data-grid .row-label,
.calculator-main .readonly-cell {
  min-height: 42px;
  display: flex;
  align-items: center;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-muted);
  color: #52677d;
  white-space: nowrap;
}

.calculator-main .bracelet-line-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.calculator-main .bracelet-line-field {
  min-width: 0;
}

.calculator-main .bracelet-line-field .readonly-cell,
.calculator-main .engraving-field .readonly-cell {
  min-height: 38px;
  font-size: 13px;
}

.calculator-main .engraving-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(184px, 1fr));
  gap: 12px;
  overflow-x: auto;
  padding-bottom: 4px;
}

.calculator-main .engraving-field {
  min-width: 184px;
}

.calculator-main .engraving-field .inline-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.calculator-main .engraving-field .mini-field {
  display: grid;
  gap: 5px;
  color: var(--ink-muted);
  font-size: 11px;
}

.calculator-main .actions { display: flex; gap: 8px; margin-top: 12px; }

.calculator-main button {
  min-height: 38px;
  padding: 0 12px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: #ffffff;
  color: var(--ink);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}

.calculator-main button.primary {
  border-color: var(--teal);
  background: var(--teal);
  color: #ffffff;
}

.calculator-main button.warn { color: var(--danger); }

.calculator-main .internal-only { display: none !important; }
.calculator-main .result { display: none; }

@media (max-width: 1180px) {
  .calculator-header-inner {
    grid-template-columns: minmax(190px, 1fr) auto minmax(276px, 1fr);
    gap: 12px;
  }

  .calculator-brand-copy span { display: none; }
  .header-tools button span { display: none; }
  .header-tools button { width: 36px; padding: 0; }
}

@media (max-width: 900px) {
  :root { --header-height: auto; }

  .calculator-header-inner {
    width: min(100% - 28px, 760px);
    grid-template-columns: 1fr auto;
    grid-template-areas:
      "brand actions"
      "nav nav";
    gap: 10px 14px;
    padding: 10px 0;
  }

  .calculator-brand { grid-area: brand; }
  .calculator-tabs { grid-area: nav; justify-self: stretch; }
  .calculator-header-actions { grid-area: actions; }
  .header-score { min-width: 144px; }
  .header-score .value { font-size: 23px; }

  .calculator-main { width: min(100% - 28px, 760px); padding-top: 16px; }
  .calculator-main .subsections { grid-template-columns: 1fr; }
  .calculator-main .subsections > .excel-block,
  .calculator-main .subsections > .parameter-block { grid-column: 1; }
  .calculator-main .bracelet-line-grid { grid-template-columns: 1fr; }
  .calculator-main .engraving-grid { grid-template-columns: 1fr; overflow: visible; }
  .calculator-main .engraving-field { min-width: 0; }

  .home-hero h1 { font-size: 44px; }
  .home-hero p:not(.home-kicker) { font-size: 16px; }
}

@media (max-width: 620px) {
  .home-header { height: 66px; }
  .home-header-inner,
  .home-section-inner,
  .home-hero-copy { width: min(100% - 32px, 560px); }
  .home-header-note { display: none; }
  .home-brand-copy span { display: none; }
  .home-hero {
    height: min(700px, calc(100svh - 24px));
    min-height: 560px;
  }
  .home-hero-media img { object-position: 68% center; }
  .home-hero-shade { background: rgba(3, 12, 21, 0.54); }
  .home-hero-copy { padding: 82px 0 136px; }
  .home-hero h1 { max-width: 390px; font-size: 36px; }
  .home-hero p:not(.home-kicker) { max-width: 360px; margin-top: 16px; line-height: 1.7; }
  .home-directory { padding-bottom: 28px; }
  .home-directory .home-section-inner { transform: translateY(-58px); }
  .home-directory-heading { align-items: start; flex-direction: column; gap: 5px; }
  .tool-directory-grid { grid-template-columns: 1fr; }
  .tool-entry { min-height: 148px; grid-template-columns: 46px minmax(0, 1fr) 20px; gap: 14px; padding: 20px; }
  .tool-entry-icon { width: 46px; height: 46px; }
  .tool-entry-icon svg { width: 23px; height: 23px; }
  .tool-entry-copy h3 { font-size: 20px; }

  .calculator-header-inner {
    width: min(100% - 20px, 560px);
    grid-template-columns: 1fr;
    grid-template-areas:
      "brand"
      "nav"
      "actions";
  }
  .calculator-brand-copy strong { font-size: 14px; }
  .brand-mark { width: 30px; height: 30px; }
  .calculator-tabs { gap: 2px; }
  .calculator-tab { flex: 1; padding: 0 8px; font-size: 13px; }
  .calculator-header-actions { width: 100%; justify-content: space-between; }
  .header-score { min-width: 0; }
  .header-score .label { font-size: 10px; }
  .header-score .value { font-size: 20px; }
  .header-tools { gap: 4px; }
  .header-tools { display: flex; width: auto; }
  .header-tools button { width: 32px; min-height: 32px; }
  .header-tools svg { width: 15px; height: 15px; }

  .calculator-main { width: min(100% - 20px, 560px); padding-bottom: 34px; }
  .workspace-heading { margin-bottom: 10px; }
  .workspace-heading h1 { font-size: 20px; }
  .workspace-heading p { display: none; }
  .calculator-main .layout section,
  .calculator-main section { padding: 14px; }
  .calculator-main .excel-block,
  .calculator-main .parameter-block { padding: 13px; }
  .calculator-main h2 { font-size: 18px; }
  .calculator-main .excel-title,
  .calculator-main .parameter-title { font-size: 15px; }
  .calculator-main .grid { grid-template-columns: 1fr; }
  .calculator-main .data-grid { min-width: 760px; }
}
