:root {
  --text-main: #f4f7ff;
  --text-dim: rgba(229, 236, 255, 0.75);
  --magenta: #ba47ff;
  --cyan-strong: #00a7ff;
  --flow-font-family: "Roboto", sans-serif;
  --flow-primary-bg: linear-gradient(135deg, #2764ff 0%, #675bff 58%, #9165ff 100%);
  --flow-primary-shadow: 0 18px 40px rgba(39, 100, 255, 0.26);
  --flow-primary-focus: 3px solid rgba(70, 113, 255, 0.3);
  --flow-secondary-bg: rgba(255, 255, 255, 0.06);
  --flow-secondary-bg-hover: rgba(255, 255, 255, 0.12);
  --flow-secondary-border: rgba(255, 255, 255, 0.16);
  --flow-secondary-border-hover: rgba(255, 255, 255, 0.3);
  --flow-button-color: var(--text-main);
  --flow-button-font-size: 0.95rem;
  --flow-button-font-weight: 800;
  --flow-button-letter-spacing: 0.01em;
  --flow-button-min-height: 48px;
  --flow-button-radius: 999px;
  --flow-button-padding: 0 24px;
  --flow-button-transition: background 0.2s ease, border-color 0.2s ease, opacity 0.2s ease, transform 0.2s ease;
}

.flow-modal[hidden] {
  display: none;
}

.flow-modal {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: center;
  padding: 24px;
}

.flow-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(6, 10, 28, 0.7);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}

.flow-panel {
  position: relative;
  z-index: 1;
  width: min(520px, 100%);
  border-radius: 28px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: linear-gradient(180deg, rgba(12, 18, 52, 0.96), rgba(17, 9, 45, 0.96));
  box-shadow: 0 24px 80px rgba(2, 6, 22, 0.45);
  font-family: var(--flow-font-family);
  padding: 48px 24px;
  color: var(--text-main);
}

#legal-modal .flow-panel {
  width: min(800px, 100%);
}

.flow-back,
.flow-close {
  appearance: none;
  position: absolute;
  top: 16px;
  width: 42px;
  height: 42px;
  border: 0;
  border-radius: 999px;
  cursor: pointer;
  opacity: 0.82;
  transition: opacity 0.2s ease, background-color 0.2s ease;
}

.flow-back {
  left: 16px;
  background: transparent url("./images/Icon_back.svg") center / 28px 28px no-repeat;
}

.flow-close {
  right: 16px;
  background: transparent url("./images/Icon_close.svg") center / 28px 28px no-repeat;
}

.flow-back:hover,
.flow-back:focus-visible,
.flow-close:hover,
.flow-close:focus-visible {
  background-color: rgba(255, 255, 255, 0.1);
  opacity: 1;
}

.flow-close:disabled {
  opacity: 0.3;
  cursor: not-allowed;
  pointer-events: none;
}

.flow-header {
  display: grid;
  gap: 10px;
}

#verification-modal .flow-header,
#verification-modal .flow-divider,
#verification-modal .flow-progress,
#verification-modal .flow-consent-notice {
  width: min(100%, 400px);
  margin-right: auto;
  margin-left: auto;
}

.flow-header h2 {
  margin: 0;
  font-size: clamp(1.8rem, 4vw, 2.3rem);
  line-height: 1.06;
}

.flow-header p {
  margin: 0;
  color: var(--text-dim);
  line-height: 1.6;
}

.flow-field {
  display: grid;
  gap: 8px;
  width: min(100%, 400px);
  margin: 18px auto 0;
}

.flow-field span {
  font-size: 0.9rem;
  color: rgba(232, 238, 255, 0.92);
}

.flow-field input {
  width: 100%;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 16px;
  padding: 14px 16px;
  background: rgba(5, 11, 32, 0.88);
  color: var(--text-main);
  font: inherit;
}

.flow-field input:focus {
  outline: 2px solid rgba(0, 167, 255, 0.5);
  outline-offset: 2px;
}

#verification-code-input {
  width: 100%;
  min-height: 80px;
  margin: 0 auto;
  padding: 18px 20px;
  font-size: 2.2rem;
  font-weight: 700;
  line-height: 1;
  letter-spacing: 0.28em;
  text-align: center;
}

.flow-google-row {
  display: grid;
  gap: 16px;
  margin-top: 20px;
}

.flow-google-row[hidden] {
  display: none;
}

.flow-google-button {
  position: relative;
  display: block;
  width: min(100%, 400px);
  height: 48px;
  margin: 0 auto;
}

.flow-google-native {
  position: absolute !important;
  inset: 0 !important;
  z-index: 2;
  width: 100% !important;
  height: 100% !important;
  opacity: 0;
}

.flow-google-native > div,
.flow-google-native iframe {
  width: 100% !important;
  height: 100% !important;
}

.flow-google-native iframe {
  height: 48px !important;
}

.flow-google-block {
  display: none;
  position: absolute;
  inset: 0;
  z-index: 3;
  cursor: not-allowed;
  border-radius: var(--flow-button-radius);
}

.flow-google-button.is-blocked .flow-google-block {
  display: block;
}

.flow-google-custom {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: 24px 1fr 24px;
  align-items: center;
  gap: 12px;
  width: 100%;
  height: 48px;
  border: 1px solid var(--flow-secondary-border);
  border-radius: var(--flow-button-radius);
  background: var(--flow-secondary-bg);
  color: var(--flow-button-color);
  font-family: var(--flow-font-family);
  font-size: var(--flow-button-font-size);
  font-weight: var(--flow-button-font-weight);
  letter-spacing: var(--flow-button-letter-spacing);
  padding: 0 20px;
  pointer-events: none;
  transition: var(--flow-button-transition);
}

.flow-google-button:hover .flow-google-custom,
.flow-google-button:focus-within .flow-google-custom {
  background: var(--flow-secondary-bg-hover);
  border-color: var(--flow-secondary-border-hover);
  transform: translateY(-1px);
}

.flow-google-logo {
  width: 20px;
  height: 20px;
}

.flow-google-custom span {
  text-align: center;
}

.flow-divider {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 14px;
  align-items: center;
  color: rgba(232, 238, 255, 0.6);
  font-size: 0.86rem;
  line-height: 1;
}

.flow-divider::before,
.flow-divider::after {
  content: "";
  height: 1px;
  background: rgba(255, 255, 255, 0.14);
}

.flow-status {
  min-height: 1.4em;
  margin: 16px 0 0;
  color: rgba(229, 236, 255, 0.86);
}

.flow-status.is-error {
  color: #ffb4c4;
}

.flow-status.is-success {
  color: #8fffd8;
}

.flow-progress {
  display: grid;
  gap: 10px;
  margin-top: 16px;
}

.flow-progress-track {
  overflow: hidden;
  height: 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.flow-progress-bar {
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--magenta), var(--cyan-strong));
  box-shadow: 0 0 18px rgba(181, 52, 255, 0.24), 0 0 24px rgba(36, 185, 255, 0.18);
  transition: width 0.2s ease;
}

.flow-progress-meta {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 0.88rem;
  color: rgba(229, 236, 255, 0.78);
}

#signup-complete-panel[hidden],
#auth-preparing-panel[hidden],
#avatar-limit-panel[hidden],
#guest-library-limit-panel[hidden],
#discard-draft-panel[hidden],
#verification-workflow[hidden],
#verification-progress[hidden],
.flow-actions[hidden],
#verification-step-email[hidden],
#verification-step-code[hidden],
#verification-resend-row[hidden] {
  display: none;
}

.flow-loading-panel {
  display: flex;
  justify-content: center;
  margin-top: 24px;
  min-height: 32px;
}

.flow-loading-spinner {
  width: 24px;
  height: 24px;
  border: 4px solid rgba(255, 255, 255, 0.22);
  border-top-color: rgba(255, 255, 255, 0.95);
  border-radius: 50%;
  box-shadow: 0 0 10px rgba(180, 208, 255, 0.28);
  animation: flow-loading-spin 0.85s linear infinite;
}

@keyframes flow-loading-spin {
  to {
    transform: rotate(360deg);
  }
}

.flow-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 12px;
  margin-top: 22px;
}

.flow-inline-action {
  display: flex;
  justify-content: center;
  margin-top: 14px;
}

.flow-button-wide {
  width: min(100%, 400px);
  min-width: 0;
}

.flow-primary,
.flow-secondary {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: var(--flow-button-min-height);
  padding: var(--flow-button-padding);
  border-radius: var(--flow-button-radius);
  color: var(--flow-button-color);
  font-family: var(--flow-font-family);
  font-size: var(--flow-button-font-size);
  font-weight: var(--flow-button-font-weight);
  letter-spacing: var(--flow-button-letter-spacing);
  text-align: center;
  cursor: pointer;
  transition: var(--flow-button-transition);
}

.flow-primary {
  border: 0;
  background: var(--flow-primary-bg);
  box-shadow: var(--flow-primary-shadow);
}

.flow-primary:hover,
.flow-primary:focus-visible {
  filter: brightness(1.06);
  outline: var(--flow-primary-focus);
  outline-offset: 4px;
}

.flow-secondary {
  border: 1px solid var(--flow-secondary-border);
  background: var(--flow-secondary-bg);
  box-shadow: none;
  text-decoration: none;
}

.flow-secondary:hover,
.flow-secondary:focus-visible {
  background: var(--flow-secondary-bg-hover);
  border-color: var(--flow-secondary-border-hover);
  transform: translateY(-1px);
  outline: none;
}

.flow-primary:disabled,
.flow-secondary:disabled {
  cursor: not-allowed;
  opacity: 0.54;
  filter: grayscale(1);
  box-shadow: none;
  transform: none;
}

.flow-consent-notice {
  margin: 12px 0 0;
  color: rgba(229, 236, 255, 0.74);
  font-size: 0.78rem;
  line-height: 1.5;
  text-align: center;
}

.flow-link-button {
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  text-decoration: underline;
  text-underline-offset: 0.18em;
  cursor: pointer;
}

.flow-legal-frame {
  margin-top: 24px;
  max-height: min(540px, calc(100vh - 240px));
  min-height: 0;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 24px;
  background: rgba(7, 12, 34, 0.62);
  overflow: hidden;
}

.flow-legal-panel-copy {
  display: grid;
  gap: 22px;
  max-height: inherit;
  min-height: 0;
  overflow: auto;
  padding: 22px 34px 22px 24px;
}

.flow-legal-section h3 {
  margin: 0 0 14px;
  font-size: 1.05rem;
}

.flow-legal-section p {
  margin: 0 0 14px;
  color: rgba(229, 236, 255, 0.8);
  line-height: 1.6;
}

.flow-legal-list {
  margin: 0 0 14px 1.2rem;
  padding: 0;
  color: rgba(229, 236, 255, 0.8);
  line-height: 1.6;
}

.flow-legal-list li + li {
  margin-top: 4px;
}

.flow-legal-link {
  color: #d8e8ff;
  text-decoration: underline;
  text-underline-offset: 0.18em;
}

.draft-viewer-hint-panel {
  position: absolute;
  top: 70px;
  right: 18px;
  z-index: 12;
  width: max-content;
  max-width: calc(100% - 36px);
  padding: 16px 18px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 8px;
  background: rgba(8, 12, 34, 0.88);
  color: rgba(244, 247, 255, 0.9);
  box-shadow: 0 18px 42px rgba(0, 0, 0, 0.28);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  font-family: var(--flow-font-family);
  font-size: 0.9rem;
  font-weight: 400;
  line-height: 1.45;
  text-align: left;
}

.draft-viewer-hint-panel p {
  margin: 0;
  white-space: nowrap;
}

.draft-viewer-hint-panel p + p {
  margin-top: 10px;
}

.draft-viewer-signin-link {
  appearance: none;
  display: inline;
  padding: 0;
  border: 0;
  background: transparent;
  color: #8fffd8;
  cursor: pointer;
  font: inherit;
  font-weight: 800;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.draft-viewer-signin-link:hover,
.draft-viewer-signin-link:focus-visible {
  color: #bffff0;
  outline: none;
}

@media (max-width: 960px) {
  .flow-modal {
    padding: 16px;
  }

  .flow-panel {
    padding: 22px 18px;
    border-radius: 22px;
  }

  .flow-legal-frame {
    max-height: calc(100vh - 220px);
  }

  .flow-progress-meta {
    flex-direction: column;
    gap: 6px;
  }

  .draft-viewer-hint-panel {
    top: calc(74px + env(safe-area-inset-top, 0px));
    right: 12px;
    max-width: calc(100vw - 24px);
  }

  .draft-viewer-hint-panel p {
    white-space: normal;
  }
}