:root {
  color-scheme: dark;
  --table-aspect: 1100 / 620;
  --table-ratio: 1.774193548;
  --table-landscape-width: 177.4193548svh;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #04171f;
  color: #f7fbff;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  min-height: 100%;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  background:
    radial-gradient(circle at 50% 15%, rgba(41, 190, 205, 0.18), transparent 35%),
    linear-gradient(135deg, #06131b, #072b37 45%, #041017);
}

button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.55rem;
  border: 0;
  border-radius: 999px;
  min-height: 48px;
  padding: 0.78rem 1.2rem;
  background: linear-gradient(180deg, #f9c45c, #df8e24);
  color: #2a1603;
  font: inherit;
  font-weight: 800;
  line-height: 1;
  cursor: pointer;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.36),
    0 12px 28px rgba(0, 0, 0, 0.24);
  transition:
    transform 160ms ease,
    box-shadow 160ms ease,
    filter 160ms ease,
    opacity 160ms ease;
}

button:hover:not(:disabled) {
  transform: translateY(-1px);
  filter: brightness(1.05);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.44),
    0 16px 34px rgba(0, 0, 0, 0.3);
}

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

button:disabled {
  cursor: not-allowed;
  opacity: 0.42;
  filter: saturate(0.55);
}

.game-shell {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: clamp(8px, 1.4vh, 14px);
  min-height: 100vh;
  min-height: 100dvh;
  height: 100vh;
  height: 100dvh;
  padding: clamp(8px, 1.5vw, 18px);
}

.topbar,
.controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: min(1180px, 100%);
  margin: 0 auto;
}

.topbar h1,
.eyebrow {
  margin: 0;
}

.topbar h1 {
  font-size: clamp(1.45rem, 3vw, 2.65rem);
  letter-spacing: -0.04em;
}

.eyebrow {
  color: #7ee7f2;
  font-size: 0.78rem;
  font-weight: 900;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

.status-card {
  display: grid;
  justify-items: end;
  gap: 4px;
  min-width: min(430px, 48vw);
  padding: 12px 14px;
  border: 1px solid rgba(126, 231, 242, 0.22);
  border-radius: 18px;
  background: rgba(3, 14, 20, 0.65);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.05);
}

#game-status {
  color: #ffffff;
  font-weight: 800;
}

#room-status {
  min-height: 1.1em;
  color: #a6c7cf;
  font-size: 0.9rem;
}

.table-wrap {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 0;
  width: min(1180px, 100%, calc((100dvh - 190px) * var(--table-ratio)));
  margin: 0 auto;
  padding: clamp(6px, 1.2vw, 12px);
  aspect-ratio: var(--table-aspect);
  border: 1px solid rgba(126, 231, 242, 0.18);
  border-radius: 28px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.08), transparent),
    rgba(2, 10, 15, 0.72);
  box-shadow: 0 22px 70px rgba(0, 0, 0, 0.35);
}

#pool-canvas {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: var(--table-aspect);
  border-radius: 24px;
  touch-action: none;
}

.turn-banner {
  position: absolute;
  left: 50%;
  bottom: clamp(18px, 4vh, 42px);
  transform: translateX(-50%);
  max-width: min(780px, calc(100% - 32px));
  padding: 10px 16px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 999px;
  background: rgba(3, 16, 23, 0.76);
  color: #ecfbff;
  font-weight: 800;
  text-align: center;
  backdrop-filter: blur(12px);
}

.controls {
  justify-content: center;
  flex-wrap: wrap;
  padding: 8px;
  border: 1px solid rgba(126, 231, 242, 0.12);
  border-radius: 28px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.06), transparent),
    rgba(2, 13, 18, 0.58);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04);
}

.control-button {
  min-width: clamp(150px, 18vw, 230px);
  min-height: 44px;
  padding-block: 0.68rem;
  white-space: nowrap;
}

.control-button--primary {
  background: linear-gradient(180deg, #ffd76a, #ef9c1d);
}

.control-button--share {
  background: linear-gradient(180deg, #ffe48a, #f1a526);
}

.control-button--home {
  background: linear-gradient(180deg, #f8bd58, #e18a22);
}

.button-icon {
  display: grid;
  place-items: center;
  width: 1.35rem;
  height: 1.35rem;
  border-radius: 999px;
  background: rgba(58, 30, 4, 0.12);
  color: currentColor;
  flex: 0 0 auto;
}

.button-icon svg {
  width: 1rem;
  height: 1rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.4;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.orientation-hint {
  display: none;
}

.orientation-card {
  display: grid;
  justify-items: center;
  gap: 12px;
  width: min(360px, calc(100vw - 40px));
  padding: 22px;
  border: 1px solid rgba(126, 231, 242, 0.24);
  border-radius: 24px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.08), transparent),
    rgba(4, 20, 28, 0.95);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.46);
  text-align: center;
}

.orientation-card svg {
  width: 54px;
  height: 54px;
  fill: none;
  stroke: #ffd76a;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.orientation-card p {
  margin: 0;
  color: #ecfbff;
  font-size: 1rem;
  font-weight: 900;
  line-height: 1.35;
}

.auth-gate {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 20px;
  background:
    radial-gradient(circle at 50% 35%, rgba(45, 206, 217, 0.16), transparent 34%),
    rgba(2, 10, 15, 0.74);
  backdrop-filter: blur(10px);
}

.auth-gate[hidden] {
  display: none;
}

.auth-card {
  width: min(420px, 100%);
  padding: 24px;
  border: 1px solid rgba(126, 231, 242, 0.22);
  border-radius: 24px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.08), transparent),
    rgba(4, 20, 28, 0.94);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.46);
  text-align: center;
}

.auth-eyebrow {
  margin: 0 0 6px;
  color: #7ee7f2;
  font-size: 0.72rem;
  font-weight: 900;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

.auth-card h2 {
  margin: 0;
  font-size: clamp(1.35rem, 4vw, 1.9rem);
  letter-spacing: -0.04em;
}

.auth-card p {
  color: #b7d5dc;
  font-weight: 700;
  line-height: 1.45;
}

.google-signin {
  display: grid;
  place-items: center;
  min-height: 44px;
  margin-top: 16px;
}

.auth-back {
  margin: 14px auto 0;
  min-height: 42px;
  padding: 0.68rem 1rem;
  background: rgba(126, 231, 242, 0.1);
  color: #ecfbff;
  border: 1px solid rgba(126, 231, 242, 0.22);
  box-shadow: none;
}

.auth-error {
  min-height: 1.2em;
  margin: 12px 0 0;
  color: #ffb4a8;
  font-size: 0.88rem;
}

@media (max-width: 760px) {
  body {
    overflow: auto;
  }

  .game-shell {
    min-height: 100svh;
  }

  .topbar {
    align-items: stretch;
    flex-direction: column;
  }

  .status-card {
    justify-items: start;
    min-width: 0;
  }

  #pool-canvas {
    height: auto;
  }

  button {
    flex: 1 1 150px;
  }

  .controls {
    gap: 8px;
    padding: 8px;
  }

  .control-button {
    min-width: 0;
    padding-inline: 0.9rem;
  }
}

@media (orientation: portrait) and (max-width: 760px) {
  body {
    overflow: hidden;
  }

  .orientation-hint {
    position: fixed;
    inset: 0;
    z-index: 20;
    display: grid;
    place-items: center;
    padding: 20px;
    background:
      radial-gradient(circle at 50% 35%, rgba(45, 206, 217, 0.18), transparent 34%),
      rgba(2, 10, 15, 0.86);
    backdrop-filter: blur(10px);
  }
}

@media (orientation: landscape) and (max-width: 980px) and (max-height: 520px) {
  body {
    overflow: hidden;
  }

  .game-shell {
    gap: 5px;
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr);
    grid-template-areas:
      "table";
    min-height: 100svh;
    height: 100svh;
    padding: max(4px, env(safe-area-inset-top)) max(6px, env(safe-area-inset-right))
      max(4px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
  }

  .topbar {
    position: fixed;
    top: max(4px, env(safe-area-inset-top));
    right: max(6px, env(safe-area-inset-right));
    z-index: 12;
    width: auto;
    max-width: calc(100vw - 86px);
    margin: 0;
    pointer-events: none;
  }

  .table-wrap {
    grid-area: table;
  }

  .topbar {
    gap: 5px;
  }

  .topbar {
    align-items: center;
    flex-direction: row;
    justify-content: flex-end;
  }

  .topbar h1 {
    overflow: hidden;
    max-width: 28vw;
    font-size: 0.72rem;
    line-height: 1;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .eyebrow {
    display: none;
  }

  .status-card {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    min-width: 0;
    max-width: 46vw;
    padding: 4px 8px;
    border-radius: 999px;
    gap: 2px;
  }

  #game-status {
    display: none;
  }

  #room-status {
    flex: 0 0 auto;
    color: #ecfbff;
    font-size: 0.72rem;
    font-weight: 900;
    white-space: nowrap;
  }

  #room-status {
    font-size: 0;
  }

  #room-status::after {
    content: attr(data-short-status);
    font-size: 0.72rem;
  }

  #room-status::before {
    content: "";
    margin: 0;
  }

  .table-wrap {
    width: min(100%, calc(var(--table-landscape-width) - 38px));
    max-height: calc(100svh - 8px);
    padding: 4px;
    border-radius: 18px;
  }

  #pool-canvas {
    height: auto;
    border-radius: 16px;
  }

  .turn-banner {
    bottom: 10px;
    max-width: calc(100% - 20px);
    padding: 6px 10px;
    font-size: 0.72rem;
  }

  .controls {
    position: fixed;
    top: 50%;
    right: max(5px, env(safe-area-inset-right));
    z-index: 10;
    width: 58px;
    transform: translateY(-50%);
    flex-direction: column;
    flex-wrap: nowrap;
    gap: 6px;
    justify-content: center;
    padding: 5px;
    border-radius: 999px;
    background: rgba(2, 13, 18, 0.42);
    backdrop-filter: blur(10px);
  }

  button {
    min-height: 44px;
    padding: 0;
    font-size: 0;
  }

  .control-button {
    min-width: 0;
    width: 48px;
    height: 48px;
    flex: 0 1 auto;
    gap: 0;
    border-radius: 999px;
  }

  .button-icon {
    width: 1.25rem;
    height: 1.25rem;
  }

  .button-icon svg {
    width: 0.95rem;
    height: 0.95rem;
  }

  .control-button > span:not(.button-icon) {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
  }
}
