/* Page: green table on every width; the clip grows with the game instead of keeping 4:3,
   and "Spiel vergrößern" enlarges the board instead of zooming the whole game. */

.page-tic-tac-toe .game-section {
  background: #005000;
}

.page-tic-tac-toe .game-clip {
  --ttt-max: 420px;
  aspect-ratio: auto;
}

.page-tic-tac-toe .game-clip--large {
  --ttt-max: 600px;
}

.page-tic-tac-toe .game-clip--large .game-inner {
  zoom: 1;
}

@media (max-width: 850px) {
  .page-tic-tac-toe .game-section {
    padding: 20px 5px;
  }
}

/* Game */

#ttt-app {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
}

#ttt-game {
  --ttt-size: min(var(--ttt-max), calc(100vw - 60px), calc(100vh - 230px));
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-areas: "modes new" "score score" "board board" "status status";
  justify-items: center;
  gap: 12px 8px;
  box-sizing: border-box;
  width: max(300px, calc(var(--ttt-size) + 32px));
  max-width: 100%;
  padding: 16px;
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.25);
  color: #1f2d1f;
  font-family: 'Inter', system-ui, sans-serif;
  text-transform: uppercase;
  user-select: none;
}

/* Buttons do not inherit the capitals on their own (the browser sets text-transform: none on them). */
#ttt-game button {
  text-transform: inherit;
}

/* The levels and "Zwei Spieler" as one row of buttons; the one in play is lit. */
#ttt-modes {
  grid-area: modes;
  justify-self: stretch;
  display: flex;
  gap: 2px;
  padding: 3px;
  background: #edf1ed;
  border: 1px solid #d6ded6;
  border-radius: 8px;
}

#ttt-modes button {
  flex: 1 1 auto;
  min-width: 0;
  padding: 5px 9px;
  font: 600 13px 'Inter', system-ui, sans-serif;
  color: #556355;
  background: transparent;
  border: 0;
  border-radius: 5px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

#ttt-modes button.ttt-on {
  color: #005000;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
  cursor: default;
}

#ttt-modes button[data-mode="pvp"] {
  flex: 0 0 auto;
}

#ttt-modes svg {
  display: block;
  width: 20px;
  height: 18px;
}

#ttt-new {
  grid-area: new;
  align-self: stretch;
  padding: 7px 14px;
  font: 600 13px 'Inter', system-ui, sans-serif;
  color: #fff;
  background: #00b050;
  border: 0;
  border-radius: 6px;
  cursor: pointer;
}

/* Hover only where there is a mouse: after a tap on a phone it would stick to the cell. */
@media (hover: hover) {
  #ttt-modes button:not(.ttt-on):hover {
    color: #1f2d1f;
    background: rgba(0, 0, 0, 0.05);
  }

  #ttt-new:hover {
    background: #00c45a;
  }

  .ttt-cell:not(.ttt-x):not(.ttt-o):hover {
    background: #f0f6f0;
  }
}

#ttt-new.ttt-pulse {
  animation: ttt-pulse 1.2s ease-in-out infinite;
}

#ttt-score {
  grid-area: score;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  width: 100%;
  container-type: inline-size;
}

.ttt-score-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  min-width: 0;
  padding: 6px 2px;
  background: #f1f4f1;
  border-radius: 8px;
  box-shadow: inset 0 -3px 0 transparent;
  transition: box-shadow 0.2s;
}

.ttt-score-box.ttt-active {
  box-shadow: inset 0 -3px 0 #00b050;
}

/* "UNENTSCHIEDEN" in capitals is the widest label: it shrinks with the score row on narrow screens. */
.ttt-score-label {
  font-size: min(12px, 3.4cqw);
  color: #556355;
  white-space: nowrap;
}

.ttt-score-value {
  font-size: 22px;
  font-weight: 600;
  line-height: 1.1;
}

/* The board's own color shows through the gaps between the cells as the lines of the grid. */
#ttt-board {
  grid-area: board;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  grid-template-rows: repeat(3, minmax(0, 1fr));
  gap: calc(var(--ttt-size) / 60);
  width: var(--ttt-size);
  height: var(--ttt-size);
  background: #c3cfc3;
}

.ttt-cell {
  display: block;
  margin: 0;
  padding: 0;
  border: 0;
  background: #fff;
  cursor: pointer;
  transition: background 0.15s;
}

.ttt-cell:focus-visible {
  outline: 3px solid #00b050;
  outline-offset: -3px;
}

.ttt-cell.ttt-x,
.ttt-cell.ttt-o,
#ttt-board.ttt-wait .ttt-cell {
  cursor: default;
}

#ttt-board.ttt-over .ttt-cell {
  cursor: pointer;
}

.ttt-cell svg {
  display: block;
  width: 100%;
  height: 100%;
  transition: opacity 0.3s;
}

.ttt-cell line,
.ttt-cell circle {
  fill: none;
  stroke-width: 10;
  stroke-linecap: round;
  stroke-dasharray: 1;
  stroke-dashoffset: 1;
  animation: ttt-draw 0.25s ease-out forwards;
}

.ttt-x line {
  stroke: #005000;
}

.ttt-x line + line {
  animation-delay: 0.12s;
}

.ttt-o circle {
  stroke: #ffb300;
}

#ttt-board.ttt-over .ttt-cell:not(.ttt-win) svg {
  opacity: 0.35;
}

.ttt-cell.ttt-win {
  background: #dff0df;
}

.ttt-win svg {
  animation: ttt-pop 0.5s ease-out 0.2s;
}

#ttt-status {
  grid-area: status;
  min-height: 1.4em;
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  text-align: center;
}

@keyframes ttt-draw {
  to { stroke-dashoffset: 0; }
}

@keyframes ttt-pop {
  50% { transform: scale(1.15); }
}

@keyframes ttt-pulse {
  50% { box-shadow: 0 0 0 4px rgba(0, 176, 80, 0.35); }
}

/* Phones: the four mode buttons take the whole top row, "Neue Runde" goes under the result. */
@media (max-width: 480px) {
  #ttt-game {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas: "modes" "score" "board" "status" "new";
  }

  #ttt-new {
    align-self: auto;
  }
}

/* The narrowest phones: a little less padding, so that all four mode buttons fit. */
@media (max-width: 360px) {
  #ttt-game {
    padding: 12px;
  }

  #ttt-modes button {
    padding: 5px 6px;
    font-size: 12px;
  }
}

/* Phones held sideways: board on the left, everything else beside it. */
@media (orientation: landscape) and (max-height: 500px) {
  #ttt-game {
    --ttt-size: min(var(--ttt-max), calc(100vh - 100px), calc(100vw - 360px));
    grid-template-areas: "board modes" "board score" "board status" "board new";
    grid-template-columns: auto 290px;
    grid-template-rows: auto auto auto 1fr;
    align-items: start;
    width: auto;
  }

  #ttt-new {
    align-self: start;
  }
}
