:root {
  color-scheme: light;
  font-family: Inter, system-ui, sans-serif;
  --ink: #142923;
  --muted: #4e645b;
  --line: #ccd9d0;
  --paper: #fbfcf8;
  --mono: "IBM Plex Mono", "Cascadia Mono", Consolas, monospace;
}

*, *::before, *::after { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background-color: #edf1e9;
  background-image: radial-gradient(#c5d2c5 0.8px, transparent 0.8px);
  background-size: 18px 18px;
}

.calculator {
  width: min(100% - 2.5rem, 44rem);
  margin-inline: auto;
  padding-block: clamp(3rem, 12vh, 7.5rem) 3rem;
}

.intro { margin-bottom: 1.85rem; }

h1 {
  width: fit-content;
  margin: 0 0 0.65rem;
  padding-bottom: 0.5rem;
  border-bottom: 3px solid #218862;
  font-size: clamp(2.3rem, 7.6vw, 4rem);
  font-weight: 800;
  line-height: 1.06;
  letter-spacing: -0.065em;
}

.intro p {
  margin: 0;
  color: var(--muted);
  font-size: 1rem;
  line-height: 1.55;
}

.expression-card {
  padding: clamp(1rem, 3.5vw, 1.55rem);
  border: 1px solid var(--line);
  border-radius: 1.25rem;
  background: var(--paper);
  box-shadow: 0 12px 26px #283e2910;
}

.expression {
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

legend {
  display: block;
  margin-bottom: 0.45rem;
  padding: 0;
  font-size: 0.84rem;
  font-weight: 700;
}

.entry {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: start;
  gap: 0.45rem;
}

.operands {
  display: flex;
  gap: 0.35rem;
  min-width: 0;
  padding: 0.2rem 0.22rem 0.4rem;
  overflow-x: auto;
  scrollbar-width: thin;
}

input, select, button { font: inherit; }

input, select {
  border: 1px solid #becdc2;
  border-radius: 0.7rem;
  color: var(--ink);
  background: #f1f5ef;
  font-family: var(--mono);
  font-size: 1.02rem;
}

input {
  flex: 1 0 7.2rem;
  min-width: 0;
  width: 0;
  padding: 0.77rem 0.75rem;
}

select {
  flex: 0 0 3.25rem;
  width: 3.25rem;
  padding-inline: 0.46rem 0.18rem;
  color: #124d39;
  background: #e8f0e6;
  font-weight: 700;
  cursor: pointer;
}

.operand-actions { display: flex; gap: 0.28rem; padding-top: 0.2rem; }

.operand-button {
  width: 2.45rem;
  height: 2.88rem;
  padding: 0;
  border: 1px solid #becdc2;
  border-radius: 0.7rem;
  color: #154b38;
  background: #e8f0e6;
  font: 700 1.35rem/1 var(--mono);
}

.add-number { border-color: #154b38; color: #fff; background: #154b38; }
.add-number:hover { background: #206447; }
.remove-number:hover { background: #dcebe0; }

input::placeholder { color: #61736a; }
input[aria-invalid="true"] { border-color: #a64f38; }

button { cursor: pointer; }

:where(button, input, select):focus-visible {
  outline: 2px solid #087c58;
  outline-offset: 3px;
}

.calculate {
  margin-top: 0.8rem;
  padding: 0.65rem 1.05rem;
  border: 1px solid #123f30;
  border-radius: 0.7rem;
  color: #fff;
  background: #154b38;
  font-size: 0.88rem;
  font-weight: 700;
}

.calculate:hover { background: #206447; }

.hint, .error {
  margin: 0.75rem 0 0;
  color: var(--muted);
  font-size: 0.79rem;
  line-height: 1.5;
}

.hint code { font-family: var(--mono); color: var(--ink); }

.hint-divider {
  display: inline-block;
  width: 1px;
  height: 0.65rem;
  margin-inline: 0.55rem;
  background: var(--line);
}

.error { color: #943822; }

.results {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.75rem;
  margin-top: 0.85rem;
}

.result-card {
  min-width: 0;
  min-height: 8.7rem;
  padding: clamp(1rem, 3.5vw, 1.55rem);
  border: 1px solid var(--line);
  border-radius: 1.1rem;
}

.hex-card {
  border-color: #1e4738;
  color: #effff5;
  background: #173c31;
}

.dec-card { background: #e0eadf; }

.result-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.base {
  font-family: var(--mono);
  font-size: 0.83rem;
  font-weight: 700;
  letter-spacing: 0.1em;
}

.hex-card .base { color: #a9ddbd; }

.copy {
  padding: 0.32rem 0.58rem;
  border: 1px solid #a6b9ac;
  border-radius: 0.45rem;
  color: inherit;
  background: transparent;
  font-size: 0.73rem;
  white-space: nowrap;
}

.hex-card .copy { border-color: #6d9080; }
.hex-card .copy:focus-visible { outline-color: #b0ebc7; }
.copy:disabled { opacity: 0.54; cursor: default; }
.copy:enabled:hover { background: #43795b24; }
.hex-card .copy:enabled:hover { background: #ffffff1a; }

output {
  display: block;
  margin-top: 0.85rem;
  font: 650 clamp(1.9rem, 6vw, 2.85rem)/1.15 var(--mono);
  letter-spacing: -0.06em;
  overflow-wrap: anywhere;
}

output[data-long] { font-size: 1.05rem; letter-spacing: 0; line-height: 1.45; }

.examples {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.45rem;
  margin-top: 1.15rem;
  color: var(--muted);
  font-size: 0.78rem;
}

.examples > span { margin-right: 0.2rem; }

.examples button {
  padding: 0.38rem 0.64rem;
  border: 1px solid var(--line);
  border-radius: 2rem;
  color: var(--ink);
  background: var(--paper);
  font-family: var(--mono);
}

.examples button:hover { border-color: #57947b; background: #e1eee3; }

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

@media (max-width: 35rem) {
  .calculator {
    width: min(100% - 1.5rem, 44rem);
    padding-top: clamp(2.5rem, 8vh, 4rem);
  }
  .entry { gap: 0.28rem; }
  input { flex-basis: 3.65rem; padding-inline: 0.48rem; }
  select { flex-basis: 2.85rem; width: 2.85rem; padding-inline-start: 0.28rem; }
  .operand-button { width: 2.06rem; }
  .calculate { width: 100%; padding-block: 0.7rem; }
  .results { grid-template-columns: minmax(0, 1fr); }
  .result-card { min-height: 7rem; }
}
