:root {
  --bg: #f7f3f4;
  --surface: #ffffff;
  --border: #e7dfe1;
  --text: #2c2429;
  --muted: #8a7c82;
  --accent: #c0567a;
  --accent-soft: #fdeef3;
  --line: #06c755;
  --radius: 14px;
  color-scheme: light;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  padding: 0 0 env(safe-area-inset-bottom, 0px);
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Hiragino Kaku Gothic ProN",
    "Noto Sans JP", "Yu Gothic UI", Meiryo, sans-serif;
  font-size: 15px;
  line-height: 1.7;
}

/* ---------- header ---------- */
.header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
  padding-top: env(safe-area-inset-top, 0px);
}

.header__inner {
  max-width: 1080px;
  margin: 0 auto;
  padding: 12px 16px;
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
}

.header__title {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.segmented {
  display: inline-flex;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px;
}

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

.segmented span {
  display: block;
  padding: 5px 16px;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.segmented input:checked + span { background: var(--accent); color: #fff; }
.segmented input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- layout ---------- */
.layout {
  max-width: 1080px;
  margin: 0 auto;
  padding: 16px;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 16px;
}

@media (min-width: 900px) {
  .layout { grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr); align-items: start; }
}

.form { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.output { min-width: 0; }

/* ---------- card ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}

@media (min-width: 900px) {
  .card--sticky { position: sticky; top: 78px; }
}

.card__title {
  margin: 0 0 12px;
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--accent);
}

.card__title--spaced { margin-top: 20px; }

/* ---------- form controls ---------- */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 12px;
}

.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field--full { grid-column: 1 / -1; }

.field label {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--muted);
}

input:where(:not([type="checkbox"], [type="radio"])), select, textarea {
  width: 100%;
  padding: 9px 11px;
  font: inherit;
  font-size: 0.95rem;
  color: var(--text);
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 9px;
  appearance: none;
}

/* 入力候補つきの入力欄（datalist）も select と同じ見た目にそろえる */
select,
input[list] {
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='8'><path d='M1 1l5 5 5-5' fill='none' stroke='%238a7c82' stroke-width='1.6'/></svg>");
  background-repeat: no-repeat;
  background-position: right 11px center;
  padding-right: 30px;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

input[list]::-webkit-calendar-picker-indicator { display: none; }

.suffix-wrap { position: relative; }
.suffix-wrap input { padding-right: 34px; }
.suffix {
  position: absolute;
  right: 11px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
  font-size: 0.9rem;
  pointer-events: none;
}

.note {
  margin: 10px 0 0;
  font-size: 0.78rem;
  line-height: 1.6;
  color: var(--muted);
}

.note:empty { display: none; }

/* ---------- checkboxes ---------- */
.checks { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }

.check {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 7px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 0.85rem;
  cursor: pointer;
}

.check input { accent-color: var(--accent); width: 15px; height: 15px; margin: 0; }
.check:has(input:checked) { background: var(--accent-soft); border-color: var(--accent); }

.badge {
  margin-left: 6px;
  padding: 1px 6px;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-size: 0.68rem;
  font-style: normal;
}

/* ---------- breakdown ---------- */
.breakdown { list-style: none; margin: 0; padding: 0; }

.breakdown li {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 7px 0;
  border-bottom: 1px dashed var(--border);
  font-size: 0.9rem;
}

.breakdown li span:last-child { font-variant-numeric: tabular-nums; white-space: nowrap; }
.breakdown li.is-minus span:last-child { color: var(--accent); }

.total {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin: 14px 0 0;
  font-size: 0.85rem;
  color: var(--muted);
}

.total strong {
  font-size: 1.6rem;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}

/* ---------- preview ---------- */
.preview {
  min-height: 340px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Hiragino Sans", monospace;
  font-size: 0.82rem;
  line-height: 1.75;
  white-space: pre;
  overflow-x: auto;
  resize: vertical;
  background: #fffdfd;
}

/* ---------- buttons ---------- */
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }

.btn {
  flex: 1 1 150px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 11px 16px;
  border: 1px solid transparent;
  border-radius: 10px;
  font: inherit;
  font-size: 0.92rem;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
  transition: opacity 0.15s;
}

.btn:active { opacity: 0.75; }
.btn--primary { background: var(--accent); color: #fff; }
.btn--line { background: var(--line); color: #fff; }
.btn--ghost {
  background: transparent;
  border-color: var(--border);
  color: var(--muted);
  padding: 10px;
}

/* ---------- toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  z-index: 50;
  padding: 10px 20px;
  background: var(--text);
  color: #fff;
  border-radius: 999px;
  font-size: 0.85rem;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.18);
}
