/*  =================================================
    Custom Fonts
    =================================================   */
@font-face {
  font-family: 'Space Mono';
  src: url('../assets/fonts/SpaceMono-Bold.woff2') format('woff2');
  font-weight: 700;
}

/*  =================================================
    Custom Properties (Variables)
    =================================================   */
:root {
  --white: hsl(0, 100%, 100%);
  --black: hsl(0, 0%, 0%);

  --grey-50: hsl(189, 47%, 97%);
  --grey-200: hsl(185, 41%, 84%);
  --grey-300: hsl(184, 19%, 68%);
  --grey-400: hsl(184, 14%, 56%);
  --grey-500: hsl(186, 14%, 43%);
  --grey-550: hsl(180, 18%, 40%);
  --grey-600: hsl(180, 25%, 32%);

  --green-200: hsl(173, 61%, 77%);
  --green-400: hsl(172, 67%, 45%);
  --green-750: hsl(183, 79%, 24%);
  --green-800: hsl(183, 85%, 21%);
  --green-900: hsl(183, 100%, 15%);

  --orange-400: hsl(13, 70%, 60%);

  --spacing-100: 0.8rem;
  --spacing-200: 1.6rem;
  --spacing-300: 2.4rem;
  --spacing-400: 3.2rem;
  --spacing-600: 4.8rem;
  --spacing-1000: 8.0rem;
  --spacing-1200: 9.6rem;
  --spacing-1500: 12.0rem;
  --spacing-1600: 12.8rem;
}

/*  =================================================
    CSS Reset
    =================================================   */

/* 1. Use a more-intuitive box-sizing model */
*, *::before, *::after {
  box-sizing: border-box;
}

/* 2. Remove default margin */
*:not(dialog) {
  margin: 0;
}

/* 3. Enable keyword animations */
@media (prefers-reduced-motion: no-preference) {
  html {
    interpolate-size: allow-keywords;
  }
}

body {
  /* 4. Add accessible line-height */
  line-height: 1.5;
  /* 5. Improve text rendering */
  -webkit-font-smoothing: antialiased;
}

/* 6. Improve media defaults */
img, picture, video, canvas, svg {
  display: block;
  max-width: 100%;
}

/* 7. Inherit fonts for form controls */
input, button, textarea, select {
  font: inherit;
}

/* 8. Avoid text overflows */
p, h1, h2, h3, h4, h5, h6 {
  overflow-wrap: break-word;
}

/* 9. Improve line wrapping */
p {
  text-wrap: pretty;
}
h1, h2, h3, h4, h5, h6 {
  text-wrap: balance;
}

/*
  10. Create a root stacking context
*/
#root, #__next {
  isolation: isolate;
}

/* 11. 10 pixels = 1rem */
html {
  font-size: 62.5%;
}

input::-webkit-outer-spin-button,
input::-webkit-inner-spin-button {
    /* display: none; <- Crashes Chrome on hover */
    -webkit-appearance: none;
    margin: 0; /* <-- Apparently some margin are still there even though it's hidden */
}

input[type=number] {
    -moz-appearance:textfield; /* Firefox */
}

/*  =================================================
    Typography Utilities
    =================================================   */
.text--p1 {
  font-size: 4.8rem;
  line-height: 7.1rem;
  letter-spacing: -0.1rem;
}

.text--p2 {
  font-size: 3.2rem;
  line-height: 4.7rem;
  letter-spacing: -0.067rem;
}

.text--p2--green {
  color: var(--green-400);
}

.text--p3 {
  font-size: 2.4rem;
  line-height: 3.6rem;
}

.text--p4 {
  font-size: 2.0rem;
  line-height: 3.0rem;
}

.text--p5 {
  font-size: 1.6rem;
  line-height: 2.4rem;
}

.text--p5--white {
  color: var(--white);
}

.text--p6 {
  font-size: 1.3rem;
  line-height: 1.9rem;
}

.text--p6--grey {
  color: var(--grey-400);
}

/*  =================================================
    Base Styles
    =================================================   */
body {
  display: flex;
  flex-direction: column;
  align-items: center;
  font-family: 'Space Mono', monospace;
  font-weight: 700;
  min-height: 100vh;
  background-color: var(--green-200);
}

.header {
  display: flex;
  justify-content: center;
  margin: 4.1rem 0;
}

.calculator {
  display: flex;
  flex-direction: column;
  gap: var(--spacing-400);
  max-width: 45.0rem;
  padding: var(--spacing-400) var(--spacing-300);
  background-color: var(--white);
  border-radius: 2.5rem;
}

.form {
  display: flex;
  flex-direction: column;
  gap: var(--spacing-400);
}

.fieldset {
  display: flex;
  flex-direction: column;
  gap: var(--spacing-100);
  padding: 0;
  border: none;
}

.fieldset__title {
  color: var(--grey-500);
}

.bill-information {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.bill-information__error {
  display: none;
  color: var(--orange-400);
}

.fieldset__input {
  position: relative;
}

.fieldset__input img {
  position: absolute;
  top: 1.7rem;
  left: 2rem;
}

.fieldset__input input {
  width: 100%;
  padding: var(--spacing-100) var(--spacing-200);
  color: var(--green-900);
  text-align: right;
  background-color: var(--grey-50);
  border: none;
  border-radius: 0.5rem;
  cursor: pointer;
}

.fieldset__input--error {
  border: 0.2rem solid var(--orange-400);
  border-radius: 0.5rem;
  outline: 0.2rem solid var(--orange-400);
}

.fieldset__input input:focus {
  outline: 0.2rem solid var(--green-400);
}

.tip-percentage {
  display: flex;
  flex-direction: column;
  gap: var(--spacing-100);
  padding: 0;
  border: none;
}

.tip-percentage-information {
  display: flex;
  justify-content: space-between;
}

.tip-percentage-information__error {
  display: none;
  color: var(--orange-400);
}

.tip-percentage__heading {
  padding: 0;
  margin-bottom: var(--spacing-100);
  color: var(--grey-500);
}

.grid {
  display: grid;
  grid-template-rows: repeat(3, 1fr);
  grid-template-columns: repeat(2, 1fr);
  gap: var(--spacing-200);
  position: relative;
}

.grid__button {
  position: absolute;
  width: 0.1rem;
  height: 0.1rem;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
}

.grid__label {
  display: block;
  padding: var(--spacing-100) var(--spacing-200);
  width: 100%;
  height: 100%;
  text-align: center;
  color: var(--white);
  background-color: var(--green-900);
  border-radius: 0.5rem;
  cursor: pointer;
}

.grid__button:checked + .grid__label {
  background-color: var(--green-400);
  color: var(--black);
}

.grid__button:hover + .grid__label {
  background-color: var(--green-200);
  color: var(--black);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
  pointer-events: none;
}

.grid__write-button {
  padding: var(--spacing-100) var(--spacing-200);
  width: 100%;
  height: 100%;
  background-color: var(--grey-50);
  color: var(--grey-550); 
  text-align: center;
  border-radius: 0.5rem;
  border: none;
  outline: none;
  cursor: pointer;
}
.grid__write-button:focus {
  outline: 0.2rem solid var(--green-400);
}

.grid__write-button--error {
  border: 0.2rem solid var(--orange-400);
}

.people-information {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.people-information__error {
  display: none;
  color: var(--orange-400);
}

.results-container {
  display: flex;
  flex-direction: column;
  gap: var(--spacing-400);
  padding: var(--spacing-300);
  background-color: var(--green-900);
  border-radius: 1.5rem;
}

.results-details {
  display: flex;
  flex-direction: column;
  gap: var(--spacing-300);
}

.money {
  display: flex;
  justify-content: space-between;
}

.reset-button {
  padding: var(--spacing-100) var(--spacing-400);
  width: 100%;
  color: var(--green-800);
  background-color: var(--green-750);
  text-transform: uppercase;
  border: none;
  border-radius: 0.5rem;
}

.reset-button:hover {
  color: var(--green-900);
  background-color: var(--green-200);
  cursor: pointer;
}

/*  =================================================
    Tablet Styles
    =================================================   */
@media (min-width: 768px) {
  body {
    justify-content: center;
    padding-bottom: 4.1rem;
  }

  .calculator {
    gap: 4.0rem;
    padding: var(--spacing-600) var(--spacing-1000);
    min-width: 60.8rem;
    border-radius: 2.5rem;
  }

  .form {
    gap: var(--spacing-300);
  }

  .grid {
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(2, 1fr);
  }

  .results-container {
    gap: var(--spacing-200);
    padding: var(--spacing-300) var(--spacing-400);
  }

  .money {
    align-items: center;
  }

  .results-details {
    justify-content: center;
    gap: var(--spacing-100);
  }

  .text--p2 {
    font-size: 4.8rem;
    line-height: 7.1rem;
    letter-spacing: -0.1rem;
  }

  .reset-button {
    padding: var(--spacing-100) 4.0rem;
  }
}

/*  =================================================
    Desktop Styles
    =================================================   */
@media (min-width: 1440px) {
  body {
    padding: 0;
  }

  .header {
    margin-top: 0;
  }

  .calculator {
    flex-direction: row;
    gap: var(--spacing-600);
    padding: var(--spacing-400);
    max-width: 92.0rem;
  }

  .form {
    gap: 4.0rem;
    max-width: 37.9rem;
  }

  .grid__write-button {
    padding: 0;
  }

  .results-container {
    gap: var(--spacing-1600);
    width: 41.3rem;
  }

  .results-details {
    gap: var(--spacing-300);
  }
}