:root {
  --bg: #f4f2ee;
  --card: #ffffff;
  --text: #22201c;
  --muted: #6f6a62;
  --border: #ddd8cf;
  --accent: #2f6f5e;
  --accent-text: #ffffff;
  --accent-soft: #e3efe9;
  --danger: #b3412f;
  --radius: 14px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161513;
    --card: #22201d;
    --text: #ece8e1;
    --muted: #a39d93;
    --border: #3a3732;
    --accent: #5fb39a;
    --accent-text: #0e1a16;
    --accent-soft: #233630;
    --danger: #e07a68;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Noto Sans JP", sans-serif;
  line-height: 1.5;
  padding-bottom: calc(24px + env(safe-area-inset-bottom));
}

.app-header {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}
.app-header h1 { font-size: 1.1rem; margin: 0; }
.icon-btn {
  font-size: 1.3rem; background: none; border: 0; color: var(--text);
  width: 44px; height: 44px; border-radius: 50%;
}

main { max-width: 520px; margin: 0 auto; padding: 12px 16px; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
}
.card h2 { font-size: 0.95rem; margin: 0 0 8px; color: var(--muted); font-weight: 600; }

.field { display: block; margin: 12px 0; }
.field > span { display: block; font-size: 0.85rem; font-weight: 600; margin-bottom: 6px; }
.hint { display: block; color: var(--muted); font-size: 0.78rem; margin-top: 4px; }

input[type="number"], input[type="text"], input[type="date"], input[type="time"] {
  width: 100%;
  font-size: 16px; /* iOSの自動ズーム防止 */
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  -webkit-appearance: none;
  appearance: none;
  min-height: 44px;
}
.with-unit { display: flex; align-items: center; gap: 8px; }
.with-unit em { font-style: normal; color: var(--muted); }

.segmented {
  display: flex;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 3px;
  gap: 3px;
}
.segmented button {
  flex: 1;
  min-height: 40px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  font-size: 0.9rem;
}
.segmented button[aria-pressed="true"] {
  background: var(--accent);
  color: var(--accent-text);
  font-weight: 600;
}

.primary-btn, .secondary-btn {
  display: flex; align-items: center; justify-content: center;
  min-height: 46px;
  padding: 10px 14px;
  border-radius: 10px;
  font-size: 0.95rem;
  font-weight: 600;
  text-decoration: none;
  text-align: center;
  cursor: pointer;
  border: 1px solid var(--accent);
}
.primary-btn { background: var(--accent); color: var(--accent-text); }
.secondary-btn { background: transparent; color: var(--accent); }
.btn-row { display: flex; gap: 8px; margin-top: 12px; }
.btn-row > * { flex: 1; }

#preview {
  width: 100%; max-height: 220px; object-fit: contain;
  margin-top: 10px; border-radius: 10px; background: var(--bg);
}
.status { font-size: 0.85rem; color: var(--muted); margin: 8px 0 0; min-height: 1em; }
.status.error { color: var(--danger); }
.reason {
  font-size: 0.85rem; margin: 6px 0 0; padding: 8px 10px;
  background: var(--accent-soft); border-radius: 8px;
}

.result { text-align: center; }
.big { font-size: 2.2rem; font-weight: 700; margin: 4px 0; color: var(--accent); }
.sub { color: var(--muted); font-size: 0.85rem; margin: 0; }

.schedule-result {
  display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 12px;
}
.schedule-result .stat {
  background: var(--accent-soft); border-radius: 10px; padding: 10px; text-align: center;
}
.stat .label { display: block; font-size: 0.75rem; color: var(--muted); }
.stat .value { display: block; font-size: 1.25rem; font-weight: 700; }
.schedule-result .wide { grid-column: 1 / -1; }
.placeholder, .schedule-error { grid-column: 1 / -1; color: var(--muted); font-size: 0.85rem; margin: 0; }
.schedule-error { color: var(--danger); }

.help { margin-top: 10px; font-size: 0.85rem; }
.help summary { color: var(--accent); cursor: pointer; padding: 6px 0; }
.help ol { padding-left: 1.2em; margin: 6px 0; }
.help li { margin-bottom: 4px; }
.help p { color: var(--muted); margin: 6px 0 0; }

dialog {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--card);
  color: var(--text);
  width: min(92vw, 420px);
  padding: 16px;
}
dialog::backdrop { background: rgba(0, 0, 0, 0.4); }
dialog h2 { margin: 0 0 8px; font-size: 1.05rem; }

[hidden] { display: none !important; }
