@font-face {
  font-family: "Russo One";
  src: url("/fonts/RussoOne-Regular.woff2") format("woff2");
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}

:root {
  --paper: #ffffff;
  --ink: #000000;
  --bg: #128f8a;
  --pink: #e31278;
  --purple: #c084fc;
  --board-h: 5.25rem;
  --logout-h: 3.25rem;
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--paper);
  font-family: "Russo One", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-text-size-adjust: 100%;
}

body {
  min-height: 100dvh;
  overflow: hidden;
  overscroll-behavior: none;
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  user-select: none;
}

.home,
.session,
.gate {
  position: fixed;
  inset: 0;
}

.gate {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(1.5rem + env(safe-area-inset-top)) 1.5rem calc(1.5rem + env(safe-area-inset-bottom));
  background: var(--bg);
}

.gate[hidden] {
  display: none;
}

.gate-form {
  width: min(100%, 22rem);
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.85rem;
}

.gate-face {
  display: block;
  width: auto;
  max-width: min(70%, 14rem);
  max-height: 34dvh;
  height: auto;
  margin: 0 auto;
  align-self: center;
  object-fit: contain;
  transform-origin: center;
}

.gate-face.is-in,
.gate-face.is-out {
  animation: face-spin 1.45s cubic-bezier(0.33, 0.2, 0.2, 1) both;
}

.gate-face.is-out {
  animation-direction: reverse;
}

.gate-fields {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  opacity: 0;
}

.gate-fields.is-in,
.gate-fields.is-out {
  animation: gate-fade 1.45s cubic-bezier(0.33, 0.2, 0.2, 1) both;
}

.gate-fields.is-out {
  animation-direction: reverse;
}

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

.home.is-in {
  animation: gate-fade 0.85s cubic-bezier(0.22, 0.61, 0.36, 1) both;
}

@keyframes face-spin {
  from {
    transform: rotate(-720deg) scale(0.12);
  }
  to {
    transform: rotate(0deg) scale(1);
  }
}

.gate-form label {
  margin: 0;
  text-align: center;
  letter-spacing: 0.16em;
}

.gate-form label {
  font-size: 0.95rem;
}

.gate-form input {
  font: inherit;
  height: 4.25rem;
  border: 0;
  background: var(--paper);
  color: var(--ink);
  text-align: center;
  font-size: 1.45rem;
  letter-spacing: 0.04em;
}

.gate-form input:focus {
  outline: 2px solid var(--paper);
  outline-offset: 3px;
}

.gate-go {
  height: 4.5rem;
  background: var(--paper);
  color: var(--ink);
  font-size: 1.7rem;
  letter-spacing: 0.14em;
}

.gate-go:active {
  background: var(--ink);
  color: var(--paper);
  box-shadow: inset 0 0 0 1px var(--paper);
}

.gate-error {
  margin: 0;
  text-align: center;
  font-size: 0.82rem;
  line-height: 1.35;
  letter-spacing: 0.03em;
  color: #ffe08a;
}

.home {
  display: grid;
  grid-template-rows: 1fr 1fr auto auto;
  background: var(--bg);
}

.home[hidden] {
  display: none;
}

.home button:not(.board-btn):not(.logout-btn) {
  font-size: clamp(4rem, 22vw, 8rem);
  font-weight: 500;
  letter-spacing: 0.06em;
  white-space: nowrap;
}

.half {
  container-type: size;
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: 0;
}

.half:first-child {
  padding-top: env(safe-area-inset-top);
}

#pick-rock,
#pick-stick {
  display: block;
  width: fit-content;
  max-width: min(92cqw, 46rem);
  line-height: 0;
}

.prompt {
  position: absolute;
  left: 0;
  right: 0;
  top: calc((100% - var(--board-h) - var(--logout-h) - env(safe-area-inset-bottom)) / 2);
  z-index: 2;
  margin: 0;
  padding: 0 1.25rem;
  transform: translateY(-50%);
  text-align: center;
  pointer-events: none;
  font-size: clamp(1.35rem, 5.4vw, 2.4rem);
  font-weight: 500;
  letter-spacing: 0.01em;
  line-height: 1.2;
}

#pick-rock img,
#pick-stick img {
  display: block;
  width: auto;
  /* Same rendered height. STICK is the wider file, so its width cap sets the shared letter size. */
  height: min(78cqh, calc(min(92cqw, 46rem) * 505 / 1624));
  max-width: min(92cqw, 46rem);
  object-fit: contain;
  image-rendering: pixelated;
  pointer-events: none;
}

.board-btn {
  height: var(--board-h);
  background: var(--pink);
  color: var(--paper);
  font-size: clamp(1.15rem, 5vw, 1.65rem);
  font-weight: 500;
  letter-spacing: 0.12em;
  white-space: nowrap;
}

.logout-btn {
  flex: none;
  width: 100%;
  height: calc(var(--logout-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--purple);
  color: var(--ink);
  font-size: clamp(1rem, 4.2vw, 1.35rem);
  font-weight: 500;
  letter-spacing: 0.14em;
  white-space: nowrap;
}

#pick-rock:active img,
#pick-stick:active img {
  filter:
    drop-shadow(0 0 1px #fff)
    drop-shadow(0 0 3px rgba(255, 255, 255, 0.95))
    drop-shadow(0 0 10px rgba(255, 255, 255, 0.55));
}

.board-btn:active {
  background: #b80d5e;
  color: var(--paper);
}

.logout-btn:active {
  background: #9a5cf0;
  color: var(--ink);
}

.session {
  display: flex;
  flex-direction: column;
  background: var(--bg);
}

.session[hidden],
.records[hidden],
.gate[hidden] {
  display: none;
}

.records {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}

.records-body {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: min(100%, 28rem);
  margin: 0 auto;
  padding: 0 1.25rem 1.25rem;
}

.records-back {
  flex: none;
  width: 100%;
  height: calc(var(--board-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
}

.records-title {
  margin: 0 0 1.75rem;
  font-size: 1rem;
  font-weight: 500;
  letter-spacing: 0.16em;
}

.board {
  list-style: none;
  width: 100%;
  margin: 0;
  padding: 0;
}

.board li {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 0.7rem;
  padding: 0.9rem 0;
  border-top: 1px solid rgba(255, 255, 255, 0.22);
  font-size: 1.15rem;
  font-weight: 500;
  letter-spacing: 0.04em;
}

.board .name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.board .stats {
  display: flex;
  gap: 0.85rem;
}

.board .stat {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  min-width: 3.1rem;
}

.board .stat-label {
  color: var(--paper);
  font-size: 0.62rem;
  letter-spacing: 0.08em;
  white-space: nowrap;
}

.board .stat-num {
  font-size: 1.45rem;
  letter-spacing: 0;
  font-variant-numeric: tabular-nums;
}

.board li:last-child {
  border-bottom: 1px solid rgba(255, 255, 255, 0.22);
}

.board .rank {
  display: grid;
  place-items: center;
  min-width: 1.85rem;
  height: 1.85rem;
  padding: 0 0.3rem;
  border: 2px solid var(--paper);
  color: var(--paper);
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.board .score {
  font-variant-numeric: tabular-nums;
}

.board-total {
  margin: 1.75rem 0 0;
  color: #9a9a9a;
  font-size: 1rem;
  letter-spacing: 0.08em;
}

.stage {
  position: relative;
  flex: 1;
  min-height: 0;
  display: grid;
  place-items: center;
}

.session-mark {
  flex: none;
  display: grid;
  place-items: center;
  padding: calc(0.7rem + env(safe-area-inset-top)) 1rem 0.15rem;
}

.session-mark img {
  display: block;
  width: auto;
  height: 3.6rem;
  max-width: min(86vw, 20rem);
  object-fit: contain;
  image-rendering: pixelated;
}

.count {
  margin: 0;
  height: 1em;
  overflow: hidden;
  font-size: clamp(7rem, 42vw, 16rem);
  font-weight: 500;
  line-height: 1;
  letter-spacing: -0.05em;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.count-roll {
  display: block;
}

.count-roll span {
  display: block;
  height: 1em;
  line-height: 1;
}

.count-roll.is-rolling {
  animation: count-roll 0.5s cubic-bezier(0.22, 0.61, 0.36, 1) forwards;
}

@keyframes count-roll {
  from {
    transform: translateY(0);
  }
  to {
    transform: translateY(-50%);
  }
}

.action {
  flex: 0 0 33dvh;
  height: 33vh;
  height: 33dvh;
  display: grid;
  place-items: center;
  background: var(--pink);
  color: var(--paper);
  font-size: clamp(3rem, 14vw, 6rem);
  font-weight: 500;
  letter-spacing: 0.08em;
}

.action:active {
  background: #b80d5e;
  color: var(--paper);
}

@media (hover: hover) and (pointer: fine) {
  #pick-rock:hover img,
  #pick-stick:hover img {
    filter:
      drop-shadow(0 0 1px #fff)
      drop-shadow(0 0 3px rgba(255, 255, 255, 0.95))
      drop-shadow(0 0 10px rgba(255, 255, 255, 0.55));
  }
}

@media (prefers-reduced-motion: reduce) {
  .count-roll.is-rolling {
    animation: none;
  }

  .gate-face.is-in,
  .gate-face.is-out,
  .gate-fields,
  .gate-fields.is-in,
  .gate-fields.is-out,
  .home.is-in {
    animation: none;
    opacity: 1;
  }
}
