body {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  margin: 0;
  display: flex;
  flex-direction: row;
  align-items: stretch;
  font-family: sans-serif;
}

button {
  margin: 10px 8px;
  padding: 10px 18px;
  font-size: 18px;
  background: #cce;
  border: none;
  border-radius: 6px;
  box-shadow: 2px 2px 5px #aaa;
  cursor: pointer;
}

button:hover {
  background: #bbd;
}

button:disabled,
button:disabled:hover {
  background: #ccc;
  cursor: default;
}

#directory {
  max-width: 350px;
  background: #fff;
}

#directory > a {
  display: none;
}

#directory > main {
  box-sizing: border-box;
  width: 100%;
  height: 100%;
  padding: 10px 20px 10px 0;
  border-right: 2px solid #ccc;
  overflow: auto;
}

.no-deck #directory {
  width: 100%;
  max-width: 100%;
  border-right: none;
}

.no-deck #directory > a {
  display: none;
}

#directory ol {
  margin: 0;
  padding: 0;
  list-style: none;
}

#directory > main > ol ol {
  padding-left: 20px;
}

#directory > main ol > li {
  margin: 0;
  padding: 0;
}

#directory ol > li > a,
#directory ol > li > span {
  display: block;
  padding: 5px 20px;
}

#directory ol > li > a {
  text-decoration: none;
}

#directory ol > li > a:hover {
  background: #dce;
}

#directory ol > li > a.current {
  background: #a9c;
  color: #fff;
}

#viewer {
  position: relative;
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  z-index: 1;
}

.no-deck #viewer {
  display: none;
}

.loading #viewer {
  justify-content: center;
  text-align: center;
}

.loading #viewer > * {
  display: none;
}

#viewer #loading {
  display: none;
}

.loading #viewer > #loading {
  display: block;
  background: text linear-gradient(45deg, #ccc 0%, #999 50%, #ccc 100%) 0% 0% /
    200% 100%;
  animation: background-wipe 2s linear infinite;
  color: transparent;
}

@keyframes background-wipe {
  to {
    background-position: 200% 0%;
  }
}

.no-cards #viewer #controls,
.no-cards #viewer > main {
  display: none;
}

#viewer > main {
  flex: 1;
  overflow: auto;
}

#viewer > main > header {
  display: flex;
  padding: 0 10px;
}

#viewer > main > header > a {
  display: block;
  flex: 1;
  min-width: 100px;
  padding: 10px;
  line-height: 50px;
  overflow: hidden;
  text-wrap: nowrap;
  white-space: nowrap;
  text-overflow: ellipsis;
  text-decoration: none;
  font-size: 24px;
  font-weight: bold;
  color: #000;
}

#directory-icon {
  display: none;
  padding-right: 10px;
  color: #a9c;
}

#viewer > main > header > label {
  font-size: 16px;
  line-height: 50px;
  padding: 13px 0 0 0;
  color: #666;
  min-width: 0;
}

#direction-control {
  display: inline-flex;
  margin: 21px 8px 17px 8px;
  font-size: 14px;
}

#direction-control > button {
  flex: 1;
  box-sizing: content-box;
  padding: 0.333lh 0.666lh;
  font-size: 1em;
  background: #dce;
  border-radius: 0;
  border-right: 1px solid #999;
  margin: 0 0 2px 0;
  box-shadow: 2px 2px 5px #999;
  z-index: 2;
}

#direction-control > button:first-child {
  border-radius: 0.333lh 0 0 0.333lh;
}

#direction-control > button:last-child {
  border-radius: 0 0.333lh 0.333lh 0;
  border-right: none;
}

#direction-control > button:hover {
  background: #cbd;
}

#direction-control > button.active,
#direction-control > button.active:hover {
  background: #a9c;
  color: #fff;
  box-shadow: inset 1px 1px 2px #999;
  z-index: 1;
  margin: 2px 0 0 0;
}

#controls {
  height: 65px;
  border-top: 2px solid #ccc;
  background: #f9f9f9;
  text-align: center;
}

#controls button {
  display: inline-block;
}

button#next-button {
  width: 150px;
  background: #66a;
  color: #fff;
}

button#next-button:hover {
  background: #99c;
}

#cards {
  clear: both;
}

#cards > div {
  display: none;
}

#cards > div.question,
#cards > div.answer,
#cards > div#finished {
  display: block;
  position: relative;
  margin: 0 auto;
  min-height: calc(100dvh - 70px - 67px - 2.5rlh);
  max-width: 600px;
  text-align: center;

  /* Flash card to make it clear that it’s new. */
  opacity: 1;
  transition: opacity 0.3s;
  @starting-style {
    opacity: 0;
  }
}

#cards > div#finished {
  display: none;
  line-height: 400px;
  font-size: 24px;
}

#cards > div video,
#cards > div img {
  display: block;
  max-height: 300px;
  max-width: 100%;
  margin: 0 auto;
}

#cards > div > .more {
  padding: 0 25px;
  background: #eee;
  border: 1px solid #ccc;
  border-top: none;
  overflow: hidden; /* Contain margins */
  min-height: 1em; /* If empty, we need to maintain margin for answer */
}

#cards > div.question > .more {
  display: none;
}

.sides {
  display: flex;
  flex-direction: column;
  border: 1px solid #ccc;
  background: #eee;
}

#cards > div.media-first > .sides {
  flex-direction: column-reverse;
}

#cards > div.answer > .sides {
  border-bottom: none;
}

.sides > h3 {
  margin: 0;
}

.sides > .media {
  /* Don’t display scroll bars on page if this hangs off the end when hidden: */
  overflow: hidden;
  padding: 20px 0;
}

#cards > div.text-first > .sides > h3,
#cards > div.media-first > .sides > .media {
  background: #fff;
}

/* Make question area bigger for text questions */
#cards > div.text-first.question > .sides > h3 {
  padding: 200px 25px;
}

#cards > div.text-first.question > .sides > .media {
  height: 0;
  padding: 0;
  visibility: hidden;
  transition: height 0.1s;
  transition: padding 0.1s;
}

#cards > div.text-first.answer > .sides > h3 {
  padding: 25px;
  transition: padding 0.1s;
}

#cards > div.text-first.answer > .sides > .media {
  padding-bottom: 0;
  transition: padding 0.1s;
}

#cards > div.media-first.question > .sides > h3 {
  padding: 0;
  height: 0;
  visibility: hidden;
}

#cards > div.media-first.answer > .sides > h3 {
  padding: 25px;
  padding-bottom: calc(25px - 1em);
  transition: height 0.1s;
  transition: padding 0.1s;
}

#status {
  text-align: center;
  margin: 1rlh 0 0 0;
  color: #666;
}

@media (max-width: 850px) {
  #directory {
    display: none;
  }

  #directory-icon {
    display: inline-block;
  }

  .no-deck #directory {
    display: block;
    width: 100%;
    max-width: 100%;
    border-right: none;
  }
}

@media (max-width: 600px) {
  #viewer > main > header {
    padding: 0;
  }

  #viewer > main > header > label {
    display: none;
  }

  #cards > div.question,
  #cards > div.answer,
  #cards > div#finished {
    width: 100%;
  }

  .sides,
  #cards > div > .more {
    border: none;
  }

  #cards > div.text-first.question > .sides > .media,
  #cards > div.text-first.answer > .sides > .media,
  #cards > div.media-first.question > .sides > .media,
  #cards > div.media-first.answer > .sides > .media {
    padding: 0;
  }
  #cards > div.text-first.answer > .sides > .media {
    padding-top: 25px;
  }
}
