/* ==========================================================================
   1. Font Imports & CSS Reset
   ========================================================================== */

@font-face {
  font-family: contra;
  src: url(./fonts/contra.ttf);
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  font-family: arial;
}

/* ==========================================================================
   2. Global Styles
   ========================================================================== */

html,
body {
  height: 100%;
  margin: 0;
}

body {
  min-height: 100dvh;
  padding: 0.5rem;
  background-color: #fcfefc;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ==========================================================================
   3. Header/Title Styles
   ========================================================================== */

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
  flex: 0 0 auto;
  gap: 10px;
}

#title {
  font-family: contra;
  font-size: clamp(2.4rem, 4vw, 4rem);
  animation: bounceInDown 1s;
  cursor: default;
  line-height: 1;
}

#menuToggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 4px;
  border: 2px black solid;
  border-radius: 10px;
  background-color: black;
  color: white;
  font-weight: bold;
  cursor: pointer;
  padding: 8px 15px;
}

#menuToggle:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ==========================================================================
   4. Main Layout and Game Wrapper
   ========================================================================== */

#nogglegame {
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 1rem;
  flex: 1 1 auto;
  min-height: 0;
}

.gamescreen {
  display: flex;
  justify-content: center;
  align-items: center;
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
}

.gridwrapper {
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
}

/* ==========================================================================
   5. Parameters Panel
   ========================================================================== */

#parametersWrapper {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 1rem;
  overflow-y: auto;
  overflow-x: hidden;
  pointer-events: auto;
}

#parametersWrapper.closed {
  display: none;
}

#parameters {
  border: 2px black solid;
  border-radius: 10px;
  box-shadow: 1px 1px 1px black;
  padding: 0.85rem;
  background-color: #eaeaea;
  font-weight: bold;
  height: auto;
  max-width: min(90vw, 620px);
  width: 100%;
  margin: 0 auto;
}

#parameters input,
#parameters select {
  border-radius: 10px;
  padding: 4px;
  text-align: center;
}

form {
  display: flex;
  flex-direction: column;
}

.parametersLine {
  display: flex;
  justify-content: space-between;
  margin: 0.1rem 0;
  align-items: center;
  border-bottom: 1px dotted black;
  gap: 8px;
}

.parametersLine label {
  flex: 1 1 auto;
}

.parametersLine input,
.parametersLine select,
.parametersLine span {
  flex: 0 0 auto;
}

.parametersSection {
  text-align: center;
  margin-top: 0.35rem;
  font-weight: bolder;
  font-size: 0.95rem;
}

.parametersButton {
  position: absolute;
  bottom: 8px;
  right: 8px;
  margin-top: 5px;
  z-index: 20;
}

/* ==========================================================================
   6. Game Grid and Cell Styles
   ========================================================================== */

#grid {
  display: grid;
  justify-content: center;
  align-items: center;
  gap: 0.75rem;
  text-align: center;
  width: fit-content;
  max-width: 100%;
  max-height: 100%;
}

.cell,
.cell-img {
  display: flex;
  justify-content: center;
  align-items: center;
  width: min(16vw, 16vh);
  height: min(16vw, 16vh);
  min-width: 70px;
  min-height: 70px;
  max-width: 150px;
  max-height: 150px;
  border-radius: 1.2rem;
  user-select: none;
  padding: 0.2em;
  overflow: hidden;
}

.cell {
  background-color: #00a8e6;
  box-shadow: 2px 2px 2px darkblue;
  font-size: clamp(1.8rem, 4vw, 4rem);
  color: white;
  font-family: arial;
  text-align: center;
  margin: auto;
  line-height: 1;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.cell-img {
  border-radius: 5px;
  margin: 0;
  font-size: clamp(1.8rem, 4vw, 4rem);
  color: white;
  font-family: arial;
  line-height: 1;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.cell-img img {
  width: 100%;
  height: 100%;
  border-radius: 5px;
  object-fit: cover;
}

.cell.decimal,
.cell-img.decimal {
  font-size: clamp(1.5rem, 3.2vw, 3.2rem);
  letter-spacing: -0.03em;
}

/* ==========================================================================
   7. Fraction Formatting
   ========================================================================== */

.fraction {
  display: inline-block;
  text-align: center;
  vertical-align: middle;
  font-size: 0.8em;
  line-height: 1;
}

.fraction .top {
  display: block;
  border-bottom: 5px solid #ffffff;
  padding: 0 2px;
}

.fraction .bottom {
  display: block;
  padding: 0 2px;
}

/* ==========================================================================
   8. Timer and Display Wrappers
   ========================================================================== */

.displaysWrapper {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.timerWrapper {
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 10;
  cursor: default;
  user-select: none;
}

#timerimgwrapper {
  display: inline;
  padding: 20px;
}

#timer {
  font-size: clamp(2rem, 3vw, 3rem);
  padding-right: 10px;
}

#timerimg {
  width: 32px;
  height: 32px;
}

#timerbackground {
  border-radius: 10px;
  z-index: -1;
  border: black 1px solid;
  box-shadow: 1px 1px 1px black;
}

/* ==========================================================================
   9. Target Number Styles
   ========================================================================== */

#targetNumberWrapper {
  border: 2px black solid;
  border-radius: 10px;
  padding: 0.5rem;
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 5px;
  height: 100%;
  user-select: none;
  cursor: default;
}

#targetNumber {
  font-size: 2rem;
}

#targetNumberDeleteButton {
  padding: 3px 5px;
  background-color: red;
  outline: none;
  border: 1px black solid;
  border-radius: 5px;
  cursor: pointer;
}

#targetNumberDeleteButton:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

#targetNumberRandomButton {
  border: 1px black solid;
  border-radius: 5px;
  padding: 1px;
  background-color: #00a8e6;
  color: white;
  cursor: pointer;
}

#targetNumberRandomButton img {
  width: 18px;
  height: 18px;
}

/* ==========================================================================
   10. Game Controls and Buttons
   ========================================================================== */

#controls {
  display: flex;
  justify-content: center;
  gap: 2rem;
  margin-top: 10px;
}

.control_button {
  border: 2px black solid;
  border-radius: 10px;
  padding: 15px 10px;
  background-color: #00a8e6;
  color: white;
  font-weight: bold;
  cursor: pointer;
  width: 125px;
}

.control_button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

#printGridButton {
  display: flex;
  justify-content: center;
  align-items: center;
  margin: 0 auto;
  border: 2px black solid;
  border-radius: 10px;
  padding: 5px;
  background-color: black;
  color: white;
  font-weight: bold;
}

/* ==========================================================================
   11. Responsive Design (Media Queries)
   ========================================================================== */

@media (max-width: 964px) {
  body {
    min-height: 100dvh;
    overflow: auto;
  }

  header {
    flex-direction: column;
    gap: 3px;
  }

  input,
  select,
  textarea {
    font-size: 16px !important;
  }

  .displaysWrapper {
    flex-direction: column;
    align-items: center;
  }

  .cell,
  .cell-img {
    width: 21vw;
    height: 21vw;
    font-size: 8vw;
    border-radius: 15px;
    user-select: none;
    min-width: 60px;
    min-height: 60px;
    max-width: none;
    max-height: none;
    padding: 0.15em;
  }

  .cell.decimal,
  .cell-img.decimal {
    font-size: 6.5vw;
  }

  .parametersButton {
    position: fixed;
    bottom: 8px;
    right: 8px;
  }

  #parametersWrapper {
    padding: 0.5rem;
  }
}

@media (max-width: 480px) {
  #grid {
    width: 85vw;
  }

  #title {
    font-size: 4rem;
  }
}

/* ==========================================================================
   12. Animations
   ========================================================================== */

@keyframes bounceInDown {
  from,
  60%,
  75%,
  90%,
  to {
    animation-timing-function: cubic-bezier(0.215, 0.61, 0.355, 1);
  }

  0% {
    opacity: 0;
    transform: translate3d(0, -3000px, 0) scaleY(3);
  }

  60% {
    opacity: 1;
    transform: translate3d(0, 25px, 0) scaleY(0.9);
  }

  75% {
    transform: translate3d(0, -10px, 0) scaleY(0.95);
  }

  90% {
    transform: translate3d(0, 5px, 0) scaleY(0.985);
  }

  to {
    transform: translate3d(0, 0, 0);
  }
}

.bounceInDown {
  animation-name: bounceInDown;
}

/* ==========================================================================
   13. Print Styles
   ========================================================================== */

@media print {
  @page {
    size: auto;
    margin: 6mm;
  }

  html,
  body {
    height: auto !important;
    overflow: visible !important;
  }

  body * {
    visibility: hidden !important;
  }

  #printTarget,
  #printTarget *,
  .gridwrapper,
  .gridwrapper * {
    visibility: visible !important;
  }

  #printTarget {
    position: absolute !important;
    top: 6mm !important;
    left: 50% !important;
    transform: translateX(-50%) !important;
    display: flex !important;
    flex-direction: column !important;
    align-items: center !important;
    background: #fff !important;
    color: #000 !important;
    border: 2px solid #333 !important;
    padding: 0.3rem 0.7rem !important;
    font-size: 1.1rem !important;
    line-height: 1.1 !important;
    box-shadow: none !important;
  }

  #printTarget h2 {
    margin: 0 !important;
    font-size: 1.2rem !important;
  }

  #printTargetNumber {
    margin-top: 0.1rem !important;
    font-size: 1rem !important;
  }

  .gridwrapper {
    position: absolute !important;
    top: 28mm !important;
    left: 50% !important;
    transform: translateX(-50%) !important;
    margin: 0 !important;
    width: auto !important;
    height: auto !important;
    background: #fff !important;
    box-shadow: none !important;
    page-break-inside: avoid !important;
    break-inside: avoid !important;
  }

  #grid {
    gap: 6px !important;
    transform: none !important;
  }

  .cell,
  .cell-img {
    width: 100px !important;
    height: 100px !important;
    min-width: 100px !important;
    min-height: 100px !important;
    max-width: 100px !important;
    max-height: 100px !important;
    padding: 0 !important;
  }

  .cell {
    background: #00a8e6 !important;
    border: 1px solid #000 !important;
    color: white !important;
    font-size: 2.2rem !important;
  }

  .cell.decimal {
    font-size: 1.8rem !important;
  }

  .fraction .top {
    border-bottom: 1px solid #ffffff !important;
  }
}