:root {
  color-scheme: light;
  --ink: #142033;
  --muted: #5c6678;
  --line: #d8dee8;
  --panel: #ffffff;
  --surface: #f4f6f9;
  --accent: #cc1f2f;
  --accent-dark: #9d1321;
  --ok: #137a4a;
  --warn: #a15f00;
  --shadow: 0 18px 50px rgba(20, 32, 51, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family: "Segoe UI", Arial, sans-serif;
  background:
    linear-gradient(90deg, rgba(204, 31, 47, 0.08), transparent 34%),
    var(--surface);
}

button,
input,
textarea {
  font: inherit;
}

.shell {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0;
}

.workspace {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.titlebar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 24px 26px 20px;
  border-bottom: 1px solid var(--line);
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent);
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0;
}

h1 {
  margin: 0;
  font-size: clamp(26px, 4vw, 38px);
  line-height: 1.08;
  letter-spacing: 0;
}

.unit-toggle,
.segmented {
  display: inline-flex;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #eef2f7;
}

.unit-toggle label,
.segmented label {
  min-width: 82px;
  padding: 10px 14px;
  border-radius: 6px;
  color: var(--muted);
  text-align: center;
  cursor: pointer;
}

.unit-toggle input,
.segmented input {
  position: absolute;
  opacity: 0;
}

.unit-toggle label:has(input:checked),
.segmented label:has(input:checked) {
  color: var(--ink);
  background: #fff;
  box-shadow: 0 1px 5px rgba(20, 32, 51, 0.12);
}

.calculator {
  padding: 24px 26px 18px;
}

.input-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(120px, 1fr));
  gap: 14px;
}

label span {
  display: block;
  margin-bottom: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

input[type="number"] {
  width: 100%;
  min-height: 46px;
  padding: 9px 11px;
  border: 1px solid #bfc8d6;
  border-radius: 6px;
  color: var(--ink);
  background: #fff;
}

input[type="number"]:focus {
  outline: 3px solid rgba(204, 31, 47, 0.18);
  border-color: var(--accent);
}

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

.control-groups {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

fieldset {
  margin: 0;
}

.segmented legend {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

.actions {
  display: flex;
  gap: 10px;
}

button {
  min-height: 44px;
  padding: 10px 16px;
  border: 1px solid transparent;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 700;
}

.file-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 10px 16px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--ink);
  background: #fff;
  cursor: pointer;
  font-weight: 700;
}

.file-button input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.primary {
  color: #fff;
  background: var(--accent);
}

.primary:hover {
  background: var(--accent-dark);
}

.secondary {
  color: var(--ink);
  border-color: var(--line);
  background: #fff;
}

.extractor,
.pieces {
  padding: 18px 26px;
  border-top: 1px solid var(--line);
}

.extractor-head,
.pieces-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 12px;
}

h2 {
  margin: 0;
  font-size: 16px;
  line-height: 1.2;
  letter-spacing: 0;
}

.extractor-actions {
  display: flex;
  gap: 10px;
}

.paste-box {
  display: grid;
  gap: 12px;
}

textarea {
  width: 100%;
  min-height: 112px;
  padding: 11px;
  border: 1px solid #bfc8d6;
  border-radius: 6px;
  resize: vertical;
  color: var(--ink);
}

textarea:focus,
.paste-box:focus-within {
  outline: 3px solid rgba(204, 31, 47, 0.12);
}

.image-preview {
  min-height: 96px;
  border: 1px dashed #bfc8d6;
  border-radius: 6px;
  background: #f9fafc;
  overflow: hidden;
}

.image-preview img {
  display: block;
  max-width: 100%;
  max-height: 260px;
}

.pieces-list {
  display: grid;
  gap: 8px;
}

.piece-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f9fafc;
  color: var(--muted);
  font-size: 13px;
}

.piece-item strong {
  color: var(--ink);
}

.summary {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 18px 26px;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  background: #f9fafc;
}

.summary span {
  color: var(--muted);
  font-weight: 700;
}

.summary strong {
  min-width: 72px;
  font-size: 30px;
  line-height: 1;
}

.results {
  overflow-x: auto;
}

table {
  width: 100%;
  min-width: 840px;
  border-collapse: collapse;
}

th,
td {
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  white-space: nowrap;
}

th {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0;
  background: #f4f6f9;
}

td {
  font-size: 15px;
}

.status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
}

.status::before {
  content: "";
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--warn);
}

.status.loadable::before {
  background: var(--ok);
}

.message {
  min-height: 24px;
  margin: 14px 0 0;
  padding: 0;
  color: var(--accent-dark);
  font-weight: 700;
}

.notes {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin-top: 18px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.notes p {
  margin: 0;
  padding: 0 2px;
}

@media (max-width: 820px) {
  .titlebar,
  .controls {
    align-items: stretch;
    flex-direction: column;
  }

  .control-groups {
    flex-direction: column;
  }

  .input-grid,
  .notes {
    grid-template-columns: 1fr;
  }

  .actions {
    flex-direction: column-reverse;
  }

  .extractor-head,
  .pieces-head,
  .piece-item {
    align-items: stretch;
    flex-direction: column;
  }

  .extractor-actions {
    flex-direction: column;
  }

  button,
  .file-button {
    width: 100%;
  }
}
