/* ── Modern Calculator Design System ── */
:root {
  --bg-deep: #070b16;
  --bg-card: #0f172a;
  --bg-surface: #1a2540;
  --bg-hover: #243352;
  --text-primary: #e2e8f0;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --accent: #38bdf8;
  --accent-glow: rgba(56, 189, 248, 0.12);
  --fn-blue: #0ea5e9;
  --fn-blue-hover: #38bdf8;
  --fn-bg: rgba(14, 165, 233, 0.1);
  --fn-bg-hover: rgba(14, 165, 233, 0.18);
  --op-purple: #a78bfa;
  --op-purple-hover: #c4b5fd;
  --op-bg: rgba(167, 139, 250, 0.12);
  --op-bg-hover: rgba(167, 139, 250, 0.2);
  --num-color: #e2e8f0;
  --num-bg: rgba(148, 163, 184, 0.06);
  --num-bg-hover: rgba(148, 163, 184, 0.12);
  --orange: #f59e0b;
  --orange-hover: #fbbf24;
  --orange-bg: rgba(245, 158, 11, 0.1);
  --orange-bg-hover: rgba(245, 158, 11, 0.18);
  --equals-bg: linear-gradient(135deg, #3b82f6, #6366f1);
  --equals-hover: linear-gradient(135deg, #60a5fa, #818cf8);
  --clear-bg: rgba(239, 68, 68, 0.1);
  --clear-hover: rgba(239, 68, 68, 0.25);
  --border: rgba(148, 163, 184, 0.08);
  --border-glow: rgba(56, 189, 248, 0.08);
  --radius: 10px;
  --radius-sm: 7px;
  --radius-xs: 5px;
  --transition: 0.15s ease;
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', monospace;
}

/* ── Reset ── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  background: var(--bg-deep);
  color: var(--text-primary);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button { font-family: inherit; cursor: pointer; border: none; }
input { font-family: inherit; }

/* ── Hide non-calculator elements (navbar, ads, intro, footer, etc.) ── */
.navbar, .calc5, .intro, .board, footer, .footer-above, .footer-below,
.container.board, .container.board.second, .carousel, .seealso,
#noscriptdialog, #symbolics, #matrixhelper, #inputhelpermenu,
#displaycontextmenu, #quicklinkframe {
  display: none !important;
}

/* ── Calculator Container ── */
#calccontainer {
  max-width: 720px;
  margin: 48px auto 48px;
  background: var(--bg-card);
  border-radius: 20px;
  padding: 28px 24px 32px;
  border: 1px solid var(--border);
  box-shadow:
    0 4px 40px rgba(0, 0, 0, 0.5),
    0 1px 2px rgba(56, 189, 248, 0.04),
    inset 0 1px 0 rgba(255, 255, 255, 0.02);
}

/* Title */
#calccontainer::before {
  content: 'Web3 Calculator';
  display: block;
  text-align: center;
  font-size: 1.6rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--text-primary);
  text-transform: uppercase;
  margin-bottom: 20px;
  opacity: 0.9;
}

/* ── Display ── */
#display {
  margin-bottom: 6px;
  min-height: 60px;
  position: relative;
  overflow: visible;
}

#display > div {
  position: absolute;
  bottom: 0;
  right: 0;
  text-align: right;
  padding: 8px 4px;
}

#display > div img {
  max-width: 100%;
  height: auto;
}

#result {
  display: none;
  cursor: pointer;
  font-family: var(--font-mono);
  font-size: 1.6rem;
  color: var(--accent);
}

#preview { display: none; }
#graph { display: none; }

#error {
  display: none;
  font-family: var(--font-mono);
  font-size: 1rem;
  color: #ef4444;
}

/* ── Input Field ── */
.center {
  margin: 0 auto;
  width: 100%;
  max-width: 100%;
  padding: 0;
  background: none;
  border: none;
  border-radius: 0;
  box-shadow: none;
  resize: none;
  overflow: visible;
  position: static;
}

.inputs {
  position: relative;
  height: 48px;
  margin-bottom: 12px;
}

.inputs input {
  box-sizing: border-box;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: var(--font-mono);
  font-size: 1.2rem;
  height: 48px;
  left: 0;
  margin: 0;
  padding: 0 14px;
  position: absolute;
  top: 0;
  width: 100%;
  color: var(--text-primary);
  transition: border-color var(--transition), box-shadow var(--transition);
  outline: none;
}

.inputs input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.inputs input#syntax {
  color: var(--text-muted);
  font-size: 0.95rem;
}

.inputs input#input {
  background: transparent;
}

#input.loading {
  background-image: url(../images/loading.gif);
  background-position: right 12px center;
  background-repeat: no-repeat;
}

#inputhelper {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  cursor: pointer;
  color: var(--text-muted);
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  gap: 6px;
}

#inputhelper:hover { color: var(--text-primary); }

/* Button group helpers */
.helper { display: none; }
.programmer { display: none; }
.dropdowns { display: none; }
.btnpop { display: none; }
.nonprogrammer hr.programmer { display: none; }

/* ── Keypad Grid ── */
.btns {
  max-width: 100%;
  width: 100%;
  margin: 0 auto;
  user-select: none;
  white-space: nowrap;
  font-size: 0;
}

.btns > div {
  text-align: center;
  white-space: nowrap;
  margin-bottom: 6px;
}

.btns .subcmd { margin-bottom: 4px; }

/* Base button */
.btns button {
  vertical-align: top;
  display: inline-block;
  width: 9.3%;
  margin: 0;
  padding: 0;
  height: 44px;
  margin-top: 2px;
  margin-bottom: 2px;
  margin-right: 0.25%;
  margin-left: 0.25%;
  line-height: 44px;
  text-align: center;
  position: relative;
  border-radius: var(--radius-xs);
  font-family: var(--font);
  font-size: 1.15rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
  color: var(--num-color);
  background: var(--num-bg);
  border: 1px solid transparent;
  white-space: nowrap;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}

.btns button:hover {
  background: var(--num-bg-hover);
  transform: translateY(-1px);
}

.btns button:active {
  transform: translateY(0);
}

/* Function buttons */
.btns .f {
  font-size: 0.85rem;
  color: var(--fn-blue);
  background: var(--fn-bg);
  width: 8.415%;
  font-weight: 500;
}

.btns .f:hover {
  color: var(--fn-blue-hover);
  background: var(--fn-bg-hover);
}

/* Orange/utility buttons */
.btns .o {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--orange);
  background: var(--orange-bg);
  width: 10.56%;
}

.btns .o:hover {
  color: var(--orange-hover);
  background: var(--orange-bg-hover);
}

/* Operator buttons */
.btns .op {
  font-weight: 700;
  font-size: 1.25rem;
  color: var(--op-purple);
  background: var(--op-bg);
  line-height: 44px;
}

.btns .op:hover {
  color: var(--op-purple-hover);
  background: var(--op-bg-hover);
}

/* Equals button */
.btns p {
  vertical-align: top;
  display: inline-block;
  width: 9.3%;
  height: 44px;
  margin: 2px 0.25%;
  position: relative;
  border-radius: var(--radius-xs);
  overflow: hidden;
}

.btns p button {
  width: 100% !important;
  height: 100% !important;
  margin: 0;
}

#BtnCalc {
  background: var(--equals-bg) !important;
  color: #fff !important;
  font-size: 1.4rem;
  font-weight: 700;
  border: none !important;
  height: 100% !important;
  line-height: 100% !important;
}

#BtnCalc:hover {
  background: var(--equals-hover) !important;
  box-shadow: 0 0 20px rgba(99, 102, 241, 0.3);
}

/* Equals sub-buttons (hex, bin, dec) */
#BtnCalcHex, #BtnCalcBin, #BtnCalcDec, #BtnCalcEqual,
#BtnCalcHex_1, #BtnCalcBin_1 {
  font-size: 0.8rem;
  line-height: 44px;
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  display: none;
  z-index: 1;
}

/* Clear button */
#BtnClear {
  color: #ef4444;
  background: var(--clear-bg);
  font-weight: 700;
}

#BtnClear:hover {
  background: var(--clear-hover);
}

/* Sub-command row */
.btns div.subcmd button {
  height: 34px;
  line-height: 32px;
  font-size: 0.8rem;
  font-weight: 500;
}

/* Spacing helpers */
.btns .br { margin-right: 0.75%; }
.btns .bl { margin-left: 0.75%; }

/* Shift/secondary labels */
.btns button sup {
  color: var(--text-muted);
  font-size: 0.55rem;
  line-height: 1;
  opacity: 0.6;
  position: absolute;
  right: 3px;
  top: 1px;
}

.btns button b { font-weight: 600; }
.btns button i { font-size: 0.65rem; font-style: normal; }

.btns span.sec { display: none; }

/* 2nd shift toggle */
#Btn2nd b { font-size: 0.75rem; }
#Btn2nd.shift {
  color: #7dd3fc;
  background: rgba(56, 189, 248, 0.2);
  border-color: rgba(56, 189, 248, 0.3);
}

/* Shift state */
.btns .shift span { display: none; }
.btns .shift span.sec { display: inline; }

/* Active/pressed state */
.btns button.active {
  border-color: var(--accent);
  background: var(--bg-hover);
  box-shadow: inset 0 1px 3px rgba(0,0,0,0.3);
}

/* Navigation buttons */
#BtnLeft { padding-top: 2px; }
#BtnLeft i.leftright { font-size: 0.8rem; }
#BtnLeft i.left, #BtnLeft i.right { display: none; }
#BtnLeft.left .left { display: inline; }
#BtnLeft.left .right, #BtnLeft.left .leftright { display: none; }
#BtnLeft.right .right { display: inline; }
#BtnLeft.right .left, #BtnLeft.right .leftright { display: none; }

#BtnBack { padding-top: 4px; }
#BtnBack i { transform: rotate(180deg); display: inline-block; font-size: 1rem; }

/* ── Options Bar (Deg/Rad, History) ── */
.options {
  width: 100%;
  max-width: 100%;
  margin: 10px auto 0;
  padding-top: 0;
  display: flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
  font-size: 0;
}

.options label.option {
  display: inline-flex;
  align-items: center;
  cursor: pointer;
  padding: 4px 10px;
  border-radius: var(--radius-xs);
  background: var(--num-bg);
  border: 1px solid transparent;
  transition: all var(--transition);
  gap: 6px;
  font-size: 0.8rem;
  white-space: nowrap;
}

.options label.option:hover {
  background: var(--num-bg-hover);
}

.options label.option input[type="radio"] {
  accent-color: var(--accent);
  margin: 0;
  cursor: pointer;
}

.options label.option .desc .label {
  color: var(--text-primary);
  font-size: 0.8rem;
  font-weight: 500;
}

.options label.option .desc .sym {
  color: var(--text-muted);
  font-size: 0.65rem;
  margin-left: 2px;
}

.options .history {
  display: inline-flex;
  align-items: center;
  margin-left: auto;
  background: var(--num-bg);
  border: 1px solid transparent;
  border-radius: var(--radius-xs);
  cursor: pointer;
  font-size: 0.8rem;
  padding: 4px 8px;
  color: var(--text-secondary);
  transition: all var(--transition);
}

.options .history:hover { background: var(--num-bg-hover); }
.options .history button {
  background: none;
  border: none;
  color: inherit;
  font-size: 0.8rem;
  padding: 2px 6px;
  cursor: pointer;
}

.options .history .btn.dropdown-toggle {
  border-left: 1px solid var(--border);
  padding: 2px 8px;
}

.options button.no, .options a.btn.no {
  background: var(--num-bg);
  border: 1px solid transparent;
  border-radius: var(--radius-xs);
  padding: 4px 10px;
  color: var(--text-secondary);
  font-size: 0.85rem;
  cursor: pointer;
  transition: all var(--transition);
  display: inline-flex;
  align-items: center;
}

.options button.no:hover, .options a.btn.no:hover {
  background: var(--num-bg-hover);
  color: var(--text-primary);
}

/* ── History Panel ── */
#histframe {
  position: relative;
  padding: 0;
  margin-top: 8px;
  padding: 8px 12px;
  min-width: 100%;
  background: var(--bg-surface) !important;
  border: 1px solid var(--border);
  border-radius: var(--radius) !important;
  z-index: 5;
  display: none;
  max-height: 200px;
  overflow-y: auto;
}

#histframe.open { display: block; }
#histframe button.close {
  float: right;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1rem;
  cursor: pointer;
}
#histframe #clearhistory { font-size: 0.75rem; color: var(--text-muted); }
#histframe ul { list-style: none; padding: 0; margin: 4px 0; }
#histframe ul li { padding: 2px 0; }
#histframe ul li p {
  width: 49%;
  float: left;
  color: var(--accent);
  cursor: pointer;
  font-size: 0.85rem;
  overflow: hidden;
}
#histframe ul li p.r { float: right; text-align: right; }
#histframe ul li p:hover { text-decoration: underline; }

#quicklink { display: none; }
.clipboard { display: none; }

/* ── Keyboard toggle button ── */
#keyboardbtn {
  display: none;
  float: right;
  padding: 4px;
  background: var(--num-bg);
  border-radius: var(--radius-xs);
  cursor: pointer;
}

/* ── Soft keyboard mode ── */
html.softkeyboard .inputs { width: calc(100% - 56px); }
html.softkeyboard #keyboardbtn { display: inline-flex; align-items: center; justify-content: center; }
html.softkeyboard #keyboardbtn img { height: 24px; }
html.softkeyboard #keyboardbtn > input { margin: 0; }

/* ── Mobile class adjustments ── */
html.mobile #calccontainer {
  margin: 12px 6px 24px;
  padding: 16px 10px 20px;
  border-radius: 14px;
}

html.mobile .inputs input {
  font-size: 16px; /* Prevents iOS zoom on focus */
}

html.mobile .btns button {
  -webkit-tap-highlight-color: rgba(56, 189, 248, 0.2);
}

/* Disable 1D (single-line input mode) */
input.disable1d {
  ime-mode: disabled;
}

/* ── Modal (cookie consent, etc.) ── */
.modal {
  position: fixed;
  top: 0; right: 0; bottom: 0; left: 0;
  z-index: 1050;
  display: none;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
}

.modal.fade.in, .modal.in { display: flex; align-items: center; justify-content: center; }
.modal-dialog {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  max-width: 500px;
  width: 90%;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}
.modal-content { background: none; border: none; }
.modal-header { margin-bottom: 12px; }
.modal-title { font-size: 1.1rem; font-weight: 600; }
.modal-body { margin-bottom: 16px; color: var(--text-secondary); font-size: 0.9rem; }
.modal-footer { display: flex; gap: 8px; justify-content: flex-end; }

.btn {
  display: inline-flex;
  align-items: center;
  padding: 8px 16px;
  border-radius: var(--radius-xs);
  font-size: 0.9rem;
  font-weight: 500;
  background: var(--num-bg);
  color: var(--text-primary);
  border: 1px solid var(--border);
  cursor: pointer;
  transition: all var(--transition);
}

.btn-primary {
  background: var(--equals-bg);
  color: #fff;
  border: none;
}

.btn-primary:hover { background: var(--equals-hover); }
.btn:hover { background: var(--num-bg-hover); }

/* ── Loading spinner ── */
#input.cmdloading {
  background-image: url(../images/loading.gif);
  background-position: right 12px center;
  background-repeat: no-repeat;
}

/* ── Responsive ── */
@media (max-width: 768px) {
  #calccontainer {
    margin: 16px 8px 24px;
    padding: 16px 10px 20px;
    border-radius: 16px;
  }

  #calccontainer::before { font-size: 1.3rem; }

  .btns button {
    height: 38px;
    line-height: 38px;
    font-size: 1rem;
  }

  .btns .f { font-size: 0.7rem; }
  .btns .o { font-size: 0.75rem; }
  .btns .op { font-size: 1.1rem; line-height: 38px; }
  .btns div.subcmd button { height: 30px; line-height: 28px; font-size: 0.7rem; }
  .btns p { height: 38px; }
  .btns p button { line-height: 38px !important; }

  .inputs { height: 42px; margin-bottom: 10px; }
  .inputs input { height: 42px; font-size: 1.05rem; }
  #display { min-height: 56px; }
  #result { font-size: 1.3rem; }
}

@media (max-width: 480px) {
  #calccontainer { margin: 8px 4px 16px; padding: 12px 6px 16px; border-radius: 12px; }
  #calccontainer::before { font-size: 1.1rem; margin-bottom: 12px; }

  .btns button {
    height: 36px;
    line-height: 36px;
    font-size: 0.9rem;
    margin-right: 0.15%;
    margin-left: 0.15%;
    margin-top: 1px;
    margin-bottom: 1px;
  }
  .btns .f { font-size: 0.65rem; width: 8.2%; }
  .btns .o { font-size: 0.7rem; width: 10.3%; }
  .btns .op { font-size: 1rem; line-height: 36px; }
  .btns div.subcmd button { height: 28px; line-height: 26px; font-size: 0.65rem; }
  .btns p { height: 36px; }
  .btns .br { margin-right: 0.5%; }
  .btns .bl { margin-left: 0.5%; }

  .options label.option { font-size: 0.7rem; padding: 3px 6px; }
  .options .history { font-size: 0.7rem; padding: 3px 5px; }
}

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ── Focus visible ── */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ── Old Bootstrap utility classes kept for JS compatibility ── */
.pull-right { float: right !important; }
.pull-left { float: left !important; }
.text-center { text-align: center; }
.clearfix::after { content: ""; display: table; clear: both; }
.hidden { display: none !important; }
.caret { display: inline-block; width: 0; height: 0; border: 4px solid transparent; border-top-color: currentColor; margin-left: 4px; }
