* {
  box-sizing: border-box;
}

html {
  width: 100%;
  min-height: 100%;
  margin: 0;
}

body {
  margin: 0 auto;
  padding: 0;
  width: 100%;
  max-width: 960px;
  font-family: Arial, sans-serif;
  font-size: 16px;
  background: #fff;
  text-align: center;
  overflow-x: clip;
}

.wrapper {
  width: 100%;
  min-height: 100vh;
  margin: 0 auto;
  background: #000 radial-gradient(1000px 500px, #3f546b, #000);
  overflow: clip;
}

.content {
  width: 100%;
  margin: 0 auto;
  padding: 0 10px;
}

.gamegrid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-areas:
    "bb1"
    "wb1";
  gap: 8px;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  margin: 0 auto;
  padding: 4px;
  color: #ccc;
  font-family: Arial, sans-serif;
}

.bb1 {
  grid-area: bb1;
  min-width: 0;
}

.wb1 {
  grid-area: wb1;
  min-width: 0;
  padding-top: calc(min(96%, 428px) / 7 - 5px);
}

.sidebar {
  width: 100%;
  min-width: 0;
  margin: 0 auto;
  text-align: center;
  font-family: Arial, sans-serif;
  color: #ccc;
}

h1,
h2 {
  margin: 0;
  color: #fff;
  font-weight: normal;
}

h1 {
  padding: 18px 0;
  font-size: clamp(27px, 5.5vw, 43px);
  line-height: 1.2;
}

h2 {
  min-height: 2.6em;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(16px, 2.5vw, 20px);
  line-height: 1.3;
  text-align: center;
}

.dif h2 {
  min-height: 0;
  margin: 2px 0;
  font-size: clamp(19px, 3vw, 25px);
  line-height: 1.2;
}

p {
  margin: 8px 0;
  font-size: clamp(13px, 2vw, 17px);
  line-height: 1.3;
  text-align: center;
}

a:link {
  color: #0000ee;
  font-size: 14px;
  font-family: "Times New Roman", serif;
}

.panel {
  margin-bottom: 8px;
  padding: 8px 10px;
  background-color: rgba(255, 255, 255, 0.1);
  border-radius: 8px;
}

.dif-options {
  display: flex;
  justify-content: center;
  gap: 6px;
  margin: 10px 0 0;
}

.dif-options div {
  flex: 0 1 38px;
  min-width: 0;
}

.dif-options input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.dif-options label {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  margin: 0 auto;
  border: 2px solid #ccc;
  border-radius: 8px;
  background-color: #fff;
  color: #000080;
  cursor: pointer;
}

.dif-options input:checked + label {
  border-color: #fff;
  background-color: #3ec0ff;
  color: #fff;
}

.dif-options input:focus-visible + label {
  outline: 2px solid #fff;
  outline-offset: 3px;
}

.freeze .dif-options input:not(:checked) + label {
  width: 10px;
  height: 10px;
  margin: 10px auto;
  overflow: hidden;
  border-radius: 4px;
  font-size: 0;
  color: transparent;
  cursor: default;
}

.start {
  margin-top: 4px;
}

.start button {
  display: block;
  width: min(100%, 230px);
  min-height: 42px;
  margin: 0 auto;
  padding: 5px 10px;
  border: 2px solid #fff;
  border-radius: 8px;
  background-color: #3ec0ff;
  color: #fff;
  font-family: inherit;
  font-size: 18px;
  cursor: pointer;
  order: -1;
}

.start button:focus-visible {
  outline: 2px solid #fff;
  outline-offset: 3px;
}

.info div {
  margin-top: 6px;
  font-size: clamp(13px, 2vw, 17px);
  line-height: 1.3;
}

/* Responsive board container.
   JavaScript sets the matching rendered dimensions. */
.board {
  position: relative;
  float: none;
  width: min(96%, 428px);
  aspect-ratio: 1;
  height: auto;
  margin: 4px auto 8px;
  transform: translateX(2px);
  background-image: url("../img/board-sm.webp");
  background-position: center;
  background-size: 100% 100%;
  background-repeat: no-repeat;
  box-shadow: 0 0 20px rgba(0, 0, 0, 0.4);
  touch-action: manipulation;
}

.lit-columns,
.lit-cells,
.chips,
.click-columns {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.lit-columns {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
}

.lit-columns div {
  min-width: 0;
  height: 100%;
  margin: 0;
  transition: background-color 0.1s;
}

.lit-columns .lit {
  background-color: rgba(255, 255, 255, 0.1);
}

.lit-cells div,
.chips div {
  position: absolute;
  width: calc(100% / 7);
  aspect-ratio: 1;
}

.lit-cells div {
  background-color: rgba(255, 255, 255, 0.3);
  pointer-events: none;
}

.chips div {
  background-position: center;
  background-repeat: no-repeat;
  background-size: 100% 100%;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  pointer-events: none;
}

.chips .p1 {
  background-image: url("../img/p1-chip-sm.webp");
}

.chips .p2 {
  background-image: url("../img/p2-chip-sm.webp");
}

.chips .cursor {
  bottom: 100%;
  transition: left 0.1s ease-out;
}

.chips .dropped {
  transition: bottom ease-in;
  animation: bounce 0.3s;
}

.click-columns {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
}

.click-columns div {
  min-width: 0;
  height: 100%;
  padding: 0;
  cursor: default;
  touch-action: manipulation;
}

.click-columns .hover {
  cursor: pointer;
}

@keyframes bounce {
  0% {
    animation-timing-function: ease-out;
    transform: translateY(0);
  }

  30% {
    animation-timing-function: ease-in;
    transform: translateY(-8%);
  }

  60% {
    animation-timing-function: ease-out;
    transform: translateY(0);
  }

  80% {
    animation-timing-function: ease-in;
    transform: translateY(-2%);
  }

  100% {
    animation-timing-function: ease-out;
    transform: translateY(0);
  }
}

/* Wider screens: restore the side-by-side arrangement. */
@media screen and (min-width: 600px) {
  .content {
    width: 100%;
    max-width: 960px;
    padding: 0 16px;
  }

  .gamegrid {
    width: 100%;
    max-width: 928px;
    min-height: 100vh;
    margin: 0 auto;
    padding: 24px 0;
    gap: 24px;
    grid-template-columns: minmax(180px, 278px) minmax(0, 428px);
    grid-template-areas: "bb1 wb1";
    justify-content: center;
    align-content: center;
    align-items: center;
  }

  .sidebar {
    width: 100%;
    margin: 0;
  }

  h1 {
    min-height: 0;
    padding: 12px 0;
  }

  .panel {
    padding: 12px;
    margin-bottom: 12px;
  }

  /* Wrapper reserves room above the board for the cursor chip. */
  .wb1 {
    align-self: center;
    padding-top: calc(min(100%, 428px) / 7);
  }

  .wb1 .board {
    width: min(100%, 428px);
    margin: 0 auto;
    background-image: url("../img/board.webp");
  }

  .chips .p1 {
    background-image: url("../img/p1-chip.webp");
  }

  .chips .p2 {
    background-image: url("../img/p2-chip.webp");
  }
}

/* Compact phones */
@media screen and (max-width: 380px) {
  .content {
    padding: 0 4px;
  }

  .gamegrid {
    padding: 2px;
    gap: 4px;
  }

  h1 {
    font-size: 24px;
  }

  .panel {
    padding: 6px;
    margin-bottom: 5px;
  }

  .start {
    margin-top: 6px;
  }

  .start button {
    min-height: 36px;
    font-size: 16px;
  }

  .board {
    margin-top: 2px;
  }
}

/* Short screens: preserve the larger title while tightening other spacing. */
@media screen and (max-height: 650px) and (max-width: 599px) {
  h1 {
    padding: 5px 0;
    font-size: clamp(27px, 5.5vw, 43px);
  }

  .panel {
    padding: 4px 8px;
    margin-bottom: 4px;
  }

  .dif-options {
    margin-top: 5px;
  }

  .start {
    margin-top: 5px;
  }

  .start button {
    min-height: 32px;
    padding: 3px 8px;
    font-size: 16px;
  }

  p {
    margin: 4px 0;
  }
}

@media screen and (max-width: 599px) {
  .board {
    transform: translateX(1px);
  }
}