:root {
  color-scheme: dark;
  font-family: Georgia, "Times New Roman", "Yu Mincho", "Hiragino Mincho ProN", serif;
  --parchment: #d8c49b;
  --ink: #21180e;
  --gold: #c99a3d;
  --deep-shadow: #090704;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: #f5ead0;
  scroll-behavior: smooth;
  background:
    linear-gradient(rgba(22, 13, 6, 0.28), rgba(9, 6, 4, 0.64)),
    repeating-linear-gradient(90deg, rgba(255, 255, 255, 0.04) 0 2px, transparent 2px 92px),
    linear-gradient(135deg, #7d694e 0%, #b49a74 28%, #7b603f 55%, #3a2a1c 100%);
}

button,
input {
  font: inherit;
}

.hall {
  min-height: 100vh;
  padding: clamp(18px, 3vw, 42px);
  display: grid;
  place-items: center;
}

.scoreboard {
  width: min(1180px, 100%);
  min-height: min(760px, calc(100vh - 36px));
  position: relative;
  overflow: hidden;
  padding: clamp(20px, 3vw, 40px);
  border: 2px solid rgba(222, 178, 86, 0.72);
  background:
    linear-gradient(rgba(20, 13, 8, 0.7), rgba(20, 13, 8, 0.9)),
    repeating-linear-gradient(0deg, rgba(230, 202, 154, 0.08) 0 1px, transparent 1px 7px);
  box-shadow: 0 28px 80px rgba(0, 0, 0, 0.55), inset 0 0 70px rgba(230, 176, 67, 0.1);
}

.scoreboard::before,
.scoreboard::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  height: 20px;
  background: linear-gradient(90deg, #382313, #9a6a2d 12%, #e1b75e 50%, #9a6a2d 88%, #382313);
  box-shadow: 0 0 18px rgba(225, 183, 94, 0.4);
}

.scoreboard::before {
  top: 0;
}

.scoreboard::after {
  bottom: 0;
}

.board-header {
  position: relative;
  z-index: 1;
  text-align: center;
  margin-bottom: clamp(14px, 3vw, 30px);
}

.eyebrow {
  margin: 0 0 6px;
  color: #d7b86b;
  font-size: 0.78rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: clamp(2rem, 5vw, 4.4rem);
  line-height: 0.98;
  color: #f6df9f;
  text-shadow: 0 2px 0 #251405, 0 0 28px rgba(224, 174, 76, 0.34);
}

.hourglass-rail {
  position: absolute;
  inset: 138px 34px auto;
  height: 18px;
  display: grid;
  grid-template-rows: 6px 6px;
  gap: 6px;
  opacity: 0.78;
}

.view-page .hourglass-rail {
  inset: 188px 34px auto;
}

.house-tabs {
  position: sticky;
  top: 10px;
  z-index: 8;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  width: min(820px, 100%);
  margin: 18px auto 26px;
  padding: 6px;
  border: 1px solid rgba(224, 184, 97, 0.42);
  border-radius: 999px;
  background: rgba(17, 11, 6, 0.78);
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.3), inset 0 1px 0 rgba(255, 255, 255, 0.08);
  backdrop-filter: blur(8px);
}

.auth-panel {
  position: relative;
  z-index: 2;
  display: grid;
  grid-template-columns: minmax(180px, 1fr) minmax(180px, 1fr) auto auto;
  gap: 10px;
  align-items: end;
  width: min(820px, 100%);
  margin: 18px auto 24px;
  padding: 12px;
  border: 1px solid rgba(224, 184, 97, 0.42);
  background: rgba(17, 11, 6, 0.68);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08), 0 10px 24px rgba(0, 0, 0, 0.28);
}

.auth-panel label {
  display: grid;
  gap: 4px;
  color: rgba(246, 223, 159, 0.78);
  font-family: "Courier New", monospace;
  font-size: 0.68rem;
  letter-spacing: 0.12em;
}

.auth-panel input,
.auth-panel button {
  min-width: 0;
  height: 38px;
  border: 1px solid rgba(224, 184, 97, 0.46);
  border-radius: 6px;
  color: #f9e4aa;
  background: linear-gradient(#3c2814, #1d1209);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.12);
}

.auth-panel input {
  width: 100%;
  padding: 0 10px;
  font-family: "Courier New", monospace;
}

.auth-panel button {
  padding: 0 16px;
  cursor: pointer;
  font-weight: 700;
}

.auth-message {
  grid-column: 1 / -1;
  margin: 0;
  min-height: 1.2em;
  color: #f6df9f;
  font-size: 0.9rem;
  text-align: center;
}

.controls button:disabled,
.controls input:disabled,
.auth-panel input:disabled,
.auth-panel button:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

.house-tab {
  min-width: 0;
  height: 36px;
  display: grid;
  place-items: center;
  border: 1px solid color-mix(in srgb, var(--house) 64%, #f4d784);
  border-radius: 999px;
  color: #fbe7ae;
  background:
    linear-gradient(rgba(255, 255, 255, 0.08), rgba(0, 0, 0, 0.18)),
    color-mix(in srgb, var(--house) 42%, #1b1008);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.16);
  font-size: clamp(0.76rem, 1.4vw, 1rem);
  font-weight: 700;
  text-align: center;
  text-decoration: none;
  text-shadow: 0 1px 0 rgba(0, 0, 0, 0.52);
  white-space: nowrap;
}

.house-tab:hover,
.house-tab:focus {
  outline: 2px solid rgba(247, 213, 126, 0.42);
  outline-offset: 2px;
  filter: brightness(1.14);
}

.hourglass-rail span {
  background: linear-gradient(90deg, #46270d, #e2b45a 9%, #6c4519 50%, #e2b45a 91%, #46270d);
  border-radius: 999px;
}

.houses {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: clamp(14px, 2vw, 24px);
  align-items: end;
}

.house-card {
  --house: #a51f2b;
  --house-dark: #421015;
  --sand-height: 40%;
  min-width: 0;
  display: grid;
  justify-items: center;
  gap: 12px;
  padding: 12px 10px 16px;
  border: 1px solid rgba(218, 180, 91, 0.35);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.06), rgba(0, 0, 0, 0.14));
  box-shadow: inset 0 0 30px rgba(0, 0, 0, 0.23);
  scroll-margin-top: 92px;
}

.crest {
  width: min(132px, 70%);
  aspect-ratio: 0.82;
  padding: 8px;
  background: linear-gradient(145deg, #e9c66d, #7b531d 46%, #f4d87b);
  clip-path: polygon(50% 0, 93% 13%, 87% 74%, 50% 100%, 13% 74%, 7% 13%);
}

.crest-shield {
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
  background:
    radial-gradient(circle at 50% 18%, rgba(255, 255, 255, 0.22), transparent 24%),
    linear-gradient(145deg, var(--house), var(--house-dark));
  clip-path: inherit;
}

.crest-animal {
  width: 58%;
  aspect-ratio: 1;
  display: block;
  color: #f6e4b7;
  filter: drop-shadow(0 3px 0 rgba(0, 0, 0, 0.42));
}

.crest-animal::before {
  content: attr(data-symbol);
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  font-size: clamp(2.2rem, 6vw, 4.2rem);
  line-height: 1;
}

.hourglass {
  position: relative;
  width: min(150px, 72%);
  height: clamp(260px, 42vw, 380px);
  display: grid;
  grid-template-rows: 18px 1fr 18px;
  justify-items: center;
}

.hourglass::before,
.hourglass::after {
  content: "";
  position: absolute;
  top: 4px;
  bottom: 4px;
  width: 8px;
  z-index: 3;
  background: linear-gradient(90deg, #553210, #e9be62, #714714);
  border-radius: 999px;
  box-shadow: 0 0 9px rgba(255, 216, 122, 0.32);
}

.hourglass::before {
  left: -14px;
}

.hourglass::after {
  right: -14px;
}

.cap {
  width: 120%;
  height: 20px;
  z-index: 4;
  border-radius: 50%;
  background: linear-gradient(90deg, #4b2b0f, #f1c971 24%, #7f531e 50%, #f1c971 76%, #4b2b0f);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.45);
}

.top-cap {
  align-self: start;
}

.bottom-cap {
  align-self: end;
}

.glass {
  position: relative;
  width: 88%;
  height: 100%;
  overflow: hidden;
  border: 2px solid rgba(229, 215, 181, 0.42);
  border-radius: 44% 44% 24px 24px / 16% 16% 22px 22px;
  background: linear-gradient(90deg, rgba(255, 255, 255, 0.16), rgba(255, 255, 255, 0.03) 28%, rgba(255, 255, 255, 0.12) 72%, rgba(255, 255, 255, 0.22));
  box-shadow: inset 0 0 22px rgba(255, 255, 255, 0.16), 0 10px 24px rgba(0, 0, 0, 0.33);
}

.sand {
  position: absolute;
  left: 0;
  right: 0;
  background:
    radial-gradient(circle, rgba(255, 255, 255, 0.7) 0 1px, transparent 1.6px) 0 0 / 10px 10px,
    linear-gradient(180deg, color-mix(in srgb, var(--house) 92%, white), var(--house-dark));
  box-shadow: inset 0 0 26px rgba(255, 255, 255, 0.22), 0 0 20px color-mix(in srgb, var(--house) 60%, transparent);
  transition: height 520ms cubic-bezier(0.2, 0.8, 0.2, 1);
}

.bottom-sand {
  bottom: 0;
  height: var(--sand-height);
  border-radius: 54% 54% 0 0 / 16% 16% 0 0;
}

.top-sand {
  top: 0;
  height: calc(100% - var(--sand-height));
  opacity: 0.34;
  transform: scaleY(0.18);
  transform-origin: top;
}

.sand-stream {
  position: absolute;
  left: calc(50% - 2px);
  top: 13%;
  bottom: calc(var(--sand-height) + 8px);
  width: 4px;
  min-height: 20px;
  border-radius: 999px;
  background: linear-gradient(var(--house), #f7df91);
  opacity: 0.76;
  box-shadow: 0 0 12px var(--house);
}

.glass-shine {
  position: absolute;
  top: 8%;
  right: 18%;
  width: 12px;
  height: 82%;
  border-radius: 999px;
  background: linear-gradient(rgba(255, 255, 255, 0.46), transparent);
  opacity: 0.42;
}

.house-name {
  margin: 0;
  min-height: 2.6rem;
  display: grid;
  place-items: center;
  color: #f6df9f;
  font-size: clamp(1rem, 2vw, 1.45rem);
  text-align: center;
  text-transform: uppercase;
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.58);
}

.flip-score {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  width: min(168px, 92%);
}

.digit {
  position: relative;
  height: 62px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(231, 196, 119, 0.42);
  border-radius: 6px;
  color: #fbe7ae;
  background: linear-gradient(#2b2116 0 49%, #120d08 50% 100%);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.12), 0 8px 16px rgba(0, 0, 0, 0.34);
  font-family: "Courier New", monospace;
  font-size: 2.35rem;
  font-weight: 700;
  overflow: hidden;
}

.digit::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: calc(50% - 1px);
  height: 2px;
  background: rgba(0, 0, 0, 0.7);
  box-shadow: 0 -1px 0 rgba(255, 255, 255, 0.08);
}

.digit.flip {
  animation: flipDigit 300ms ease;
}

@keyframes flipDigit {
  0% {
    transform: rotateX(0deg);
    filter: brightness(1);
  }
  48% {
    transform: rotateX(-82deg);
    filter: brightness(0.58);
  }
  100% {
    transform: rotateX(0deg);
    filter: brightness(1);
  }
}

.controls {
  width: min(220px, 100%);
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 6px;
  align-items: end;
}

.controls label {
  grid-column: span 5;
  display: grid;
  gap: 4px;
  color: rgba(246, 223, 159, 0.75);
  font-family: "Courier New", monospace;
  font-size: 0.68rem;
  letter-spacing: 0.12em;
  text-align: center;
}

.point-input,
.icon-button {
  min-width: 0;
  height: 36px;
  border: 1px solid rgba(224, 184, 97, 0.46);
  color: #f9e4aa;
  background: linear-gradient(#3c2814, #1d1209);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.12);
}

.point-input {
  width: 100%;
  text-align: center;
  border-radius: 6px;
  font-family: "Courier New", monospace;
  font-size: 1.05rem;
}

.icon-button {
  border-radius: 999px;
  cursor: pointer;
  font-size: 0.82rem;
}

.icon-button:hover,
.point-input:focus {
  outline: 2px solid rgba(247, 213, 126, 0.38);
  outline-offset: 2px;
}

@media (max-width: 900px) {
  .auth-panel {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .house-tabs {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    border-radius: 18px;
  }

  .houses {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .hourglass-rail {
    display: none;
  }
}

@media (max-width: 560px) {
  .hall {
    padding: 10px;
  }

  .scoreboard {
    padding: 22px 12px;
  }

  .house-tabs {
    top: 8px;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    margin: 14px auto 18px;
  }

  .auth-panel {
    grid-template-columns: 1fr;
    margin: 14px auto 18px;
  }

  .house-tab {
    height: 34px;
    padding: 0 6px;
    white-space: normal;
    line-height: 1.1;
  }

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

  .house-card {
    grid-template-columns: 92px 1fr;
    gap: 8px 14px;
    align-items: center;
    justify-items: center;
  }

  .crest,
  .hourglass {
    grid-row: span 3;
  }

  .hourglass {
    width: 76px;
    height: 190px;
  }

  .house-name,
  .flip-score,
  .controls {
    grid-column: 2;
  }
}
