:root {
  color-scheme: light;
  --ink: #201f1b;
  --muted: #676157;
  --paper: #fbfaf4;
  --panel: #ffffff;
  --line: #d7d0c4;
  --field: #fffdfa;
  --soft: #f3eee6;
  --soft-hover: #e8dfd1;
  --top-control: rgba(255, 255, 255, 0.82);
  --accent: #b23a2f;
  --accent-strong: #84281f;
  --shadow: 0 18px 45px rgba(31, 30, 27, 0.12);
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --ink: #f2eee6;
  --muted: #b7ada0;
  --paper: #161513;
  --panel: #211f1c;
  --line: #4d453d;
  --field: #181716;
  --soft: #302b26;
  --soft-hover: #3b342e;
  --top-control: rgba(33, 31, 28, 0.9);
  --accent: #d15a4e;
  --accent-strong: #f07a6d;
  --shadow: 0 18px 45px rgba(0, 0, 0, 0.35);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(135deg, rgba(178, 58, 47, 0.10), transparent 34%),
    linear-gradient(225deg, rgba(40, 94, 131, 0.12), transparent 38%),
    var(--paper);
  color: var(--ink);
  font-family: Avenir Next, Avenir, "Segoe UI", sans-serif;
  line-height: 1.45;
  position: relative;
}

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

header {
  display: block;
  padding: 8px 0 16px;
  position: relative;
}

.logo {
  width: min(600px, 100%);
  height: auto;
  margin-left: 10px;
  image-rendering: auto;
}

.theme-toggle {
  position: absolute;
  top: 8px;
  right: 0;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--top-control);
  color: var(--accent-strong);
  font-size: 0.83rem;
  font-weight: 650;
  box-shadow: 0 8px 20px rgba(31, 30, 27, 0.08);
  cursor: pointer;
}

.theme-toggle:hover {
  background: var(--panel);
}

.panel {
  box-sizing: border-box;
  padding: 3rem;
  background: color-mix(in srgb, var(--panel) 88%, transparent);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.panel h2 {
  margin: 0 0 2rem;
  font-size: 1.75rem;
}

.accent {
  color: var(--accent-strong);
}

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 1.5rem;
  margin-bottom: 1.5rem;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  min-width: 140px;
}

.field label {
  display: block;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
  text-transform: uppercase;
}

.info {
  cursor: help;
  opacity: 0.7;
}

select,
textarea {
  background: var(--field);
  border: 1px solid var(--line);
  color: var(--ink);
  border-radius: 6px;
  padding: 0.5rem 0.6rem;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 0.95rem;
}

select {
  cursor: pointer;
}

.calculator-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(260px, 0.85fr);
  gap: 1.5rem;
  align-items: stretch;
  margin-bottom: 2rem;
}

.input-block {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.input-block label,
.output-block label {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
  text-transform: uppercase;
}

.output-block {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

textarea,
.result-block {
  min-height: 320px;
}

textarea {
  resize: vertical;
  line-height: 1.6;
}

.input-block textarea {
  height: 100%;
}

.result-block {
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--field);
  padding: 1rem;
}

#result {
  color: var(--accent-strong);
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 1.35rem;
  margin: 0;
  overflow-wrap: anywhere;
}

.menu-button {
  position: fixed;
  top: 18px;
  left: 18px;
  z-index: 20;
  width: 42px;
  height: 42px;
  display: inline-grid;
  place-items: center;
  gap: 4px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--top-control);
  box-shadow: 0 8px 20px rgba(31, 30, 27, 0.08);
}

.menu-button span {
  width: 18px;
  height: 2px;
  border-radius: 999px;
  background: var(--accent-strong);
}

.menu-panel {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 30;
  width: min(300px, calc(100vw - 58px));
  padding: 20px;
  border-right: 1px solid var(--line);
  background: var(--panel);
  box-shadow: var(--shadow);
  transform: translateX(-105%);
  transition: transform 180ms ease;
}

.menu-panel[data-open="true"] {
  transform: translateX(0);
}

.menu-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 18px;
}

.menu-title {
  font-weight: 800;
  color: var(--ink);
}

.menu-close {
  width: 34px;
  height: 34px;
  padding: 0;
  border: 1px solid var(--line);
  background: var(--soft);
  color: var(--accent-strong);
  font-size: 1.15rem;
  line-height: 1;
}

.menu-links {
  display: grid;
  gap: 8px;
}

.menu-links a {
  display: block;
  padding: 10px 12px;
  border-radius: 6px;
  color: var(--ink);
  font-weight: 700;
  text-decoration: none;
}

.menu-links a:hover,
.menu-links a[aria-current="page"] {
  background: var(--soft);
  color: var(--accent-strong);
  text-decoration: none;
}

.menu-overlay {
  position: fixed;
  inset: 0;
  z-index: 25;
  background: rgba(0, 0, 0, 0.26);
}

@media (max-width: 900px) {
  .calculator-grid {
    grid-template-columns: 1fr;
  }

  .result-block {
    min-height: 120px;
  }
}

@media (max-width: 860px) {
  header {
    display: flex;
    flex-direction: column;
    align-items: stretch;
  }

  .theme-toggle {
    position: static;
    align-self: flex-end;
    margin: 0 0 12px;
  }

  .logo {
    margin-left: 0;
  }
}
