:root {
  color-scheme: light;
  --ink: #151a17;
  --muted: #68716b;
  --paper: #f6f6f4;
  --card: #fff;
  --line: rgba(21, 26, 23, 0.16);
  --soft: #eeeeeb;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--paper);
}

* {
  box-sizing: border-box;
}

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
}

button,
input,
textarea,
select {
  font: inherit;
}

.tool-header,
.tool-page {
  width: min(860px, calc(100% - 40px));
  margin-inline: auto;
}

.tool-header {
  min-height: 72px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  border-bottom: 1px solid var(--line);
}

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  color: var(--ink);
  font-size: 0.92rem;
  font-weight: 700;
  text-decoration: none;
}

.back-link span {
  transition: transform 160ms ease;
}

.back-link:hover span {
  transform: translateX(-3px);
}

.collection-name {
  color: var(--muted);
  font-size: 0.86rem;
}

.tool-page {
  padding: 72px 0 100px;
}

.tool-intro {
  margin-bottom: 38px;
}

.tool-type {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 14px;
  font-size: clamp(2.3rem, 7vw, 4rem);
  line-height: 1;
  letter-spacing: -0.05em;
}

.tool-intro > p:last-child {
  max-width: 560px;
  margin-bottom: 0;
  color: var(--muted);
  line-height: 1.6;
}

.tool-panel {
  padding: clamp(24px, 5vw, 44px);
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--card);
}

h2 {
  margin-bottom: 26px;
  font-size: 1.1rem;
  letter-spacing: -0.02em;
}

.panel-description {
  max-width: 580px;
  margin: -14px 0 28px;
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.5;
}

label {
  display: block;
  margin-bottom: 9px;
  font-size: 0.88rem;
  font-weight: 700;
}

input,
textarea {
  width: 100%;
  border: 1px solid #c9ccc9;
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  outline: none;
  transition: border-color 150ms, box-shadow 150ms;
}

input:focus,
textarea:focus,
select:focus {
  border-color: var(--ink);
  box-shadow: 0 0 0 3px rgba(21, 26, 23, 0.1);
}

input[type="number"] {
  appearance: textfield;
  -moz-appearance: textfield;
}

input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button {
  margin: 0;
  -webkit-appearance: none;
}

.input-with-unit {
  position: relative;
}

.input-with-unit input {
  padding: 14px 58px 14px 14px;
  font-size: 1.1rem;
}

.input-with-unit > span {
  position: absolute;
  top: 50%;
  right: 16px;
  color: var(--muted);
  transform: translateY(-50%);
}

.field-message {
  min-height: 21px;
  margin: 7px 0 0;
  color: #9b3228;
  font-size: 0.84rem;
}

.quantity-fields {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

textarea {
  min-height: 180px;
  padding: 14px;
  resize: vertical;
  line-height: 1.55;
}

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

.result-controls {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 20px;
  margin-top: 14px;
}

.result-controls .actions {
  margin-top: 0;
}

.sort-control {
  flex: 0 1 220px;
}

.sort-control label {
  margin-bottom: 6px;
}

select {
  width: 100%;
  padding: 10px 36px 10px 12px;
  border: 1px solid #c9ccc9;
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
}

button {
  padding: 11px 16px;
  border: 1px solid var(--ink);
  border-radius: 8px;
  background: var(--ink);
  color: #fff;
  font-weight: 750;
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

button:hover {
  background: #303632;
}

button.secondary {
  border-color: var(--line);
  background: var(--soft);
  color: var(--ink);
}

button.secondary:hover {
  background: #e3e3df;
}

.results {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-top: 28px;
  padding-top: 28px;
  border-top: 1px solid var(--line);
}

.result {
  padding: 20px;
  border-radius: 8px;
  background: var(--soft);
}

.result > span {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 0.82rem;
}

.result strong {
  font-size: clamp(1.7rem, 5vw, 2.4rem);
  letter-spacing: -0.04em;
}

.result small {
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 500;
}

.status {
  min-height: 24px;
  margin: 26px 0 12px;
  color: var(--muted);
}

.letter-results {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(94px, 1fr));
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.letter-results li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 11px 12px;
  border-radius: 8px;
  background: var(--soft);
}

.letter {
  font-size: 1.1rem;
  font-weight: 800;
  text-transform: uppercase;
}

.count {
  min-width: 28px;
  padding: 3px 7px;
  border-radius: 999px;
  background: var(--ink);
  color: white;
  text-align: center;
  font-size: 0.82rem;
  font-weight: 700;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 600px) {
  .tool-header,
  .tool-page {
    width: min(100% - 28px, 860px);
  }

  .collection-name {
    display: none;
  }

  .tool-page {
    padding: 52px 0 72px;
  }

  .tool-panel {
    padding: 22px;
  }

  .results {
    grid-template-columns: 1fr;
  }

  .quantity-fields {
    grid-template-columns: 1fr;
  }

  .actions {
    align-items: stretch;
    flex-direction: column;
  }

  .result-controls {
    align-items: stretch;
    flex-direction: column;
  }

  .sort-control {
    flex-basis: auto;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
  }
}
