:root {
  --bg: #070403;
  --panel: rgba(18, 10, 8, 0.74);
  --panel-strong: rgba(11, 7, 6, 0.9);
  --line: rgba(224, 178, 104, 0.28);
  --line-strong: rgba(224, 178, 104, 0.52);
  --wood: #b66a32;
  --gold: #e0b268;
  --red: #b94131;
  --teal: #59d7c5;
  --ink: #f6efe5;
  --muted: rgba(246, 239, 229, 0.66);
  --shadow: rgba(0, 0, 0, 0.45);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  font-family:
    "Noto Sans SC", ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-width: 320px;
  min-height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--ink);
}

button,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
}

.stage {
  position: relative;
  min-height: 100dvh;
  overflow-x: hidden;
  background:
    linear-gradient(140deg, rgba(89, 215, 197, 0.08), transparent 30%),
    radial-gradient(ellipse at 48% 18%, rgba(185, 65, 49, 0.28), transparent 48%),
    linear-gradient(180deg, #120806, #070403 68%);
}

#camera-video {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
  transform: scaleX(-1);
  filter: saturate(0.78) contrast(1.08) brightness(0.68);
  transition: opacity 0.32s ease;
}

.camera-mode #camera-video {
  opacity: 1;
}

#gesture-canvas {
  position: fixed;
  inset: 0;
  z-index: 1;
  width: 100%;
  height: 100%;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.28s ease;
}

.camera-mode #gesture-canvas {
  opacity: 1;
}

.scene-wash {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    linear-gradient(to bottom, rgba(7, 4, 3, 0.72), transparent 24%, transparent 68%, rgba(7, 4, 3, 0.9)),
    radial-gradient(ellipse at center, transparent 38%, rgba(7, 4, 3, 0.74));
}

.topbar {
  position: relative;
  z-index: 8;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: calc(18px + var(--safe-top)) 24px 12px;
}

.back-link {
  color: var(--gold);
  text-decoration: none;
  font-size: 13px;
  letter-spacing: 0.16em;
}

.top-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
}

.mode-switch {
  display: flex;
  gap: 8px;
  padding: 5px;
  border: 1px solid var(--line);
  background: rgba(7, 4, 3, 0.48);
  backdrop-filter: blur(14px);
}

.mode-button,
.sound-button,
.primary,
.secondary,
.ghost {
  min-height: 42px;
  border-radius: 4px;
  letter-spacing: 0.08em;
}

.mode-button {
  padding: 0 14px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
}

.mode-button.is-active {
  color: var(--ink);
  border-color: rgba(224, 178, 104, 0.58);
  background: rgba(224, 178, 104, 0.11);
}

.sound-button {
  padding: 0 14px;
  border: 1px solid var(--line);
  background: rgba(7, 4, 3, 0.48);
  color: var(--gold);
  backdrop-filter: blur(14px);
}

.sound-button[aria-pressed="false"] {
  color: rgba(246, 239, 229, 0.46);
  border-color: rgba(246, 239, 229, 0.16);
}

.ritual-layout {
  position: relative;
  z-index: 2;
  width: min(1360px, 100%);
  min-height: calc(100dvh - 76px);
  margin: 0 auto;
  padding: 14px 24px calc(22px + var(--safe-bottom));
  display: grid;
  grid-template-columns: minmax(260px, 0.88fr) minmax(420px, 1.24fr) minmax(300px, 0.92fr);
  gap: 18px;
  align-items: stretch;
}

.copy-panel,
.muyu-stage,
.result-panel {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 28px 70px var(--shadow);
}

.camera-mode .copy-panel,
.camera-mode .result-panel {
  background: rgba(12, 7, 6, 0.58);
}

.copy-panel,
.result-panel {
  padding: 20px;
}

.kicker {
  margin: 0;
  color: var(--teal);
  font-size: 11px;
  letter-spacing: 0.28em;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  font-family: "Noto Serif SC", serif;
}

h1 {
  margin-top: 10px;
  font-size: 58px;
  line-height: 1.04;
  letter-spacing: 0.12em;
}

h2 {
  margin-top: 8px;
  font-size: 28px;
  line-height: 1.2;
  letter-spacing: 0.08em;
}

.lead {
  margin: 18px 0 0;
  color: var(--gold);
  line-height: 1.85;
  font-size: 15px;
}

.question-box {
  display: grid;
  gap: 8px;
  margin-top: 22px;
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0.08em;
}

.question-box textarea {
  width: 100%;
  min-height: 88px;
  resize: vertical;
  border: 1px solid rgba(224, 178, 104, 0.24);
  border-radius: 6px;
  outline: none;
  background: rgba(5, 3, 3, 0.48);
  color: var(--ink);
  padding: 12px;
  line-height: 1.65;
}

.question-box textarea:focus {
  border-color: rgba(224, 178, 104, 0.74);
  box-shadow: 0 0 0 3px rgba(224, 178, 104, 0.1);
}

.guide-strip {
  display: grid;
  gap: 8px;
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid rgba(224, 178, 104, 0.18);
}

.guide-strip strong {
  color: var(--ink);
  font-family: "Noto Serif SC", serif;
  font-size: 17px;
  letter-spacing: 0.12em;
}

.guide-strip span {
  color: var(--muted);
  line-height: 1.7;
  font-size: 13px;
}

.muyu-stage {
  position: relative;
  contain: layout paint;
  min-height: 520px;
  overflow: hidden;
  padding: 22px 18px 18px;
  display: grid;
  grid-template-rows: 1fr auto auto;
  align-items: end;
  background:
    linear-gradient(180deg, rgba(224, 178, 104, 0.08), transparent 44%),
    linear-gradient(145deg, rgba(89, 215, 197, 0.08), transparent 34%),
    rgba(18, 10, 8, 0.72);
}

.muyu-stage::before {
  content: "";
  position: absolute;
  inset: 18px;
  border: 1px solid rgba(224, 178, 104, 0.12);
  border-radius: 8px;
  pointer-events: none;
}

.camera-hint {
  position: absolute;
  top: 20px;
  right: 20px;
  z-index: 3;
  min-height: 34px;
  padding: 8px 12px;
  border: 1px solid rgba(89, 215, 197, 0.34);
  border-radius: 4px;
  background: rgba(5, 3, 3, 0.58);
  color: rgba(246, 239, 229, 0.82);
  font-size: 12px;
  letter-spacing: 0.08em;
  opacity: 0;
  transform: translateY(-6px);
  transition: opacity 0.24s ease, transform 0.24s ease;
}

.camera-mode .camera-hint {
  opacity: 1;
  transform: translateY(0);
}

.merit-counter {
  position: absolute;
  left: 20px;
  top: 20px;
  z-index: 3;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 34px;
  padding: 7px 12px;
  border: 1px solid rgba(224, 178, 104, 0.34);
  border-radius: 4px;
  background: rgba(5, 3, 3, 0.5);
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0.1em;
}

.merit-counter strong {
  color: var(--gold);
  font-family: "Noto Serif SC", serif;
  font-size: 20px;
  line-height: 1;
}

.strike-zone {
  position: absolute;
  right: 7%;
  bottom: 31%;
  z-index: 2;
  width: 41%;
  height: 33%;
  border: 1px dashed rgba(89, 215, 197, 0.34);
  border-radius: 8px;
  opacity: 0;
  pointer-events: none;
}

.camera-mode .strike-zone {
  opacity: 1;
}

.strike-zone span {
  position: absolute;
  right: 10px;
  top: 10px;
  color: rgba(89, 215, 197, 0.78);
  font-size: 12px;
  letter-spacing: 0.16em;
}

.muyu-pad {
  position: relative;
  isolation: isolate;
  width: min(500px, 92%);
  aspect-ratio: 1.42;
  justify-self: center;
  align-self: center;
  margin-top: 20px;
  border: 0;
  padding: 0;
  background: transparent;
  outline: none;
  -webkit-tap-highlight-color: transparent;
}

.muyu-pad:focus-visible {
  outline: 3px solid rgba(89, 215, 197, 0.58);
  outline-offset: 8px;
}

.muyu-asset {
  position: absolute;
  z-index: 2;
  left: 50%;
  bottom: 6%;
  width: 96%;
  height: auto;
  transform: translateX(-50%);
  filter:
    drop-shadow(0 28px 34px rgba(0, 0, 0, 0.5))
    drop-shadow(0 0 24px rgba(224, 178, 104, 0.12));
  transform-origin: 50% 76%;
  will-change: transform;
}

.mallet-asset {
  position: absolute;
  z-index: 4;
  left: 39%;
  top: 29%;
  width: 40%;
  height: auto;
  transform: rotate(180deg);
  transform-origin: 78% 16%;
  opacity: 0.92;
  filter: drop-shadow(0 18px 18px rgba(0, 0, 0, 0.38));
  pointer-events: none;
  will-change: transform;
}

.muyu-shadow {
  position: absolute;
  z-index: 1;
  left: 50%;
  bottom: 4%;
  width: 82%;
  height: 16%;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.46);
  filter: blur(10px);
  transform: translateX(-50%);
}

.ripple-layer {
  position: absolute;
  inset: 0;
  z-index: 3;
  pointer-events: none;
}

.merit-layer {
  position: absolute;
  inset: 0;
  z-index: 5;
  pointer-events: none;
}

.ripple {
  position: absolute;
  left: 60%;
  top: 52%;
  width: 30px;
  height: 30px;
  border: 2px solid rgba(224, 178, 104, 0.7);
  border-radius: 50%;
  transform: translate(-50%, -50%) scale(0.3);
  animation: ripple-out 700ms ease-out forwards;
}

.merit-pop {
  position: absolute;
  left: 58%;
  top: 42%;
  min-width: 86px;
  padding: 5px 10px;
  border: 1px solid rgba(224, 178, 104, 0.42);
  border-radius: 4px;
  background: rgba(7, 4, 3, 0.66);
  color: var(--gold);
  font-family: "Noto Serif SC", serif;
  font-size: 17px;
  line-height: 1;
  letter-spacing: 0.08em;
  text-shadow: 0 0 14px rgba(224, 178, 104, 0.4);
  transform: translate(-50%, -50%);
  animation: merit-rise 900ms ease-out forwards;
  white-space: nowrap;
}

.muyu-pad.is-hit .muyu-asset {
  animation: muyu-hit 190ms ease-out;
}

.mallet-asset.is-striking {
  animation: mallet-strike 220ms ease-out;
}

.hit-meter {
  position: relative;
  z-index: 3;
  display: grid;
  gap: 10px;
  width: min(520px, 94%);
  justify-self: center;
  margin: 0 auto 16px;
}

.meter-track {
  height: 8px;
  overflow: hidden;
  border-radius: 99px;
  background: rgba(246, 239, 229, 0.12);
}

.meter-track span {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--teal), var(--gold), var(--red));
  transition: width 0.16s ease;
}

.meter-text {
  display: flex;
  justify-content: center;
  align-items: baseline;
  gap: 6px;
  color: var(--muted);
}

.meter-text strong {
  color: var(--ink);
  font-family: "Noto Serif SC", serif;
  font-size: 34px;
  line-height: 1;
}

.meter-text span {
  font-size: 13px;
  letter-spacing: 0.08em;
}

.action-row {
  position: relative;
  z-index: 3;
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 10px;
}

.primary,
.secondary,
.ghost {
  padding: 0 16px;
  border: 1px solid transparent;
  color: var(--ink);
}

.primary {
  background: linear-gradient(180deg, rgba(224, 178, 104, 0.92), rgba(141, 78, 35, 0.94));
  color: #170907;
  font-weight: 700;
}

.secondary {
  border-color: var(--line-strong);
  background: rgba(224, 178, 104, 0.08);
}

.auto-toggle[aria-pressed="true"] {
  border-color: rgba(89, 215, 197, 0.62);
  background: rgba(89, 215, 197, 0.12);
  color: var(--teal);
  box-shadow: 0 0 20px rgba(89, 215, 197, 0.08);
}

.secondary:disabled {
  color: rgba(246, 239, 229, 0.34);
  border-color: rgba(246, 239, 229, 0.12);
  background: rgba(246, 239, 229, 0.04);
}

.ghost {
  border-color: rgba(246, 239, 229, 0.18);
  background: rgba(5, 3, 3, 0.28);
  color: var(--muted);
}

.result-panel {
  display: grid;
  align-content: start;
  gap: 18px;
}

.copy-panel,
.result-panel {
  scrollbar-width: thin;
  scrollbar-color: rgba(224, 178, 104, 0.45) rgba(5, 3, 3, 0.18);
}

.copy-panel::-webkit-scrollbar,
.result-panel::-webkit-scrollbar {
  width: 8px;
}

.copy-panel::-webkit-scrollbar-track,
.result-panel::-webkit-scrollbar-track {
  background: rgba(5, 3, 3, 0.18);
}

.copy-panel::-webkit-scrollbar-thumb,
.result-panel::-webkit-scrollbar-thumb {
  border-radius: 99px;
  background: rgba(224, 178, 104, 0.45);
}

.result-head {
  padding-bottom: 16px;
  border-bottom: 1px solid rgba(224, 178, 104, 0.18);
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.metric {
  min-width: 0;
  min-height: 88px;
  display: grid;
  align-content: center;
  gap: 8px;
  padding: 12px;
  border: 1px solid rgba(224, 178, 104, 0.18);
  border-radius: 6px;
  background: rgba(5, 3, 3, 0.28);
}

.metric.wide {
  grid-column: 1 / -1;
}

.metric span,
.rhythm-line span {
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0.12em;
}

.metric strong {
  min-width: 0;
  color: var(--ink);
  font-family: "Noto Serif SC", serif;
  font-size: 28px;
  line-height: 1.12;
  overflow-wrap: anywhere;
}

.metric.wide strong {
  font-size: 22px;
}

.rhythm-line {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: center;
  padding-bottom: 14px;
  border-bottom: 1px solid rgba(224, 178, 104, 0.18);
}

.rhythm-line strong {
  color: var(--teal);
  font-size: 15px;
  letter-spacing: 0.08em;
  text-align: right;
}

.intervals-text {
  min-height: 54px;
  margin: 0;
  color: rgba(246, 239, 229, 0.54);
  line-height: 1.7;
  font-size: 13px;
}

.ai-text {
  min-height: 96px;
  margin: 0;
  color: var(--ink);
  line-height: 1.85;
  font-size: 15px;
  white-space: pre-wrap;
}

.ai-text.is-loading::after {
  content: "";
  display: inline-block;
  width: 1.2em;
  animation: dots 1.1s steps(4, end) infinite;
}

@keyframes ripple-out {
  0% {
    opacity: 0.78;
    transform: translate(-50%, -50%) scale(0.3);
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(6.6);
  }
}

@keyframes merit-rise {
  0% {
    opacity: 0;
    transform: translate(-50%, 8px) scale(0.9);
  }
  18% {
    opacity: 1;
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -62px) scale(1.08);
  }
}

@keyframes muyu-hit {
  0% {
    transform: translateX(-50%) scale(1);
  }
  42% {
    transform: translateX(-50%) translateY(7px) scale(0.985);
  }
  100% {
    transform: translateX(-50%) scale(1);
  }
}

@keyframes mallet-strike {
  0% {
    transform: rotate(180deg) translate(0, 0);
  }
  46% {
    transform: rotate(173deg) translate(-5px, 12px);
  }
  100% {
    transform: rotate(180deg) translate(0, 0);
  }
}

@keyframes dots {
  0% {
    content: "";
  }
  25% {
    content: ".";
  }
  50% {
    content: "..";
  }
  75%,
  100% {
    content: "...";
  }
}

@media (max-width: 1120px) {
  .ritual-layout {
    grid-template-columns: minmax(260px, 0.9fr) minmax(390px, 1.1fr);
  }

  .result-panel {
    grid-column: 1 / -1;
  }
}

@media (min-width: 1121px) {
  .copy-panel,
  .muyu-stage,
  .result-panel {
    max-height: calc(100dvh - 128px);
  }

  .copy-panel,
  .result-panel {
    overflow: auto;
  }
}

@media (max-width: 820px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .top-actions,
  .mode-switch {
    width: 100%;
  }

  .mode-button,
  .sound-button {
    flex: 1;
  }

  .ritual-layout {
    grid-template-columns: 1fr;
    padding-inline: 18px;
  }

  h1 {
    font-size: 48px;
  }

  .muyu-stage {
    min-height: 520px;
  }
}

@media (max-width: 460px) {
  .copy-panel,
  .result-panel {
    padding: 18px;
  }

  h1 {
    font-size: 42px;
  }

  .lead,
  .ai-text {
    font-size: 14px;
  }

  .muyu-stage {
    min-height: 470px;
    padding-inline: 12px;
  }

  .mallet-asset {
    left: 36%;
    top: 30%;
    width: 46%;
  }

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

  .metric.wide {
    grid-column: auto;
  }
}
