/* コンタクトいつ変えた？ — 色や寸法の根拠は DESIGN_DIRECTION.md（消耗品リストと同じ色・書体） */

:root {
  --ground: #F8F1EE;
  --surface: #FFFFFF;
  --paper: #FFFCFA;
  --line: #EFE2DF;
  --ink: #3B2D31;
  --ink-2: #76636A;
  --accent: #9E4D67;
  --accent-soft: #F7E6EA;
  --warn-ink: #865219;
  --warn-soft: #FBEEDC;
  --danger: #B3362B;
  --control-line: #9A8086;
  --ink-rgb: 59, 45, 49;

  --r-s: 8px;
  --r-m: 14px;
  --r-l: 20px;
  --r-pill: 999px;

  --shadow: 0 1px 2px rgba(90, 50, 62, .10), 0 6px 18px rgba(90, 50, 62, .06);
  --ease: 160ms ease-out;

  --font: "Zen Kaku Gothic New", "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", sans-serif;
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--ground);
  color: var(--ink);
  font-family: var(--font);
  font-weight: 500;
  font-size: 16px;
  line-height: 1.5;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}

[hidden] { display: none !important; }

h1, h2, p { margin: 0; }

button, input { font: inherit; color: inherit; }

svg { display: block; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ---- ボタン ---- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 44px;
  padding: 0 16px;
  border: 0;
  border-radius: var(--r-pill);
  background: transparent;
  font-weight: 700;
  font-size: 15px;
  cursor: pointer;
  transition: transform var(--ease), background-color var(--ease), color var(--ease);
  user-select: none;
  -webkit-user-select: none;
}
.btn:active { transform: scale(.97); }

.btn.primary { background: var(--accent); color: #fff; }
.btn.ghost { color: var(--accent); }
.btn.ghost:active { background: var(--accent-soft); }
.btn.danger-text { color: var(--danger); }
.btn.wide { width: 100%; }

.btn.icon { width: 44px; padding: 0; }
.btn.icon svg {
  width: 22px; height: 22px;
  fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round;
}

/* ---- 合言葉 ---- */

.lock {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.lock-card {
  width: min(100%, 360px);
  display: flex;
  flex-direction: column;
  gap: 12px;
  text-align: center;
}
.lock-card img { margin: 0 auto 4px; border-radius: 16px; }
.lock-card h1 { font-size: 22px; font-weight: 700; margin-bottom: 16px; letter-spacing: .04em; font-feature-settings: "palt"; }
.lock-card label { text-align: left; font-weight: 700; font-size: 14px; }
.lock-error { min-height: 1.5em; color: var(--danger); font-size: 14px; text-align: left; }

/* ---- 上のバー ---- */

.bar {
  position: sticky;
  top: 0;
  z-index: 5;
  max-width: 720px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 8px) 0 8px;
  background: var(--ground);
}
.bar-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 12px 0 20px;
}
.bar h1 { font-size: 20px; font-weight: 700; letter-spacing: .06em; font-feature-settings: "palt"; }

.offline {
  max-width: 720px;
  margin: 0 auto 4px;
  padding: 8px 20px;
  font-size: 13px;
  color: var(--warn-ink);
}

/* ---- 一覧（カード） ---- */

main {
  max-width: 720px;
  margin: 0 auto;
  padding: 8px 12px calc(env(safe-area-inset-bottom) + 112px);
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 16px;
  align-items: start;
}

.card {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 12px 16px 16px 20px;
  background: var(--surface);
  border-radius: var(--r-l);
  box-shadow: var(--shadow);
  transition: background-color var(--ease);
}
.card.due { background: var(--warn-soft); }
.card.flash { animation: flash 900ms ease-out; }
@keyframes flash {
  from { box-shadow: 0 0 0 3px var(--accent-soft), var(--shadow); }
  to { box-shadow: 0 0 0 3px transparent, var(--shadow); }
}

.card-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-right: -8px;
}
.card-name {
  flex: 1;
  min-width: 0;
  font-size: 17px;
  font-weight: 700;
  overflow-wrap: anywhere;
}
.cycle {
  flex: none;
  padding: 2px 10px;
  border-radius: var(--r-pill);
  background: rgba(var(--ink-rgb), .06);
  color: var(--ink-2);
  font-size: 13px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.card.due .cycle { background: rgba(138, 84, 16, .10); color: var(--warn-ink); }
.fix { flex: none; padding: 0 12px; font-size: 14px; }
.fix svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }

/* 次に変える日 */
.next { display: flex; flex-direction: column; gap: 2px; }
.next-label { font-size: 13px; color: var(--ink-2); }
.card.due .next-label { color: var(--warn-ink); }
.next-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.next-date {
  font-size: 34px;
  font-weight: 700;
  line-height: 1.2;
  font-variant-numeric: tabular-nums;
  letter-spacing: .01em;
}
.next-date .wd { font-size: 20px; margin-left: 2px; }
.next-empty { font-size: 20px; font-weight: 700; line-height: 1.4; }

.left {
  flex: none;
  padding: 4px 14px;
  border-radius: var(--r-pill);
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 16px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.left.soon { background: var(--accent); color: #fff; }
.left.due { background: var(--warn-ink); color: #fff; }

/* 日めくりの粒（左＝つかった日、右＝のこりの日） */
.days {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(var(--cols), 16px);
  justify-content: space-between;
  gap: 8px 4px;
}
.days li {
  width: 16px; height: 16px;
  border-radius: 50%;
  border: 2px solid rgba(var(--ink-rgb), .16);
}
.days li.on { background: var(--accent); border-color: var(--accent); }
.days li.today { box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--accent-soft); }
.card.due .days li { border-color: rgba(138, 84, 16, .28); }

/* 周期が長いときは粒のかわりに帯 */
.track {
  height: 10px;
  border-radius: var(--r-pill);
  background: rgba(var(--ink-rgb), .10);
  overflow: hidden;
}
.track span { display: block; height: 100%; margin-left: auto; border-radius: var(--r-pill); background: var(--accent); }

.since { font-size: 13px; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.card.due .since { color: var(--warn-ink); }

.change {
  min-height: 52px;
  font-size: 16px;
}
.change svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.change.done { background: var(--accent-soft); color: var(--accent); cursor: default; }
.change.done:active { transform: none; }

/* 空のとき */
.empty-all {
  grid-column: 1 / -1;
  margin-top: 15vh;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  color: var(--ink-2);
}
.loading { grid-column: 1 / -1; margin-top: 20vh; text-align: center; color: var(--ink-2); }

/* ---- 追加・編集のシート ---- */

.sheet {
  width: 100%;
  max-width: 560px;
  max-height: calc(100dvh - 24px);
  margin: auto auto 0;
  padding: 0;
  border: 0;
  border-radius: 20px 20px 0 0;
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 -8px 32px rgba(70, 35, 48, .18);
  overflow-y: auto;
  overscroll-behavior: contain;
}
.sheet::backdrop { background: rgba(59, 45, 49, .38); }  /* ::backdrop は古い Safari で変数を受けつがない */
.sheet[open] { animation: sheet-in 220ms ease-out; }
@keyframes sheet-in {
  from { transform: translateY(24px); opacity: 0; }
  to { transform: none; opacity: 1; }
}
@media (min-width: 700px) {
  .sheet { margin: auto; border-radius: 20px; }
}

.sheet-body {
  display: flex;
  flex-direction: column;
  gap: 20px;
  padding: 8px 20px calc(env(safe-area-inset-bottom) + 20px);
}
.sheet-head {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 0 -20px;
  padding: 12px 8px 8px 20px;
  background: var(--surface);
}
.sheet-head h2 { font-size: 18px; font-weight: 700; }

.field { display: flex; flex-direction: column; gap: 6px; margin: 0; padding: 0; border: 0; min-width: 0; }
.field label, .field legend { font-size: 14px; font-weight: 700; padding: 0; }
.field legend { margin-bottom: 8px; }
.hint { font-size: 13px; color: var(--ink-2); margin-top: 4px; }
.field-error { font-size: 13px; color: var(--danger); }
.field-error:empty { display: none; }

input:not([type]), input[type="text"], input[type="password"], input[type="date"], input[type="number"] {
  width: 100%;
  min-height: 48px;
  padding: 10px 12px;
  border: 1px solid var(--control-line);
  border-radius: 10px;
  background: var(--surface);
  font-size: 16px;
  font-weight: 500;
  -webkit-appearance: none;
  appearance: none;
}
input[type="date"] { font-variant-numeric: tabular-nums; }
input[aria-invalid="true"] { border-color: var(--danger); }

.date-row { display: flex; gap: 4px; align-items: center; }
.date-row input { flex: 1; min-width: 0; margin-right: 4px; }
.date-row .btn { padding: 0 12px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chips label { position: relative; }
.chips input { position: absolute; opacity: 0; pointer-events: none; }
.chips span {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 56px;
  min-height: 44px;
  padding: 0 16px;
  border-radius: var(--r-pill);
  border: 1px solid var(--control-line);
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  transition: background-color var(--ease), color var(--ease);
}
.chips input:checked + span { background: var(--accent); border-color: var(--accent); color: #fff; }
.chips input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }

.stepper { display: flex; align-items: center; gap: 8px; margin-top: 12px; }
.step {
  flex: none;
  width: 44px; height: 44px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 1px solid var(--control-line);
  border-radius: 50%;
  background: var(--surface);
  color: var(--accent);
  cursor: pointer;
  transition: transform var(--ease), background-color var(--ease);
}
.step svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; }
.step:active { transform: scale(.94); background: var(--accent-soft); }
.stepper input[type="number"] {
  width: 72px;
  flex: none;
  text-align: center;
  font-size: 18px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  -moz-appearance: textfield;
}
.stepper input::-webkit-inner-spin-button,
.stepper input::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
.stepper-unit { font-size: 15px; }

.next-preview {
  padding: 12px 16px;
  border-radius: var(--r-m);
  background: var(--ground);
  font-size: 15px;
  font-variant-numeric: tabular-nums;
}
.next-preview strong { font-weight: 700; }

.sheet-actions { display: flex; flex-direction: column; gap: 8px; margin-top: 4px; }

/* ---- レシート（「今日変えた」のあと） ---- */

.toast {
  position: fixed;
  left: 0; right: 0;
  bottom: calc(env(safe-area-inset-bottom) + 16px);
  z-index: 20;
  display: flex;
  justify-content: center;
  padding: 0 12px;
  pointer-events: none;
  filter: drop-shadow(0 2px 3px rgba(70, 35, 48, .16)) drop-shadow(0 10px 20px rgba(70, 35, 48, .12));
  animation: toast-in 200ms ease-out;
}
@keyframes toast-in {
  from { transform: translateY(16px); opacity: 0; }
  to { transform: none; opacity: 1; }
}
.receipt {
  --z: 6px;
  pointer-events: auto;
  width: min(100%, 480px);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: calc(var(--z) + 12px) 8px 12px 16px;
  background: var(--paper);
  /* 上の端だけギザギザ（ちぎったレシート） */
  -webkit-mask:
    conic-gradient(from 135deg at top, #000 90deg, #0000 0) top / calc(2 * var(--z)) var(--z) repeat-x,
    linear-gradient(#000 0 0) 0 var(--z) / 100% calc(100% - var(--z)) no-repeat;
  mask:
    conic-gradient(from 135deg at top, #000 90deg, #0000 0) top / calc(2 * var(--z)) var(--z) repeat-x,
    linear-gradient(#000 0 0) 0 var(--z) / 100% calc(100% - var(--z)) no-repeat;
  border-radius: 0 0 var(--r-s) var(--r-s);
}
.stamp {
  flex: none;
  padding: 2px 8px;
  border: 2px solid var(--accent);
  border-radius: 6px;
  color: var(--accent);
  font-size: 13px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  transform: rotate(-4deg);
  white-space: nowrap;
}
.toast-msg {
  flex: 1;
  min-width: 0;
  font-size: 14px;
  line-height: 1.4;
  overflow-wrap: anywhere;
}
.toast-btn { flex: none; color: var(--accent); }
.toast-btn:active { background: var(--accent-soft); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 1ms !important;
    transition-duration: 1ms !important;
  }
}
