:root {
  --bg: #f5f7f8;
  --panel: #ffffff;
  --panel-strong: #eef3f2;
  --text: #1f282b;
  --muted: #647174;
  --line: #cbd6d8;
  --primary: #176b5f;
  --primary-dark: #105348;
  --accent: #b46a22;
  --danger: #b3261e;
  --shadow: 0 10px 28px rgba(31, 40, 43, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", "Yu Gothic UI", "Meiryo", sans-serif;
  line-height: 1.6;
}

html,
body {
  width: 100%;
  overflow-x: hidden;
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  max-width: 1440px;
  margin: 0 auto;
  padding: 16px;
}

.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 16px 20px;
  border: 1px solid var(--line);
  background: var(--panel);
  box-shadow: var(--shadow);
}

.title-block {
  display: grid;
  gap: 4px;
}

.app-header h1 {
  margin: 0;
  font-size: clamp(1.25rem, 2vw, 1.8rem);
  line-height: 1.25;
}

.app-header p,
.brand-links {
  margin: 0;
  color: var(--muted);
}

.brand-links {
  display: flex;
  align-items: center;
  justify-content: end;
  gap: 14px;
  flex-wrap: wrap;
}

.brand-logo-link img,
.site-links img {
  display: block;
  width: min(220px, 36vw);
  height: auto;
  max-height: 48px;
  object-fit: contain;
}

.profile-link,
.site-links a {
  color: var(--primary-dark);
  font-weight: 700;
  text-decoration: none;
}

.profile-link:hover,
.site-links a:hover {
  text-decoration: underline;
}

.mode-tabs {
  display: flex;
  align-items: stretch;
  margin-top: 14px;
  border: 1px solid var(--line);
  background: var(--panel);
  overflow-x: auto;
}

.mode-tab {
  display: grid;
  place-items: center;
  min-width: 180px;
  padding: 12px 20px;
  border: 0;
  border-right: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  font-weight: 700;
  text-align: center;
  text-decoration: none;
}

.mode-tab:last-child {
  border-right: 0;
}

.mode-tab.is-active {
  background: var(--primary);
  color: #ffffff;
}

main {
  display: grid;
  gap: 14px;
  margin-top: 14px;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(320px, 0.9fr) minmax(520px, 1.8fr);
  gap: 14px;
  align-items: stretch;
}

.workspace > *,
.bars-grid > *,
.details-grid > * {
  min-width: 0;
}

.input-panel,
.results-panel,
.bar-card,
.version-panel,
details,
.notice-box {
  border: 1px solid var(--line);
  background: var(--panel);
  box-shadow: var(--shadow);
}

.input-panel,
.results-panel,
.version-panel {
  padding: 18px;
}

h2 {
  margin: 0 0 12px;
  font-size: 1.12rem;
  line-height: 1.35;
}

.field-group {
  margin: 0 0 14px;
  padding: 14px;
  border: 1px solid var(--line);
  background: #fbfcfc;
}

.field-group legend,
.field-group > label:first-child,
.primary-input > label {
  font-weight: 700;
}

.money-input {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: center;
  margin-top: 8px;
}

input[type="text"],
input[type="number"],
.money-input input {
  width: 100%;
  min-height: 42px;
  border: 1px solid #aebcbf;
  border-radius: 4px;
  padding: 8px 10px;
  background: #ffffff;
}

.field-note,
.mini-notice {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.amount-tools {
  display: grid;
  grid-template-columns: repeat(6, max-content);
  justify-content: space-between;
  gap: 4px;
  margin-top: 8px;
}

.amount-tools button,
.number-pad button,
.number-pad-actions button {
  min-height: 34px;
  min-width: max-content;
  border: 1px solid #98aaad;
  border-radius: 4px;
  padding: 6px 8px;
  background: #ffffff;
  color: var(--text);
  font-weight: 700;
  font-size: 0.94rem;
  white-space: nowrap;
}

.amount-tools button:hover,
.number-pad button:hover,
.number-pad-actions button:hover {
  border-color: var(--primary);
  color: var(--primary-dark);
}

.number-pad {
  display: grid;
  grid-template-columns: repeat(10, minmax(0, 1fr));
  gap: 5px;
  margin-top: 10px;
}

.number-pad button {
  min-height: 38px;
  background: #eef3f2;
}

.number-pad-actions {
  display: grid;
  grid-template-columns: 1fr 1.5fr;
  gap: 8px;
  margin-top: 8px;
}

.number-pad-actions button {
  min-height: 42px;
}

.number-pad-actions button:last-child {
  background: var(--primary);
  border-color: var(--primary-dark);
  color: #ffffff;
}

.special-amount-row {
  display: flex;
  justify-content: flex-end;
  margin-top: 6px;
}

.special-amount-button {
  min-height: 28px;
  width: auto;
  border: 1px solid #d58a20;
  border-radius: 4px;
  padding: 2px 8px;
  background: #fff5dd;
  color: #8a4b08;
  font-size: 0.9rem;
  font-weight: 700;
  line-height: 1.25;
}

.special-amount-button:hover {
  border-color: #a96910;
  color: #6f3900;
}

.error-message {
  min-height: 1.3em;
  margin: 6px 0 0;
  color: var(--danger);
  font-weight: 700;
  font-size: 0.9rem;
}

.choice {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  margin: 8px 18px 0 0;
}

.settings-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.settings-grid label {
  display: grid;
  gap: 6px;
  font-weight: 700;
}

.settings-grid label span::after {
  content: " %";
  color: var(--muted);
  font-weight: 400;
}

.form-actions,
.copy-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-end;
}

.secondary-button {
  min-height: 42px;
  border-radius: 4px;
  padding: 8px 18px;
  font-weight: 700;
}

.secondary-button {
  border: 1px solid #98aaad;
  background: #ffffff;
  color: var(--text);
}

.section-heading {
  display: flex;
  justify-content: space-between;
  align-items: start;
  gap: 12px;
}

.section-heading p {
  max-width: 42rem;
  margin: 0;
  color: var(--muted);
  font-size: 0.94rem;
}

.result-cards {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin: 14px 0;
}

.result-card {
  min-height: 124px;
  border: 1px solid var(--line);
  border-left: 5px solid var(--primary);
  border-radius: 6px;
  padding: 14px;
  background: var(--panel-strong);
}

.result-card.accent {
  border-left-color: var(--accent);
}

.result-card span,
.result-card small {
  display: block;
  color: var(--muted);
  font-weight: 700;
}

.result-card strong {
  display: block;
  margin: 8px 0;
  font-size: clamp(1.45rem, 2.6vw, 2rem);
  line-height: 1.15;
  overflow-wrap: anywhere;
  word-break: normal;
}

.result-card strong.amount-size-l {
  font-size: clamp(1.24rem, 2.1vw, 1.62rem);
}

.result-card strong.amount-size-xl {
  font-size: clamp(1.02rem, 1.75vw, 1.34rem);
}

.result-card strong.amount-size-xxl {
  font-size: clamp(0.88rem, 1.45vw, 1.08rem);
}

.bar-total strong.amount-size-l {
  font-size: 0.95em;
}

.bar-total strong.amount-size-xl,
.bar-total strong.amount-size-xxl {
  display: block;
  margin-top: 2px;
  font-size: 0.88em;
  overflow-wrap: anywhere;
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
}

table {
  width: 100%;
  min-width: 760px;
  border-collapse: collapse;
  background: #ffffff;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 9px 10px;
  text-align: left;
  vertical-align: top;
}

th {
  background: #e8eeee;
  font-weight: 700;
}

td:nth-child(2) {
  text-align: right;
  font-weight: 700;
  white-space: nowrap;
}

tr:last-child td {
  border-bottom: 0;
}

.source-row td {
  background: #fff5dd;
  border-top: 2px solid #d58a20;
  border-bottom: 2px solid #d58a20;
}

.source-row td:first-child {
  border-left: 5px solid #d58a20;
  font-weight: 800;
}

.source-badge {
  display: inline-block;
  margin-left: 8px;
  padding: 2px 7px;
  border-radius: 999px;
  background: #d58a20;
  color: #ffffff;
  font-size: 0.78rem;
  font-weight: 800;
  white-space: nowrap;
}

.copy-actions {
  margin-top: 12px;
}

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

.bar-card {
  padding: 18px;
}

.stacked-bar {
  display: flex;
  min-height: 64px;
  overflow: hidden;
  border: 1px solid #8fa0a3;
  background: #edf1f2;
}

.bar-segment {
  display: grid;
  place-items: center;
  min-width: 34px;
  padding: 8px;
  color: #ffffff;
  font-weight: 700;
  text-align: center;
  overflow-wrap: anywhere;
}

.segment-estimate {
  background: #176b5f;
}

.segment-tax {
  background: #587b9d;
}

.segment-buyer-fee {
  background: #b46a22;
}

.segment-net {
  background: #247052;
}

.segment-seller-fee {
  background: #954f48;
}

.bar-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 14px;
  margin-top: 12px;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--muted);
  font-weight: 700;
}

.legend-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  flex: 0 0 auto;
}

.bar-total {
  margin: 14px 0 0;
  text-align: center;
  font-size: 1.05rem;
}

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

details {
  min-height: 150px;
}

summary {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  background: #eef3f2;
  font-weight: 700;
  cursor: pointer;
}

.details-body {
  padding: 14px;
}

.details-body p {
  margin: 0 0 10px;
}

.formula-list {
  margin: 0;
  padding-left: 1.2em;
}

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

.basis-note {
  margin: 0 0 4px;
  color: var(--muted);
}

.links-list a {
  color: var(--primary-dark);
  font-weight: 700;
}

.site-links {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 14px 22px;
  padding: 14px 18px;
  border: 1px solid var(--line);
  background: var(--panel);
  box-shadow: var(--shadow);
}

.notice-box {
  display: grid;
  grid-template-columns: auto 1fr 1fr 1fr;
  gap: 12px;
  align-items: start;
  padding: 14px 18px;
}

.notice-box p {
  margin: 0;
  color: var(--muted);
}

.version-list {
  display: grid;
  gap: 14px;
  margin: 14px 0 0;
  padding: 0;
  list-style: none;
}

.version-lead {
  margin: 12px 0 0;
  color: var(--muted);
}

.version-lead a {
  color: var(--primary-dark);
  font-weight: 700;
}

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

.primary-link-button {
  display: inline-grid;
  place-items: center;
  min-height: 42px;
  border: 1px solid var(--primary-dark);
  border-radius: 4px;
  padding: 8px 18px;
  background: var(--primary);
  color: #ffffff;
  font-weight: 700;
  text-decoration: none;
}

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

.version-entry {
  border: 1px solid var(--line);
  border-left: 5px solid var(--primary);
  padding: 14px;
  background: #fbfcfc;
}

.version-entry:first-child {
  border-left-color: var(--accent);
}

.version-meta {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}

.version-meta strong {
  font-size: 1.12rem;
}

.version-meta time {
  color: var(--muted);
  font-weight: 700;
}

.version-entry ul {
  margin: 0;
  padding-left: 1.25em;
}

.version-entry li + li {
  margin-top: 4px;
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 10;
  min-width: 220px;
  max-width: calc(100vw - 40px);
  padding: 12px 14px;
  border-radius: 6px;
  background: #1f282b;
  color: #ffffff;
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
  transition: opacity 160ms ease, transform 160ms ease;
}

.toast.is-visible {
  opacity: 1;
  transform: translateY(0);
}

@media (max-width: 1100px) {
  .workspace,
  .bars-grid,
  .details-grid {
    grid-template-columns: 1fr;
  }

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

  .notice-box {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 720px) {
  .app-shell {
    width: 100%;
    padding: 8px;
  }

  .app-header,
  .section-heading {
    display: grid;
  }

  .app-header {
    padding: 14px;
    gap: 10px;
  }

  .app-header h1 {
    font-size: 1.14rem;
  }

  .brand-links {
    justify-content: start;
    gap: 8px;
  }

  .brand-logo-link img,
  .site-links img {
    width: min(180px, 58vw);
    max-height: 38px;
  }

  .profile-link {
    font-size: 0.92rem;
  }

  .mode-tabs {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    overflow: visible;
  }

  .mode-tab {
    min-width: 0;
    padding: 10px 6px;
    border-right: 1px solid var(--line);
    font-size: 0.86rem;
    line-height: 1.35;
    white-space: normal;
  }

  .input-panel,
  .results-panel,
  .bar-card,
  .version-panel {
    padding: 12px;
  }

  .version-meta {
    display: grid;
    gap: 2px;
  }

  .version-actions,
  .primary-link-button {
    width: 100%;
  }

  .field-group {
    padding: 12px;
  }

  .settings-grid,
  .result-cards {
    grid-template-columns: 1fr;
  }

  .form-actions,
  .copy-actions {
    justify-content: stretch;
  }

  .secondary-button {
    width: 100%;
  }

  .amount-tools {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    justify-content: stretch;
    gap: 7px;
  }

  .amount-tools button {
    width: 100%;
    min-width: 0;
  }

  .amount-tools button:nth-child(1) {
    order: 1;
  }

  .amount-tools button:nth-child(2) {
    order: 3;
  }

  .amount-tools button:nth-child(3) {
    order: 5;
  }

  .amount-tools button:nth-child(4) {
    order: 6;
  }

  .amount-tools button:nth-child(5) {
    order: 4;
  }

  .amount-tools button:nth-child(6) {
    order: 2;
  }

  .special-amount-row {
    justify-content: flex-end;
  }

  .number-pad {
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 7px;
  }

  .amount-tools button,
  .number-pad button {
    min-height: 42px;
  }

  .number-pad-actions {
    grid-template-columns: 1fr 1fr;
  }

  .choice {
    display: flex;
    margin-right: 0;
  }

  .bar-segment {
    font-size: 0.78rem;
  }

  .table-wrap {
    overflow: visible;
    border: 0;
  }

  table,
  thead,
  tbody,
  tr,
  td {
    display: block;
    width: 100%;
    min-width: 0;
  }

  table {
    background: transparent;
  }

  thead {
    display: none;
  }

  tr {
    margin-bottom: 10px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: #ffffff;
    overflow: hidden;
  }

  td {
    display: grid;
    grid-template-columns: 7.5em minmax(0, 1fr);
    gap: 8px;
    border-bottom: 1px solid var(--line);
    padding: 8px 10px;
    text-align: left;
  }

  td::before {
    color: var(--muted);
    font-weight: 700;
  }

  td:nth-child(1)::before {
    content: "項目";
  }

  td:nth-child(2)::before {
    content: "金額";
  }

  td:nth-child(3)::before {
    content: "計算式";
  }

  td:nth-child(4)::before {
    content: "備考";
  }

  td:nth-child(2) {
    text-align: left;
    white-space: normal;
  }

  .source-row td {
    border-top: 0;
    border-bottom: 1px solid var(--line);
  }

  .source-row td:first-child {
    border-left: 0;
    border-top: 5px solid #d58a20;
  }

  .source-badge {
    display: block;
    width: fit-content;
    margin: 4px 0 0;
  }
}
