:root {
  color-scheme: light;
  --ink: #20211d;
  --muted: #5f6258;
  --paper: #f8f4e8;
  --paper-strong: #fffaf0;
  --line: #d9ceb6;
  --red: #a83232;
  --green: #276749;
  --gold: #d6a23a;
  --indigo: #323f7a;
  --shadow: 0 18px 50px rgba(32, 33, 29, 0.12);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
}

body {
  min-height: 100vh;
  margin: 0;
  overflow-x: hidden;
  color: var(--ink);
  font-family:
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    "Hiragino Sans",
    "Yu Gothic",
    sans-serif;
  background:
    linear-gradient(90deg, rgba(39, 103, 73, 0.08) 1px, transparent 1px),
    linear-gradient(rgba(39, 103, 73, 0.08) 1px, transparent 1px),
    linear-gradient(135deg, #f8f4e8 0%, #f7efe0 52%, #eef3ed 100%);
  background-size: 28px 28px, 28px 28px, auto;
}

button,
input,
a {
  font: inherit;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

.site-header {
  position: fixed;
  z-index: 10;
  top: 0;
  left: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 16px max(18px, env(safe-area-inset-left)) 0 max(18px, env(safe-area-inset-left));
  pointer-events: none;
}

.site-tag {
  display: inline-flex;
  align-items: center;
  min-height: 36px;
  padding: 0 13px;
  color: var(--ink);
  text-decoration: none;
  background: rgba(255, 250, 240, 0.88);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(32, 33, 29, 0.08);
  pointer-events: auto;
}

.site-mark {
  pointer-events: auto;
}

.site-tag {
  color: var(--muted);
  font-size: 0.9rem;
}

.temple-logo {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 48px;
  padding: 6px 16px 6px 8px;
  color: #fffaf0;
  text-decoration: none;
  background:
    linear-gradient(180deg, rgba(214, 162, 58, 0.22), transparent 42%),
    linear-gradient(135deg, #2f2119 0%, #171710 52%, #244533 100%);
  border: 1px solid rgba(214, 162, 58, 0.92);
  border-radius: 8px;
  box-shadow:
    inset 0 0 0 1px rgba(255, 250, 240, 0.08),
    0 10px 26px rgba(32, 33, 29, 0.16);
  text-shadow: 0 2px 0 rgba(32, 33, 29, 0.36);
}

.temple-logo::after {
  position: absolute;
  right: 12px;
  bottom: 5px;
  left: 48px;
  height: 1px;
  content: "";
  background: linear-gradient(90deg, rgba(214, 162, 58, 0), rgba(214, 162, 58, 0.8), rgba(214, 162, 58, 0));
}

.temple-logo__emblem {
  position: relative;
  flex: 0 0 auto;
  width: 34px;
  height: 34px;
  overflow: hidden;
  background:
    linear-gradient(135deg, rgba(255, 250, 240, 0.16), transparent 46%),
    var(--red);
  border: 2px solid var(--gold);
  border-radius: 6px;
  box-shadow:
    inset 0 0 0 1px rgba(32, 33, 29, 0.42),
    0 0 0 1px rgba(255, 250, 240, 0.16);
}

.temple-logo__emblem::before {
  position: absolute;
  inset: 6px;
  content: "";
  background:
    linear-gradient(90deg, rgba(255, 250, 240, 0.72) 1px, transparent 1px),
    linear-gradient(rgba(255, 250, 240, 0.72) 1px, transparent 1px);
  background-size: 7px 7px;
  border: 1px solid rgba(255, 250, 240, 0.62);
}

.temple-logo__emblem::after {
  position: absolute;
  inset: 10px;
  content: "";
  background: rgba(214, 162, 58, 0.92);
  border: 1px solid rgba(32, 33, 29, 0.58);
  transform: rotate(45deg);
}

.temple-logo__text {
  position: relative;
  z-index: 1;
  font-size: 1.08rem;
  font-weight: 900;
  line-height: 1;
}

.reception-logo {
  margin-bottom: 18px;
  transform: scale(1.08);
}

.app-shell {
  display: grid;
  place-items: center;
  width: 100%;
  min-height: 100vh;
  padding: 84px 16px 28px;
}

.view {
  width: min(780px, 100%);
  max-width: 100%;
  min-width: 0;
  margin: 0 auto;
  text-align: center;
}

.compact-view {
  width: min(640px, 100%);
}

.diagnosis-view {
  align-self: start;
}

.section-kicker {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 34px;
  margin-bottom: 18px;
  padding: 0 14px;
  color: #fffaf0;
  font-weight: 800;
  background: var(--red);
  border-radius: 999px;
}

h1 {
  max-width: 100%;
  margin: 0 auto 16px;
  font-size: clamp(2.4rem, 13vw, 5.7rem);
  line-height: 0.98;
  letter-spacing: 0;
  overflow-wrap: anywhere;
}

.diagnosis-view h1,
.ceremony-view h1,
.certificate-view h1,
.ascension-view h1 {
  font-size: clamp(2.1rem, 8vw, 4rem);
  line-height: 1.08;
}

.kaimyo-frame {
  display: grid;
  place-items: center;
  width: min(740px, 100%);
  min-height: clamp(168px, 31vw, 286px);
  margin: 0 auto 20px;
  padding: clamp(36px, 7vw, 76px) clamp(48px, 10vw, 112px);
  background-image: url("./kaimyo-frame.png");
  background-repeat: no-repeat;
  background-position: center;
  background-size: 100% 100%;
  filter: drop-shadow(0 16px 30px rgba(32, 33, 29, 0.16));
}

.kaimyo-frame h1 {
  max-width: 100%;
  margin: 0;
  color: var(--ink);
  font-size: clamp(1.9rem, 6.8vw, 3.7rem);
  line-height: 1.08;
  text-shadow:
    0 2px 0 rgba(255, 250, 240, 0.82),
    0 8px 18px rgba(32, 33, 29, 0.12);
}

.lead {
  max-width: 42rem;
  margin: 0 auto 28px;
  color: var(--muted);
  font-size: 1.08rem;
  line-height: 1.8;
  overflow-wrap: anywhere;
}

.lead strong {
  color: var(--red);
  font-size: 1.2em;
}

.drop-zone {
  display: grid;
  place-items: center;
  gap: 12px;
  width: min(620px, 100%);
  max-width: 100%;
  min-width: 0;
  min-height: 260px;
  margin: 0 auto;
  padding: 30px;
  cursor: pointer;
  background: rgba(255, 250, 240, 0.9);
  border: 2px dashed var(--green);
  border-radius: 8px;
  box-shadow: var(--shadow);
  transition:
    transform 160ms ease,
    border-color 160ms ease,
    background 160ms ease;
}

.drop-zone:hover,
.drop-zone:focus-visible,
.drop-zone.is-dragging {
  background: #fffdf7;
  border-color: var(--red);
  outline: none;
  transform: translateY(-2px);
}

.drop-zone strong {
  font-size: clamp(1.4rem, 6vw, 2rem);
  overflow-wrap: anywhere;
}

.drop-zone span {
  color: var(--muted);
}

.drop-icon {
  position: relative;
  width: 96px;
  height: 96px;
  background: var(--green);
  border: 3px solid var(--ink);
  border-radius: 8px;
}

.drop-icon::before,
.drop-icon::after {
  position: absolute;
  content: "";
  background: rgba(255, 250, 240, 0.72);
}

.drop-icon::before {
  top: 0;
  left: 30px;
  width: 3px;
  height: 100%;
  box-shadow: 30px 0 rgba(255, 250, 240, 0.72);
}

.drop-icon::after {
  top: 30px;
  left: 0;
  width: 100%;
  height: 3px;
  box-shadow: 0 30px rgba(255, 250, 240, 0.72);
}

.file-input {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

.privacy-notice {
  width: min(680px, 100%);
  max-width: 680px;
  margin: 24px auto 0;
  padding: 16px 18px;
  color: var(--ink);
  font-size: clamp(1rem, 4.6vw, 1.35rem);
  font-weight: 800;
  line-height: 1.65;
  background: rgba(255, 250, 240, 0.86);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow-wrap: anywhere;
}

.primary-button,
.secondary-button,
.text-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  padding: 0 20px;
  border-radius: 8px;
  border: 1px solid transparent;
  cursor: pointer;
  font-weight: 800;
  text-decoration: none;
}

.primary-button {
  color: #fffaf0;
  background: var(--red);
  box-shadow: 0 12px 24px rgba(168, 50, 50, 0.22);
}

.secondary-button {
  color: #fffaf0;
  background: var(--indigo);
}

.text-button {
  margin-top: 12px;
  color: var(--muted);
  background: transparent;
}

.primary-button:hover,
.secondary-button:hover,
.text-button:hover {
  filter: brightness(1.04);
}

.diagnosis-start-button {
  min-width: min(320px, 100%);
  margin: -6px auto 22px;
  padding: 0 28px;
  font-size: 1.06rem;
}

.working-grid {
  display: grid;
  grid-template-columns: repeat(6, 32px);
  justify-content: center;
  gap: 5px;
  margin-top: 28px;
}

.working-line {
  min-height: 42px;
  margin: 0 auto;
  color: var(--green);
  font-size: clamp(1.1rem, 4.6vw, 1.45rem);
  font-weight: 900;
  line-height: 1.55;
  overflow-wrap: anywhere;
}

.working-grid span {
  width: 32px;
  height: 24px;
  background: rgba(39, 103, 73, 0.15);
  border: 1px solid rgba(39, 103, 73, 0.28);
  animation: cellPulse 1100ms ease-in-out infinite;
}

.working-grid span:nth-child(3n) {
  animation-delay: 120ms;
}

.working-grid span:nth-child(4n) {
  animation-delay: 240ms;
}

.diagnosis-grid {
  display: grid;
  grid-template-columns: minmax(160px, 220px) 1fr;
  gap: 16px;
  align-items: stretch;
  margin: 0 auto 18px;
}

.score-panel,
.metrics-list {
  background: rgba(255, 250, 240, 0.92);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.score-panel {
  display: grid;
  place-items: center;
  min-height: 150px;
  padding: 18px;
}

.score-panel span {
  color: var(--muted);
  font-weight: 800;
}

.score-panel strong {
  color: var(--red);
  font-size: 4rem;
  line-height: 1;
}

.metrics-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1px;
  margin: 0;
  overflow: hidden;
  text-align: left;
  background: var(--line);
}

.metrics-list div {
  padding: 16px;
  background: rgba(255, 250, 240, 0.94);
}

.metrics-list dt {
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 800;
}

.metrics-list dd {
  margin: 5px 0 0;
  font-size: 1.45rem;
  font-weight: 900;
}

.crime-list {
  display: grid;
  gap: 10px;
  margin: 20px 0 24px;
}

.crime-row {
  display: grid;
  grid-template-columns: 1fr minmax(92px, 160px);
  gap: 16px;
  align-items: center;
  min-height: 80px;
  padding: 16px;
  text-align: left;
  background: rgba(255, 250, 240, 0.92);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.crime-row strong,
.crime-row span {
  display: block;
}

.crime-row strong {
  margin-bottom: 4px;
  font-size: 1.08rem;
}

.crime-row span {
  color: var(--muted);
  line-height: 1.55;
}

.crime-meter {
  height: 12px;
  overflow: hidden;
  background: rgba(32, 33, 29, 0.12);
  border-radius: 999px;
}

.crime-meter span {
  display: block;
  height: 100%;
  background: var(--red);
}

.chant-line {
  display: grid;
  place-items: center;
  min-height: 72px;
  max-width: 42rem;
  margin: 0 auto 18px;
  color: var(--green);
  font-size: clamp(1.18rem, 5.2vw, 2.05rem);
  font-weight: 900;
  line-height: 1.38;
  overflow-wrap: anywhere;
}

.mokugyo-button {
  position: relative;
  display: grid;
  place-items: center;
  width: min(70vw, 310px);
  aspect-ratio: 1;
  margin: 0 auto 24px;
  color: #fffaf0;
  cursor: pointer;
  background: #7a4928;
  border: 5px solid #3b2417;
  border-radius: 50%;
  box-shadow:
    inset 0 -18px 0 rgba(32, 33, 29, 0.18),
    0 20px 42px rgba(32, 33, 29, 0.2);
  transition: transform 90ms ease;
}

.mokugyo-button::before {
  position: absolute;
  top: 22%;
  left: 25%;
  width: 50%;
  height: 30%;
  content: "";
  background: rgba(255, 250, 240, 0.14);
  border-radius: 50%;
}

.mokugyo-button.is-hit {
  animation: mokugyoHit 150ms ease;
}

.mokugyo-button:disabled {
  cursor: default;
  filter: saturate(0.8);
}

.mokugyo-hit {
  position: relative;
  z-index: 1;
  font-size: clamp(2.6rem, 12vw, 5rem);
  font-weight: 900;
  text-shadow: 0 3px 0 rgba(32, 33, 29, 0.24);
}

.progress-wrap {
  width: min(520px, 100%);
  height: 18px;
  margin: 0 auto 10px;
  overflow: hidden;
  background: rgba(32, 33, 29, 0.13);
  border: 1px solid rgba(32, 33, 29, 0.15);
  border-radius: 999px;
}

.progress-bar {
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, var(--green), var(--gold), var(--red));
  transition: width 120ms ease;
}

.beat-counter {
  color: var(--muted);
  font-weight: 800;
}

.beat-counter strong {
  color: var(--ink);
  font-size: 1.8rem;
}

.ascension-view {
  position: relative;
  min-height: min(620px, calc(100vh - 120px));
  display: grid;
  place-items: center;
  align-content: center;
  overflow: hidden;
}

.excel-ghost {
  position: relative;
  width: 164px;
  height: 164px;
  margin: 0 auto 30px;
  background: var(--green);
  border: 4px solid var(--ink);
  border-radius: 8px 8px 46px 46px;
  animation: ascend 2200ms ease-in forwards;
}

.excel-ghost::before,
.excel-ghost::after {
  position: absolute;
  content: "";
}

.excel-ghost::before {
  inset: 28px 24px auto;
  height: 8px;
  background: #fffaf0;
  box-shadow:
    0 34px #fffaf0,
    0 68px #fffaf0;
}

.excel-ghost::after {
  top: 20px;
  left: 50%;
  width: 8px;
  height: 108px;
  background: #fffaf0;
  box-shadow:
    -38px 0 #fffaf0,
    38px 0 #fffaf0;
  transform: translateX(-50%);
}

.particle-field {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.particle-field i {
  position: absolute;
  left: calc(8% + (var(--i) * 5%));
  bottom: 18%;
  width: 8px;
  height: 8px;
  background: var(--gold);
  border-radius: 50%;
  animation: particleRise 1800ms ease-out forwards;
  animation-delay: calc(var(--i) * 42ms);
}

.certificate-frame {
  width: min(100%, 900px);
  margin: 0 auto 14px;
  padding: 8px;
  background: rgba(255, 250, 240, 0.92);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

canvas {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 4px;
}

.toggle-line {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: 42px;
  margin-bottom: 14px;
  color: var(--muted);
  font-weight: 800;
  cursor: pointer;
}

.toggle-line input {
  width: 22px;
  height: 22px;
  accent-color: var(--red);
}

.action-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 12px;
}

@keyframes cellPulse {
  0%,
  100% {
    transform: translateY(0);
    background: rgba(39, 103, 73, 0.15);
  }

  50% {
    transform: translateY(-5px);
    background: rgba(168, 50, 50, 0.18);
  }
}

@keyframes mokugyoHit {
  0% {
    transform: scale(1);
  }

  50% {
    transform: scale(0.94);
  }

  100% {
    transform: scale(1);
  }
}

@keyframes ascend {
  0% {
    opacity: 1;
    transform: translateY(20px) rotate(0deg);
  }

  100% {
    opacity: 0;
    transform: translateY(-180px) rotate(-4deg);
  }
}

@keyframes particleRise {
  0% {
    opacity: 0;
    transform: translateY(0) scale(0.6);
  }

  20% {
    opacity: 1;
  }

  100% {
    opacity: 0;
    transform: translateY(-220px) scale(1.3);
  }
}

@media (max-width: 680px) {
  .site-header {
    padding-top: 10px;
  }

  .site-tag {
    display: none;
  }

  .app-shell {
    align-items: start;
    padding-top: 76px;
  }

  h1 {
    font-size: clamp(2.25rem, 11vw, 3.4rem);
    line-height: 1.08;
  }

  .temple-logo {
    gap: 8px;
    min-height: 44px;
    padding: 5px 12px 5px 7px;
  }

  .temple-logo::after {
    left: 42px;
  }

  .temple-logo__emblem {
    width: 30px;
    height: 30px;
  }

  .temple-logo__emblem::before {
    inset: 5px;
    background-size: 6px 6px;
  }

  .temple-logo__emblem::after {
    inset: 9px;
  }

  .temple-logo__text {
    font-size: 1rem;
  }

  .reception-logo {
    margin-bottom: 16px;
    transform: none;
  }

  .diagnosis-view h1,
  .ceremony-view h1,
  .certificate-view h1,
  .ascension-view h1 {
    font-size: clamp(1.8rem, 8.5vw, 2.6rem);
  }

  .kaimyo-frame {
    min-height: 150px;
    margin-bottom: 16px;
    padding: 34px 34px;
  }

  .kaimyo-frame h1 {
    font-size: clamp(1.5rem, 7.2vw, 2.3rem);
  }

  .diagnosis-start-button {
    margin: -4px auto 18px;
  }

  .drop-zone {
    min-height: 230px;
    padding: 24px 16px;
  }

  .diagnosis-grid {
    grid-template-columns: 1fr;
  }

  .metrics-list {
    grid-template-columns: 1fr 1fr;
  }

  .crime-row {
    grid-template-columns: 1fr;
  }

  .crime-meter {
    width: 100%;
  }

  .primary-button,
  .secondary-button {
    width: 100%;
  }

  .action-row {
    width: 100%;
  }
}

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