/*
 * The page that joins an online game by its code, code.html, on top of style.css: one field
 * drawn as six tiles, the paste button and « Rejoindre ». From the screen 19 of docs/design/.
 */

/* The header: the way back home, and what the page does. */
.code-header {
  width: 100%;
  max-width: 520px;
  margin: 0 auto;
  padding: 16px 20px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.back-button {
  width: 44px;
  padding: 0;
}

.code-header-title {
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.code-screen {
  flex: 1;
  width: 100%;
  max-width: 520px;
  margin: 0 auto;
  padding: 32px 24px 28px;
  display: flex;
  flex-direction: column;
}

.code-form {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.code-intro {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.code-title {
  margin: 0;
  font-family: var(--font-display);
  font-size: 30px;
  font-weight: 700;
  line-height: 1.1;
  letter-spacing: -0.02em;
}

.code-lead {
  font-size: 15px;
  line-height: 1.5;
  color: var(--color-text-secondary);
}

/*
 * The field lies over the tiles, which show what it holds: it keeps the keyboard, the paste and
 * the screen readers of a real field, and the tiles draw its text, its caret and its focus.
 */
.code-entry {
  position: relative;
  margin-top: 28px;
  align-self: flex-start;
}

.code-input {
  position: absolute;
  inset: 0;
  z-index: 1;
  width: 100%;
  padding: 0;
  border: 0;
  background: transparent;
  color: transparent;
  caret-color: transparent;
  font: inherit;
  font-size: 16px;
  cursor: text;
}

.code-input:focus-visible {
  outline: none;
}

.code-input::selection {
  background: transparent;
}

.code-tiles {
  display: flex;
  gap: 8px;
}

.code-tile {
  width: 48px;
  height: 60px;
  box-sizing: border-box;
  border-radius: var(--radius-md);
  border: 1px solid var(--color-border);
  background: var(--color-surface-inset);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-mono);
  font-size: 26px;
  font-weight: 700;
}

.code-tile.is-filled {
  border-color: var(--color-border-strong);
  background: var(--color-surface);
}

/* The tile that the next character fills, while the field has the focus. */
.code-entry:focus-within .code-tile.is-current {
  border: 2px solid var(--color-text);
  background: var(--color-surface-raised);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--color-text) 10%, transparent);
}

.code-entry:focus-within .code-tile.has-caret::after {
  content: '';
  width: 2px;
  height: 28px;
  background: var(--color-text);
  animation: code-caret 1s steps(1) infinite;
}

@keyframes code-caret {
  50% {
    opacity: 0;
  }
}

.paste-button {
  margin-top: 16px;
  align-self: flex-start;
  min-height: 44px;
  padding: 0;
  border: 0;
  background: none;
  color: var(--color-text-secondary);
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}

.paste-button:hover {
  color: var(--color-text);
}

.paste-button[hidden] {
  display: none;
}

.code-message {
  font-size: 14px;
  color: var(--color-warning);
}

.code-message:empty {
  display: none;
}

.code-actions {
  margin-top: auto;
  padding-top: 32px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.code-submit {
  min-height: 54px;
  border-radius: var(--radius-lg);
}

.code-submit[aria-disabled="true"] {
  background: var(--color-border-strong);
  color: var(--color-text-muted);
  cursor: not-allowed;
  filter: none;
}

.code-hint {
  font-size: 13px;
  color: var(--color-text-muted);
  text-align: center;
}

@media (prefers-reduced-motion: reduce) {
  .code-entry:focus-within .code-tile.has-caret::after {
    animation: none;
  }
}

/* Medium and wide screens: the form in the middle of the screen, its button under the field. */
@media (min-width: 600px) {
  .code-header {
    padding: 24px 24px 16px;
  }

  .code-screen {
    justify-content: center;
    padding-bottom: 96px;
  }

  .code-form {
    flex: 0 1 auto;
  }

  .code-title {
    font-size: 36px;
  }

  .code-tile {
    width: 56px;
    height: 68px;
    font-size: 30px;
  }

  .code-actions {
    margin-top: 0;
    padding-top: 40px;
  }
}
