:root {
  --navy: #3c447c;
  --navy-deep: #2e3464;
  --bench: #f9f9f9;
  --housing: #ffffff;
  --ink: #3c447c;
  --muted: #6d74a3;
  --line: #e2e4f0;
  --field: #ffffff;
  --field-border: #c9cde0;
  --accent: #3c447c;
  --display: #3c447c;
  --digit: #ffffff;
  --digit-dim: #d7dbef;
  --danger: #9a3040;
  --shadow: 0 14px 34px rgba(60, 68, 124, 0.08);
  --radius: 16px;
}

* { box-sizing: border-box; }

html { overflow-x: hidden; }

body {
  margin: 0;
  padding: 0 0 16px;
  color: var(--ink);
  background: var(--bench);
  font-family: Roboto, "Segoe UI", sans-serif;
  font-size: 16px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea { font: inherit; color: inherit; }

.page-head {
  padding: 36px 28px 2px;
}
.page-head h1 { font-size: clamp(2rem, 3.2vw, 2.6rem); }

.housing {
  width: min(1180px, calc(100% - 32px));
  margin: 8px auto 0;
  padding: 12px 16px 8px;
  border: 1px solid #e7e9f2;
  border-radius: 20px;
  background: var(--housing);
  box-shadow: var(--shadow);
}

.bezel {
  padding: 4px 6px 16px;
  border-bottom: 1px solid var(--line);
}

.brand {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.brand a { color: inherit; text-decoration: none; }
.brand a:hover { color: var(--ink); }

h1, h2 { margin: 0; font-family: "Roboto Condensed", Roboto, sans-serif; font-weight: 700; letter-spacing: 0; }
h1 { font-size: clamp(2rem, 3.2vw, 2.6rem); line-height: 1.1; }
h2 { font-size: 1.05rem; letter-spacing: 0.01em; }
.bezel-note { margin: 2px 0 0; color: var(--muted); font-size: 0.92rem; }

.sheet { min-width: 0; }
.measure-bar {
  display: flex;
  align-items: center;
  gap: 18px;
  width: min(1180px, calc(100% - 32px));
  margin: 8px auto 0;
  padding: 8px 14px;
  border: 1px solid #e7e9f2;
  border-radius: 14px;
  background: #fff;
}
.measure-bar label {
  flex: 1;
  margin: 0;
  color: var(--navy);
  font-size: 1rem;
  font-weight: 700;
}
.measure-bar .control {
  flex: 0 0 220px;
  min-height: 46px;
  border: 2px solid var(--navy);
}
.measure-bar input { font-size: 1.35rem; font-weight: 700; }
.columns {
  display: grid;
  grid-template-columns: 1.15fr 1fr 1fr;
  gap: 8px 22px;
  align-items: start;
}
.column h2 { margin-bottom: 4px; }
.column .field + .field,
.column .hint { margin-top: 6px; }
.radius-row {
  display: flex;
  align-items: flex-end;
  gap: 18px;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--line);
}
.radius-row .field { flex: 0 1 320px; }
.standard-button {
  margin-left: auto;
  min-height: 40px;
  padding: 0 16px;
  border: 1px solid var(--navy);
  border-radius: 12px;
  background: var(--navy);
  color: #fff;
  font-size: 0.95rem;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
}
.standard-button:hover { background: var(--navy-deep); }

.fields {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px 14px;
}

.field { min-width: 0; }
.field-wide { margin: 4px 0 12px; }
.field-half { max-width: calc(50% - 7px); }
.field label {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 3px;
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 600;
}
abbr { text-decoration: none; color: var(--ink); font-variant-numeric: tabular-nums; }

.control, select {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--field-border);
  border-radius: 12px;
  background: var(--field);
}

.control { display: grid; grid-template-columns: minmax(0, 1fr) auto; overflow: hidden; }
.control:focus-within, select:focus {
  border-color: var(--ink);
  box-shadow: 0 0 0 3px rgba(60, 68, 124, 0.18);
  outline: none;
}

.control input, select {
  border: 0;
  background: transparent;
  padding: 0 12px;
  font-size: 1.05rem;
  font-variant-numeric: tabular-nums;
}
.control input { min-width: 0; width: 100%; }
.control input:focus, select:focus { outline: none; }

select {
  appearance: none;
  padding-right: 38px;
  cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='none' stroke='%233c447c' stroke-width='1.6' d='M1 1.2 6 6.2 11 1.2'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
}
select:disabled { color: var(--muted); cursor: wait; }

#material {
  min-height: 44px;
  border: 2px solid var(--navy);
  border-radius: 12px;
  background-color: #e7eaf6;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='9' viewBox='0 0 12 8'%3E%3Cpath fill='none' stroke='%233c447c' stroke-width='1.8' d='M1 1.2 6 6.2 11 1.2'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 16px center;
  color: var(--navy);
  font-size: 1.2rem;
  font-weight: 700;
  padding: 0 46px 0 16px;
  box-shadow: 0 0 0 4px rgba(60, 68, 124, 0.1);
}
#material:focus {
  border-color: var(--navy);
  box-shadow: 0 0 0 4px rgba(60, 68, 124, 0.24);
  outline: none;
}
#material:disabled { cursor: wait; }

.unit {
  display: grid;
  place-items: center;
  min-width: 3.4rem;
  padding: 0 10px;
  border-left: 1px solid var(--line);
  background: #f4f5fa;
  color: var(--muted);
  font-size: 0.84rem;
}

.group-measure .control { min-height: 72px; border-color: var(--navy); border-width: 1.5px; }
.group-measure input { font-size: 1.85rem; font-weight: 500; }
.group-measure .unit { min-width: 4.4rem; font-size: 1rem; background: #eef0f8; }

.hint { margin: 6px 0 0; color: var(--muted); font-size: 0.82rem; }
.sheet-foot { display: flex; padding: 4px 4px 2px; }

.text-button, .secondary-button, .primary-button, .icon-button {
  border-radius: 12px;
  cursor: pointer;
}
.text-button {
  min-height: 44px;
  padding: 8px 2px;
  border: 0;
  background: transparent;
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 3px;
}
.text-button:hover, .icon-button:hover { color: var(--ink); }
button:active { transform: translateY(1px); }
button:focus-visible, a:focus-visible {
  outline: 3px solid rgba(60, 68, 124, 0.35);
  outline-offset: 2px;
}

.display {
  position: sticky;
  top: 0;
  z-index: 5;
  display: grid;
  grid-template-columns: minmax(220px, 1fr) minmax(240px, 380px);
  gap: 8px 28px;
  align-items: center;
  width: 100%;
  padding: 10px 28px 12px;
  border-radius: 0;
  background: var(--display);
  color: var(--digit);
  box-shadow: 0 10px 28px rgba(46, 52, 100, 0.16);
}

.display-stress { min-width: 0; }
.display-kicker {
  margin: 0 0 8px;
  color: var(--digit-dim);
  font-size: 0.78rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.display h2 { color: var(--digit); font-size: 0.95rem; font-weight: 600; }

.stress-line {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  margin: 8px 0 0;
}
.stress-line output {
  min-width: 0;
  font-family: Consolas, "Cascadia Mono", "Segoe UI Mono", monospace;
  font-size: clamp(2.8rem, 4.4vw, 4.4rem);
  font-weight: 500;
  letter-spacing: -0.04em;
  line-height: 0.9;
  font-variant-numeric: tabular-nums;
}
.stress-unit { padding-bottom: 0.35rem; color: var(--digit-dim); font-size: 1rem; }

.details {
  margin: 0;
  min-width: 0;
  padding-left: 28px;
  border-left: 1px solid rgba(255, 255, 255, 0.18);
}
.details div {
  display: grid;
  grid-template-columns: 4.6rem minmax(0, 1fr) auto;
  gap: 8px;
  align-items: baseline;
  padding: 2px 0;
  border-top: 1px solid rgba(255, 255, 255, 0.18);
  color: var(--digit-dim);
  font-variant-numeric: tabular-nums;
}
.details strong {
  color: var(--digit);
  font-family: Consolas, "Cascadia Mono", monospace;
  font-size: 1rem;
  font-weight: 500;
  text-align: right;
}
.details small { min-width: 2.2rem; text-align: right; }
.details .is-emphasis strong { color: #ffffff; }

.status { min-height: 0; margin: 4px 0 0; color: var(--muted); font-size: 0.9rem; }

.explanation {
  width: min(1180px, calc(100% - 32px));
  margin: 18px auto 0;
}
.explanation img {
  display: block;
  width: 70%;
  height: auto;
  margin: 0 auto;
  border-radius: 16px;
  background: #fff;
}
.status[data-tone="error"] { color: var(--danger); }

dialog {
  width: min(640px, calc(100% - 28px));
  padding: 0;
  border: 0;
  border-radius: 20px;
  background: var(--housing);
  color: var(--ink);
  box-shadow: 0 24px 70px rgba(46, 52, 100, 0.28);
}
dialog::backdrop { background: rgba(46, 52, 100, 0.45); }
.editor-form { padding: 22px; }
.dialog-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.icon-button {
  width: 44px;
  height: 44px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 1.7rem;
  line-height: 1;
}
.editor-form .hint { margin: 12px 0; }
code { padding: 1px 5px; border-radius: 6px; background: #f4f5fa; font-family: Consolas, monospace; font-size: 0.84em; }
textarea {
  display: block;
  width: 100%;
  min-height: 240px;
  resize: vertical;
  padding: 12px 14px;
  border: 1px solid var(--field-border);
  border-radius: 12px;
  background: var(--field);
  font-family: Consolas, monospace;
  font-size: 0.92rem;
  line-height: 1.55;
}
textarea:focus { outline: none; border-color: var(--ink); box-shadow: 0 0 0 3px rgba(60, 68, 124, 0.18); }
.editor-status { min-height: 1.3rem; margin: 8px 0 0; color: var(--danger); font-size: 0.88rem; }
.dialog-actions { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.secondary-button, .primary-button { min-height: 44px; padding: 0 16px; }
.secondary-button { border: 1px solid var(--field-border); background: transparent; }
.secondary-button:hover { background: #f4f5fa; }
.primary-button { border: 1px solid var(--navy); background: var(--navy); color: #fff; }
.primary-button:hover { background: var(--navy-deep); }

@media (max-width: 980px) {
  .display { grid-template-columns: 1fr; gap: 16px; padding: 16px 18px 18px; }
  .details { padding-left: 0; border-left: 0; padding-top: 12px; border-top: 1px solid rgba(255, 255, 255, 0.18); }
}
@media (max-width: 640px) {
  .columns { grid-template-columns: 1fr; }
  .measure-bar { align-items: stretch; flex-direction: column; }
  .measure-bar .control { flex-basis: auto; }
  .radius-row { align-items: stretch; flex-direction: column; }
}
@media (max-width: 860px) {
  .page-head { padding: 28px 16px 6px; }
  .housing, .measure-bar, .explanation { width: calc(100% - 20px); }
  .housing { margin-top: 12px; padding: 16px; border-radius: 18px; }
}

@media (prefers-reduced-motion: reduce) {
  button:active { transform: none; }
}
