:root {
  --bg: #e6ecf0;
  --paper: #f6f8f9;
  --ink: #1c2838;
  --ink-soft: #4f5d6e;
  --ai: #274a78;      /* 吉 */
  --nibi: #8c96a3;    /* 中 */
  --hai: #c9cfd6;     /* 凶 */
  --shu: #c13a23;     /* 満場一致だけに使う */
  --focus: #e0a400;
  --serif: "Zen Old Mincho", "Hiragino Mincho ProN", "Yu Mincho", serif;
  --sans: "BIZ UDPGothic", "Hiragino Sans", "Yu Gothic", "Meiryo", sans-serif;
  color-scheme: light dark;
  box-sizing: border-box;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121a24; --paper: #1a2431; --ink: #e4e9ee; --ink-soft: #a3aebb;
    --ai: #6f95c9; --nibi: #7c8795; --hai: #3a4553; --shu: #e0654c;
  }
}
*, *::before, *::after { box-sizing: inherit; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 1rem;
  line-height: 1.75;
}
.page { max-width: 46rem; margin: 0 auto; padding: 3rem 1.25rem 4rem; }

h1, h2, .verdict-big, .plate-mark, .plate-word { font-family: var(--serif); }
h1 { font-size: clamp(2.4rem, 8vw, 3.6rem); font-weight: 900; line-height: 1.15; margin: 0 0 1rem; letter-spacing: .04em; }
h2 { font-size: 1.35rem; font-weight: 700; margin: 0 0 .75rem; }
.lead { max-width: 34em; margin: 0 0 2rem; color: var(--ink-soft); }

button, input { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

/* 入力 */
.form label { display: block; font-weight: 700; margin-bottom: .4rem; }
.form-row { display: flex; gap: .6rem; flex-wrap: wrap; }
.form input {
  flex: 1 1 12rem; min-height: 3rem; padding: .5rem .75rem;
  border: 1.5px solid var(--nibi); border-radius: 4px; background: var(--paper);
}
.form button[type="submit"] {
  min-height: 3rem; padding: .5rem 1.5rem; border: 0; border-radius: 4px;
  background: var(--ink); color: var(--paper); font-weight: 700; cursor: pointer;
}
.error { color: var(--shu); margin: .6rem 0 0; }

/* 今日の判定 */
#result { margin-top: 3rem; }
.today { scroll-margin-top: 1rem; }
.day-row { display: flex; align-items: baseline; gap: 1rem; flex-wrap: wrap; }
.day-label { margin: 0; font-weight: 700; }
.link-btn { background: none; border: 0; padding: 0; color: var(--ai); text-decoration: underline; cursor: pointer; }
.verdict { margin: .25rem 0 1.5rem; }
.verdict-big { font-size: clamp(2.2rem, 9vw, 3.4rem); font-weight: 900; line-height: 1.2; margin: 0; }
.verdict-sub { margin: .25rem 0 0; color: var(--ink-soft); }
.verdict.is-full .verdict-big { color: var(--shu); }

/* 審査員の札 */
.board {
  list-style: none; padding: 0; margin: 0 0 1.75rem;
  display: grid; grid-template-columns: repeat(5, 1fr); gap: clamp(.35rem, 1.5vw, .8rem);
  perspective: 600px;
}
.verdict.is-full + .board { padding-bottom: .9rem; border-bottom: 3px solid var(--shu); }
.plate {
  display: flex; flex-direction: column; align-items: center; justify-content: space-between;
  aspect-ratio: 3 / 4.2; padding: .55rem .25rem .6rem; border-radius: 3px;
  transform-origin: bottom center;
}
.plate-name { font-size: clamp(.62rem, 2.4vw, .8rem); line-height: 1.3; text-align: center; font-weight: 700; }
.plate-mark { font-size: clamp(1.8rem, 8vw, 3rem); line-height: 1; }
.plate-word { font-size: clamp(.9rem, 3vw, 1.1rem); font-weight: 700; }
.plate.v2 { background: var(--ai); color: #fff; }
.plate.v1 { background: var(--paper); border: 1.5px solid var(--nibi); color: var(--ink); }
.plate.v0 { background: var(--hai); color: var(--ink-soft); }

.board.raise .plate { animation: raise .5s cubic-bezier(.2, .8, .3, 1.1) both; animation-delay: calc(var(--i) * 110ms); }
@keyframes raise {
  from { transform: rotateX(80deg) translateY(12px); opacity: 0; }
  to   { transform: none; opacity: 1; }
}

/* 理由 */
.reasons { list-style: none; padding: 0; margin: 0; border-top: 1px solid var(--hai); }
.reason {
  display: grid; grid-template-columns: 8.5rem 11rem 1fr; gap: .25rem 1rem;
  padding: .7rem 0; border-bottom: 1px solid var(--hai); align-items: baseline;
}
.reason-judge { font-weight: 700; display: flex; justify-content: space-between; gap: .5rem; }
.reason-judge b { font-family: var(--serif); }
.reason.v2 .reason-judge b { color: var(--ai); }
.reason.v0 .reason-judge b { color: var(--ink-soft); }
.reason-key { color: var(--ink-soft); font-size: .9rem; }
@media (max-width: 40rem) {
  .reason { grid-template-columns: 1fr; }
  .reason-judge { justify-content: flex-start; }
}

/* 次の満場一致 */
.next-wrap { margin-top: 3rem; }
.next { display: flex; align-items: baseline; gap: .75rem; flex-wrap: wrap; margin: 0; }
.next-date {
  font-family: var(--serif); font-size: 1.6rem; font-weight: 700; color: var(--shu);
  background: none; border: 0; padding: 0; cursor: pointer; text-decoration: underline; text-underline-offset: .25em; text-decoration-thickness: 1px;
}
span.next-date { text-decoration: none; cursor: default; }
.next-note { color: var(--ink-soft); }
.year-stats { margin: .5rem 0 0; }

/* カレンダー */
.cal-wrap { margin-top: 3rem; }
.legend { color: var(--ink-soft); font-size: .9rem; display: flex; flex-wrap: wrap; align-items: center; gap: .25rem .75rem; margin: 0 0 1.25rem; }
.legend-scale { display: inline-flex; gap: 3px; }
.legend-scale .day { width: 1.2rem; height: 1.2rem; display: inline-block; }
.calendar { display: grid; grid-template-columns: repeat(auto-fill, minmax(14.5rem, 1fr)); gap: 1.75rem 1.5rem; }
.month h3 { font-size: 1rem; margin: 0 0 .4rem; }
.grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 3px; }
.wd { font-size: .72rem; text-align: center; color: var(--ink-soft); }
.day {
  aspect-ratio: 1; border: 0; border-radius: 2px; padding: 0;
  font-size: .78rem; font-variant-numeric: tabular-nums; cursor: pointer;
  background: var(--paper); color: var(--ink);
}
.day.k0 { background: var(--paper); }
.day.k1 { background: color-mix(in srgb, var(--ai) 12%, var(--paper)); }
.day.k2 { background: color-mix(in srgb, var(--ai) 26%, var(--paper)); }
.day.k3 { background: color-mix(in srgb, var(--ai) 45%, var(--paper)); }
.day.k4 { background: var(--ai); color: #fff; }
.day.k5 { background: var(--shu); color: #fff; font-weight: 700; }
.day.out { background: transparent; color: var(--nibi); cursor: default; opacity: .5; }
.day.is-today { box-shadow: inset 0 0 0 2px var(--ink); }
.day.is-selected { outline: 2px solid var(--focus); outline-offset: 1px; }

.foot { margin-top: 4rem; padding-top: 1.25rem; border-top: 1px solid var(--hai); color: var(--ink-soft); font-size: .85rem; }
.foot p { margin: 0 0 .5rem; max-width: 40em; }

@media (prefers-reduced-motion: reduce) {
  .board.raise .plate { animation: none; }
}
