:root {
  color-scheme: light;
  --ink: #183230;
  --muted: #607371;
  --line: #cfe0de;
  --paper: #ffffff;
  --wash: #eef7f5;
  --primary: #087f78;
  --primary-dark: #075f5a;
  --primary-soft: #dff3f0;
  --saturday: #1769aa;
  --holiday: #c13d3d;
  --danger-soft: #fff0f0;
  --shadow: 0 16px 38px rgba(24, 50, 48, 0.09);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: linear-gradient(180deg, #e7f3f1 0, #f7faf9 300px, #f7faf9 100%);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Yu Gothic", "Noto Sans JP", sans-serif;
  font-size: 17px;
  line-height: 1.6;
}

button, input { font: inherit; }
button { touch-action: manipulation; }

.app-shell {
  width: min(100% - 28px, 720px);
  margin: 0 auto;
  padding: max(24px, env(safe-area-inset-top)) 0 calc(36px + env(safe-area-inset-bottom));
}

.app-header { margin: 0 2px 20px; }
.eyebrow { margin: 0 0 2px; color: var(--primary); font-size: 0.72rem; font-weight: 800; letter-spacing: 0.16em; }
h1 { margin: 0; font-size: clamp(1.75rem, 7vw, 2.4rem); line-height: 1.2; letter-spacing: 0.02em; }
.app-header > p:last-child { margin: 6px 0 0; color: var(--muted); font-size: 0.93rem; }

.calculator, .history-section {
  background: var(--paper);
  border: 1px solid rgba(207, 224, 222, 0.9);
  border-radius: 18px;
  box-shadow: var(--shadow);
}

.calculator { padding: clamp(18px, 5vw, 30px); }
[hidden] { display: none !important; }
.view-title { margin: 0 0 4px; font-size: clamp(1.45rem, 6vw, 1.95rem); line-height: 1.3; }

.field-group > label, .label-row label, .presets > p {
  display: block;
  margin: 0 0 8px;
  font-weight: 800;
  font-size: 0.92rem;
}

.field-group { margin-top: 20px; }
.label-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.text-button, .delete-button {
  border: 0;
  background: transparent;
  color: var(--primary-dark);
  font-weight: 800;
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}
.text-button { min-height: 44px; padding: 4px 2px 4px 14px; }

input[type="date"], input[type="number"] {
  width: 100%;
  min-height: 56px;
  border: 2px solid #9fbab7;
  border-radius: 10px;
  background: #fff;
  color: var(--ink);
  font-size: 1.2rem;
  font-weight: 700;
}
input[type="date"] { padding: 10px 12px; }
input:focus { border-color: var(--primary); outline: 3px solid rgba(8, 127, 120, 0.16); }
.number-input-wrap { position: relative; }
.number-input-wrap input { padding: 8px 72px 8px 14px; font-size: 1.5rem; }
.number-input-wrap span { position: absolute; right: 17px; top: 50%; translate: 0 -50%; font-weight: 800; color: var(--muted); pointer-events: none; }
.field-help { margin: 5px 0 0; color: var(--muted); font-size: 0.84rem; }

.presets { margin-top: 20px; }
.preset-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
.preset-button {
  min-height: 46px;
  padding: 7px 3px;
  border: 1px solid #abc8c5;
  border-radius: 9px;
  background: #fff;
  color: var(--primary-dark);
  font-weight: 800;
  cursor: pointer;
}
.preset-button:hover, .preset-button:focus-visible, .preset-button.active { border-color: var(--primary); background: var(--primary-soft); }

.result-card {
  margin-top: 24px;
  padding: 20px 14px 16px;
  border-radius: 14px;
  background: var(--primary-dark);
  color: #fff;
  text-align: center;
}
.result-rule { margin: 0 0 6px; font-size: 0.88rem; font-weight: 700; opacity: 0.9; }
#result-date { display: block; font-size: clamp(1.72rem, 7vw, 2.9rem); font-weight: 900; line-height: 1.32; letter-spacing: 0.01em; overflow-wrap: anywhere; }
.holiday-label { min-height: 1.55em; margin: 5px 0 10px; font-weight: 800; }
.calculation-note { margin: -2px 0 13px; font-size: 0.82rem; font-weight: 800; opacity: 0.92; }
.result-card.is-saturday { background: var(--saturday); }
.result-card.is-holiday { background: var(--holiday); }
.copy-button {
  width: min(100%, 300px);
  min-height: 50px;
  border: 0;
  border-radius: 10px;
  background: #fff;
  color: var(--ink);
  font-weight: 900;
  cursor: pointer;
}
.copy-button:disabled { opacity: 0.55; cursor: not-allowed; }
.copy-status { min-height: 1.4em; margin: 5px 0 -5px; font-size: 0.82rem; font-weight: 700; }
.error-message { min-height: 1.5em; margin: 10px 0 0; color: var(--holiday); font-weight: 800; text-align: center; }

.sub-tool { margin-top: 24px; padding-top: 20px; border-top: 1px solid var(--line); text-align: center; }
.sub-tool p { margin: 0 0 9px; color: var(--muted); font-size: 0.9rem; font-weight: 700; }
.secondary-button {
  width: 100%;
  min-height: 54px;
  padding: 10px 16px;
  border: 2px solid var(--primary);
  border-radius: 11px;
  background: #fff;
  color: var(--primary-dark);
  font-weight: 900;
  cursor: pointer;
}
.secondary-button:hover, .secondary-button:focus-visible { background: var(--primary-soft); outline: 3px solid rgba(8, 127, 120, 0.14); outline-offset: 2px; }
.back-button { margin-top: 8px; }

.period-result-card {
  margin-top: 24px;
  padding: 18px 14px;
  border: 2px solid var(--primary);
  border-radius: 14px;
  background: var(--wash);
  text-align: center;
}
.period-endpoints { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.period-endpoints p { margin: 0; padding: 10px 6px; border-radius: 9px; background: #fff; }
.period-endpoints span { display: block; color: var(--muted); font-size: 0.78rem; font-weight: 800; }
.period-endpoints strong { display: block; margin-top: 2px; font-size: 0.98rem; line-height: 1.4; }
#period-result { display: block; margin: 14px 0 2px; color: var(--primary-dark); font-size: clamp(2.5rem, 11vw, 4.2rem); font-weight: 900; line-height: 1.15; }
.period-result-card > p { margin: 7px 0 0; color: var(--muted); font-size: 0.86rem; font-weight: 800; }

.history-section { margin-top: 18px; padding: 18px clamp(18px, 5vw, 26px); }
.section-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.section-heading h2 { margin: 0; font-size: 1.15rem; }
.delete-button { min-height: 44px; padding: 4px 0 4px 12px; color: #8c3a3a; font-size: 0.86rem; }
.history-list { margin: 12px 0 0; padding: 0; list-style: none; }
.history-list li { padding: 12px 2px; border-top: 1px solid var(--line); }
.history-main { display: block; font-weight: 800; }
.history-detail { display: block; color: var(--muted); font-size: 0.82rem; }
.empty-message { margin: 12px 0 2px; color: var(--muted); font-size: 0.9rem; }

footer { padding: 18px 8px 0; color: var(--muted); font-size: 0.78rem; text-align: center; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

@media (max-width: 520px) {
  .app-shell { width: min(100% - 20px, 720px); padding-top: max(16px, env(safe-area-inset-top)); }
  .calculator { padding: 16px 14px 18px; border-radius: 15px; }
  .preset-grid { grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 6px; }
  .preset-button { min-height: 44px; font-size: 0.86rem; }
  .result-card { margin-top: 20px; padding-inline: 8px; }
}

@media (max-width: 360px) {
  .preset-grid { grid-template-columns: repeat(2, 1fr); }
  .period-endpoints { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}
