:root {
  color-scheme: light;
  --paper: #fbf8fb;
  --pattern: #efe6ef;
  --ink: #241824;
  --muted: #705f70;
  --purple: #9a69b0;
  --purple-dark: #58346c;
  --lilac: #d7bed8;
  --blue: #58c3dc;
  --blue-dark: #1599b8;
  --yellow: #fff200;
  --red: #f32c2c;
  --white: #ffffff;
}

* {
  box-sizing: border-box;
}

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

body {
  background:
    linear-gradient(60deg, transparent 40%, rgba(154, 105, 176, 0.08) 40% 44%, transparent 44%),
    linear-gradient(-60deg, transparent 40%, rgba(154, 105, 176, 0.08) 40% 44%, transparent 44%),
    var(--paper);
  background-size: 96px 160px;
  color: var(--ink);
  font-family:
    "Trebuchet MS", "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont,
    sans-serif;
  padding: 18px;
}

button {
  border: 0;
  cursor: pointer;
  font: inherit;
}

.page {
  margin: 0 auto;
  max-width: 1180px;
}

.topbar {
  align-items: center;
  display: grid;
  gap: 18px;
  grid-template-columns: 138px 1fr;
  margin: 0 auto 18px;
  max-width: 980px;
}

.badge {
  align-items: center;
  background: var(--lilac);
  border-radius: 999px;
  color: var(--ink);
  display: flex;
  font-weight: 900;
  gap: 10px;
  justify-content: end;
  min-height: 72px;
  padding: 8px 12px 8px 24px;
  position: relative;
  transform: rotate(18deg);
}

.badge span {
  font-size: 1.35rem;
  letter-spacing: 0;
}

.badge strong {
  align-items: center;
  background: var(--white);
  border-radius: 50%;
  display: flex;
  font-size: 2.6rem;
  height: 64px;
  justify-content: center;
  width: 64px;
}

.title-block {
  background: linear-gradient(180deg, var(--lilac), var(--lilac) 62%, #b77ab4 62%);
  border-radius: 48px 48px 48px 0;
  color: #090609;
  padding: 18px 42px 24px;
}

.title-block p {
  color: var(--muted);
  font-size: 0.92rem;
  font-weight: 900;
  margin: 0 0 2px;
  text-transform: uppercase;
}

.title-block h1 {
  font-size: clamp(1.65rem, 5vw, 3rem);
  line-height: 1;
  margin: 0;
}

.game-layout {
  align-items: start;
  display: grid;
  gap: 20px;
  grid-template-columns: minmax(300px, 760px) minmax(260px, 320px);
  justify-content: center;
}

.board-wrap {
  aspect-ratio: 557 / 580;
  background: #83d0e0;
  border-radius: 8px;
  box-shadow: 0 28px 70px rgba(47, 24, 62, 0.25);
  overflow: hidden;
  position: relative;
  width: 100%;
}

canvas {
  display: block;
  height: 100%;
  width: 100%;
}

.player-token {
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.34);
  display: block;
  height: clamp(36px, 6vw, 52px);
  left: 0;
  object-fit: contain;
  position: absolute;
  top: 0;
  transform: translate(-50%, -50%);
  transition:
    left 260ms ease,
    top 260ms ease;
  width: clamp(36px, 6vw, 52px);
  z-index: 2;
}

.player-token.is-waiting {
  opacity: 0.62;
  transform: translate(-50%, -50%) scale(0.88);
}

.player-token.is-hidden {
  display: none;
}

.panel {
  background: rgba(255, 255, 255, 0.86);
  border: 4px solid var(--blue);
  border-radius: 8px;
  box-shadow: 0 20px 55px rgba(47, 24, 62, 0.16);
  display: grid;
  gap: 12px;
  padding: 16px;
  position: sticky;
  top: 18px;
}

.stat-card {
  background: #f7eef8;
  border-radius: 8px;
  padding: 12px;
}

.stat-card span {
  color: var(--muted);
  display: block;
  font-size: 0.82rem;
  font-weight: 900;
  text-transform: uppercase;
}

.stat-card strong {
  color: var(--purple-dark);
  display: block;
  font-size: clamp(1.55rem, 4vw, 2.4rem);
  line-height: 1;
  margin-top: 6px;
}

.dice-view {
  align-items: center;
  display: flex;
  gap: 12px;
  margin-top: 8px;
}

.dice-view img {
  aspect-ratio: 1;
  display: block;
  filter: drop-shadow(0 8px 12px rgba(88, 52, 108, 0.22));
  height: 72px;
  object-fit: contain;
  transform-origin: center;
  width: 72px;
}

.dice-view img.is-rolling {
  animation: dice-bounce 420ms ease-in-out infinite;
}

.dice-view strong {
  margin-top: 0;
}

@keyframes dice-bounce {
  0% {
    transform: rotate(-10deg) scale(0.96);
  }

  50% {
    transform: rotate(12deg) scale(1.08);
  }

  100% {
    transform: rotate(-10deg) scale(0.96);
  }
}

.primary,
.secondary,
.modal-card button,
.answer-option {
  border-radius: 8px;
  font-weight: 900;
  min-height: 48px;
  padding: 12px 16px;
}

.primary {
  background: var(--red);
  color: var(--white);
}

.secondary,
.modal-card button {
  background: var(--blue);
  color: #08232b;
}

.primary:disabled {
  cursor: wait;
  opacity: 0.65;
}

.modal-card button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.question-box {
  border-top: 3px dotted var(--lilac);
  margin-top: 4px;
  padding-top: 14px;
}

.question-box h2 {
  color: var(--red);
  font-size: 1.5rem;
  line-height: 1;
  margin: 0 0 8px;
  text-transform: uppercase;
}

.question-box p {
  color: var(--ink);
  font-size: 1.03rem;
  line-height: 1.35;
  margin: 0;
}

.modal {
  align-items: center;
  background: rgba(21, 11, 30, 0.64);
  display: none;
  inset: 0;
  justify-content: center;
  padding: 20px;
  position: fixed;
  z-index: 10;
}

.start-screen {
  align-items: center;
  background: rgba(21, 11, 30, 0.72);
  display: flex;
  inset: 0;
  justify-content: center;
  padding: 20px;
  position: fixed;
  z-index: 12;
}

.start-screen.is-hidden {
  display: none;
}

.start-card {
  background: var(--white);
  border: 5px solid var(--blue);
  border-radius: 8px;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.28);
  max-width: 440px;
  padding: 24px;
  text-align: center;
  width: min(100%, 440px);
}

.start-card h2 {
  color: var(--purple-dark);
  font-size: clamp(1.8rem, 8vw, 2.7rem);
  line-height: 1;
  margin: 0 0 10px;
}

.start-card p {
  color: var(--muted);
  font-size: 1.05rem;
  line-height: 1.35;
  margin: 0 0 18px;
}

.mode-buttons {
  display: grid;
  gap: 10px;
}

.mode-buttons button {
  background: var(--blue);
  border-radius: 8px;
  color: #08232b;
  font-weight: 900;
  min-height: 50px;
  padding: 12px 16px;
}

.mode-buttons button:first-child {
  background: var(--red);
  color: var(--white);
}

.name-form {
  display: grid;
  gap: 12px;
}

.name-form.is-hidden,
#modeStep.is-hidden,
.name-form label.is-hidden {
  display: none;
}

.name-form label {
  color: var(--purple-dark);
  display: grid;
  font-weight: 900;
  gap: 6px;
  text-align: left;
}

.name-form input {
  border: 2px solid var(--lilac);
  border-radius: 8px;
  color: var(--ink);
  font: inherit;
  min-height: 46px;
  padding: 10px 12px;
}

.name-form input:focus {
  border-color: var(--blue);
  outline: none;
}

.leaderboard-preview {
  border-top: 3px dotted var(--lilac);
  margin-top: 18px;
  padding-top: 14px;
  text-align: left;
}

.leaderboard-preview h3 {
  color: var(--purple-dark);
  font-size: 1.2rem;
  margin: 0 0 8px;
  text-align: center;
}

.leaderboard-preview ol,
.leaderboard-list {
  display: grid;
  gap: 8px;
  list-style-position: inside;
  margin: 0;
  padding: 0;
}

.leaderboard-preview li,
.leaderboard-list li {
  background: #f7eef8;
  border-radius: 8px;
  font-weight: 900;
  padding: 9px 10px;
}

.leaderboard-preview:has(ol:empty)::after {
  color: var(--muted);
  content: "Belum ada markah.";
  display: block;
  text-align: center;
}

.modal.is-open {
  display: flex;
}

.modal-card {
  background: var(--white);
  border: 5px solid var(--blue);
  border-radius: 8px;
  max-width: 560px;
  padding: 22px;
  text-align: left;
  width: min(100%, 560px);
}

.modal-card h2 {
  color: var(--purple-dark);
  font-size: 2rem;
  margin: 0 0 10px;
  text-align: center;
}

.modal-card p {
  color: var(--ink);
  font-size: 1.2rem;
  line-height: 1.35;
  margin: 0 0 18px;
}

.answer-list {
  display: grid;
  gap: 10px;
  margin-bottom: 14px;
}

.answer-option {
  background: #f7eef8;
  border: 2px solid transparent;
  color: var(--ink);
  text-align: left;
  width: 100%;
}

.answer-option:hover:not(:disabled) {
  border-color: var(--blue);
}

.answer-option.is-correct {
  background: #dff8e8;
  border-color: #26a65b;
}

.answer-option.is-wrong {
  background: #ffe1e1;
  border-color: var(--red);
}

.answer-option:disabled {
  cursor: default;
}

.answer-feedback {
  color: var(--purple-dark);
  font-weight: 900;
  min-height: 1.5em;
  text-align: center;
}

.modal-card > button {
  display: block;
  margin-inline: auto;
  min-width: 120px;
}

.rotate-phone {
  align-items: center;
  background: rgba(21, 11, 30, 0.88);
  color: var(--white);
  display: none;
  inset: 0;
  justify-content: center;
  padding: 24px;
  position: fixed;
  text-align: center;
  z-index: 30;
}

.rotate-phone div {
  background: var(--white);
  border: 5px solid var(--blue);
  border-radius: 8px;
  color: var(--ink);
  max-width: 320px;
  padding: 22px;
}

.rotate-phone strong,
.rotate-phone span {
  display: block;
}

.rotate-phone strong {
  color: var(--purple-dark);
  font-size: 2rem;
  line-height: 1;
  margin-bottom: 10px;
}

.rotate-phone span {
  color: var(--muted);
  font-weight: 900;
  line-height: 1.35;
}

@media (max-width: 860px) and (orientation: portrait) {
  .rotate-phone {
    display: none;
  }
}

@media (max-width: 940px) and (orientation: landscape) {
  html,
  body {
    height: auto;
    overflow: auto;
  }

  body {
    align-items: start;
    padding: 8px;
  }

  .page {
    height: auto;
    max-width: 560px;
    width: 100%;
  }

  .topbar {
    display: grid;
  }

  .game-layout {
    align-items: start;
    background: transparent;
    border: 0;
    gap: 10px;
    grid-template-columns: 1fr;
    height: auto;
    overflow: visible;
  }

  .board-wrap {
    box-shadow: 0 28px 70px rgba(47, 24, 62, 0.25);
    height: auto;
    max-height: none;
    width: 100%;
  }

  .panel {
    align-content: start;
    border: 4px solid var(--blue);
    border-radius: 8px;
    box-shadow: 0 20px 55px rgba(47, 24, 62, 0.16);
    gap: 6px;
    height: auto;
    max-height: none;
    overflow: visible;
    padding: 8px;
    position: static;
  }

  .stat-card {
    padding: 8px;
  }

  .stat-card strong {
    font-size: 1.25rem;
  }

  .dice-view img {
    height: 44px;
    width: 44px;
  }

  .primary,
  .secondary,
  .modal-card button,
  .answer-option {
    min-height: 38px;
    padding: 8px 10px;
  }

  .question-box h2 {
    font-size: 1.1rem;
  }

  .question-box p {
    font-size: 0.9rem;
  }

  .modal-card {
    max-height: calc(100vh - 20px);
    overflow-y: auto;
  }
}

@media (max-width: 700px) and (orientation: landscape) {
  .panel {
    font-size: 0.82rem;
  }
}

@media (max-width: 860px) {
  .page {
    max-width: none;
    width: 100%;
  }

  .topbar {
    grid-template-columns: 88px 1fr;
    margin-bottom: 8px;
  }

  .badge {
    min-height: 58px;
    padding-left: 12px;
  }

  .badge strong {
    font-size: 2rem;
    height: 48px;
    width: 48px;
  }

  .game-layout {
    gap: 8px;
    grid-template-columns: 1fr;
  }

  .panel {
    position: static;
  }
}

@media (max-width: 520px) {
  body {
    padding: 4px;
  }

  .topbar {
    gap: 8px;
    grid-template-columns: 1fr;
  }

  .badge {
    justify-self: end;
  }

  .title-block {
    border-radius: 28px 28px 28px 0;
    padding: 12px 16px 16px;
  }
}
