:root {
  color-scheme: dark;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
}

body {
  font-family: "Trebuchet MS", "Verdana", sans-serif;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  background: #000 url("./chalkboard-bg.png") center center / cover no-repeat;
}

body.is-shell-embedded .top-controls {
  top: 14px;
  left: 14px;
  right: 14px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto auto;
  align-items: center;
  gap: 8px;
}

body.is-shell-embedded .score-orb {
  width: 100%;
  min-width: 0;
  padding: 0 10px;
  gap: 6px;
  justify-content: center;
  overflow: hidden;
}

body.is-shell-embedded .score-orb__glyph {
  font-size: 18px;
  flex: 0 0 auto;
}

body.is-shell-embedded .score-orb__value {
  min-width: 0;
  font-size: 12px;
  gap: 3px;
  white-space: nowrap;
}

body.is-shell-embedded .icon-button,
body.is-shell-embedded .mode-toggle {
  width: 44px;
  height: 44px;
}

body.is-shell-embedded .mode-toggle {
  min-width: 56px;
  padding: 0 8px;
  font-size: 12px;
  letter-spacing: 0.05em;
}

body.is-shell-embedded #exit-button {
  display: none;
}

.game-shell {
  position: relative;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
}

.top-controls {
  position: absolute;
  top: max(16px, env(safe-area-inset-top, 0px) + 10px);
  right: max(16px, env(safe-area-inset-right, 0px) + 10px);
  z-index: 2;
  display: flex;
  align-items: center;
  gap: 10px;
}

.icon-button,
.score-orb,
.mode-toggle {
  width: 52px;
  height: 52px;
  border-radius: 999px;
  border: 1.5px solid rgba(245, 242, 229, 0.58);
  background: rgba(8, 8, 8, 0.18);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.06);
  color: rgba(248, 245, 233, 0.96);
}

.icon-button,
.mode-toggle {
  display: grid;
  place-items: center;
  padding: 0;
  cursor: pointer;
  font: inherit;
  font-size: 24px;
  line-height: 1;
}

.icon-button:active {
  transform: scale(0.96);
}

.mode-toggle {
  width: auto;
  min-width: 68px;
  padding: 0 14px;
  font-size: 15px;
  font-weight: 800;
  letter-spacing: 0.08em;
}

.mode-toggle:active {
  transform: scale(0.98);
}

.mode-toggle.is-ai {
  border-color: rgba(255, 196, 128, 0.72);
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.06),
    0 0 16px rgba(255, 196, 128, 0.12);
}

.mode-toggle.is-friend {
  border-color: rgba(243, 239, 223, 0.62);
}

.icon-button:disabled {
  opacity: 0.42;
  cursor: default;
  transform: none;
}

.icon-button.is-muted {
  opacity: 0.62;
}

.icon-button.is-sound-ready {
  border-color: rgba(255, 196, 128, 0.72);
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.06),
    0 0 16px rgba(255, 196, 128, 0.12);
}

.icon-button:focus-visible,
.mode-toggle:focus-visible,
#board:focus-visible {
  outline: 2px solid rgba(245, 242, 229, 0.78);
  outline-offset: 3px;
}

.score-orb {
  width: auto;
  min-width: 116px;
  padding: 0 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.score-orb__glyph {
  font-size: 22px;
  font-weight: 700;
  opacity: 0.95;
}

.score-orb__value {
  display: inline-flex;
  align-items: baseline;
  gap: 4px;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.score-divider {
  opacity: 0.45;
}

#board {
  position: absolute;
  inset: 0;
  margin: auto;
  width: min(100vw, 100vh);
  width: min(100vw, 100dvh);
  height: min(100vw, 100vh);
  height: min(100vw, 100dvh);
  display: block;
  touch-action: manipulation;
  background: transparent;
  outline: none;
}

.mode-modal {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(6, 7, 7, 0.42);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

.mode-modal[hidden] {
  display: none;
}

.mode-modal__panel {
  width: min(100%, 360px);
  padding: 26px 22px 22px;
  border-radius: 28px;
  border: none;
  background:
    radial-gradient(circle at 20% 18%, rgba(255, 255, 255, 0.035), transparent 28%),
    radial-gradient(circle at 82% 30%, rgba(255, 255, 255, 0.025), transparent 26%),
    rgba(9, 11, 10, 0.78);
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.32);
  text-align: center;
  overflow: hidden;
}

.mode-modal__panel::before,
.mode-modal__panel::after {
  content: "";
  position: absolute;
  inset: 10px;
  border-radius: 22px;
  pointer-events: none;
}

.mode-modal__panel::before {
  border: 2px solid rgba(243, 239, 223, 0.68);
  opacity: 0.9;
  transform: rotate(-0.7deg) scale(0.995, 1.008);
  filter: drop-shadow(0 0 8px rgba(243, 239, 223, 0.08));
}

.mode-modal__panel::after {
  inset: 15px 13px 13px 15px;
  border: 1.5px solid rgba(243, 239, 223, 0.3);
  transform: rotate(0.85deg) scale(1.004, 0.994);
  opacity: 0.72;
}

.mode-modal__eyebrow {
  margin: 0 0 8px;
  font-family: "Marker Felt", "Bradley Hand", "Segoe Print", "Comic Sans MS", cursive;
  font-size: 12px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: rgba(248, 245, 233, 0.56);
}

.mode-modal__title {
  margin: 0 0 16px;
  font-family: "Marker Felt", "Bradley Hand", "Segoe Print", "Comic Sans MS", cursive;
  font-size: 24px;
  font-weight: 700;
  line-height: 1.1;
  color: rgba(248, 245, 233, 0.96);
  text-shadow: 0 0 10px rgba(243, 239, 223, 0.08);
}

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

.mode-modal__button {
  width: 100%;
  position: relative;
  min-height: 56px;
  border: none;
  border-radius: 999px;
  background:
    linear-gradient(180deg, rgba(248, 245, 233, 0.05), rgba(248, 245, 233, 0.02)),
    rgba(248, 245, 233, 0.02);
  color: rgba(248, 245, 233, 0.96);
  font-family: "Marker Felt", "Bradley Hand", "Segoe Print", "Comic Sans MS", cursive;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 0.02em;
  cursor: pointer;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.03);
  overflow: hidden;
}

.mode-modal__button::before,
.mode-modal__button::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
}

.mode-modal__button::before {
  inset: 3px 4px 4px 3px;
  border: 2px solid rgba(243, 239, 223, 0.6);
  transform: rotate(-0.8deg) scale(0.994, 1.01);
}

.mode-modal__button::after {
  inset: 6px 8px 7px 7px;
  border: 1px solid rgba(243, 239, 223, 0.24);
  transform: rotate(0.75deg) scale(1.003, 0.992);
}

.mode-modal__button:active {
  transform: scale(0.98);
}

.mode-modal__button:hover {
  background:
    linear-gradient(180deg, rgba(248, 245, 233, 0.08), rgba(248, 245, 233, 0.03)),
    rgba(248, 245, 233, 0.03);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  clip-path: inset(50%);
  border: 0;
  white-space: nowrap;
}

@media (max-width: 640px) {
  .top-controls {
    gap: 8px;
  }

  .icon-button,
  .score-orb,
  .mode-toggle {
    width: 48px;
    height: 48px;
  }

  .score-orb {
    min-width: 104px;
    padding: 0 12px;
  }

  .mode-toggle {
    min-width: 60px;
    padding: 0 12px;
    font-size: 14px;
  }

  .score-orb__value {
    font-size: 14px;
  }
}
