:root {
  --bg: #f4f5f9;
  --card: #ffffff;
  --text: #111216;
  --muted: #8b8d94;
  --line: #e4e5e9;
  --blue: #2f80ed;
  --danger: #d33a45;
  --positive: #168b52;
  --shadow: 0 14px 40px rgba(27, 33, 55, 0.08);
  --radius: 24px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

[hidden] {
  display: none !important;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  min-height: 100%;
  margin: 0;
  color: var(--text);
  background: var(--bg);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Hiragino Sans", "Yu Gothic", "Noto Sans JP", sans-serif;
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

button, input, select {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  width: min(100%, 560px);
  min-height: 100vh;
  margin: 0 auto;
  padding: max(8px, env(safe-area-inset-top)) 12px calc(86px + var(--safe-bottom));
}

.top-line {
  display: flex;
  justify-content: flex-end;
  min-height: 12px;
  margin-bottom: 4px;
}

.offline-badge {
  margin: 0;
  color: var(--danger);
  font-size: 11px;
  font-weight: 700;
}

.view {
  display: none;
}

.view.active {
  display: block;
  animation: view-in .18s ease-out;
}

@keyframes view-in {
  from { opacity: 0; transform: translateY(3px); }
  to { opacity: 1; transform: none; }
}

.platform-switch {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 4px;
  margin: 0 0 12px;
  border: 1px solid rgba(255,255,255,.9);
  border-radius: 20px;
  background: #e8e9ed;
  box-shadow: inset 0 1px 1px rgba(0,0,0,.04);
}

.platform-button {
  min-height: 42px;
  border: 0;
  border-radius: 16px;
  color: #6f7178;
  background: transparent;
  font-size: 15px;
  font-weight: 700;
}

.platform-button.active {
  color: var(--text);
  background: var(--card);
  box-shadow: 0 4px 12px rgba(26, 34, 51, .08);
}

.section-title {
  margin: 0 0 8px 10px;
  color: var(--muted);
  font-size: 16px;
  letter-spacing: .02em;
}

.first-title {
  margin-top: 0;
}

.card {
  overflow: hidden;
  margin-bottom: 12px;
  border-radius: var(--radius);
  background: var(--card);
  box-shadow: 0 1px 0 rgba(0,0,0,.01);
}

.form-row,
.setting-row,
.result-row {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 48px;
  padding: 8px 16px;
  font-size: 16px;
}

.form-row:not(:last-child)::after,
.setting-row:not(:last-child)::after,
.result-row:not(:last-child)::after {
  position: absolute;
  right: 16px;
  bottom: 0;
  left: 16px;
  height: 1px;
  content: "";
  background: var(--line);
}

.value-field {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  min-width: 100px;
}

.value-field input {
  width: 86px;
  padding: 2px 0;
  border: 0;
  outline: 0;
  color: var(--text);
  background: transparent;
  text-align: right;
  font-size: 18px;
  font-variant-numeric: tabular-nums;
}

.value-field input:focus {
  color: var(--blue);
}

.value-field input::-webkit-outer-spin-button,
.value-field input::-webkit-inner-spin-button {
  margin: 0;
  -webkit-appearance: none;
}

.unit {
  flex: 0 0 auto;
  font-size: 16px;
}

.select-wrap {
  position: relative;
  display: inline-flex;
  max-width: 64%;
  align-items: center;
  justify-content: flex-end;
}

.select-wrap select {
  width: 100%;
  padding: 6px 22px 6px 4px;
  border: 0;
  outline: 0;
  color: var(--text);
  background: transparent;
  text-align: right;
  text-align-last: right;
  font-size: 16px;
  -webkit-appearance: none;
  appearance: none;
}

.chevron {
  position: absolute;
  right: 2px;
  color: #a1a3aa;
  font-size: 24px;
  pointer-events: none;
}

.readonly-row strong,
.result-row strong {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.readonly-row strong {
  text-align: right;
  font-size: 16px;
}

.action-card {
  padding: 0;
}

.compact-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
}

.compact-actions .action-button + .action-button {
  border-top: 0;
  border-left: 1px solid var(--line);
}

.action-button {
  width: 100%;
  min-height: 46px;
  padding: 0;
  border: 0;
  color: var(--blue);
  background: transparent;
  text-align: center;
  font-size: 18px;
}

.settings-actions .action-button {
  min-height: 56px;
  text-align: left;
  padding: 0 18px;
}

.settings-actions .action-button + .action-button {
  border-top: 1px solid var(--line);
}

.action-button:active {
  opacity: .58;
}

.action-button.primary {
  color: var(--blue);
}

.action-button.danger {
  color: var(--danger);
}

.result-row strong {
  font-size: 18px;
}

.result-row strong.positive {
  color: var(--positive);
}

.result-row strong.negative,
#payoutResult.negative {
  color: var(--danger);
}

.breakdown-card {
  padding: 0 16px;
  margin-bottom: 10px;
}

.breakdown-card summary {
  min-height: 46px;
  padding: 14px 0;
  color: var(--blue);
  font-size: 17px;
  list-style: none;
}

.breakdown-card summary::-webkit-details-marker {
  display: none;
}

.breakdown-card summary::after {
  float: right;
  content: "＋";
  color: #999ba2;
}

.breakdown-card[open] summary::after {
  content: "−";
}

.breakdown-list {
  padding: 0 0 12px;
  border-top: 1px solid var(--line);
}

.breakdown-list > div {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 0;
  color: #575960;
  font-size: 14px;
}

.breakdown-list strong {
  color: var(--text);
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}

.breakdown-list .breakdown-total {
  margin-top: 2px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
  color: var(--text);
  font-size: 16px;
}

.settings-card {
  padding: 4px 16px 12px;
}

.settings-card h3 {
  margin: 14px 0 4px;
  font-size: 17px;
}

.settings-card .setting-row {
  min-height: 52px;
  padding-right: 0;
  padding-left: 0;
  font-size: 16px;
}

.settings-card .setting-row::after {
  right: 0;
  left: 0;
}

.settings-card .value-field {
  min-width: 110px;
}

.settings-card .value-field input {
  width: 78px;
  font-size: 18px;
}

.setting-note {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
}

.subtabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 4px;
  margin: 14px 0 8px;
  border-radius: 16px;
  background: #eceef2;
}

.subtab {
  min-height: 38px;
  border: 0;
  border-radius: 13px;
  color: #777981;
  background: transparent;
  font-size: 14px;
  font-weight: 700;
}

.subtab.active {
  color: var(--text);
  background: #fff;
  box-shadow: 0 3px 10px rgba(0,0,0,.07);
}

.shipping-setting-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 90px;
  gap: 10px;
  align-items: center;
  min-height: 56px;
  border-bottom: 1px solid var(--line);
}

.shipping-setting-row:last-child {
  border-bottom: 0;
}

.shipping-setting-row label {
  min-width: 0;
  font-size: 15px;
  line-height: 1.35;
}

.shipping-setting-row .value-field {
  min-width: 0;
}

.shipping-setting-row .value-field input {
  width: 62px;
  font-size: 17px;
}

.install-card p {
  line-height: 1.65;
}

.install-card ol {
  margin: 12px 0 0;
  padding-left: 23px;
  color: #46484f;
  line-height: 1.8;
}

.settings-actions {
  margin-top: 2px;
}

.save-message {
  min-height: 22px;
  margin: -4px 0 18px;
  color: var(--positive);
  text-align: center;
  font-size: 14px;
}

.bottom-nav {
  position: fixed;
  z-index: 20;
  right: 50%;
  bottom: calc(12px + var(--safe-bottom));
  display: grid;
  grid-template-columns: 1fr 1fr;
  width: min(320px, calc(100vw - 40px));
  padding: 4px;
  border: 1px solid rgba(255,255,255,.95);
  border-radius: 999px;
  background: rgba(250,250,252,.88);
  box-shadow: var(--shadow);
  transform: translateX(50%);
  -webkit-backdrop-filter: blur(18px);
  backdrop-filter: blur(18px);
}

.nav-button {
  display: flex;
  min-height: 54px;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 1px;
  border: 0;
  border-radius: 999px;
  color: var(--text);
  background: transparent;
  font-size: 12px;
  font-weight: 600;
}

.nav-button.active {
  color: var(--blue);
  background: rgba(221, 223, 228, .8);
}

.nav-icon {
  position: relative;
  display: block;
  width: 24px;
  height: 24px;
}

.home-icon::before {
  position: absolute;
  top: 5px;
  left: 4px;
  width: 15px;
  height: 13px;
  content: "";
  border: 3px solid currentColor;
  border-top: 0;
  border-radius: 2px;
}

.home-icon::after {
  position: absolute;
  top: 1px;
  left: 4px;
  width: 15px;
  height: 15px;
  content: "";
  border-top: 3px solid currentColor;
  border-left: 3px solid currentColor;
  transform: rotate(45deg);
}

.gear-icon {
  display: grid;
  place-items: center;
  font-size: 24px;
  line-height: 1;
}

@media (min-width: 700px) {
  body {
    padding: 24px 0;
  }

  .app-shell {
    min-height: calc(100vh - 48px);
    border-radius: 36px;
    box-shadow: 0 25px 80px rgba(30,37,56,.12);
  }
}

@media (max-width: 390px) {
  .app-shell {
    padding-left: 10px;
    padding-right: 10px;
    padding-bottom: calc(82px + var(--safe-bottom));
  }

  .section-title {
    font-size: 15px;
    margin-left: 8px;
  }

  .form-row,
  .result-row {
    min-height: 46px;
    padding-left: 14px;
    padding-right: 14px;
    font-size: 15px;
  }

  .form-row:not(:last-child)::after,
  .result-row:not(:last-child)::after {
    right: 14px;
    left: 14px;
  }

  .value-field input {
    width: 74px;
    font-size: 17px;
  }

  .select-wrap {
    max-width: 62%;
  }

  .select-wrap select {
    font-size: 15px;
  }

  .action-button {
    font-size: 17px;
  }

  .result-row strong {
    font-size: 17px;
  }
}
