:root {
  color-scheme: dark;
  --bg: #090b12;
  --panel: #121724;
  --panel-strong: #182033;
  --text: #f7f3ea;
  --muted: #b8c0d6;
  --line: rgba(226, 232, 255, 0.16);
  --gold: #c79a43;
  --gold-strong: #f1c96b;
  --ruby: #bf4055;
  --emerald: #2f9b75;
  --sapphire: #3978c8;
  --violet: #8a63d2;
  --shadow: 0 24px 80px rgba(0, 0, 0, 0.46);
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  background:
    radial-gradient(circle at 17% 10%, rgba(57, 120, 200, 0.23), transparent 28rem),
    radial-gradient(circle at 82% 4%, rgba(191, 64, 85, 0.18), transparent 26rem),
    radial-gradient(circle at 52% 100%, rgba(47, 155, 117, 0.16), transparent 32rem),
    linear-gradient(145deg, #080a12 0%, #101625 48%, #090b12 100%);
  color: var(--text);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  min-height: 100vh;
  padding: clamp(1rem, 2vw, 2rem);
}

.setup-view,
.ceremony-view {
  min-height: calc(100vh - clamp(2rem, 4vw, 4rem));
}

.setup-view {
  display: grid;
  place-items: center;
}

.setup-panel {
  width: min(760px, 100%);
  background: rgba(18, 23, 36, 0.9);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: clamp(1.25rem, 3vw, 2.5rem);
}

.eyebrow {
  margin: 0 0 0.45rem;
  color: var(--gold-strong);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
p {
  overflow-wrap: anywhere;
}

h1 {
  margin: 0;
  font-size: clamp(2rem, 5vw, 4.4rem);
  line-height: 0.95;
  letter-spacing: 0;
}

.setup-form {
  display: grid;
  gap: 1rem;
  margin-top: 1.7rem;
}

.field-label {
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 700;
}

.stepper-row {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) 44px;
  gap: 0.5rem;
  align-items: center;
}

.icon-button,
.primary-button,
.secondary-button,
.ghost-button {
  min-height: 44px;
  border: 1px solid transparent;
  border-radius: 8px;
  color: var(--text);
  font-weight: 800;
  transition:
    transform 160ms ease,
    border-color 160ms ease,
    background 160ms ease;
}

.icon-button {
  background: #202a42;
  border-color: var(--line);
  font-size: 1.35rem;
}

.primary-button {
  background: linear-gradient(180deg, #f1c96b, #c07c2f);
  color: #140d06;
  padding: 0 1.2rem;
}

.secondary-button {
  background: #172033;
  border-color: rgba(241, 201, 107, 0.32);
  padding: 0 1.2rem;
}

.ghost-button {
  background: rgba(255, 255, 255, 0.05);
  border-color: var(--line);
  padding: 0 0.9rem;
}

button:hover:not(:disabled) {
  transform: translateY(-1px);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.46;
}

input,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.055);
  color: var(--text);
  outline: none;
}

input {
  min-height: 44px;
  padding: 0 0.85rem;
}

textarea {
  min-height: 180px;
  padding: 0.85rem;
  resize: vertical;
}

input:focus,
textarea:focus {
  border-color: rgba(255, 207, 106, 0.7);
  box-shadow: 0 0 0 3px rgba(255, 207, 106, 0.13);
}

.house-name-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.8rem;
}

.house-config {
  display: grid;
  grid-template-columns: 32px minmax(0, 1fr);
  gap: 0.65rem;
  align-items: center;
}

.color-dot {
  width: 32px;
  height: 32px;
  border: 2px solid rgba(255, 255, 255, 0.36);
  border-radius: 50%;
}

.setup-actions {
  display: flex;
  justify-content: flex-end;
  padding-top: 0.4rem;
}

.is-hidden {
  display: none;
}

.top-bar {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: flex-start;
  margin: 0 auto 1rem;
  width: min(1440px, 100%);
}

.top-bar h1 {
  font-size: clamp(1.8rem, 3vw, 3.2rem);
}

.top-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 0.55rem;
}

.ceremony-grid {
  display: grid;
  grid-template-columns: minmax(330px, 460px) minmax(0, 1fr);
  gap: 1rem;
  width: min(1440px, 100%);
  margin: 0 auto;
  align-items: start;
}

.hat-stage {
  position: sticky;
  top: 1rem;
  display: grid;
  gap: 0.8rem;
}

.queue-meter {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 800;
}

.hat-box {
  position: relative;
  min-height: 560px;
  display: grid;
  justify-items: center;
  align-content: center;
  gap: 0.65rem;
  overflow: hidden;
  background:
    radial-gradient(circle at 50% 34%, rgba(241, 201, 107, 0.23), transparent 11.5rem),
    radial-gradient(circle at 19% 72%, rgba(138, 99, 210, 0.16), transparent 11rem),
    radial-gradient(circle at 85% 64%, rgba(47, 155, 117, 0.13), transparent 12rem),
    linear-gradient(180deg, rgba(20, 27, 43, 0.96), rgba(7, 9, 16, 0.98));
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 1.25rem;
}

.hat-box::before {
  content: "";
  position: absolute;
  inset: 14px;
  border: 1px solid rgba(255, 207, 106, 0.16);
  border-radius: 8px;
  pointer-events: none;
}

.hat-box.is-thinking {
  animation: boxPulse 760ms ease-in-out infinite alternate;
}

.spark {
  position: absolute;
  width: 5px;
  height: 5px;
  background: var(--gold-strong);
  border-radius: 50%;
  box-shadow: 0 0 18px var(--gold-strong);
  opacity: 0.65;
}

.spark-one {
  top: 24%;
  left: 21%;
  animation: floatSpark 3.2s ease-in-out infinite;
}

.spark-two {
  top: 39%;
  right: 20%;
  animation: floatSpark 2.6s ease-in-out infinite 320ms;
}

.spark-three {
  bottom: 25%;
  left: 52%;
  animation: floatSpark 3.7s ease-in-out infinite 700ms;
}

.hat-visual {
  position: relative;
  width: min(390px, 82vw);
  height: 305px;
  margin: -0.4rem 0 -0.3rem;
}

.sorting-hat-svg {
  width: 100%;
  height: 100%;
  display: block;
  overflow: visible;
}

.hat-box.is-thinking .sorting-hat-svg {
  animation: hatThink 760ms ease-in-out infinite alternate;
}

.hat-box.is-thinking .hat-mouth-svg {
  transform-origin: 50% 70%;
  animation: mouthMutter 520ms ease-in-out infinite alternate;
}

.current-label {
  position: relative;
  margin: 0;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 900;
  letter-spacing: 0;
  text-transform: uppercase;
}

#currentName {
  position: relative;
  width: 100%;
  margin: 0;
  text-align: center;
  font-size: clamp(2.1rem, 5vw, 4rem);
  line-height: 1;
}

.hat-message {
  position: relative;
  min-height: 3.6rem;
  max-width: 28rem;
  margin: 0;
  color: var(--muted);
  font-size: clamp(1rem, 2vw, 1.2rem);
  font-weight: 700;
  line-height: 1.45;
  text-align: center;
}

.stage-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.7rem;
}

.houses-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 0.85rem;
}

.house-card {
  min-height: 210px;
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 0.75rem;
  background: rgba(18, 23, 36, 0.84);
  border: 1px solid var(--line);
  border-top: 5px solid var(--house-color);
  border-radius: 8px;
  padding: 1rem;
}

.house-head {
  display: flex;
  justify-content: space-between;
  align-items: start;
  gap: 0.7rem;
}

.house-title {
  margin: 0;
  font-size: 1.25rem;
  line-height: 1.1;
}

.house-count {
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  min-width: 36px;
  height: 30px;
  padding: 0 0.5rem;
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid var(--house-color);
  border-radius: 999px;
  font-weight: 900;
}

.member-list {
  display: flex;
  flex-wrap: wrap;
  align-content: flex-start;
  gap: 0.45rem;
  min-height: 96px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.member-list li {
  max-width: 100%;
  padding: 0.45rem 0.6rem;
  background: rgba(255, 255, 255, 0.055);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 999px;
  color: #fff8e8;
  font-size: 0.92rem;
  font-weight: 750;
  overflow-wrap: anywhere;
}

.member-list li.is-new {
  animation: memberPop 520ms cubic-bezier(0.18, 0.9, 0.22, 1.18);
}

.empty-house {
  color: rgba(246, 240, 223, 0.42);
  font-size: 0.94rem;
  font-weight: 700;
}

.toast {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  max-width: min(340px, calc(100vw - 2rem));
  padding: 0.75rem 0.95rem;
  background: #f6f0df;
  color: #17120f;
  border-radius: 8px;
  box-shadow: 0 16px 50px rgba(0, 0, 0, 0.35);
  font-weight: 850;
  opacity: 0;
  transform: translateY(10px);
  pointer-events: none;
  transition:
    opacity 180ms ease,
    transform 180ms ease;
}

.toast.is-visible {
  opacity: 1;
  transform: translateY(0);
}

@keyframes boxPulse {
  from {
    border-color: rgba(255, 207, 106, 0.22);
    box-shadow: 0 24px 80px rgba(0, 0, 0, 0.38);
  }
  to {
    border-color: rgba(255, 207, 106, 0.68);
    box-shadow: 0 24px 90px rgba(255, 207, 106, 0.16);
  }
}

@keyframes floatSpark {
  0%,
  100% {
    transform: translate3d(0, 0, 0) scale(1);
    opacity: 0.35;
  }
  50% {
    transform: translate3d(12px, -18px, 0) scale(1.6);
    opacity: 1;
  }
}

@keyframes memberPop {
  from {
    transform: translateY(-8px) scale(0.92);
    opacity: 0;
  }
  to {
    transform: translateY(0) scale(1);
    opacity: 1;
  }
}

@keyframes hatThink {
  from {
    transform: rotate(-1deg) translateY(0);
  }
  to {
    transform: rotate(1.2deg) translateY(-5px);
  }
}

@keyframes mouthMutter {
  from {
    transform: scaleY(0.75);
  }
  to {
    transform: scaleY(1.12);
  }
}

@media (max-width: 900px) {
  .top-bar,
  .ceremony-grid {
    grid-template-columns: 1fr;
  }

  .top-bar {
    display: grid;
  }

  .top-actions {
    justify-content: stretch;
  }

  .top-actions button {
    flex: 1;
  }

  .hat-stage {
    position: static;
  }

  .hat-box {
    min-height: 500px;
  }
}

@media (max-width: 620px) {
  .app-shell {
    padding: 0.75rem;
  }

  .setup-panel {
    padding: 1rem;
  }

  .house-name-grid {
    grid-template-columns: 1fr;
  }

  .stage-actions {
    grid-template-columns: 1fr;
  }

  .hat-box {
    min-height: 450px;
  }

  .hat-visual {
    transform: scale(0.84);
    margin-bottom: -2.2rem;
  }

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