/* Basic reset / layout */
body {
  margin: 0;
  padding: 0;
  font-family: sans-serif;
  background: #fafafa;
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* Headings */
h1 {
  font-family: "Playwrite IT Moderna", serif;
}

p {
  font-size: 16px;
}

/* Header bar */
#header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 1.25rem 1.25rem;
  box-sizing: border-box;
  position: relative;
}

#title-wrapper {
  flex: 1;
  text-align: center;
}

#game-title {
  font-size: 3rem;
  margin: 0.5rem 0;
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  top: 0px;
}

#archive-header #game-title {
  /* same font-size, or adjust as desired */
  font-size: 3rem;
  margin: 0.5rem 0;

  /* override the absolute positioning from the default rule */
  position: static;      /* or remove position property entirely */
  transform: none;       /* remove translateX(-50%) */
  top: auto;             /* reset top from 0 to normal flow */
  left: auto;            /* reset left from 50% to normal flow */
}


#header-buttons {
  display: flex;
  gap: 0.5rem;
}


/* Primary button styling used widely */
.primary-button {
  padding: 0.8rem 1.5rem;
  font-size: 1.2rem;
  font-weight: bold;
  background-color: #8CC084;
  color: white;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: background-color 0.3s, transform 0.1s;
}

.primary-button:hover {
  background-color: #668d60;
}

.primary-button:active {
  transform: scale(0.98);
}

.primary-button:disabled {
  background-color: gray;
  cursor: not-allowed;
}

.header-button {
  width: 3rem;
  height: 3rem;
  border-radius: 50%;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

/* Container for puzzle area */
#puzzle-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-bottom: 1rem;
}

/* Move counter */
#timer-display {
  font-size: 1.5rem;
  margin-bottom: 0.5rem;
  text-align: center;
  font-weight: bold;
}

/* The circular board */
#board {
  position: relative;
  width: 500px;
  height: 500px;
  border-radius: 50%;
  margin: 20px 0;
  background: #ffffff;
  box-shadow: 0 0 10px rgba(0,0,0,0.2);
  overflow: hidden;
}

#rotate-icon {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 200px;
  height: 200px;
  pointer-events: none;
  opacity: 0.1;
}

/* Board nodes (drop targets) */
.board-node {
  position: absolute;
  width: 75px;
  height: 75px;
  border-radius: 50%;
  background: #ccc;
  transform: translate(-50%, -50%);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.board-node.drag-over {
  background-color: #8CC084;
}

/* Tray area */
#tray {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
  width: 80%;
  max-width: 600px;
  margin-bottom: 30px;
}

/* Tiles */
.tile {
  background: #ffffff;
  width: 70px;
  height: 70px;
  border-radius: 50%;
  border: 4px solid #333;
  cursor: grab;
  user-select: none;
  text-align: center;
  display: flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  font-weight: bold;
  font-size: 1rem;
}

.tile.valid {
  background-color: #8CC084;
  color: white;
  border: white;
}

.tile.selected {
  border: 4px solid #8CC084;
  color: #8CC084;
}

.tile span {
  display: block;
  max-width: 90%;
  white-space: nowrap;
  text-overflow: ellipsis;
  font-size: 20px; /* default */
  transform-origin: center;
}

/* Hide / show class */
.hidden {
  display: none !important;
}

/* Copy-notification toast */
#copy-notification {
  position: fixed;
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  background: #333;
  color: white;
  padding: 10px 15px;
  border-radius: 5px;
  opacity: 0;
  transition: opacity 0.5s ease-in-out;
  z-index: 100;
}

/* Modal overlay (shared for help, stats, etc.) */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
.modal-content {
  background: #fff;
  padding: 2rem;
  border-radius: 8px;
  text-align: center;
  font-size: 1.2rem;
  width: 80%;
  max-width: 500px;
  position: relative;
}
.close-button {
  position: absolute;
  top: 10px;
  right: 15px;
  font-size: 1.5rem;
  cursor: pointer;
  font-weight: bold;
  color: #555;
}
.close-button:hover {
  color: black;
}

.intro-modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background-color: #fff;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  overflow-y: auto;
  padding: 5vh 5vw;
}

.intro-modal-content {
  width: 100%;
  max-width: 100%;
  height: 100%;
  max-height: 100vh;
  text-align: center;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}


.intro-modal-content h1 {
  font-size: 4rem;
  margin: 0;
  max-width: 80%;
}

.intro-modal-content p {
  font-size: 1.25rem;
  margin: 0.25rem;
  max-width: 80%;
}

#recall-button, #share-button {
  margin: 0.3rem;
}

#rotate-button {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 40%;          /* Use a percentage of the board's width */
  aspect-ratio: 1;     /* Maintains a 1:1 ratio so it stays circular */
  border: none;
  background: #8CC084;
  cursor: pointer;
  border-radius: 50%;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
  transition: background-color 0.2s, box-shadow 0.2s;
  touch-action: manipulation;
}

#rotate-button img {
  width: 70%;
  height: 70%;
  object-fit: contain;
  -webkit-touch-callout: none;
  position: relative;
  top: -1px;
  right: -5px;
}

#rotate-button,
#rotate-button img {
  user-select: none;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  -webkit-tap-highlight-color: transparent; /* For mobile devices */
  -webkit-user-drag: none; /* Prevents image dragging */
}

@media (hover: hover) and (pointer: fine) {
  #rotate-button:hover {
    background: #668d60;
    box-shadow: 0 6px 8px rgba(0, 0, 0, 0.15);
  }
}

#rotate-button:active {
  background-color: #668d60;
  box-shadow: 0 6px 8px rgba(0, 0, 0, 0.15);
}


#archive-header {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem;
  box-sizing: border-box;
}

#archive-header h1 {
  margin: 0;
  font-family: "Playwrite IT Moderna", serif;
}

#archive-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 1rem;
  width: 90%;
  max-width: 1200px;
  margin: 1rem auto;
  box-sizing: border-box;
}

.archive-puzzle-button {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  text-align: center;
  border: 2px solid #8CC084;
  border-radius: 8px;
  background-color: #fff;
  cursor: pointer;
  transition: background-color 0.3s;
  font-family: sans-serif;
}
.archive-puzzle-button:hover {
  background-color: #8cc084;
}
.won-game {
  background-color: #8CC084;
  color: white;
}
.won-game:hover {
  background-color: #668d60;
}
.won-game:active{
  background-color: #54734f;
}
.puzzle-title {
  font-weight: bold;
  font-size: 1.2rem;
  margin-bottom: 0.2rem;
}
.puzzle-date {
  font-size: 1rem;
  margin-bottom: 0.3rem;
}
.puzzle-state {
  font-size: 1rem;
}

/* Stats container - grid layout for stat boxes */
.stats-container {
  display: flex;
  justify-content: center;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin: 1rem 0;
}

.stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0.5rem;
  min-width: 60px;
}

.stat-header {
  font-size: 0.8rem;
  margin: 0 0 0.25rem 0;
  font-weight: normal;
  color: #666;
}

.stat p {
  font-size: 1.5rem;
  font-weight: bold;
  margin: 0;
}

.stat hr {
  border: none;
  border-top: 2px solid #ccc;
  width: 100%;
  max-width: 60px;
  margin: 0.25rem 0;
}

/* Distribution bar chart */
.distribution-row {
  display: flex;
  align-items: center;
  margin-bottom: 0.3em;
}

.distribution-label {
  width: 50px;
  text-align: right;
  margin-right: 0.5em;
  font-weight: bold;
  font-size: 0.9rem;
}

.distribution-bar-container {
  flex: 1;
  background-color: #eee;
  height: 20px;
  position: relative;
  border-radius: 4px;
  overflow: hidden;
}

.distribution-bar {
  background-color: #8CC084;
  height: 100%;
  display: flex;
  align-items: center;
  transition: width 1s ease;
  border-radius: 4px 0 0 4px;
  white-space: nowrap;
}

.distribution-count {
  margin-left: 8px;
  color: #fff;
  font-weight: bold;
  font-size: 1rem;
}

#share-distribution-chart,
#stats-distribution-chart {
  width: 100%;
  text-align: left;
  margin-top: 1em;
}

/* Win modal buttons */
.win-modal-button {
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100px;
  height: 100px;
  padding: 0.5rem;
  text-align: center;
  border: 3px solid #8CC084;
  border-radius: 8px;
  background-color: transparent;
  cursor: pointer;
  transition: background-color 0.3s;
  font-size: 0.8rem;
  text-decoration: none;
  color: inherit;
  white-space: normal;
  word-wrap: break-word;
  overflow: hidden;
}

.win-modal-button:hover {
  background-color: rgba(140, 192, 132, 0.2);
}

.button-container {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 10px;
  margin-top: 1em;
}

/* RESPONSIVE MEDIA QUERIES */
@media (max-width: 700px) {
  #board {
    width: 300px;
    height: 300px;
  }
  #rotate-icon {
    width: 120px;
    height: 120px;
  }
  .board-node {
    width: 50px;
    height: 50px;
  }
  .tile {
    width: 50px;
    height: 50px;
    font-size: 0.8rem;
  }
  .tile span {
    font-size: 14px;
  }
  .primary-button {
    padding: 0.6rem 1rem;
    font-size: 1rem;
  }
  .header-button {
    width: 2.5rem;
    height: 2.5rem;
  }
  #game-title {
    font-size: 2rem;
    position: static;
    transform: none;
  }
  #archive-header #game-title {
    font-size: 1.8rem;
  }
  .modal-content {
    width: 100%;
    max-width: none;
    border-radius: 16px 16px 0 0;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    box-sizing: border-box;
  }
  .intro-modal-content{
    border-radius: 0 0 0 0;
  }
  #archive-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  .puzzle-title {
    font-size: 1rem;
  }
  .puzzle-state, .puzzle-date {
    font-size: 0.8rem;
  }
  .intro-modal-content h1 {
    font-size: 3rem;
  }

  @media (max-width: 500px){
    #game-title {
      font-size: 1.5rem;
    }
    #archive-header #game-title {
      font-size: 1.4rem;
    }
  }

  @media (max-width: 400px){
    #game-title {
      font-size: 1rem;
    }
    #archive-header #game-title {
      font-size: 0.8rem;
    }
  }
}
