:root {
  --bg: #070504;
  --panel: rgba(15, 10, 8, 0.68);
  --panel-strong: rgba(9, 7, 6, 0.88);
  --line: rgba(218, 179, 113, 0.28);
  --line-strong: rgba(218, 179, 113, 0.5);
  --gold: #dab371;
  --ember: #d75a3f;
  --teal: #64d9ca;
  --ink: #f6efe6;
  --muted: rgba(246, 239, 230, 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: hidden;
  background:
    radial-gradient(ellipse at 52% 18%, rgba(215, 90, 63, 0.16), transparent 36%),
    radial-gradient(ellipse at 20% 82%, rgba(100, 217, 202, 0.08), transparent 34%),
    linear-gradient(180deg, #120b08, #070504 74%);
}

#scene-root,
#scene-root canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
}

#scene-root {
  z-index: 0;
}

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

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

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

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

.atmosphere {
  position: fixed;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  background:
    radial-gradient(ellipse at center, transparent 34%, rgba(7, 5, 4, 0.72) 100%),
    linear-gradient(to bottom, rgba(7, 5, 4, 0.74), transparent 24%, transparent 70%, rgba(7, 5, 4, 0.92));
}

.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;
  gap: 10px;
}

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

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

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

.mode-button.is-active {
  color: var(--ink);
  border-color: rgba(218, 179, 113, 0.56);
  background: rgba(218, 179, 113, 0.1);
}

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

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

.copy-panel,
.result-panel {
  position: fixed;
  z-index: 6;
  top: calc(92px + var(--safe-top));
  width: min(330px, calc(100vw - 48px));
  max-height: calc(100dvh - 174px - var(--safe-top) - var(--safe-bottom));
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 28px 70px var(--shadow);
  backdrop-filter: blur(16px);
  scrollbar-width: thin;
  scrollbar-color: rgba(218, 179, 113, 0.42) rgba(5, 3, 3, 0.18);
}

.copy-panel {
  left: 24px;
  padding: 20px;
}

.result-panel {
  right: 24px;
  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: 48px;
  line-height: 1.05;
  letter-spacing: 0.1em;
}

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

.lead {
  margin: 16px 0 0;
  color: var(--gold);
  line-height: 1.82;
  font-size: 14px;
}

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

.question-box textarea {
  width: 100%;
  min-height: 84px;
  resize: vertical;
  border: 1px solid rgba(218, 179, 113, 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(218, 179, 113, 0.74);
  box-shadow: 0 0 0 3px rgba(218, 179, 113, 0.1);
}

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

.guide-strip strong {
  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;
}

.result-head {
  padding-bottom: 16px;
  border-bottom: 1px solid rgba(218, 179, 113, 0.18);
}

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

.omen-item {
  min-height: 74px;
  display: grid;
  align-content: center;
  gap: 8px;
  padding: 12px;
  border: 1px solid rgba(218, 179, 113, 0.18);
  border-radius: 6px;
  background: rgba(5, 3, 3, 0.28);
}

.omen-item span {
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0.12em;
}

.omen-item strong {
  color: var(--ink);
  font-family: "Noto Serif SC", serif;
  font-size: 22px;
  line-height: 1.15;
  overflow-wrap: anywhere;
}

.ai-text {
  min-height: 126px;
  margin: 18px 0 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;
}

.flame-zone {
  position: fixed;
  z-index: 5;
  left: 50%;
  top: 44%;
  width: 118px;
  height: 118px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(218, 179, 113, 0.24);
  border-radius: 50%;
  color: rgba(246, 239, 230, 0.76);
  font-size: 12px;
  letter-spacing: 0.14em;
  pointer-events: none;
  transform: translate(-50%, -50%);
  transition: opacity 0.35s ease, transform 0.35s ease;
}

.burning .flame-zone,
.result .flame-zone {
  opacity: 0;
  transform: translate(-50%, -50%) scale(0.84);
}

.flame-zone::before,
.flame-zone span {
  content: "";
  position: absolute;
  inset: 9px;
  border-radius: 50%;
}

.flame-zone::before {
  border: 1px dashed rgba(100, 217, 202, 0.42);
}

.flame-zone span {
  inset: 0;
  background: conic-gradient(from -90deg, rgba(215, 90, 63, 0.78) var(--charge, 0%), transparent 0);
  opacity: 0.72;
  mask: radial-gradient(circle, transparent 48px, #000 49px);
}

.flame-zone strong {
  position: relative;
  z-index: 1;
  color: var(--gold);
  font-size: 12px;
  font-weight: 500;
}

.control-rail {
  position: fixed;
  z-index: 7;
  left: 50%;
  bottom: calc(22px + var(--safe-bottom));
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 10px;
  width: min(640px, calc(100vw - 32px));
  padding: 12px;
  border: 1px solid rgba(218, 179, 113, 0.22);
  border-radius: 8px;
  background: rgba(7, 5, 4, 0.54);
  box-shadow: 0 22px 54px rgba(0, 0, 0, 0.36);
  backdrop-filter: blur(16px);
  transform: translateX(-50%);
}

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

.primary {
  min-width: 150px;
  background: linear-gradient(180deg, rgba(218, 179, 113, 0.94), rgba(145, 77, 39, 0.96));
  color: #170907;
  font-weight: 700;
}

.secondary {
  border-color: var(--line-strong);
  background: rgba(218, 179, 113, 0.08);
}

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

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

.hold-button.is-holding {
  border-color: rgba(215, 90, 63, 0.56);
  box-shadow:
    0 0 0 4px rgba(215, 90, 63, 0.1),
    0 0 30px rgba(215, 90, 63, 0.18);
}

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

@media (max-width: 1080px) {
  .copy-panel,
  .result-panel {
    position: relative;
    top: auto;
    left: auto;
    right: auto;
    width: calc(100% - 36px);
    max-height: none;
    margin: 14px 18px 0;
  }

  .copy-panel {
    margin-top: 8px;
  }

  .result-panel {
    margin-bottom: 132px;
  }

  .stage {
    overflow-y: auto;
  }

  #scene-root,
  #scene-root canvas,
  #camera-video,
  #gesture-canvas,
  .atmosphere {
    position: fixed;
  }

  .flame-zone {
    top: 50%;
  }
}

@media (max-width: 720px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
    gap: 10px;
    padding: calc(14px + var(--safe-top)) 18px 8px;
  }

  .top-actions {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 76px;
    width: 100%;
    gap: 8px;
  }

  .mode-switch {
    width: 100%;
    min-width: 0;
    gap: 4px;
  }

  .mode-button {
    min-width: 0;
    padding: 0 8px;
    flex: 1;
  }

  .sound-button {
    width: 76px;
    padding: 0 8px;
    letter-spacing: 0.04em;
  }

  h1 {
    font-size: 38px;
  }

  .copy-panel,
  .result-panel {
    width: calc(100% - 28px);
    margin-left: 14px;
    margin-right: 14px;
    padding: 16px;
    background: rgba(15, 10, 8, 0.58);
  }

  .copy-panel {
    margin-top: 6px;
  }

  .lead {
    margin-top: 12px;
    font-size: 13px;
    line-height: 1.68;
  }

  .question-box {
    margin-top: 12px;
  }

  .question-box textarea {
    min-height: 72px;
  }

  .guide-strip {
    margin-top: 12px;
    padding-top: 12px;
  }

  .result-panel {
    margin-top: clamp(128px, 24vh, 220px);
    margin-bottom: 124px;
  }

  .omen-grid {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .control-rail {
    width: calc(100vw - 24px);
    gap: 8px;
    padding: 10px;
  }

  .primary,
  .secondary,
  .ghost {
    min-height: 40px;
    padding: 0 12px;
  }
}
