/* ── Reset ── */
* { box-sizing: border-box; }

/* ── Base Typography & Body ── */
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  line-height: 1.6;
  margin: 0;
  padding: 20px;
  background-color: #ffffff;
  color: #000000;
  transition: background-color 0.3s, color 0.3s;
  font-size: 18px;
}

/* ── Dark Mode ── */
body.dark {
  background-color: #1a1a1a;
  color: #e0e0e0;
}

body.dark a { color: #87ceeb; }
body.dark a:visited { color: #dda0dd; }

/* ── Links ── */
a { color: #0066cc; }
a:visited { color: #551a8b; }
a:hover { text-decoration: underline; }

/* ── Layout ── */
.container {
  max-width: 800px;
  margin: 0 auto;
}

/* ── Nav Row (tool pages) ── */
.nav-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 20px;
  padding-bottom: 15px;
  border-bottom: 2px solid #cccccc;
}
body.dark .nav-row { border-bottom-color: #444444; }

.nav-links {
  display: flex;
  align-items: center;
  gap: 4px 10px;
  font-size: 14px;
  flex-wrap: wrap;
  min-width: 0;
}
.nav-links a { text-decoration: none; }
.nav-links a:hover { text-decoration: underline; }

.back-link {
  font-size: 14px;
  text-decoration: none;
}

/* ── Theme Toggle ── */
.theme-toggle {
  flex-shrink: 0;
  background-color: #f5f5f5;
  border: 1px solid #cccccc;
  padding: 8px 16px;
  border-radius: 20px;
  cursor: pointer;
  font-size: 0.95em;
  font-family: inherit;
}
.theme-toggle:hover { background-color: #e0e0e0; }
body.dark .theme-toggle {
  background-color: #333333;
  color: #e0e0e0;
  border-color: #555555;
}
body.dark .theme-toggle:hover { background-color: #404040; }

/* ── Headings ── */
h1 {
  font-size: 1.8em;
  margin: 0 0 5px 0;
  font-weight: 600;
}

.subtitle {
  font-size: 0.9em;
  color: #595959;
  margin: 0 0 20px 0;
}
body.dark .subtitle { color: #9a9a9a; }

/* ── Sections / Cards ── */
.section {
  border: 1px solid #cccccc;
  padding: 20px;
  margin: 20px 0;
  border-radius: 8px;
}
body.dark .section { border-color: #444444; }

/* ── Labels ── */
.lbl {
  font-size: 12px;
  font-weight: 600;
  color: #555555;
  margin-bottom: 6px;
  display: block;
}
body.dark .lbl { color: #aaaaaa; }
.lbl-hint {
  font-weight: 400;
  color: #595959;
  font-size: 11px;
}

/* ── Inputs ── */
.inp {
  width: 100%;
  background: #f9f9f9;
  border: 1px solid #cccccc;
  border-radius: 6px;
  color: #000000;
  font-family: monospace;
  font-size: 14px;
  padding: 10px 12px;
  outline: none;
  transition: border-color 0.2s;
}
.inp:focus { border-color: #0066cc; }
.inp::placeholder { color: #595959; }
body.dark .inp {
  background: #2a2a2a;
  border-color: #444444;
  color: #e0e0e0;
}
body.dark .inp:focus { border-color: #87ceeb; }
body.dark .inp::placeholder { color: #9a9a9a; }

.input-row {
  display: grid;
  grid-template-columns: 1fr 2fr;
  gap: 15px;
  margin-bottom: 15px;
}

/* ── Buttons ── */
.btn-go {
  background: #0066cc;
  color: white;
  border: none;
  border-radius: 6px;
  padding: 10px 24px;
  font-family: inherit;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  transition: background 0.2s;
}
.btn-go:hover { background: #0052a3; }
body.dark .btn-go { background: #87ceeb; color: #1a1a1a; }
body.dark .btn-go:hover { background: #6bb8d9; }

.btn-t {
  background: transparent;
  border: 1px solid #cccccc;
  color: #595959;
  border-radius: 5px;
  padding: 6px 12px;
  font-family: inherit;
  font-size: 12px;
  cursor: pointer;
  transition: all 0.15s;
}
.btn-t:hover { border-color: #999999; color: #333333; }
.btn-t.on { border-color: #0066cc; color: #0066cc; background: rgba(0, 102, 204, 0.05); }
body.dark .btn-t { border-color: #444444; color: #9a9a9a; }
body.dark .btn-t:hover { border-color: #666666; color: #cccccc; }
body.dark .btn-t.on { border-color: #87ceeb; color: #87ceeb; background: rgba(135, 206, 235, 0.1); }

.btn-copy {
  background: transparent;
  border: 1px solid #cccccc;
  color: #595959;
  border-radius: 4px;
  padding: 4px 10px;
  font-family: inherit;
  font-size: 11px;
  cursor: pointer;
  transition: all 0.15s;
}
.btn-copy:hover { border-color: #999999; color: #333333; }
body.dark .btn-copy { border-color: #444444; color: #9a9a9a; }
body.dark .btn-copy:hover { border-color: #666666; color: #cccccc; }

.btn-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 15px;
  flex-wrap: wrap;
}
.toggle-btns { margin-left: auto; display: flex; gap: 6px; flex-wrap: wrap; }

/* ── Mode Selector ── */
.mode-selector {
  display: inline-flex;
  border: 1px solid #cccccc;
  border-radius: 5px;
  overflow: hidden;
  margin-bottom: 10px;
}
body.dark .mode-selector { border-color: #444444; }

.mode-btn {
  background: transparent;
  border: none;
  color: #595959;
  padding: 6px 14px;
  font-family: inherit;
  font-size: 12px;
  cursor: pointer;
  transition: all 0.15s;
  border-right: 1px solid #cccccc;
}
.mode-btn:last-child { border-right: none; }
.mode-btn:hover { background: rgba(0, 102, 204, 0.05); color: #333333; }
.mode-btn.on { background: #0066cc; color: white; }
body.dark .mode-btn { color: #9a9a9a; border-right-color: #444444; }
body.dark .mode-btn:hover { background: rgba(135, 206, 235, 0.1); color: #cccccc; }
body.dark .mode-btn.on { background: #87ceeb; color: #1a1a1a; }

/* ── Error Box ── */
.err {
  background: rgba(220, 53, 69, 0.1);
  border: 1px solid rgba(220, 53, 69, 0.3);
  border-radius: 6px;
  padding: 10px 14px;
  color: #dc3545;
  font-size: 13px;
  margin-top: 10px;
}
body.dark .err { background: rgba(220, 53, 69, 0.15); }

/* ── Toast ── */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: #333333;
  color: white;
  padding: 10px 18px;
  border-radius: 6px;
  font-size: 13px;
  z-index: 999;
  animation: toastIn 0.2s ease;
}
@keyframes toastIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ── Reference Section ── */
.ref-section {
  font-size: 13px;
  color: #595959;
  margin-top: 15px;
  padding-top: 15px;
  border-top: 1px solid #e0e0e0;
}
body.dark .ref-section { color: #9a9a9a; border-top-color: #444444; }
.ref-section strong { color: #333333; }
body.dark .ref-section strong { color: #cccccc; }

.result-label {
  font-size: 12px;
  font-weight: 600;
  color: #555555;
  margin: 15px 0 6px 0;
}
body.dark .result-label { color: #aaaaaa; }

/* ── Expression Box ── */
.expr-box {
  background: #f9f9f9;
  border: 1px solid #cccccc;
  border-radius: 6px;
  padding: 12px 16px;
  font-size: 14px;
  font-family: monospace;
  word-break: break-all;
  line-height: 1.6;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
body.dark .expr-box { background: #2a2a2a; border-color: #444444; }
.expr-box .expr-text { flex: 1; }

/* ── How-To Accordion ── */
.how-to {
  border: 1px solid #e0e0e0;
  border-radius: 8px;
  margin-bottom: 20px;
  font-size: 14px;
}
body.dark .how-to { border-color: #444444; }
.how-to summary {
  cursor: pointer;
  padding: 10px 14px;
  font-weight: 600;
  font-size: 14px;
  color: #555555;
  user-select: none;
  list-style: none;
}
.how-to summary::-webkit-details-marker { display: none; }
.how-to summary::before { content: "\25B6\00a0"; font-size: 10px; }
.how-to[open] summary::before { content: "\25BC\00a0"; }
body.dark .how-to summary { color: #aaaaaa; }
.how-to-body {
  padding: 0 14px 12px;
  line-height: 1.7;
  color: #444444;
}
body.dark .how-to-body { color: #bbbbbb; }
.how-to-body code {
  background: rgba(0,0,0,0.05);
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 13px;
}
body.dark .how-to-body code { background: rgba(255,255,255,0.08); }
.how-to-body ul { margin: 6px 0; padding-left: 20px; }
.how-to-body li { margin-bottom: 4px; }

/* ── Footer ── */
.footer {
  text-align: center;
  padding: 30px 0 10px;
  font-size: 12px;
  color: #595959;
}
body.dark .footer { color: #9a9a9a; }

/* ── Responsive ── */
@media (max-width: 600px) {
  body {
    padding: 15px;
    font-size: 16px;
  }
  h1 { font-size: 1.5em; }
  .section { padding: 15px; }
  .nav-links > span { display: none; }
  .nav-links { gap: 6px 10px; }
  .input-row { grid-template-columns: 1fr; }
  .toggle-btns { margin-left: 0; margin-top: 10px; width: 100%; justify-content: flex-start; }
  .mode-selector { width: 100%; display: flex; }
  .mode-btn { flex: 1; text-align: center; }
}
