:root {
  --bg-ritual: #14162b;
  --bg-ritual-deep: #0c0d1c;
  --ink: #d8d3e6;
  --ink-dim: #9a93b3;
  --release-red: #6e2530;
  --release-purple: #4a3b63;
  --doll-cloth: #8a6f4e;
  --doll-cloth-dark: #6d5539;
  --doll-thread: #3a2c1e;
  --doll-patch: #7a2f2f;
  --pouch-cloth: #5b4530;

  --care-cream: #fbf2e2;
  --care-warm: #f4c98a;
  --care-cyan: #9fd6c9;

  --font-body: "PingFang SC", "Microsoft YaHei", "Noto Sans SC", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html, body {
  margin: 0;
  min-height: 100%;
}

body {
  background: radial-gradient(circle at 50% 0%, var(--bg-ritual) 0%, var(--bg-ritual-deep) 70%);
  color: var(--ink);
  font-family: var(--font-body);
  line-height: 1.6;
}

#app {
  max-width: 560px;
  margin: 0 auto;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 0 20px 48px;
}

#app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 0;
  border-bottom: 1px solid rgba(216, 211, 230, 0.12);
}

#header-title {
  font-weight: 600;
  letter-spacing: 0.04em;
}

#header-actions {
  display: flex;
  gap: 14px;
}

.link-btn {
  background: none;
  border: none;
  color: var(--ink-dim);
  font-size: 0.9rem;
  cursor: pointer;
  padding: 4px 2px;
}

.link-btn:hover {
  color: var(--ink);
}

#app-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding-top: 32px;
}

.view {
  display: flex;
  flex-direction: column;
  gap: 18px;
  animation: fade-in 0.5s ease;
}

@keyframes fade-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.ritual-title {
  font-size: 1.5rem;
  font-weight: 600;
  margin: 0;
  color: var(--ink);
}

.ritual-subtitle {
  margin: -10px 0 0;
  color: var(--ink-dim);
  font-size: 0.95rem;
}

/* ---- auth ---- */

.auth-tabs {
  display: flex;
  gap: 8px;
}

.auth-tab {
  flex: 1;
  padding: 10px;
  border-radius: 10px;
  border: 1px solid rgba(216, 211, 230, 0.2);
  background: transparent;
  color: var(--ink-dim);
  cursor: pointer;
  font-size: 0.95rem;
}

.auth-tab.active {
  background: rgba(216, 211, 230, 0.12);
  color: var(--ink);
  border-color: rgba(216, 211, 230, 0.35);
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.auth-form label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.9rem;
  color: var(--ink-dim);
}

.auth-form input {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(216, 211, 230, 0.25);
  border-radius: 8px;
  padding: 10px 12px;
  color: var(--ink);
  font-size: 1rem;
}

.auth-form input:focus {
  outline: none;
  border-color: var(--care-warm);
}

.code-row {
  display: flex;
  align-items: flex-end;
  gap: 10px;
}

.code-label {
  flex: 1;
}

.code-send-btn {
  padding: 10px 14px;
  font-size: 0.85rem;
  white-space: nowrap;
}

/* ---- write ---- */

.prompt-chips, .tag-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip {
  border: 1px solid rgba(216, 211, 230, 0.25);
  background: rgba(255, 255, 255, 0.03);
  color: var(--ink-dim);
  border-radius: 999px;
  padding: 7px 14px;
  font-size: 0.85rem;
  cursor: pointer;
}

.chip:hover {
  border-color: rgba(216, 211, 230, 0.5);
  color: var(--ink);
}

.chip.selected {
  background: var(--release-purple);
  border-color: var(--release-purple);
  color: var(--ink);
}

#text-input {
  width: 100%;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(216, 211, 230, 0.25);
  border-radius: 12px;
  padding: 14px;
  color: var(--ink);
  font-size: 1rem;
  font-family: inherit;
  resize: vertical;
}

#text-input:focus {
  outline: none;
  border-color: var(--care-warm);
}

.field-block {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.field-block > label {
  font-size: 0.9rem;
  color: var(--ink-dim);
}

.intensity-scale {
  display: flex;
  justify-content: space-between;
  font-size: 0.8rem;
  color: var(--ink-dim);
}

#intensity-value {
  color: var(--ink);
  font-weight: 600;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--release-red);
}

.primary-btn {
  background: linear-gradient(135deg, var(--release-purple), var(--release-red));
  color: var(--ink);
  border: none;
  border-radius: 10px;
  padding: 14px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  letter-spacing: 0.02em;
}

.primary-btn:hover {
  filter: brightness(1.08);
}

.primary-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.secondary-btn {
  background: transparent;
  border: 1px solid rgba(216, 211, 230, 0.3);
  color: var(--ink);
  border-radius: 10px;
  padding: 12px;
  font-size: 0.95rem;
  cursor: pointer;
}

.secondary-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.form-error {
  color: #e39a9a;
  font-size: 0.85rem;
  min-height: 1.2em;
  margin: 0;
}

/* ---- ritual stage: traditional voodoo doll, deliberately un-cute ---- */

.ritual-stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
  padding: 24px 0;
}

.doll-wrap {
  position: relative;
  width: 220px;
  height: 260px;
}

#doll-svg {
  position: absolute;
  left: 30px;
  top: 0;
  width: 160px;
  height: 220px;
}

.doll-body {
  fill: var(--doll-cloth);
  stroke: var(--doll-thread);
  stroke-width: 2.5;
}

.doll-limb {
  fill: none;
  stroke: var(--doll-cloth-dark);
  stroke-width: 10;
  stroke-linecap: round;
}

.doll-seam {
  stroke: var(--doll-thread);
  stroke-width: 1.5;
  stroke-dasharray: 5 5;
  opacity: 0.7;
}

.doll-patch {
  fill: var(--doll-patch);
  stroke: var(--doll-thread);
  stroke-width: 1.5;
  stroke-dasharray: 2 2;
  opacity: 0.85;
}

.doll-eye circle {
  fill: #16130f;
}

.doll-eye line {
  stroke: var(--care-cream);
  stroke-width: 1;
  opacity: 0.6;
}

.doll-mouth {
  fill: none;
  stroke: var(--doll-thread);
  stroke-width: 2;
  stroke-dasharray: 3 3;
  stroke-linecap: round;
}

#pouch-svg {
  position: absolute;
  left: 40px;
  bottom: -6px;
  width: 140px;
  height: 100px;
}

.pouch-body {
  fill: var(--pouch-cloth);
  stroke: var(--doll-thread);
  stroke-width: 2;
}

.pouch-tie {
  stroke: var(--doll-thread);
  stroke-width: 2;
  stroke-dasharray: 2 2;
}

.pouch-flap {
  fill: var(--pouch-cloth);
  stroke: var(--doll-thread);
  stroke-width: 2;
  transform-origin: 70px 42px;
  transition: transform 0.7s ease;
}

.doll-wrap.sealing .pouch-flap {
  transform: rotate(0deg) scaleY(1.05);
}

.paper-note {
  position: absolute;
  left: 96px;
  top: 40px;
  width: 46px;
  height: 32px;
  background: var(--care-cream);
  border: 1px solid rgba(0, 0, 0, 0.25);
  border-radius: 2px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
  opacity: 0;
  transform: translate(0, 0) rotate(0deg) scale(1);
  transition: transform 1.1s ease, opacity 0.3s ease;
}

.doll-wrap.dropping .paper-note {
  opacity: 1;
  transform: translate(-20px, 110px) rotate(50deg) scale(0.55);
}

.doll-wrap.dropped .paper-note {
  opacity: 0;
  transform: translate(-20px, 118px) rotate(60deg) scale(0.2);
}

.ritual-caption {
  color: var(--ink-dim);
  font-size: 1rem;
  text-align: center;
  min-height: 1.4em;
}

/* ---- sealed + vent ---- */

#view-vent {
  align-items: center;
  justify-content: center;
  min-height: 40vh;
}

.sealed-glow {
  width: 90px;
  height: 90px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(244, 201, 138, 0.55), rgba(244, 201, 138, 0) 70%);
  animation: breathe 2.4s ease-in-out infinite;
}

@keyframes breathe {
  0%, 100% { transform: scale(0.85); opacity: 0.6; }
  50% { transform: scale(1.15); opacity: 1; }
}

.sealed-caption {
  color: var(--ink);
  font-size: 1.05rem;
  max-width: 320px;
}

/* ---- vent stage ---- */

.vent-stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  padding: 16px 0;
}

.vent-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  text-align: center;
}

#vent-name-input {
  width: 240px;
  max-width: 80vw;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(216, 211, 230, 0.25);
  border-radius: 10px;
  padding: 10px 14px;
  color: var(--ink);
  font-size: 1rem;
  text-align: center;
}

#vent-name-input:focus {
  outline: none;
  border-color: var(--care-warm);
}

.link-btn {
  background: none;
  border: none;
  color: var(--ink-dim);
  font-size: 0.85rem;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 3px;
  padding: 4px;
}

.link-btn:hover {
  color: var(--ink);
}

.vent-mute {
  align-self: flex-end;
  background: none;
  border: none;
  font-size: 1.1rem;
  cursor: pointer;
  opacity: 0.7;
  line-height: 1;
}

.vent-mute:hover {
  opacity: 1;
}

/* the training dummy: an enlarged version of the ritual doll */
.vent-doll {
  position: relative;
  width: 240px;
  height: 330px;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.vent-doll svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  transform-origin: 50% 90%;
  filter: drop-shadow(0 12px 18px rgba(0, 0, 0, 0.35));
}

.vent-doll.shake-head svg { animation: vent-shake-head 320ms ease; }
.vent-doll.shake-body svg { animation: vent-shake-body 320ms ease; }

@keyframes vent-shake-head {
  0% { transform: rotate(0); }
  30% { transform: rotate(4deg) translateX(6px); }
  60% { transform: rotate(-2.5deg) translateX(-4px); }
  100% { transform: rotate(0); }
}

@keyframes vent-shake-body {
  0% { transform: translateX(0); }
  30% { transform: translateX(8px) skewX(-3deg); }
  60% { transform: translateX(-6px) skewX(2deg); }
  100% { transform: translateX(0); }
}

/* transparent hit targets over head + torso, boxing-glove cursor */
.vent-hit {
  position: absolute;
  border: none;
  background: transparent;
  padding: 0;
  cursor:
    url("data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20width='36'%20height='36'%20viewBox='0%200%2036%2036'%3E%3Cg%20transform='rotate(-18%2018%2018)'%3E%3Cpath%20d='M9%2013c0-6%205-8%2010-8s10%203%2010%209v6c0%206-5%208-11%208h-3c-5%200-6-4-6-8z'%20fill='%238a2b34'%20stroke='%23320f13'%20stroke-width='2'/%3E%3Cpath%20d='M9%2014c-3%200-4%202-4%204v2c0%203%202%204%204%204z'%20fill='%238a2b34'%20stroke='%23320f13'%20stroke-width='2'/%3E%3Cpath%20d='M10%2024h14'%20stroke='%23320f13'%20stroke-width='2'/%3E%3C/g%3E%3C/svg%3E")
    12 8, pointer;
}

.vent-hit[data-part="head"] { left: 28%; top: 2%; width: 44%; height: 24%; }
.vent-hit[data-part="body"] { left: 22%; top: 27%; width: 56%; height: 60%; }

.vent-hit:focus-visible {
  outline: 2px dashed rgba(216, 211, 230, 0.5);
  outline-offset: 2px;
}

/* dust burst on impact */
.vent-mark {
  position: absolute;
  width: 70px;
  height: 70px;
  border-radius: 50%;
  transform: translate(-50%, -50%) scale(0.3);
  background: radial-gradient(circle, rgba(216, 211, 230, 0.5), rgba(216, 211, 230, 0) 70%);
  opacity: 0;
  pointer-events: none;
}

.vent-mark[data-part="head"] { left: 50%; top: 14%; }
.vent-mark[data-part="body"] { left: 50%; top: 55%; }

.vent-mark.pop { animation: vent-pop 360ms ease-out; }

@keyframes vent-pop {
  0% { opacity: 0.9; transform: translate(-50%, -50%) scale(0.3); }
  100% { opacity: 0; transform: translate(-50%, -50%) scale(1.4); }
}

/* check-in popup */
.vent-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(8, 9, 20, 0.72);
  animation: vent-fade-in 0.6s ease both;
  z-index: 20;
}

@keyframes vent-fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

.vent-dialog {
  background: var(--bg-ritual);
  border: 1px solid rgba(216, 211, 230, 0.2);
  border-radius: 16px;
  padding: 24px 22px;
  max-width: 320px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  text-align: center;
}

.vent-dialog p {
  margin: 0;
  color: var(--ink);
  font-size: 1rem;
  line-height: 1.7;
}

.vent-dialog .btn-row { gap: 10px; }
.vent-dialog .btn-row button { flex: 1 1 auto; }

@media (prefers-reduced-motion: reduce) {
  .vent-doll.shake-head svg,
  .vent-doll.shake-body svg { animation-duration: 1ms; }
  .vent-mark.pop { animation-duration: 120ms; }
  .vent-overlay { animation-duration: 1ms; }
}

/* ---- history ---- */

.history-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.history-item {
  border: 1px solid rgba(216, 211, 230, 0.18);
  border-radius: 12px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.history-meta {
  display: flex;
  justify-content: space-between;
  font-size: 0.8rem;
  color: var(--ink-dim);
}

.history-text {
  margin: 0;
  color: var(--ink);
  font-size: 0.92rem;
}

.history-tags {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.history-tags span {
  background: rgba(216, 211, 230, 0.1);
  border-radius: 999px;
  padding: 3px 10px;
  font-size: 0.75rem;
  color: var(--ink-dim);
}

.history-delete {
  align-self: flex-end;
  background: none;
  border: none;
  color: #e39a9a;
  cursor: pointer;
  font-size: 0.82rem;
}

.history-empty {
  color: var(--ink-dim);
  font-size: 0.9rem;
}

/* ---- admin settings ---- */

.settings-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 18px;
  border: 1px solid rgba(216, 211, 230, 0.16);
  border-radius: 14px;
}

.settings-title {
  margin: 0 0 4px;
  font-size: 1.05rem;
  color: var(--ink);
}

.settings-form label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.88rem;
  color: var(--ink-dim);
}

.settings-form input[type="text"],
.settings-form input[type="password"],
.settings-form input[type="number"] {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(216, 211, 230, 0.25);
  border-radius: 8px;
  padding: 9px 12px;
  color: var(--ink);
  font-size: 0.95rem;
}

.settings-form input:focus {
  outline: none;
  border-color: var(--care-warm);
}

.checkbox-label {
  flex-direction: row !important;
  align-items: center;
  gap: 8px !important;
}

.checkbox-label input {
  width: auto;
}

.form-success {
  color: var(--care-cyan);
  font-size: 0.85rem;
  margin: 0;
  min-height: 1.2em;
}

.settings-hint {
  margin: -4px 0 0;
  font-size: 0.78rem;
  color: var(--ink-dim);
  opacity: 0.8;
}

.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.btn-row .secondary-btn {
  flex: 1 1 auto;
}

.model-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  max-height: 168px;
  overflow-y: auto;
  padding: 4px;
  border: 1px solid rgba(216, 211, 230, 0.16);
  border-radius: 10px;
}

.model-list .chip {
  font-size: 0.8rem;
}
