@import url('https://fonts.googleapis.com/css2?family=Lato:wght@400&display=swap');
@import './styles/exercise.scss';
@import './styles/dots.scss';
@import './styles/newTimer.scss';
@import './styles/scratch.scss';
@import './styles/alarm.scss';

*,
*:before,
*:after {
  box-sizing: border-box;
  position: relative;
}

[hidden] {
  display: none !important;
}

html,
body,
#root {
  height: 100%;
  width: 100%;
  margin: 0;
  padding: 0;
  font-family: 'Lato', sans-serif;
  font-weight: 400;
  font-size: 16px;
}

:root {
  --color-primary: #5192e6;
  --color-primary-light: hsla(214, 75%, 72%, 1);
  --color-secondary: #8b9096;
  --color-gray: #373b41;
  --color-dark-gray: #25272a;
}

#root {
  background-color: #18191c;
  color: white;
}

.app {
  height: 100%;
  width: 100%;
  display: grid;
  grid-template-columns: 1fr;
  grid-template-rows: auto 1fr;
  overflow: hidden;

  > .app-panels {
    grid-template-rows: 2 / -1;
    display: grid;
    grid-template-columns: 1fr;
    grid-template-rows: 1fr;
    overflow: scroll;

    > .app-panel {
      grid-area: 1 / 1;
      display: grid;
      grid-template-columns: 1fr;
      grid-template-rows: 1fr;
      overflow: scroll;
    }

    .timers,
    .timer,
    [data-screen] {
      grid-area: 1 / 1;
      transition: transform 0.6s ease-in-out, opacity 0.3s ease-out;
    }

    .dots {
      position: absolute;
      top: 0;
      right: 0;
      width: 5rem;
      height: 100%;
    }

    .timer:not([data-active]) {
      display: none;
    }
  }

  &[data-state='timer'] {
    [data-screen='new-timer'] {
      transform: translateY(-50%);
      opacity: 0;
    }

    .timer {
      animation: slide-up 0.6s ease-in-out both;

      @keyframes slide-up {
        from {
          opacity: 0;
          transform: translateY(50%);
        }
        50% {
          opacity: 1;
        }
      }
    }
  }
}

.app-tabs {
  display: flex;
  flex-direction: row;
  justify-content: stretch;
  background-color: var(--color-dark-gray);
}

.app-tab {
  appearance: none;
  background: transparent;
  flex-grow: 1;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 1rem 0;
  border-bottom: 0.25rem solid transparent;

  &[data-selected] {
    border-color: var(--color-primary);
  }
}

input[type='number']::-webkit-inner-spin-button,
input[type='number']::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.timer,
.clock,
[data-screen] {
  display: grid;
  grid-template-rows: 20vh 1fr 25vh;
  grid-template-areas: 'header' 'main' 'actions';
  grid-row-gap: 1rem;
}

.timer {
  --progress: calc((var(--elapsed)) / var(--duration));
  height: 100%;
  overflow: auto;

  > header {
    grid-area: header;
  }

  > .circles,
  > .display {
    grid-area: main;
    align-self: center;
    justify-self: center;
  }

  > .actions {
    grid-area: actions;
  }

  &[data-state~='idle'] {
    .progress {
      transition-duration: 0.3s;
    }
  }

  &[data-state~='paused'] {
    .elapsed {
      animation: pulse 1s steps(1) infinite;
    }
  }

  &[data-state~='running.overtime'],
  &[data-state~='expired'] {
    circle {
      animation: pulse 1s steps(1) infinite;
    }
    .elapsed {
      color: white;
    }
  }

  &[data-state~='running.overtime'],
  &[data-state~='expired'] {
    --progress: 1;
  }

  &[data-state~='running.normal'],
  &[data-state~='paused'] {
    --progress: calc((var(--elapsed) + var(--interval)) / var(--duration));
  }
}

.actions {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-areas: 'left center right';
  align-items: center;
  justify-items: center;

  > button:not(.transparent) {
    grid-area: center;
    appearance: none;
    background-color: var(--color-primary);
    color: white;
    height: 4rem;
    width: 4rem;
    border-radius: 4rem;
    border: none;
    font-size: 1.5rem;
    font-weight: bold;
    transition: background-color 0.3s ease;

    &:hover {
      background-color: var(--color-primary-light);
    }
  }

  > button.transparent {
    width: auto;
    background: transparent;
    padding: 1rem;
  }
}

button {
  appearance: none;
  color: white;
  background: rgba(white, 0.2);
  padding: 0.5rem 1rem;
  border: none;
  font-size: 1.5rem;
  cursor: pointer; // I know, I know
  transition: transform 0.3s;

  &:focus {
    outline: none; // I KNOW DO NOT @ ME
  }

  &:disabled {
    opacity: 0.2;
  }

  &[hidden] {
    transform: scale(0);
  }
}

.display {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}

.elapsed {
  color: var(--color-primary);
  font-size: 5rem;
  padding: 1rem;
  transition: color 0.3s ease;
  cursor: pointer;

  &:hover {
    color: white;
  }
}

.label {
  color: var(--color-secondary);
}

.controls {
  display: flex;
  flex-direction: row;

  > button {
    appearance: none;
    border: none;
    background: transparent;
    color: white;
    font-size: 1rem;
  }
}

.circles {
  transform: rotate(-0.25turn);
  height: 100%;
  width: 100%;
  pointer-events: none;
}

circle {
  stroke: white;
  stroke-linejoin: round;
  stroke-linecap: round;
  stroke-width: 1px;
}

.progress {
  --interval-duration: calc(var(--interval) * 1s);
  transition: stroke-dashoffset var(--interval-duration) linear;
  stroke: var(--color-primary);
  stroke-dashoffset: calc(1px - var(--progress) * -1px);
  stroke-dasharray: 1 1;
  stroke-width: 1.1px;
}

@keyframes pulse {
  from,
  to {
    opacity: 0;
  }
  50% {
    opacity: 1;
  }
}

header {
  display: flex;
  justify-content: center;
  align-items: center;

  a {
    color: white;
    opacity: 0.5;
    transition: opacity 0.3s ease;

    &:hover {
      opacity: 1;
    }
  }
}

// .....

.local {
  align-self: self-end;
}

.localTime {
  font-size: 5rem;
  font-weight: normal;
  margin: 0;
  text-align: center;
  color: var(--color-primary);
}

.localDate {
  font-size: 1.5rem;
  display: block;
  text-align: center;
}

.foreignItem {
  display: grid;
  padding: 1rem;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr;
  grid-column-gap: 1rem;
  grid-row-gap: 0.5rem;
  grid-template-areas: 'city time';
  border-top: 1px solid #333;

  > .foreignCity {
    grid-area: city;
  }
  > .foreignTime {
    grid-area: time;
  }
  > .foreignDetails {
    grid-area: details;
  }
}

.foreignCity {
  appearance: none;
  background: transparent;
  color: white;
  border: 1px solid white;
  padding: 0 1rem;
  justify-self: self-start;
  display: inline-block;

  &:focus {
    outline: none;
  }
}

.foreignTime {
  font-size: 2rem;
  align-self: center;
}
