:root {
  --ink: #17201c;
  --muted: #63706b;
  --line: #ccd6d1;
  --paper: #f6f7f4;
  --panel: #ffffff;
  --panel-2: #eef5f0;
  --teal: #0c6b5d;
  --teal-2: #e1f1ed;
  --red: #b33a31;
  --amber: #946200;
  --blue: #315f8f;
  --shadow: 0 18px 45px rgba(18, 32, 28, 0.12);
  font-family: "Aptos", "Yu Gothic", "Hiragino Kaku Gothic ProN", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(135deg, rgba(12, 107, 93, 0.12), transparent 34%),
    linear-gradient(315deg, rgba(49, 95, 143, 0.1), transparent 32%),
    var(--paper);
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(250px, 320px) 1fr;
  min-height: 100vh;
}

.side-panel {
  display: flex;
  flex-direction: column;
  gap: 18px;
  min-height: 100vh;
  padding: 22px;
  border-right: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.72);
  backdrop-filter: blur(16px);
}

.brand-block {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.brand-block strong {
  font-size: 22px;
  letter-spacing: 0;
}

.brand-block span,
.workbench-header p,
.result-head small,
.history-panel small {
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0;
}

.search-box {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
}

.search-box input,
.search-box select,
.field input,
.field select {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px 12px;
  color: var(--ink);
  background: var(--panel);
  outline: none;
}

.search-box input:focus,
.search-box select:focus,
.field input:focus,
.field select:focus {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(12, 107, 93, 0.14);
}

.side-controls {
  display: grid;
  gap: 10px;
}

.preset-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.mini-button {
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 7px 8px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.74);
  font-size: 12px;
}

.mini-button:hover,
.history-title button:hover {
  border-color: var(--teal);
  color: var(--teal);
  background: var(--teal-2);
}

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

.calculator-list {
  display: grid;
  gap: 8px;
  overflow: auto;
}

.calc-tab {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 4px;
  width: 100%;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 11px 12px;
  color: var(--ink);
  text-align: left;
  background: transparent;
}

.calc-tab span:first-child,
.calc-tab small {
  min-width: 0;
}

.calc-tab small {
  color: var(--muted);
  grid-column: 1;
}

.favorite-mark {
  grid-column: 2;
  grid-row: 1 / span 2;
  align-self: center;
  border-radius: 999px;
  padding: 4px;
  color: var(--amber);
  font-size: 18px;
  line-height: 1;
}

.calc-tab:hover,
.calc-tab.is-active {
  border-color: var(--teal);
  background: var(--teal-2);
}

.history-panel {
  margin-top: auto;
  border-top: 1px solid var(--line);
  padding-top: 16px;
}

.history-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin: 0 0 10px;
}

.history-panel h2 {
  margin: 0 0 10px;
  font-size: 14px;
}

.history-title h2 {
  margin: 0;
}

.history-title button {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 5px 8px;
  color: var(--muted);
  background: transparent;
  font-size: 12px;
}

.history-panel p {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.history-panel ol {
  display: grid;
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.history-panel li {
  color: var(--muted);
  font-size: 13px;
}

.history-panel button {
  display: grid;
  gap: 2px;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px;
  text-align: left;
  background: rgba(255, 255, 255, 0.62);
}

.history-panel strong {
  color: var(--ink);
  font-size: 13px;
  font-weight: 700;
}

.workbench {
  display: flex;
  flex-direction: column;
  gap: 22px;
  padding: 28px;
}

.workbench-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.icon-button {
  display: inline-grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--amber);
  background: rgba(255, 255, 255, 0.72);
  font-size: 22px;
  line-height: 1;
}

.icon-button:hover {
  border-color: var(--amber);
  background: #fff6df;
}

.workbench-header h1 {
  margin: 0;
  font-size: clamp(28px, 4vw, 44px);
  line-height: 1.04;
  letter-spacing: 0;
}

.workbench-header p {
  margin: 0 0 4px;
  font-size: 13px;
}

.scope-badge {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 12px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.72);
  white-space: nowrap;
}

.workspace-grid {
  display: grid;
  grid-template-columns: minmax(320px, 0.95fr) minmax(320px, 1.05fr);
  gap: 20px;
  align-items: start;
}

.tool-panel,
.result-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.88);
  box-shadow: var(--shadow);
}

.tool-panel {
  padding: 18px;
}

.result-panel {
  min-height: 320px;
  padding: 22px;
}

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

.field {
  display: grid;
  gap: 7px;
  min-width: 0;
}

.field > span:first-child,
.switch-field > span:last-child {
  color: var(--muted);
  font-size: 13px;
}

.input-with-unit {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
}

.input-with-unit input {
  border: 0;
  box-shadow: none;
  background: transparent;
}

.input-with-unit em {
  padding-right: 12px;
  color: var(--muted);
  font-size: 13px;
  font-style: normal;
  white-space: nowrap;
}

.switch-field {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px 12px;
  background: var(--panel);
}

.switch-field input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.switch-ui {
  position: relative;
  width: 40px;
  height: 22px;
  border-radius: 999px;
  background: #d5ddd8;
  flex: 0 0 auto;
}

.switch-ui::after {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
  content: "";
  transition: transform 0.16s ease;
}

.switch-field input:checked + .switch-ui {
  background: var(--teal);
}

.switch-field input:checked + .switch-ui::after {
  transform: translateX(18px);
}

.form-actions,
.result-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 18px;
}

.button {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 9px 14px;
  color: var(--ink);
  background: var(--panel);
}

.button.primary {
  border-color: var(--teal);
  color: #fff;
  background: var(--teal);
}

.button.ghost {
  color: var(--muted);
  background: transparent;
}

.result-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--line);
}

.result-head strong {
  display: block;
  margin-top: 4px;
  font-size: clamp(38px, 7vw, 68px);
  line-height: 0.95;
  letter-spacing: 0;
}

.result-head strong span {
  margin-left: 8px;
  color: var(--muted);
  font-size: 18px;
}

.result-head mark {
  border-radius: 999px;
  padding: 8px 12px;
  color: var(--teal);
  background: var(--teal-2);
  font-weight: 700;
  white-space: nowrap;
}

.result-rows {
  display: grid;
  gap: 0;
  margin: 18px 0 0;
}

.result-rows div {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(120px, auto);
  gap: 16px;
  padding: 11px 0;
  border-bottom: 1px solid #e7ece8;
}

.result-rows dt {
  color: var(--muted);
}

.result-rows dd {
  margin: 0;
  font-weight: 700;
  text-align: right;
}

.warnings {
  display: grid;
  gap: 8px;
  margin-top: 18px;
}

.warnings p {
  margin: 0;
  border-left: 3px solid var(--amber);
  padding: 7px 10px;
  color: #4f3c13;
  background: #fff6df;
  font-size: 13px;
}

.source-links {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 18px;
}

.source-links a {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 9px;
  color: var(--blue);
  font-size: 12px;
  text-decoration: none;
  background: #f7fbff;
}

.empty-state {
  display: grid;
  place-content: center;
  min-height: 270px;
  color: var(--muted);
  text-align: center;
}

.empty-state strong {
  color: var(--ink);
}

.empty-state.error {
  color: var(--red);
}

.learning-panel {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--panel);
  overflow-wrap: anywhere;
}

.learning-panel summary {
  padding: 16px 20px;
  color: var(--blue);
  cursor: pointer;
  font-weight: 700;
}

.learning-panel summary span {
  margin-left: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 400;
}

.learning-panel summary:focus-visible,
.learning-panel a:focus-visible {
  outline: 3px solid var(--blue);
  outline-offset: 3px;
}

.learning-body {
  padding: 0 20px 20px;
  line-height: 1.75;
}

.learning-sections {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px 24px;
}

.learning-panel h2 {
  margin: 18px 0 8px;
  font-size: 16px;
}

.learning-panel p { margin: 8px 0; }
.learning-context, .learning-sources small { color: var(--muted); font-size: 13px; }
.learning-sources { padding-left: 22px; }
.learning-sources li { margin-bottom: 12px; }
.learning-sources small { display: block; }
.learning-sources a { color: var(--blue); text-underline-offset: 3px; }
.learning-formula { padding: 12px; border-radius: 8px; background: #f0f5fb; }

.learning-panel .learning-review-note {
  margin: 0;
  padding: 12px 20px;
  border-bottom: 1px solid var(--line);
  border-radius: 16px 16px 0 0;
  background: #fff9ed;
  font-size: 13px;
  line-height: 1.7;
}

.app-footer {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 10px 16px;
  color: var(--muted);
  font-size: 13px;
}

.app-footer span:last-child {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.app-footer a {
  color: var(--blue);
  text-decoration: none;
}

.app-footer a:hover {
  text-decoration: underline;
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .side-panel {
    min-height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .calculator-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

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

  .learning-sections {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 620px) {
  .side-panel,
  .workbench {
    padding: 16px;
  }

  .workbench-header,
  .result-head {
    align-items: flex-start;
    flex-direction: column;
  }

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

  .scope-badge {
    white-space: normal;
  }

  .field-grid,
  .calculator-list {
    grid-template-columns: 1fr;
  }

  .result-rows div {
    grid-template-columns: 1fr;
    gap: 4px;
  }

  .result-rows dd {
    text-align: left;
  }
}

@media print {
  .side-panel,
  .form-actions,
  .result-actions,
  .app-footer,
  .icon-button {
    display: none;
  }

  .app-shell,
  .workspace-grid {
    display: block;
  }

  .tool-panel,
  .result-panel {
    box-shadow: none;
  }
}
