:root {
  --ink: #1a0f0c;
  --paper: #fff6e8;
  --gold: #f0c14b;
  --gold-deep: #c9922a;
  --ember: #e85d3a;
  --crimson: #8b1e1e;
  --rim: #2a1510;
  --muted: rgba(255, 246, 232, 0.62);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  min-height: 100%;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  min-height: 100%;
  min-height: 100dvh;
  font-family: "Noto Sans SC", sans-serif;
  color: var(--paper);
  background: var(--ink);
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.ambiance {
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(ellipse 80% 50% at 50% -10%, rgba(232, 93, 58, 0.35), transparent 55%),
    radial-gradient(ellipse 60% 40% at 80% 80%, rgba(240, 193, 75, 0.12), transparent 50%),
    radial-gradient(ellipse 50% 40% at 10% 70%, rgba(47, 111, 106, 0.18), transparent 45%),
    linear-gradient(165deg, #2a1210 0%, #1a0f0c 45%, #0f1a18 100%);
}

.ambiance::after {
  content: "";
  position: absolute;
  inset: 0;
  opacity: 0.35;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  pointer-events: none;
  mix-blend-mode: overlay;
}

/* 房间入口：在标题上方单独一行，不遮挡「大转盘」 */
.brand-top {
  display: flex;
  justify-content: flex-start;
  align-items: center;
  min-height: 36px;
  margin-bottom: 0.35rem;
  width: 100%;
}

.room-entry-btn {
  height: 34px;
  padding: 0 0.85rem;
  border: 1px solid rgba(240, 193, 75, 0.45);
  border-radius: 999px;
  background: rgba(26, 15, 12, 0.72);
  color: var(--gold);
  font: inherit;
  font-size: 0.86rem;
  letter-spacing: 0.04em;
  cursor: pointer;
  backdrop-filter: blur(8px);
}

.room-entry-btn:active {
  transform: scale(0.97);
}

.room-bar {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  max-width: 100%;
  height: 34px;
  padding: 0 0.35rem 0 0.2rem;
  border: 1px solid rgba(240, 193, 75, 0.35);
  border-radius: 999px;
  background: rgba(26, 15, 12, 0.78);
  backdrop-filter: blur(8px);
}

.room-bar-main {
  min-width: 0;
  height: 100%;
  padding: 0 0.55rem;
  border: none;
  border-radius: 999px;
  background: transparent;
  color: inherit;
  font: inherit;
  cursor: pointer;
  text-align: left;
}

.room-bar-main:active {
  background: rgba(255, 246, 232, 0.08);
}

.room-bar[hidden],
.room-entry-btn[hidden],
.modal[hidden] {
  display: none !important;
}

.room-bar-text {
  display: block;
  font-size: 0.8rem;
  color: var(--paper);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.room-leave-btn {
  flex-shrink: 0;
  height: 26px;
  padding: 0 0.65rem;
  border: none;
  border-radius: 999px;
  background: rgba(232, 93, 58, 0.85);
  color: var(--paper);
  font: inherit;
  font-size: 0.76rem;
  cursor: pointer;
}

.modal-card-sm {
  width: min(340px, 100%);
}

.member-list {
  list-style: none;
  margin-top: 0.9rem;
  display: grid;
  gap: 0.45rem;
  max-height: min(40vh, 280px);
  overflow-y: auto;
}

.member-list li {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.55rem 0.7rem;
  border-radius: 12px;
  background: rgba(255, 246, 232, 0.06);
  border: 1px solid rgba(240, 193, 75, 0.18);
  font-size: 0.95rem;
}

.member-list .member-index {
  flex-shrink: 0;
  width: 1.4rem;
  color: var(--gold);
  font-size: 0.82rem;
}

.member-list .member-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.member-list .member-me {
  margin-left: auto;
  flex-shrink: 0;
  font-size: 0.75rem;
  color: var(--gold);
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: max(1rem, env(safe-area-inset-top)) 1rem max(1rem, env(safe-area-inset-bottom));
  background: rgba(10, 6, 5, 0.72);
  backdrop-filter: blur(6px);
}

.modal-card {
  width: min(400px, 100%);
  padding: 1.25rem 1.15rem 1.1rem;
  border-radius: 18px;
  border: 1px solid rgba(240, 193, 75, 0.28);
  background:
    radial-gradient(circle at 20% 0%, rgba(240, 193, 75, 0.12), transparent 45%),
    linear-gradient(165deg, #2a1712, #1a0f0c 60%);
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.45);
}

.modal-card h2 {
  font-family: "ZCOOL XiaoWei", serif;
  font-size: 1.55rem;
  font-weight: 400;
  color: var(--gold);
  letter-spacing: 0.08em;
}

.modal-desc {
  margin-top: 0.35rem;
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.45;
}

.modal-field {
  display: grid;
  gap: 0.4rem;
  margin-top: 0.95rem;
}

.modal-field > span {
  font-size: 0.82rem;
  color: var(--muted);
}

.modal-field input {
  height: 46px;
  padding: 0 0.9rem;
  border: 1px solid rgba(240, 193, 75, 0.28);
  border-radius: 12px;
  background: rgba(255, 246, 232, 0.06);
  color: var(--paper);
  font: inherit;
  font-size: 16px;
  outline: none;
}

.modal-field input:focus {
  border-color: rgba(240, 193, 75, 0.7);
}

.modal-error {
  margin-top: 0.7rem;
  color: #ffb4a2;
  font-size: 0.88rem;
}

.modal-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 1.1rem;
}

.modal-actions .ghost-btn,
.modal-actions .add-btn {
  flex: 1 1 auto;
  min-width: 5.5rem;
  height: 44px;
}

.app {
  width: min(960px, 100%);
  height: 100dvh;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding:
    max(0.85rem, env(safe-area-inset-top, 0px))
    max(1rem, env(safe-area-inset-right, 0px))
    0
    max(1rem, env(safe-area-inset-left, 0px));
  box-sizing: border-box;
}

/* 上半：标题 + 转盘；空间不足时压缩转盘，不裁切下方结果 */
.app-scroll {
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  padding-bottom: 0.15rem;
}

.brand {
  flex-shrink: 0;
  width: 100%;
  text-align: center;
  animation: rise-in 0.7s ease both;
}

.brand h1 {
  font-family: "ZCOOL XiaoWei", serif;
  font-size: clamp(2.2rem, 7vw, 3.6rem);
  font-weight: 400;
  letter-spacing: 0.12em;
  color: var(--gold);
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.35), 0 0 40px rgba(240, 193, 75, 0.25);
}

.brand p {
  margin-top: 0.25rem;
  color: var(--muted);
  font-size: 0.92rem;
  letter-spacing: 0.08em;
}

.stage {
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  display: grid;
  justify-items: center;
  align-content: center;
  animation: rise-in 0.8s 0.1s ease both;
  overflow: hidden;
}

.wheel-wrap {
  position: relative;
  /* 预留标题、结果、输入区、底部按钮的高度，避免结果被裁切 */
  --wheel-size: min(100%, 480px, calc(48dvh + 20px), calc(100dvh - 22rem));
  width: var(--wheel-size);
  height: var(--wheel-size);
  max-width: 100%;
  margin-top: 8px;
  overflow: visible;
  flex-shrink: 1;
}

.pointer {
  position: absolute;
  top: -6px;
  left: 50%;
  z-index: 3;
  width: 0;
  height: 0;
  transform: translateX(-50%);
  border-left: 14px solid transparent;
  border-right: 14px solid transparent;
  border-top: 34px solid var(--gold);
  filter: drop-shadow(0 4px 6px rgba(0, 0, 0, 0.45));
}

.pointer::after {
  content: "";
  position: absolute;
  top: -34px;
  left: -7px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: linear-gradient(145deg, #fff0c2, var(--gold-deep));
  box-shadow: inset 0 -2px 3px rgba(0, 0, 0, 0.25);
}

.wheel-rim {
  position: relative;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  padding: 10px;
  background:
    radial-gradient(circle at 30% 25%, rgba(255, 255, 255, 0.12), transparent 40%),
    linear-gradient(145deg, #5a3a1a, var(--rim) 40%, #3d2818);
  box-shadow:
    0 18px 50px rgba(0, 0, 0, 0.55),
    inset 0 0 0 3px rgba(240, 193, 75, 0.55),
    inset 0 0 0 8px rgba(42, 21, 16, 0.9);
}

#wheel {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  transition: transform 0s;
  will-change: transform;
}

#wheel.spinning {
  transition: transform 4.2s cubic-bezier(0.12, 0.75, 0.08, 1);
}

.spin-btn {
  position: absolute;
  inset: 50% auto auto 50%;
  z-index: 2;
  width: 78px;
  height: 78px;
  margin: -39px 0 0 -39px;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  font-family: "ZCOOL XiaoWei", serif;
  font-size: 1.35rem;
  letter-spacing: 0.08em;
  color: var(--ink);
  background: radial-gradient(circle at 35% 30%, #fff3c4, var(--gold) 55%, var(--gold-deep));
  box-shadow:
    0 6px 18px rgba(0, 0, 0, 0.4),
    inset 0 2px 0 rgba(255, 255, 255, 0.45),
    0 0 0 6px var(--rim),
    0 0 0 8px rgba(240, 193, 75, 0.65);
  transition: transform 0.15s ease, filter 0.15s ease;
}

.spin-btn:hover:not(:disabled) {
  transform: scale(1.05);
  filter: brightness(1.05);
}

.spin-btn:active:not(:disabled) {
  transform: scale(0.97);
}

.spin-btn:disabled {
  cursor: not-allowed;
  filter: grayscale(0.35) brightness(0.85);
  opacity: 0.75;
}

.result {
  flex-shrink: 0;
  min-height: 1.5em;
  margin: 0.15rem 0 0.35rem;
  padding: 0 0.5rem;
  text-align: center;
  font-size: 1.1rem;
  letter-spacing: 0.04em;
  color: var(--paper);
  line-height: 1.4;
  word-break: break-word;
}

.result strong {
  color: var(--gold);
  font-weight: 700;
}

.result.pop {
  animation: pop 0.45s ease;
}

/* 中部：输入固定，类型列表滚动 */
.panel {
  flex: 0 1 28%;
  min-height: 7.5rem;
  max-height: 32%;
  width: min(480px, 100%);
  max-width: 100%;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  animation: rise-in 0.85s 0.18s ease both;
  overflow: hidden;
}

.field {
  flex-shrink: 0;
  display: grid;
  gap: 0.45rem;
  width: 100%;
  max-width: 100%;
  min-width: 0;
}

.field > span {
  font-size: 0.85rem;
  color: var(--muted);
  letter-spacing: 0.06em;
}

.input-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 0.6rem;
  width: 100%;
  align-items: stretch;
}

.input-row input {
  width: 100%;
  min-width: 0;
  height: 48px;
  padding: 0 1rem;
  border: 1px solid rgba(240, 193, 75, 0.28);
  border-radius: 12px;
  background: rgba(255, 246, 232, 0.06);
  color: var(--paper);
  font: inherit;
  font-size: 16px;
  outline: none;
  transition: border-color 0.2s ease, background 0.2s ease;
}

.input-row input::placeholder {
  color: rgba(255, 246, 232, 0.35);
}

.input-row input:focus {
  border-color: rgba(240, 193, 75, 0.7);
  background: rgba(255, 246, 232, 0.1);
}

.add-btn,
.ghost-btn {
  height: 48px;
  padding: 0 1.1rem;
  border-radius: 12px;
  font: inherit;
  font-weight: 500;
  cursor: pointer;
  transition: transform 0.15s ease, background 0.15s ease, border-color 0.15s ease;
}

.add-btn {
  border: none;
  color: var(--ink);
  background: linear-gradient(160deg, var(--gold), var(--ember));
  flex-shrink: 0;
  white-space: nowrap;
  padding: 0 1.15rem;
  min-width: 4.75em;
}

.add-btn:hover {
  transform: translateY(-1px);
}

.chips {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
  align-content: flex-start;
  flex: 1 1 auto;
  min-height: 3rem;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 0.15rem 0.1rem 0.35rem;
  scrollbar-width: thin;
  scrollbar-color: rgba(240, 193, 75, 0.35) transparent;
}

.chips::-webkit-scrollbar {
  width: 4px;
}

.chips::-webkit-scrollbar-thumb {
  background: rgba(240, 193, 75, 0.35);
  border-radius: 999px;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  max-width: 100%;
  padding: 0.4rem 0.45rem 0.4rem 0.75rem;
  border-radius: 999px;
  background: rgba(255, 246, 232, 0.08);
  border: 1px solid rgba(240, 193, 75, 0.22);
  animation: chip-in 0.28s ease both;
}

.chip span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.92rem;
}

.chip button {
  width: 26px;
  height: 26px;
  border: none;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.25);
  color: var(--paper);
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  flex-shrink: 0;
}

.chip button:hover {
  background: rgba(232, 93, 58, 0.75);
}

/* 底部固定操作栏 */
.panel-actions {
  flex-shrink: 0;
  display: flex;
  gap: 0.75rem;
  justify-content: center;
  width: min(480px, 100%);
  margin: 0 auto;
  padding:
    0.65rem 0
    max(0.85rem, env(safe-area-inset-bottom));
  background:
    linear-gradient(180deg, transparent, rgba(26, 15, 12, 0.88) 22%, rgba(26, 15, 12, 0.98));
  z-index: 5;
}

.ghost-btn {
  border: 1px solid rgba(255, 246, 232, 0.18);
  background: rgba(26, 15, 12, 0.55);
  color: var(--muted);
}

.ghost-btn:hover {
  border-color: rgba(240, 193, 75, 0.4);
  color: var(--paper);
}

@keyframes rise-in {
  from {
    opacity: 0;
    transform: translateY(16px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes chip-in {
  from {
    opacity: 0;
    transform: scale(0.85);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes pop {
  0% {
    transform: scale(0.92);
    opacity: 0.5;
  }
  60% {
    transform: scale(1.04);
  }
  100% {
    transform: scale(1);
    opacity: 1;
  }
}

@media (max-width: 560px) {
  .app {
    padding-top: max(0.65rem, env(safe-area-inset-top));
  }

  .app-scroll {
    gap: 0.4rem;
  }

  .brand h1 {
    font-size: clamp(2rem, 10vw, 2.6rem);
    letter-spacing: 0.1em;
  }

  .brand p {
    font-size: 0.82rem;
    letter-spacing: 0.04em;
    padding: 0 0.5rem;
  }

  .wheel-wrap {
    --wheel-size: min(calc(100vw - 1.5rem), 88vw, calc(42dvh + 20px), calc(100dvh - 24rem), 400px);
    margin-top: 8px;
  }

  .wheel-rim {
    padding: 7px;
    box-shadow:
      0 12px 32px rgba(0, 0, 0, 0.5),
      inset 0 0 0 2px rgba(240, 193, 75, 0.55),
      inset 0 0 0 6px rgba(42, 21, 16, 0.9);
  }

  .spin-btn {
    width: 60px;
    height: 60px;
    margin: -30px 0 0 -30px;
    font-size: 1.05rem;
    box-shadow:
      0 4px 14px rgba(0, 0, 0, 0.4),
      inset 0 2px 0 rgba(255, 255, 255, 0.45),
      0 0 0 5px var(--rim),
      0 0 0 7px rgba(240, 193, 75, 0.65);
  }

  .spin-btn:hover:not(:disabled) {
    transform: none;
  }

  .spin-btn:active:not(:disabled) {
    transform: scale(0.96);
  }

  .pointer {
    top: -4px;
    border-left-width: 11px;
    border-right-width: 11px;
    border-top-width: 26px;
  }

  .pointer::after {
    top: -26px;
    left: -5.5px;
    width: 11px;
    height: 11px;
  }

  .result {
    font-size: 1rem;
    margin: 0.1rem 0 0.3rem;
    padding: 0 0.75rem;
  }

  .panel {
    flex: 0 1 auto;
    width: 100%;
    max-width: 100%;
    min-height: 6.5rem;
    max-height: 30%;
    gap: 0.65rem;
    padding-inline: 0;
  }

  .input-row {
    gap: 0.45rem;
    width: 100%;
  }

  .input-row input {
    height: 46px;
    border-radius: 11px;
    padding: 0 0.75rem;
  }

  .add-btn {
    flex-shrink: 0;
    width: auto;
    min-width: 4.5em;
    height: 46px;
    padding: 0 1rem;
    white-space: nowrap;
    font-size: 0.95rem;
  }

  .add-btn:hover {
    transform: none;
  }

  .chips {
    gap: 0.45rem;
  }

  .chip {
    max-width: calc(50% - 0.25rem);
    padding: 0.35rem 0.35rem 0.35rem 0.65rem;
  }

  .chip button {
    width: 28px;
    height: 28px;
  }

  .panel-actions {
    gap: 0.5rem;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
  }

  .ghost-btn {
    flex: 1;
    min-width: 0;
    height: 44px;
    padding: 0 0.75rem;
    font-size: 0.92rem;
    white-space: nowrap;
  }
}

@media (max-width: 380px) {
  .wheel-wrap {
    --wheel-size: min(calc(100vw - 1.25rem), 92vw, calc(40dvh + 20px), calc(100dvh - 23rem), 360px);
  }

  .spin-btn {
    width: 54px;
    height: 54px;
    margin: -27px 0 0 -27px;
    font-size: 0.98rem;
  }

  .brand h1 {
    letter-spacing: 0.08em;
  }

  .chip {
    max-width: 100%;
  }
}

@media (max-height: 700px) and (orientation: landscape) {
  .brand p {
    display: none;
  }

  .wheel-wrap {
    --wheel-size: min(58vh, calc(36dvh + 20px), calc(100dvh - 14rem), 300px);
  }

  .result {
    font-size: 0.95rem;
  }

  .panel {
    max-height: 36%;
    min-height: 5.5rem;
  }
}

@media (max-height: 720px) and (orientation: portrait) {
  .brand p {
    display: none;
  }

  .wheel-wrap {
    --wheel-size: min(calc(100vw - 1.5rem), 82vw, calc(38dvh + 20px), calc(100dvh - 20rem), 360px);
  }

  .panel {
    max-height: 28%;
  }
}
