:root {
  --ink: #18241f;
  --muted: #53625b;
  --paper: #f7f4ed;
  --surface: #ffffff;
  --line: #c9d0cb;
  --green: #0d5c45;
  --green-dark: #083f31;
  --green-soft: #e4f0ea;
  --red: #b3262d;
  --red-dark: #7c141c;
  --red-soft: #fae7e6;
  --amber: #f0b429;
  --shadow: 0 10px 28px rgba(24, 36, 31, 0.1);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html { color-scheme: light; scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans JP", Arial, sans-serif;
  font-size: 20px;
  line-height: 1.55;
}

button, a { font: inherit; }
button { color: inherit; }
a { color: var(--green-dark); }
button, a[href] { touch-action: manipulation; }

:focus-visible {
  outline: 4px solid #0969da;
  outline-offset: 4px;
}

.skip-link {
  position: absolute;
  top: -100px;
  left: 1rem;
  z-index: 100;
  padding: .75rem 1rem;
  background: var(--ink);
  color: white;
}
.skip-link:focus { top: 1rem; }

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: min(100% - 2rem, 980px);
  margin: 0 auto;
  padding: 1.25rem 0;
  border-bottom: 1px solid var(--line);
}

.brand, .icon-button {
  border: 0;
  background: transparent;
  cursor: pointer;
}

.brand { display: flex; align-items: center; gap: .7rem; padding: .25rem; text-align: left; }
.brand-mark {
  display: grid;
  width: 2.7rem;
  height: 2.7rem;
  place-items: center;
  border-radius: 50%;
  background: var(--green);
  color: white;
  font-size: 1.4rem;
  font-weight: 800;
}
.brand strong { display: block; font-size: 1.2rem; line-height: 1.1; }
.brand small { display: block; color: var(--muted); font-size: .7rem; }
.header-actions { display: flex; gap: .5rem; }
.icon-button {
  display: flex;
  min-height: 48px;
  align-items: center;
  gap: .4rem;
  padding: .45rem .7rem;
  border-radius: .7rem;
  font-weight: 700;
}
.icon-button:hover { background: var(--green-soft); }
.home-nav-button {
  padding-right: .9rem;
  border: 1px solid var(--line);
  background: var(--surface);
}
.nav-label { text-align: left; }
.nav-label strong, .nav-label small { display: block; line-height: 1.2; }
.nav-label small { margin-top: .15rem; color: var(--red-dark); font-size: .67rem; font-weight: 800; }
.language-button {
  min-height: 48px;
  padding: .45rem .8rem;
  border: 2px solid var(--green-dark);
  border-radius: .7rem;
  background: var(--amber);
  color: var(--green-dark);
  font-weight: 900;
  cursor: pointer;
}

main { width: min(100% - 2rem, 880px); margin: 0 auto; }
.page { display: none; padding: 3.25rem 0 5rem; }
.page.is-active { display: block; animation: page-in .2s ease-out; }

@keyframes page-in { from { opacity: 0; transform: translateY(5px); } }

h1, h2, p { margin-top: 0; }
h1 { margin-bottom: .6rem; font-size: clamp(2.4rem, 8vw, 5rem); line-height: 1.03; letter-spacing: -.045em; }
h2 { font-size: clamp(1.45rem, 4vw, 2.25rem); line-height: 1.2; }
.eyebrow, .status-label, .step-kicker, .alert-type-label {
  margin-bottom: .55rem;
  color: var(--green);
  font-size: .78rem;
  font-weight: 800;
  letter-spacing: .12em;
}
.subtitle { max-width: 650px; color: var(--muted); font-size: clamp(1.1rem, 3vw, 1.45rem); }
.home-intro { padding: 1.5rem 0 2rem; }

.active-alert {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 1rem;
  align-items: center;
  margin-bottom: 3rem;
  padding: 1.4rem;
  border-radius: 1rem;
  background: var(--red-dark);
  color: white;
  box-shadow: var(--shadow);
}
.active-alert h2 { margin-bottom: .2rem; }
.active-alert p:last-child { margin-bottom: 0; }
.active-alert .status-label { color: #ffd7d7; }
.alert-icon {
  display: grid;
  width: 3.1rem;
  height: 3.1rem;
  place-items: center;
  border: 3px solid currentColor;
  border-radius: 50%;
  font-size: 1.8rem;
  font-weight: 900;
}

.listen-button {
  display: inline-flex;
  min-height: 52px;
  align-items: center;
  justify-content: center;
  gap: .55rem;
  padding: .7rem 1rem;
  border: 2px solid currentColor;
  border-radius: .8rem;
  background: transparent;
  font-weight: 800;
  cursor: pointer;
}
.listen-button.light { background: white; color: var(--red-dark); }
.listen-button.dark { border-color: white; color: white; }
.listen-button.outline { color: var(--green-dark); }
.listen-button.full { width: 100%; margin: 1.25rem 0; }
.listen-button.is-speaking { background: #f5d66c; color: #302b16; }
.listen-group { display: grid; gap: .45rem; justify-items: stretch; }
.listen-help {
  margin: 0;
  padding: .45rem .6rem;
  border: 1px solid var(--line);
  border-radius: .55rem;
  background: var(--surface);
  color: var(--muted);
  font-size: .7rem;
  line-height: 1.35;
  text-align: center;
}
.listen-help.on-dark { border-color: rgba(255,255,255,.45); background: rgba(255,255,255,.12); color: white; }
.full-listen-group { margin: 1.25rem 0; }
.full-listen-group .listen-button.full { margin: 0; }
.step-listen-group { max-width: 280px; }

.emergency-picker > p { color: var(--muted); }
.emergency-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .85rem; margin: 1.4rem 0; }
.emergency-choice {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: .85rem;
  min-height: 98px;
  align-items: center;
  padding: 1rem 1.15rem;
  border: 2px solid var(--line);
  border-radius: 1rem;
  background: var(--surface);
  text-align: left;
  box-shadow: 0 2px 0 rgba(24, 36, 31, .04);
  cursor: pointer;
}
.emergency-choice:hover { border-color: var(--green); }
.emergency-choice.selected { border: 3px solid var(--green); background: var(--green-soft); }
.emergency-choice strong, .emergency-choice small { display: block; }
.emergency-choice strong { font-size: 1.15rem; }
.emergency-choice small { color: var(--muted); font-size: .8rem; }
.choice-icon { width: 2rem; color: var(--green); font-size: 2rem; text-align: center; }
.choice-arrow { font-size: 2rem; }

.primary-action, .secondary-action {
  display: inline-flex;
  min-height: 64px;
  align-items: center;
  justify-content: center;
  gap: .7rem;
  padding: .9rem 1.35rem;
  border: 2px solid var(--green-dark);
  border-radius: .9rem;
  font-weight: 800;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
}
.primary-action { background: var(--green-dark); color: white; }
.primary-action:hover { background: #052d23; }
.danger-action { width: 100%; margin-top: .5rem; background: var(--red); border-color: var(--red-dark); text-transform: uppercase; }
.danger-action:hover { background: var(--red-dark); }
.secondary-action { background: var(--surface); color: var(--green-dark); }
.secondary-action:hover { background: var(--green-soft); }
.back-button, .text-action {
  min-height: 48px;
  margin-bottom: 2rem;
  padding: .4rem .25rem;
  border: 0;
  background: transparent;
  color: var(--green-dark);
  font-weight: 800;
  cursor: pointer;
}
.text-action { width: 100%; margin-top: 1.25rem; text-align: center; }

.alert-page-card {
  margin: .5rem 0 1.2rem;
  padding: clamp(1.5rem, 5vw, 3rem);
  border-radius: 1.25rem;
  background: var(--red-dark);
  color: white;
  box-shadow: var(--shadow);
}
.alert-page-card h1 { max-width: 700px; }
.alert-page-card .alert-type-label { color: #ffd7d7; }
.severity-row { display: flex; align-items: center; gap: .5rem; margin-bottom: 2rem; font-size: .78rem; font-weight: 800; letter-spacing: .1em; }
.severity-dot { width: .75rem; height: .75rem; border-radius: 50%; background: var(--amber); box-shadow: 0 0 0 6px rgba(240,180,41,.2); }
.immediate-instruction { display: flex; gap: 1rem; align-items: center; margin: 2rem 0; padding: 1.2rem; border-left: 6px solid var(--amber); background: rgba(255,255,255,.1); }
.immediate-instruction p { margin: 0; font-size: clamp(1.2rem, 4vw, 1.7rem); font-weight: 700; }
.large-symbol { font-size: 2.5rem; }
.page-alert > .primary-action { width: 100%; }
.reassurance { margin-top: .8rem; color: var(--muted); text-align: center; }

.step-heading-row { display: flex; align-items: end; justify-content: space-between; gap: 1rem; }
.step-heading-row h1 { font-size: clamp(2.2rem, 7vw, 4rem); }
.progress-track { height: 12px; margin: 1.2rem 0 2rem; overflow: hidden; border-radius: 99px; background: #dfe4e0; }
.progress-track span { display: block; width: 25%; height: 100%; border-radius: inherit; background: var(--green); transition: width .2s ease; }
.step-card { display: grid; grid-template-columns: 220px 1fr; gap: 2rem; min-height: 360px; align-items: center; padding: clamp(1.4rem, 5vw, 3rem); border: 2px solid var(--line); border-radius: 1.25rem; background: var(--surface); box-shadow: var(--shadow); }
.step-illustration { display: grid; width: 190px; height: 190px; place-items: center; border-radius: 50%; background: var(--green-soft); color: var(--green-dark); font-size: 5.5rem; font-weight: 900; }
.step-card h2 { margin: 0 0 .8rem; font-size: clamp(2rem, 6vw, 3.6rem); letter-spacing: -.035em; }
.step-card p:last-child { margin-bottom: 0; color: var(--muted); font-size: 1.1rem; }
.step-controls { display: grid; grid-template-columns: 1fr 2fr; gap: .8rem; margin-top: 1.2rem; }
.step-controls button { width: 100%; }

.distance-callout { display: flex; align-items: baseline; gap: .75rem; margin: 1.8rem 0; }
.distance-callout strong { font-size: clamp(3rem, 10vw, 5.5rem); line-height: 1; letter-spacing: -.05em; }
.distance-callout span { color: var(--muted); font-size: 1.1rem; }
.shelter-card { overflow: hidden; border: 2px solid var(--line); border-radius: 1.1rem; background: var(--surface); box-shadow: var(--shadow); }
.shelter-summary { display: grid; grid-template-columns: auto 1fr; gap: 1.1rem; align-items: center; padding: 1.5rem; }
.shelter-summary h2 { margin: .25rem 0; }
.shelter-summary p { margin: 0; color: var(--muted); }
.shelter-pin { display: grid; width: 4rem; height: 4rem; place-items: center; border-radius: 50%; background: var(--green-soft); color: var(--green); font-size: 2.4rem; }
.open-status { color: var(--green); font-size: .82rem; font-weight: 900; letter-spacing: .08em; }
.shelter-details { margin: 0; background: #edf3ef; }
.shelter-details div { display: grid; grid-template-columns: 1fr 1.3fr; gap: 1rem; padding: 1rem 1.5rem; border-top: 1px solid var(--line); }
dt { color: var(--muted); font-weight: 700; }
dd { margin: 0; font-weight: 800; }
.stacked-actions { display: grid; grid-template-columns: 1.25fr 1fr; gap: .8rem; }
.stacked-actions > * { width: 100%; }

.profile-identity { display: grid; grid-template-columns: auto 1fr auto; gap: 1rem; align-items: center; margin: 2rem 0 1rem; padding: 1.3rem; border-radius: 1rem; background: var(--green-dark); color: white; }
.profile-identity h2, .profile-identity p { margin: 0; }
.profile-identity p { color: #cfe1d9; }
.avatar { display: grid; width: 4.5rem; height: 4.5rem; place-items: center; border-radius: 50%; background: white; color: var(--green-dark); font-size: 1.5rem; font-weight: 900; }
.blood-type { text-align: center; }
.blood-type span, .blood-type strong { display: block; }
.blood-type span { font-size: .75rem; }
.blood-type strong { font-size: 2rem; }
.medical-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .8rem; margin: .8rem 0; }
.medical-grid > div { min-height: 150px; padding: 1.25rem; border: 2px solid var(--line); border-radius: 1rem; background: var(--surface); }
.medical-grid dt { margin-bottom: .55rem; font-size: .82rem; text-transform: uppercase; letter-spacing: .08em; }
.medical-grid dd { font-size: 1.2rem; }
.medical-grid dd { white-space: pre-line; }
.medical-grid .important { border-color: var(--red); background: var(--red-soft); }
.medical-grid .important dt, .medical-grid .important dd { color: var(--red-dark); }
.privacy-note { margin-top: 1rem; color: var(--muted); font-size: .82rem; text-align: center; }

.profile-gate {
  max-width: 660px;
  margin: 0 auto;
  padding: clamp(1.4rem, 5vw, 2.6rem);
  border: 2px solid var(--line);
  border-radius: 1.25rem;
  background: var(--surface);
  box-shadow: var(--shadow);
}
.profile-gate h1 { font-size: clamp(2.2rem, 7vw, 4rem); }
.lock-symbol {
  display: grid;
  width: 4.5rem;
  height: 4.5rem;
  place-items: center;
  margin-bottom: 1.25rem;
  border-radius: 50%;
  background: var(--green-soft);
  color: var(--green-dark);
  font-size: 1.8rem;
  box-shadow: inset 0 0 0 12px var(--surface);
  border: 5px solid var(--green-dark);
}
.profile-form { display: grid; gap: .55rem; margin-top: 1.75rem; }
.profile-form label { margin-top: .45rem; font-weight: 800; }
.profile-form input,
.profile-form textarea,
.profile-form select {
  width: 100%;
  min-height: 62px;
  padding: .75rem 1rem;
  border: 2px solid #69756f;
  border-radius: .75rem;
  background: white;
  color: var(--ink);
  font: inherit;
}
.profile-form textarea { resize: vertical; }
.password-field { display: grid; grid-template-columns: 1fr auto; gap: .55rem; }
.show-password {
  min-width: 80px;
  border: 2px solid var(--green-dark);
  border-radius: .75rem;
  background: var(--surface);
  color: var(--green-dark);
  font-weight: 800;
  cursor: pointer;
}
.field-help { margin: 0 0 .35rem; color: var(--muted); font-size: .82rem; }
.form-error { margin: .5rem 0 0; padding: .7rem .9rem; border-left: 5px solid var(--red); background: var(--red-soft); color: var(--red-dark); font-weight: 800; }
.profile-form .primary-action { width: 100%; margin-top: .7rem; }
.profile-security-note { display: grid; gap: .2rem; margin-top: 1.25rem; padding: 1rem; border-radius: .8rem; background: var(--green-soft); color: var(--green-dark); font-size: .82rem; }
.profile-actions { display: grid; gap: 1rem; margin-top: .5rem; }
.full-action { width: 100%; margin: 0; }
.edit-information-button {
  border-color: var(--green-dark);
  background: var(--amber);
  color: var(--green-dark);
}
.edit-information-button:hover { background: #ffd65a; }
.profile-title-row { display: flex; align-items: start; justify-content: space-between; gap: 1rem; }
.lock-button {
  display: inline-flex;
  min-height: 52px;
  flex-shrink: 0;
  align-items: center;
  gap: .45rem;
  padding: .65rem .9rem;
  border: 2px solid var(--green-dark);
  border-radius: .8rem;
  background: var(--surface);
  color: var(--green-dark);
  font-weight: 800;
  cursor: pointer;
}
.medical-editor { margin-top: 2rem; padding: clamp(1.2rem, 4vw, 2rem); border: 2px solid var(--line); border-radius: 1rem; background: var(--surface); box-shadow: var(--shadow); }
.editor-heading { display: flex; align-items: start; justify-content: space-between; gap: 1rem; }
.editor-heading h2 { margin-bottom: .5rem; }
.text-action.compact { width: auto; margin: 0; white-space: nowrap; }
.form-field-pair { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.form-field-pair > div { display: grid; gap: .55rem; }

.toast {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  z-index: 20;
  max-width: min(420px, calc(100% - 2rem));
  padding: 1rem 1.2rem;
  border-radius: .8rem;
  background: var(--ink);
  color: white;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(1rem);
  pointer-events: none;
  transition: .2s ease;
}
.toast.show { opacity: 1; transform: none; }
.toast.toast-yellow { border: 3px solid var(--green-dark); background: var(--amber); color: var(--green-dark); font-weight: 900; }

@media (max-width: 720px) {
  body { font-size: 18px; }
  .site-header { width: min(100% - 1rem, 980px); }
  .icon-button { flex-direction: column; gap: 0; font-size: .7rem; }
  .home-nav-button { flex-direction: row; gap: .35rem; padding: .4rem .55rem; }
  .nav-label small { font-size: .6rem; }
  .page { padding-top: 2rem; }
  .active-alert { grid-template-columns: auto 1fr; }
  .active-alert .listen-group { grid-column: 1 / -1; width: 100%; }
  .active-alert .listen-button { width: 100%; }
  .emergency-grid { grid-template-columns: 1fr; }
  .step-heading-row { align-items: start; }
  .step-heading-row .listen-button { flex-shrink: 0; }
  .step-card { grid-template-columns: 1fr; min-height: 0; text-align: center; }
  .step-illustration { width: 150px; height: 150px; margin: 0 auto; font-size: 4rem; }
  .medical-grid { grid-template-columns: 1fr; }
  .language-button { padding-inline: .55rem; font-size: .75rem; }
}

@media (max-width: 500px) {
  main { width: min(100% - 1.2rem, 880px); }
  .brand small { display: none; }
  .brand-mark { width: 2.3rem; height: 2.3rem; }
  .header-actions { gap: .15rem; }
  .icon-button { padding-inline: .4rem; }
  .home-nav-button .nav-label small { display: none; }
  .language-button { min-width: 50px; padding-inline: .35rem; }
  .active-alert { grid-template-columns: 1fr; }
  .alert-icon { width: 2.5rem; height: 2.5rem; font-size: 1.3rem; }
  .step-heading-row { display: block; }
  .step-heading-row .listen-button { width: 100%; margin-top: .5rem; }
  .step-controls, .stacked-actions { grid-template-columns: 1fr; }
  .step-controls .primary-action { grid-row: 1; }
  .shelter-details div { grid-template-columns: 1fr; gap: .2rem; }
  .profile-identity { grid-template-columns: auto 1fr; }
  .blood-type { grid-column: 1 / -1; display: flex; justify-content: space-between; align-items: baseline; padding-top: .75rem; border-top: 1px solid rgba(255,255,255,.25); }
  .profile-title-row { display: block; }
  .lock-button { width: 100%; justify-content: center; margin-bottom: 1rem; }
  .password-field { grid-template-columns: 1fr; }
  .show-password { min-height: 50px; }
  .form-field-pair { grid-template-columns: 1fr; }
  .editor-heading { display: block; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

@media (prefers-contrast: more) {
  :root { --line: #4d5752; }
  .emergency-choice, .step-card, .shelter-card, .medical-grid > div { border-width: 3px; }
}
