:root {
  color-scheme: light;
  --ink: #18352b;
  --muted: #587066;
  --line: #cadfd5;
  --paper: #ffffff;
  --wash: #f0f8f3;
  --primary: #23815f;
  --primary-dark: #176b52;
  --primary-soft: #dff2e8;
  --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, #e8f3ed 0, #f8fbf9 420px, #f8fbf9 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;
}

body[data-brand="aqua"] {
  --ink: #17344a;
  --muted: #5d7384;
  --line: #c9deed;
  --wash: #edf8ff;
  --primary: #2d86d8;
  --primary-dark: #267ac0;
  --primary-soft: #dff1ff;
  --shadow: 0 16px 38px rgba(31, 92, 134, 0.1);
  background: linear-gradient(180deg, #dceeff 0, #f4faff 420px, #f8fcff 100%);
}

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; }
.title-row { display: flex; align-items: center; gap: 10px; }
.brand-icon-aqua { display: none; }
body[data-brand="aqua"] .brand-icon-public { display: none; }
body[data-brand="aqua"] .brand-icon-aqua { display: inline-block; }
.medicine-mark { position: relative; display: inline-block; width: 39px; height: 20px; flex: 0 0 auto; overflow: hidden; border: 2px solid var(--primary-dark); border-radius: 999px; background: linear-gradient(90deg, var(--primary) 0 50%, #fff 50%); rotate: -28deg; box-shadow: 0 3px 8px rgba(23,107,82,.16); }
.medicine-mark i { position: absolute; left: 50%; top: 0; width: 2px; height: 100%; background: var(--primary-dark); translate: -50% 0; }
.aqua-character { position: relative; width: 58px; height: 54px; flex: 0 0 auto; overflow: hidden; }
.aqua-character img { position: absolute; width: 180px; max-width: none; left: -61px; top: -18px; }
.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; }
.result-sentence { margin: 4px auto 0; max-width: 580px; font-size: 0.92rem; font-weight: 800; line-height: 1.65; }
.calculation-note { margin: 5px 0 13px; font-size: 0.76rem; font-weight: 700; opacity: 0.88; }
.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; }
.install-nudge { margin: 12px 0 0; color: var(--muted); font-size: 0.8rem; text-align: center; }
.install-guide-link { min-height: 40px; padding: 5px 8px; border: 0; background: transparent; color: var(--primary-dark); font-weight: 800; text-decoration: underline; text-underline-offset: 3px; cursor: pointer; }
.error-message { min-height: 1.5em; margin: 10px 0 -8px; color: var(--holiday); font-weight: 800; text-align: left; }

.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; }
.period-result-card .period-sentence { color: var(--ink); font-size: 0.92rem; line-height: 1.65; }
.period-result-card .period-difference { font-size: 0.78rem; font-weight: 700; }
.period-copy-button { margin-top: 14px; border: 2px solid var(--primary); color: var(--primary-dark); }
.period-rule { margin-top: 12px; 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; }

.install-section {
  margin-top: 18px;
  padding: 20px clamp(18px, 5vw, 26px);
  scroll-margin-top: 18px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.78);
}
.install-section > h2 { margin: 0; font-size: 1.15rem; }
.install-section > p { margin: 7px 0 0; color: var(--muted); font-size: 0.88rem; }
.install-section details { margin-top: 12px; }
.install-section summary {
  min-height: 48px;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  color: var(--primary-dark);
  font-weight: 900;
  cursor: pointer;
}
.install-section summary:focus-visible { outline: 3px solid var(--primary-soft); outline-offset: 2px; }
.install-cards { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 12px; }
.install-card { padding: 16px; border: 1px solid var(--line); border-radius: 12px; background: #fff; }
.install-card h3 { margin: 0; font-size: 1rem; }
.install-card ol { margin: 10px 0 0; padding-left: 1.5em; }
.install-card li + li { margin-top: 5px; }
.install-note { margin: 11px 0 0; padding-top: 10px; border-top: 1px solid var(--line); color: var(--muted); font-size: 0.78rem; font-weight: 700; }

footer { padding: 18px 8px 0; color: var(--muted); font-size: 0.78rem; text-align: center; }
.brand-footer { margin-top: 6px; color: var(--primary-dark); font-weight: 800; }
.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; }
  .install-cards { grid-template-columns: 1fr; }
}

@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; }
}
