/* GHS Hydrostatics Web - global stylesheet */

:root {
  --navy: #0b2e4f;
  --navy-2: #123c63;
  --navy-solid: #0b2e4f;
  --blue: #2f7fd0;
  --blue-light: #e8f1fb;
  --accent: #1f9d8a;
  --bg: #f4f7fb;
  --card: #ffffff;
  --text: #1c2b3a;
  --muted: #5c6b7a;
  --border: #dbe4ee;
  --danger: #c0392b;
  --ok: #1e8e5a;
  --warn: #b9770e;
  --input-bg: #ffffff;
  --row-alt: #f7fafd;
  --row-active: #e8f2ff;
  --chart-bg: #ffffff;
  --result-border: #d3e5f7;
  --btn-danger-border: #e6c4bf;
  --alert-warn-bg: #fdf6e3;
  --alert-warn-border: #ecd9a0;
  --alert-info-border: #cfe3f7;
  --alert-err-bg: #fdf0ee;
  --alert-err-border: #ecc4bd;
  --formula-bg: #f7fafd;
  --radius: 10px;
  --shadow: 0 2px 10px rgba(11, 46, 79, 0.08);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", "Noto Sans CJK SC", "Noto Sans KR", "Noto Sans JP", "PingFang SC", "Microsoft YaHei", "Malgun Gothic", "Hiragino Sans", sans-serif;
  --mono: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
}

[data-theme="dark"] {
  --navy: #a8c8e8;
  --navy-2: #7fb0e0;
  --navy-solid: #24405e;
  --blue: #4aa8ff;
  --blue-light: #1e2f42;
  --accent: #2bbfa8;
  --bg: #0f1720;
  --card: #1a2430;
  --text: #dbe6f0;
  --muted: #8fa3b8;
  --border: #2c3b4d;
  --danger: #e07a6a;
  --ok: #3fbf7a;
  --warn: #e0a63d;
  --input-bg: #141d28;
  --row-alt: #1a2430;
  --row-active: #22354d;
  --chart-bg: #141d28;
  --result-border: #2c3b4d;
  --btn-danger-border: #6b3a33;
  --alert-warn-bg: #2b2413;
  --alert-warn-border: #6b5a2a;
  --alert-info-border: #24405e;
  --alert-err-bg: #2b1815;
  --alert-err-border: #6b3a33;
  --formula-bg: #141d28;
  --shadow: 0 2px 10px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }

/* ---------- Accessibility ---------- */
.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  z-index: 1000;
  background: var(--navy-solid);
  color: #fff;
  padding: 10px 16px;
  border-radius: 0 0 8px 0;
  font-weight: 600;
  font-size: 14px;
}
.skip-link:focus {
  left: 0;
  color: #fff;
  text-decoration: none;
}
:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: 2px;
}
main:focus, .container:focus { outline: none; }

html, body {
  margin: 0;
  padding: 0;
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
  line-height: 1.55;
  font-size: 15px;
}

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

/* ---------- Top bar ---------- */
.topbar {
  background: #071f36;
  color: #cfe0f0;
  font-size: 13px;
}
.topbar-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 6px 18px;
  display: flex;
  gap: 18px;
  align-items: center;
}
.toplink {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: #cfe0f0;
  text-decoration: none;
  padding: 2px 4px;
  border-radius: 5px;
}
.toplink:hover { color: #fff; background: rgba(255,255,255,0.08); text-decoration: none; }

/* ---------- Navbar ---------- */
.navbar {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow);
  position: sticky;
  top: 0;
  z-index: 100;
}
.navbar-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 10px 18px;
  display: flex;
  align-items: center;
  gap: 18px;
  flex-wrap: wrap;
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--navy);
}
.brand:hover { text-decoration: none; }
.brand-icon { flex: 0 0 auto; }
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-name { font-size: 18px; font-weight: 800; letter-spacing: 0.2px; }
.brand-tag { font-size: 11px; color: var(--muted); font-weight: 500; }

.mainnav {
  display: flex;
  gap: 2px;
  flex-wrap: wrap;
  margin-left: auto;
}
.mainnav a {
  color: var(--text);
  padding: 7px 12px;
  border-radius: 7px;
  font-weight: 500;
  font-size: 14px;
  text-decoration: none;
}
.mainnav a:hover { background: var(--blue-light); color: var(--blue); }
.mainnav a.active { background: var(--navy-solid); color: #fff; }

.langwrap {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: 6px;
}
.lang-label { font-size: 13px; color: var(--muted); }
.auto-calc-label { margin-left: 8px; }
.auto-calc-toggle {
  width: 36px; height: 20px; appearance: none; -webkit-appearance: none;
  background: var(--border); border-radius: 10px; cursor: pointer;
  position: relative; transition: background .15s; flex-shrink: 0;
  margin-left: 6px; vertical-align: middle;
}
.auto-calc-toggle::before {
  content: ''; position: absolute; left: 2px; top: 2px;
  width: 16px; height: 16px; border-radius: 50%;
  background: #fff; transition: left .15s;
  box-shadow: 0 1px 3px rgba(0,0,0,.2);
}
.auto-calc-toggle:checked { background: var(--accent); }
.auto-calc-toggle:checked::before { left: 18px; }
.auto-calc-toggle:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }
.lang-select {
  font-family: var(--font);
  font-size: 13px;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--input-bg);
  color: var(--text);
  cursor: pointer;
  max-width: 150px;
}
.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--input-bg);
  color: var(--text);
  cursor: pointer;
  flex: 0 0 auto;
}
.theme-toggle:hover { background: var(--blue-light); color: var(--blue); }
.theme-toggle svg { display: block; }
.theme-toggle .ico-sun { display: none; }
[data-theme="dark"] .theme-toggle .ico-sun { display: block; }
[data-theme="dark"] .theme-toggle .ico-moon { display: none; }

/* ---------- Hamburger menu toggle ---------- */
.nav-toggle {
  display: none;
  flex-direction: column;
  gap: 4px;
  width: 30px;
  height: 30px;
  padding: 6px 4px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--input-bg);
  cursor: pointer;
  margin-left: auto;
  flex: 0 0 auto;
}
.nav-toggle span {
  display: block;
  height: 2px;
  background: var(--text);
  border-radius: 1px;
  transition: transform .15s, opacity .15s;
}
@media (max-width: 860px) {
  .nav-toggle { display: flex; }
  .mainnav {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 0 0 var(--radius) var(--radius);
    padding: 8px 4px;
    flex-direction: column;
    z-index: 99;
    box-shadow: var(--shadow);
  }
  .mainnav.open { display: flex; }
  .mainnav a { padding: 10px 14px; font-size: 14px; }
  .navbar-inner { position: relative; flex-wrap: wrap; }
  .langwrap { margin-left: 0; width: 100%; justify-content: flex-start; }
  .lang-select { max-width: 120px; }
  .brand-tag { display: none; }
}

/* ---------- Layout ---------- */
.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 26px 18px 60px;
}
.page-head { margin-bottom: 22px; }
.page-title { font-size: 26px; font-weight: 800; color: var(--navy); margin: 0 0 6px; }
.page-sub { color: var(--muted); margin: 0; max-width: 820px; }

.grid { display: grid; gap: 18px; }
.grid > * { min-width: 0; }
.grid-2 { grid-template-columns: 1fr 1fr; }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 960px) {
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 640px) {
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}
.card h2 {
  margin: 0 0 14px;
  font-size: 17px;
  font-weight: 700;
  color: var(--navy);
  display: flex;
  align-items: center;
  gap: 8px;
}
.card h2 .ico { color: var(--blue); }
.card h3 { margin: 16px 0 8px; font-size: 14px; font-weight: 700; color: var(--navy-2); }

/* ---------- Forms ---------- */
label.field {
  display: block;
  margin-bottom: 12px;
  font-size: 13px;
  color: var(--muted);
  font-weight: 600;
}
label.field input[type="text"],
label.field input[type="number"],
label.field select,
label.field textarea {
  display: block;
  width: 100%;
  margin-top: 4px;
  padding: 8px 10px;
  font-family: var(--mono);
  font-size: 13px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--input-bg);
  color: var(--text);
}
label.field select { font-family: var(--font); }
label.field textarea { resize: vertical; min-height: 90px; line-height: 1.4; }
label.field input:focus, label.field select:focus, label.field textarea:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(47,127,208,0.15);
}
label.field input.input-invalid,
label.field select.input-invalid,
label.field textarea.input-invalid {
  border-color: var(--danger);
  box-shadow: 0 0 0 3px rgba(192,57,43,0.15);
}
.form-row { display: flex; gap: 14px; flex-wrap: wrap; }
.form-row > * { flex: 1 1 150px; }
.field.chk { display: flex; align-items: center; gap: 0.3rem; white-space: nowrap; }
.field.chk input[type="checkbox"] { width: auto; margin: 0; }
.field.chk-sm { flex: 0 0 auto; display: flex; align-items: center; gap: 0.3rem; white-space: nowrap; padding-top: 18px; }
.field.chk-sm input[type="checkbox"] { width: auto; margin: 0; }
.field.grow { flex: 3 1 220px; }
.field.grow select { width: 100%; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 9px 16px;
  font-family: var(--font);
  font-size: 14px;
  font-weight: 600;
  border-radius: 8px;
  border: 1px solid transparent;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s, transform 0.05s;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--blue); color: #fff; }
.btn-primary:hover { background: #2569b3; text-decoration: none; }
.btn-secondary { background: var(--input-bg); color: var(--navy); border-color: var(--border); }
.btn-secondary:hover { background: var(--blue-light); }
.btn-accent { background: var(--accent); color: #fff; }
.btn-accent:hover { background: #17806f; }
.btn-danger { background: var(--input-bg); color: var(--danger); border-color: var(--btn-danger-border); }
.btn-danger:hover { background: var(--alert-err-bg); }
.btn-sm { padding: 5px 10px; font-size: 12.5px; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 4px; }

/* ---------- Results ---------- */
.result-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 12px;
  margin-top: 6px;
}
.result-item {
  background: var(--blue-light);
  border: 1px solid var(--result-border);
  border-radius: 9px;
  padding: 10px 13px;
}
.result-item .label { font-size: 12px; color: var(--muted); font-weight: 600; }
.result-item .value { font-size: 17px; font-weight: 700; color: var(--navy); font-family: var(--mono); margin-top: 2px; }
.result-item .unit { font-size: 11px; color: var(--muted); font-weight: 500; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; margin-top: 8px; }
table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  font-family: var(--mono);
}
table.data th, table.data td {
  border: 1px solid var(--border);
  padding: 6px 9px;
  text-align: right;
  white-space: nowrap;
}
table.data th {
  background: var(--navy-solid);
  color: #fff;
  font-weight: 600;
  font-family: var(--font);
  text-align: center;
}
table.data tr:nth-child(even) td { background: var(--row-alt); }
table.data td:first-child { text-align: left; }
table.data .pass { color: var(--ok); font-weight: 700; }
table.data .fail { color: var(--danger); font-weight: 700; }
table.data tr.active-row td { background: var(--row-active); font-weight: 600; }

/* ---------- Charts ---------- */
.chart-box {
  position: relative;
  width: 100%;
  margin-top: 8px;
}
.chart-box canvas {
  width: 100%;
  height: auto;
  display: block;
  background: var(--chart-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
}
#view3dCanvas {
  height: 380px;
  width: 100%;
  cursor: grab;
}
.chart-legend { display: flex; gap: 16px; flex-wrap: wrap; margin-top: 8px; font-size: 12.5px; color: var(--muted); }
.chart-legend .sw { display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }
.chart-export-btn:hover { opacity: 1 !important; background: var(--navy) !important; color: #fff !important; }

/* ---------- Damage compartment legend ---------- */
.legend-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-top: 8px; font-size: 12.5px; }
.legend-swatch { display: inline-block; width: 14px; height: 14px; border-radius: 3px; border: 1px solid rgba(0,0,0,0.15); }

/* ---------- Alerts ---------- */
.alert {
  padding: 11px 14px;
  border-radius: 8px;
  font-size: 13.5px;
  margin-top: 12px;
  border: 1px solid transparent;
}
.alert-warn { background: var(--alert-warn-bg); border-color: var(--alert-warn-border); color: var(--warn); }
.alert-info { background: var(--blue-light); border-color: var(--alert-info-border); color: var(--navy-2); }
.alert-err { background: var(--alert-err-bg); border-color: var(--alert-err-border); color: var(--danger); }

/* ---------- Hero (home) ---------- */
.hero {
  background: linear-gradient(135deg, #0b2e4f 0%, #123c63 55%, #1b4f80 100%);
  color: #fff;
  border-radius: 14px;
  padding: 44px 40px;
  margin-bottom: 26px;
  position: relative;
  overflow: hidden;
}
.hero::after {
  content: "";
  position: absolute;
  right: -60px;
  top: -60px;
  width: 320px;
  height: 320px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255,255,255,0.10), rgba(255,255,255,0));
}
.hero .badge {
  display: inline-block;
  background: rgba(255,255,255,0.14);
  border: 1px solid rgba(255,255,255,0.25);
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 12.5px;
  font-weight: 600;
  letter-spacing: 0.4px;
  margin-bottom: 14px;
}
.hero h1 { font-size: 30px; font-weight: 800; margin: 0 0 10px; line-height: 1.25; }
.hero p { font-size: 15px; max-width: 720px; color: #d7e5f3; margin: 0 0 22px; }
.hero .btn { background: #fff; color: var(--navy); }
.hero .btn:hover { background: var(--blue-light); }

/* ---------- Feature cards ---------- */
.feature {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  background: var(--card);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.feature .f-ico {
  width: 42px;
  height: 42px;
  border-radius: 10px;
  background: var(--blue-light);
  color: var(--blue);
  display: flex;
  align-items: center;
  justify-content: center;
}
.feature h3 { margin: 4px 0 0; font-size: 16px; font-weight: 700; color: var(--navy); }
.feature p { margin: 0; font-size: 13.5px; color: var(--muted); flex: 1; }
.feature a { font-size: 13px; font-weight: 600; }

/* ---------- Steps ---------- */
.steps { display: grid; gap: 14px; }
.step {
  display: flex;
  gap: 14px;
  align-items: flex-start;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: var(--shadow);
}
.step .num {
  flex: 0 0 auto;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--navy-solid);
  color: #fff;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
}
.step h4 { margin: 0 0 4px; font-size: 15px; color: var(--navy); }
.step p { margin: 0; font-size: 13.5px; color: var(--muted); }

/* ---------- Theory page ---------- */
.formula {
  background: var(--formula-bg);
  border: 1px solid var(--border);
  border-left: 4px solid var(--blue);
  border-radius: 8px;
  padding: 14px 18px;
  margin: 10px 0;
  font-family: var(--mono);
  font-size: 14px;
  overflow-x: auto;
  color: var(--navy-2);
}
.formula .fnum { float: right; color: var(--muted); font-size: 12px; }
.frac { display: inline-block; vertical-align: middle; text-align: center; margin: 0 2px; }
.frac .num { display: block; border-bottom: 1px solid currentColor; padding: 0 5px; }
.frac .den { display: block; padding: 0 5px; }
.eq { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.eq .lhs { font-weight: 700; color: var(--navy); min-width: 90px; }
.eq .rhs { font-family: var(--mono); }
sub, sup { font-size: 0.72em; }
.sym-table td:first-child { font-family: var(--mono); font-weight: 600; color: var(--navy); }

/* ---------- About ---------- */
.contact-list { list-style: none; padding: 0; margin: 0; }
.contact-list li { padding: 8px 0; border-bottom: 1px solid var(--border); font-size: 14px; }
.contact-list li:last-child { border-bottom: none; }

/* ---------- Footer ---------- */
.site-footer {
  background: #071f36;
  color: #a9bfd4;
  margin-top: 20px;
}
.footer-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 26px 18px 30px;
  font-size: 13px;
}
.footer-brand { color: #fff; font-weight: 700; font-size: 15px; margin-bottom: 6px; }
.footer-note { margin: 4px 0 10px; max-width: 720px; }
.footer-links { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 8px; }
.footer-links a { color: #7fb4e8; }
.footer-rights { margin: 0; color: #6f87a0; font-size: 12px; }

/* ---------- Misc ---------- */
.mono { font-family: var(--mono); }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.mt { margin-top: 14px; }
.mb { margin-bottom: 14px; }
.center { text-align: center; }
.hidden { display: none !important; }
.section-divider { border: none; border-top: 1px solid var(--border); margin: 22px 0; }

/* ---------- Theory docs (tutorial / glossary / FAQ) ---------- */
.tutorial-steps { margin: 10px 0 4px; padding-left: 20px; }
.tutorial-steps li { margin-bottom: 10px; line-height: 1.6; }
.tutorial-steps strong { color: var(--navy); }

.glossary { margin: 10px 0 4px; }
.glossary dt {
  font-weight: 700;
  color: var(--navy);
  margin-top: 10px;
  font-size: 14px;
}
.glossary dt:first-of-type { margin-top: 0; }
.glossary dd { margin: 2px 0 0; color: var(--muted); font-size: 14px; line-height: 1.6; }

.faq-item {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--card);
  margin-top: 10px;
  overflow: hidden;
}
.faq-item summary {
  cursor: pointer;
  padding: 11px 14px;
  font-weight: 600;
  font-size: 14px;
  color: var(--navy);
  list-style: none;
  position: relative;
  padding-right: 34px;
}
.faq-item summary::-webkit-details-marker { display: none; }
.faq-item summary::after {
  content: '+';
  position: absolute;
  right: 14px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 16px;
  color: var(--muted);
  transition: transform .15s;
}
.faq-item[open] summary::after { transform: translateY(-50%) rotate(45deg); }
.faq-item[open] summary { border-bottom: 1px solid var(--border); }
.faq-item p { margin: 0; padding: 11px 14px; font-size: 14px; color: var(--muted); line-height: 1.6; }

/* ---------- RTL layout support ---------- */
[dir="rtl"] body { text-align: right; }
[dir="rtl"] .navbar-inner { flex-direction: row-reverse; }
[dir="rtl"] .mainnav { margin-left: 0; margin-right: auto; }
[dir="rtl"] .langwrap { margin-left: 0; margin-right: 6px; }
[dir="rtl"] .brand { flex-direction: row-reverse; }
[dir="rtl"] .form-row { flex-direction: row-reverse; }
[dir="rtl"] .btn-row { flex-direction: row-reverse; }
[dir="rtl"] .eq { flex-direction: row-reverse; }
[dir="rtl"] .result-item { text-align: right; }
[dir="rtl"] .result-item .value { text-align: left; }
[dir="rtl"] .chart-export-btn { right: auto; left: 6px; }
[dir="rtl"] .tutorial-steps { padding-left: 0; padding-right: 20px; }
[dir="rtl"] .faq-item summary { padding-right: 14px; padding-left: 34px; }
[dir="rtl"] .faq-item summary::after { right: auto; left: 14px; }
[dir="rtl"] .topbar-inner { flex-direction: row-reverse; }

/* ---------- Web Worker table loading indicator ---------- */
.table-busy {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px 0;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}
.spinner {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
