:root {
  --bg: #eef1f6;
  --bg-grad: linear-gradient(180deg, #f6f8fc 0%, #e9eef5 100%);
  --panel: #ffffff;
  --panel-2: #f7f9fc;
  --text: #16202e;
  --muted: #5b6b80;
  --border: #dce3ec;
  --border-strong: #c3cdda;
  --accent: #0b63ce;
  --accent-hover: #0a55b0;
  --accent-soft: #e8f1fd;
  --accent-ring: rgba(11, 99, 206, .18);
  --ok: #0f7b4f;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 10px 28px rgba(16, 24, 40, .07);
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, .07);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial,
    "Noto Sans", "Noto Sans KR", "Noto Sans JP", "Malgun Gothic", "Microsoft YaHei", sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e131a;
    --bg-grad: linear-gradient(180deg, #101720 0%, #0b1016 100%);
    --panel: #161e28;
    --panel-2: #1b2530;
    --text: #e8eef6;
    --muted: #9aa9bc;
    --border: #27313e;
    --border-strong: #36414f;
    --accent: #4f9bf0;
    --accent-hover: #6aabf4;
    --accent-soft: #132335;
    --accent-ring: rgba(79, 155, 240, .28);
    --ok: #4ecb8f;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 12px 32px rgba(0, 0, 0, .35);
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
  }
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font);
  background: var(--bg);
  background-image: var(--bg-grad);
  background-attachment: fixed;
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- Header ---------- */
.app-header {
  position: sticky;
  top: 0;
  z-index: 40;
  background: color-mix(in srgb, var(--panel) 88%, transparent);
  backdrop-filter: saturate(160%) blur(10px);
  border-bottom: 1px solid var(--border);
}

.header-inner {
  max-width: 1160px;
  margin: 0 auto;
  padding: 10px 18px;
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
  text-decoration: none;
  flex: 0 0 auto;
}
.brand:hover { text-decoration: none; }

.brand-logo {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: linear-gradient(145deg, #c9d3df, #8d9bad);
  color: #16202e;
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 15px;
  letter-spacing: .5px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .6), var(--shadow-sm);
  flex: 0 0 auto;
}

.brand-text { display: flex; flex-direction: column; line-height: 1.2; }
.brand-title { font-weight: 700; font-size: 15px; }
.brand-sub { font-size: 11.5px; color: var(--muted); letter-spacing: .3px; }

.main-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-left: 6px;
  flex: 1 1 auto;
}
.main-nav a {
  padding: 7px 13px;
  border-radius: 8px;
  color: var(--muted);
  font-weight: 600;
  font-size: 13.5px;
  white-space: nowrap;
}
.main-nav a:hover { background: var(--panel-2); color: var(--text); text-decoration: none; }
.main-nav a.active { background: var(--accent-soft); color: var(--accent); }

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 8px 14px;
  border-radius: 8px;
  border: 1px solid var(--border-strong);
  background: var(--panel);
  color: var(--text);
  font: inherit;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background .12s ease, border-color .12s ease, box-shadow .12s ease, transform .06s ease;
}
.btn:hover { background: var(--panel-2); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--accent-ring); }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }

.btn .ico { width: 15px; height: 15px; display: block; }
.btn-lg { padding: 11px 20px; font-size: 14.5px; }

/* ---------- Windows-style dropdown ---------- */
.dropdown { position: relative; }
.dropdown-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
  font: inherit;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  min-width: 132px;
  justify-content: space-between;
}
.dropdown-toggle:hover { background: var(--panel-2); }
.dropdown-toggle:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--accent-ring); }
.dropdown-toggle .caret { transition: transform .15s ease; color: var(--muted); }
.dropdown.open .dropdown-toggle .caret { transform: rotate(180deg); }

.dropdown-menu {
  position: absolute;
  top: calc(100% + 5px);
  right: 0;
  min-width: 190px;
  background: var(--panel);
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 4px;
  margin: 0;
  list-style: none;
  display: none;
  z-index: 60;
  max-height: 340px;
  overflow: auto;
}
.dropdown.open .dropdown-menu { display: block; }

.dropdown-menu li {
  padding: 8px 10px;
  border-radius: 5px;
  cursor: pointer;
  font-size: 13.5px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  color: var(--text);
}
.dropdown-menu li:hover { background: var(--accent-soft); }
.dropdown-menu li[aria-selected="true"] { font-weight: 700; color: var(--accent); }
.dropdown-menu li .code { font-size: 11px; color: var(--muted); font-weight: 600; text-transform: uppercase; }

/* ---------- Layout ---------- */
.wrap {
  max-width: 1160px;
  margin: 0 auto;
  padding: 26px 18px 10px;
  width: 100%;
  flex: 1 0 auto;
}

.page-head { margin-bottom: 18px; }
.page-head h1 { margin: 0 0 6px; font-size: 23px; letter-spacing: -.2px; }
.page-head p { margin: 0; color: var(--muted); max-width: 760px; }

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}

.calc-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr);
  gap: 20px;
  align-items: start;
}

/* ---------- Form ---------- */
.fieldset { margin: 0 0 18px; padding: 0; border: 0; }
.fieldset:last-child { margin-bottom: 0; }

.legend {
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: .6px;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 9px;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(168px, 1fr));
  gap: 13px;
}

.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field > label { font-size: 12.5px; font-weight: 600; color: var(--muted); }

input[type="number"], input[type="text"], select {
  font: inherit;
  font-size: 14.5px;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 9px 11px;
  width: 100%;
  min-width: 0;
  transition: border-color .12s ease, box-shadow .12s ease, background .12s ease;
}
input[type="number"]:focus, input[type="text"]:focus, select:focus {
  outline: none;
  border-color: var(--accent);
  background: var(--panel);
  box-shadow: 0 0 0 3px var(--accent-ring);
}
select {
  appearance: none;
  background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%235b6b80' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 32px;
  cursor: pointer;
}

.input-group { display: flex; }
.input-group input { border-top-right-radius: 0; border-bottom-right-radius: 0; }
.input-group .suffix {
  display: inline-flex;
  align-items: center;
  padding: 0 11px;
  border: 1px solid var(--border-strong);
  border-left: 0;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  background: var(--panel);
  color: var(--muted);
  font-size: 12.5px;
  font-weight: 600;
  white-space: nowrap;
}

.hint { font-size: 12px; color: var(--muted); margin-top: 6px; }

/* Segmented control */
.seg {
  display: inline-flex;
  padding: 3px;
  gap: 3px;
  background: var(--panel-2);
  border: 1px solid var(--border-strong);
  border-radius: 9px;
  width: 100%;
}
.seg button {
  flex: 1 1 0;
  border: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  padding: 7px 8px;
  border-radius: 6px;
  cursor: pointer;
  white-space: nowrap;
  transition: background .12s ease, color .12s ease;
}
.seg button:hover { color: var(--text); }
.seg button.active {
  background: var(--panel);
  color: var(--accent);
  box-shadow: var(--shadow-sm);
}

.actions { display: flex; gap: 10px; margin-top: 4px; flex-wrap: wrap; }

/* ---------- Results ---------- */
.results {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  position: sticky;
  top: 84px;
}
.results h2 {
  margin: 0 0 12px;
  font-size: 13px;
  letter-spacing: .6px;
  text-transform: uppercase;
  color: var(--muted);
}
.res-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 9px 0;
  border-bottom: 1px dashed var(--border);
}
.res-row:last-child { border-bottom: 0; }
.res-label { font-size: 13px; color: var(--muted); }
.res-value { font-family: var(--mono); font-size: 15px; font-weight: 600; text-align: right; }
.res-value .u { color: var(--muted); font-weight: 500; font-size: 12.5px; margin-left: 3px; }

.res-highlight {
  margin-top: 12px;
  padding: 14px 15px;
  border-radius: var(--radius-sm);
  background: var(--accent-soft);
  border: 1px solid color-mix(in srgb, var(--accent) 28%, transparent);
}
.res-highlight .res-label { color: var(--accent); font-weight: 700; }
.res-highlight .res-value { font-size: 24px; color: var(--accent); }

/* ---------- Converter ---------- */
.conv-cats { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 18px; }
.conv-cats button {
  border: 1px solid var(--border-strong);
  background: var(--panel);
  color: var(--muted);
  font: inherit;
  font-size: 13.5px;
  font-weight: 600;
  padding: 8px 14px;
  border-radius: 999px;
  cursor: pointer;
}
.conv-cats button:hover { background: var(--panel-2); color: var(--text); }
.conv-cats button.active { background: var(--accent); border-color: var(--accent); color: #fff; }

.conv-panel { display: none; }
.conv-panel.active { display: block; }

.conv-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(120px, .7fr) auto minmax(0, 1fr) minmax(120px, .7fr);
  gap: 10px;
  align-items: end;
}
.conv-eq { padding-bottom: 11px; color: var(--muted); font-weight: 700; }

.conv-out {
  background: var(--accent-soft);
  border-color: color-mix(in srgb, var(--accent) 30%, transparent);
  font-family: var(--mono);
  font-weight: 700;
  color: var(--accent);
  cursor: default;
}
.conv-out:focus { box-shadow: none; border-color: color-mix(in srgb, var(--accent) 30%, transparent); background: var(--accent-soft); }

.conv-result {
  margin-top: 14px;
  padding: 14px 15px;
  border-radius: var(--radius-sm);
  background: var(--accent-soft);
  border: 1px solid color-mix(in srgb, var(--accent) 28%, transparent);
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.conv-result .val { font-family: var(--mono); font-size: 22px; font-weight: 700; color: var(--accent); }

/* ---------- Tool cards (home) ---------- */
.tools-block { margin-bottom: 22px; }
.tools-block > .legend { margin-bottom: 10px; }
.tool-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(215px, 1fr));
  gap: 14px;
}
.tool-card {
  display: flex;
  flex-direction: column;
  gap: 5px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 16px 15px;
  box-shadow: var(--shadow-sm);
  color: var(--text);
  transition: border-color .12s ease, box-shadow .12s ease, transform .06s ease;
}
.tool-card:hover {
  text-decoration: none;
  border-color: color-mix(in srgb, var(--accent) 45%, var(--border));
  box-shadow: var(--shadow);
  transform: translateY(-1px);
}
.tool-card .tc-icon {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  display: grid;
  place-items: center;
  background: var(--accent-soft);
  color: var(--accent);
  margin-bottom: 5px;
}
.tool-card .tc-icon svg { width: 18px; height: 18px; }
.tool-card .tc-title { font-weight: 700; font-size: 14.5px; }
.tool-card .tc-desc { font-size: 12.5px; color: var(--muted); line-height: 1.55; }
.tool-card.current {
  border-color: color-mix(in srgb, var(--accent) 42%, var(--border));
  background: color-mix(in srgb, var(--accent-soft) 55%, var(--panel));
}

/* ---------- Reverse & estimation ---------- */
.rev-section { margin-top: 24px; }
.rev-section > .legend { margin-bottom: 6px; }
.rev-section > .hint { margin: 0 0 14px; max-width: 820px; }

/* ---------- Common notes ---------- */
.common-notes {
  margin-top: 20px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: var(--shadow-sm);
}
.common-notes h3 {
  margin: 0 0 8px;
  font-size: 12.5px;
  letter-spacing: .5px;
  text-transform: uppercase;
  color: var(--muted);
}
.common-notes p { margin: 0 0 8px; font-size: 12.5px; color: var(--muted); line-height: 1.65; }
.common-notes ul { margin: 0; padding-left: 18px; }
.common-notes li { font-size: 12.5px; color: var(--muted); line-height: 1.65; margin-bottom: 4px; }
.common-notes li:last-child { margin-bottom: 0; }

/* ---------- Cladding averaging ---------- */
.avg-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(76px, 1fr)); gap: 8px; }
.avg-grid input { text-align: center; padding-left: 6px; padding-right: 6px; }

/* ---------- Footer / Disclaimer ---------- */
.app-footer {
  max-width: 1160px;
  margin: 8px auto 0;
  padding: 20px 18px 34px;
  width: 100%;
  flex: 0 0 auto;
}

.disclaimer {
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  background: var(--panel);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  box-shadow: var(--shadow-sm);
}
.disclaimer h3 {
  margin: 0 0 7px;
  font-size: 12.5px;
  letter-spacing: .5px;
  text-transform: uppercase;
  color: var(--muted);
}
.disclaimer p { margin: 0; font-size: 12.5px; color: var(--muted); line-height: 1.65; }

.footer-note {
  margin-top: 14px;
  font-size: 12px;
  color: var(--muted);
  text-align: center;
}

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  .calc-grid { grid-template-columns: 1fr; }
  .results { position: static; }
  .conv-row { grid-template-columns: 1fr 1fr; }
  .conv-eq { display: none; }
}
@media (max-width: 720px) {
  .header-inner { padding: 10px 14px; gap: 10px; }
  .main-nav { order: 3; width: 100%; margin-left: 0; }
  .header-actions { margin-left: auto; }
  .btn .btn-label { display: none; }
  .btn { padding: 9px 11px; }
  .wrap { padding: 18px 14px 8px; }
  .page-head h1 { font-size: 20px; }
  .card { padding: 16px; }
  .brand-title { font-size: 14px; }
}
@media (max-width: 460px) {
  .grid { grid-template-columns: 1fr; }
  .conv-row { grid-template-columns: 1fr; }
  .dropdown-toggle { min-width: 0; }
}